Update of 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service
In directory 
james.mmbase.org:/tmp/cvs-serv9896/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service

Modified Files:
        ResolveDTD.java OODocUploadUtil.java OutFinishHtml.java 
        transform.xsl OdtFileTranster.java Parserfactory.java 
        ChangeHtml.java ChangeContentXml.java 
Log Message:
CMSC-471 modify build script.function finised.


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service
See also: http://www.mmbase.org/jira/browse/CMSC-471


Index: ResolveDTD.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/ResolveDTD.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ResolveDTD.java     21 Jan 2008 07:35:30 -0000      1.1
+++ ResolveDTD.java     28 Jan 2008 09:11:25 -0000      1.2
@@ -7,14 +7,12 @@
 public class ResolveDTD implements EntityResolver {
     public InputSource resolveEntity (String publicId, String systemId)
     {
-        if (systemId.endsWith(".dtd"))
-        {
+        if (systemId.endsWith(".dtd")){
             StringReader stringInput =
                 new StringReader(" ");
             return new InputSource(stringInput);
         }
-        else
-        {
+        else{
             return null;// default behavior
         }
     }


Index: OODocUploadUtil.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/OODocUploadUtil.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- OODocUploadUtil.java        22 Jan 2008 10:26:11 -0000      1.2
+++ OODocUploadUtil.java        28 Jan 2008 09:11:25 -0000      1.3
@@ -2,7 +2,6 @@
 
 import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileFilter;
 import java.io.FileOutputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
@@ -43,9 +42,9 @@
     // set max size allowed
     private static final int MAXSIZE = 16 * 1024 * 1024;
 
-    private static final String OPENOFFICE_ODT_MIME_TYPES[] = new String[]{
+       private static final String OPENOFFICE_ODT_MIME_TYPES[] = new String[] {
             "application/vnd.oasis.opendocument.text",
-            "application/x-vnd.oasis.opendocument.text"};
+                       "application/x-vnd.oasis.opendocument.text" };
 
     private static final int INITIAL_CAPACITY = 10;
 
@@ -53,14 +52,9 @@
 
     private String channel;
 
-    private String channelbak;
-
     private static final String CHANNEL_KEY = "channel";
 
-    private static final String CHANNELBAK_KEY = "channelbak";
-
     public static final String NODE_NUMBER = "node.number";
-    //private static OODocUploadUtil docUploadUtil;
 
     private OODocUploadUtil() {
     }
@@ -77,9 +71,9 @@
         return channel;
     }
 
-    public String getChannelbak() {
-        return channelbak;
-    }
+       // public String getChannelbak() {
+       // return channelbak;
+       // }
 
     /**
      * openoffice odt doc and put it in cache
@@ -99,7 +93,7 @@
         if (StringUtils.isBlank(realPath))
             realPath = dir;
 
-        realPath += File.separator + getChannelId();
+               realPath += File.separator + channel;
                if (realPath.endsWith("null"))
                        realPath = realPath.substring(0, realPath.length() - 5);
 
@@ -116,7 +110,6 @@
                 log.debug("contentType: " + binary.getContentType());
             }
      
-        
                        if (!isOdtFile(binary))
                                return false;
             persistOdtDoc(binary, realPath);
@@ -124,13 +117,10 @@
        return true;
     }
 
-    private String getChannelId() {
-        return StringUtils.isEmpty(channel) || "null".equals(channel) ? 
channelbak : channel;
-    }
-
-//     private static void addRelToWorkFlow(WorkflowService service, Node 
node) {
-//             service.create(node, null);
-//     }
+       // private static void addRelToWorkFlow(WorkflowService service, Node 
node)
+       // {
+       // service.create(node, null);
+       // }
 
     private static synchronized void persistOdtDoc(
             UploadUtil.BinaryData binary, String dir) throws IOException,
@@ -143,7 +133,8 @@
         File file = new File(directory.getCanonicalPath() + File.separator
                 + binary.getOriginalFileName());
         if (!file.createNewFile()) {
-            log.warn("   create empty file error while openoffice odt 
document!");
+                       log
+                                       .warn("   create empty file error while 
openoffice odt document!");
         }
         FileOutputStream out = new FileOutputStream(file);
         copyStream(binary.getInputStream(), out);
@@ -177,7 +168,7 @@
     }
 
     private String[] getOdtFileNames(String dir) {
-        String[] files = new String[]{};
+               String[] files = new String[] {};
         File directory = new File(dir);
         if (directory.exists() && directory.isDirectory()) {
             files = directory.list(new OdtFilter());
@@ -189,7 +180,8 @@
     /**
      * get a List object of OdtDocument
      *
-     * @param dir a directory ,file's real path
+        * @param dir
+        *            a directory ,file's real path
      * @return
      */
     public List<OdtDocument> getOdtDocuments(String dir) {
@@ -238,8 +230,6 @@
                 if (CHANNEL_KEY.equals(item.getFieldName())) {
                     channel = item.getString();
 
-                } else if (CHANNELBAK_KEY.equals(item.getFieldName())) {
-                    channelbak = item.getString();
                 }
 
             } else if (!item.isFormField()) {
@@ -277,20 +267,18 @@
             }
         }
     }
-    public class OdtFilter  implements FilenameFilter
-    {
 
+       public class OdtFilter implements FilenameFilter {
 
-
-      public boolean isFile(String file)
-      {
-        if (file.toLowerCase().endsWith(".odt")){
+               public boolean isFile(String file) {
+                       if (file.toLowerCase().endsWith(".odt")) {
           return true;
-        }else{
+                       } else {
           return false;
         }
       }
-      public boolean accept(File dir,String fname){
+
+               public boolean accept(File dir, String fname) {
         return (isFile(fname));
 
       }


Index: OutFinishHtml.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/OutFinishHtml.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- OutFinishHtml.java  21 Jan 2008 07:35:30 -0000      1.1
+++ OutFinishHtml.java  28 Jan 2008 09:11:25 -0000      1.2
@@ -33,7 +33,6 @@
     public void getFirstHtml() throws IOException, SAXException, 
TransformerException {
         FileOutputStream htmlStream = new 
FileOutputStream(this.middleFileLocation);
 
-
         StreamSource streamSource = new 
StreamSource(this.getClass().getResourceAsStream("transform.xsl"));
         TransformerFactory tFactory = TransformerFactory.newInstance();
         Transformer transformer = tFactory.newTransformer(streamSource);


Index: transform.xsl
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/transform.xsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- transform.xsl       21 Jan 2008 07:35:30 -0000      1.1
+++ transform.xsl       28 Jan 2008 09:11:25 -0000      1.2
@@ -48,7 +48,6 @@
             <xsl:attribute name="class">
       <xsl:value-of select="translate(@text:style-name,'.','_')"/>
     </xsl:attribute>
-            <a name="{generate-id()}"/>
             <xsl:apply-templates/>
         </xsl:element>
     </xsl:template>
@@ -93,19 +92,15 @@
         </a>
     </xsl:template>
     <xsl:template match="text:bookmark-start|text:bookmark">
-        <a name="[EMAIL PROTECTED]:name}">
             <span style="font-size: 0px">
                 <xsl:text> </xsl:text>
             </span>
-        </a>
     </xsl:template>
     <xsl:template match="text:note">
         <xsl:variable name="footnote-id" select="text:note-citation"/>
-        <a href="#footnote-{$footnote-id}">
             <sup>
                 <xsl:value-of select="$footnote-id"/>
             </sup>
-        </a>
     </xsl:template>
     <xsl:template match="text:note-body"/>
     <xsl:template name="add-footnote-bodies">
@@ -114,10 +109,9 @@
     <xsl:template match="text:note" mode="add-footnote-bodies">
         <xsl:variable name="footnote-id" select="text:note-citation"/>
         <p>
-            <a name="footnote-{$footnote-id}">
                 <sup>
                     <xsl:value-of select="$footnote-id"/>
-                </sup>:</a>
+            </sup>:
         </p>
         <xsl:apply-templates select="text:note-body/*"/>
     </xsl:template>
@@ -413,12 +407,12 @@
         <!-- emit appropriate list type -->
         <xsl:choose>
             <xsl:when test="local-name($node)='list-level-style-number'">
-                <ol class="{concat($listClass,'_',$level)}">
+                <ol class="{$listClass}">
                     <xsl:apply-templates/>
                 </ol>
             </xsl:when>
             <xsl:otherwise>
-                <ul class="{concat($listClass,'_',$level)}">
+                <ul class="{$listClass}">
                     <xsl:apply-templates/>
                 </ul>
             </xsl:otherwise>
@@ -545,9 +539,7 @@
         <xsl:otherwise>1</xsl:otherwise>
       </xsl:choose>
     </xsl:attribute>
-            <a href="#{generate-id()}">
                 <xsl:value-of select="."/>
-            </a>
         </xsl:element>
     </xsl:template>
 </xsl:stylesheet>
\ No newline at end of file


Index: OdtFileTranster.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/OdtFileTranster.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- OdtFileTranster.java        22 Jan 2008 10:26:11 -0000      1.2
+++ OdtFileTranster.java        28 Jan 2008 09:11:25 -0000      1.3
@@ -26,16 +26,13 @@
 
         String middelFileLocation = WORKINGFOLDER + File.separator + 
file.getName() + ".xml";
 
-
         ChangeContentXml ccx = new ChangeContentXml();
         ChangeHtml ch = new ChangeHtml();
         OutFinishHtml ofh = new OutFinishHtml(file.getPath(), 
middelFileLocation);
 
-
         HashMap styleMap = 
ccx.getStyleMap(ccx.getContentStyle(file.getPath()));
         StringBuffer buffer = new StringBuffer();
 
-
         try {
             File workingfolder = new File(WORKINGFOLDER);
             if (!workingfolder.exists()) {
@@ -45,11 +42,14 @@
             ofh.getFirstHtml();
             Map rowAndSavedImageMap = saveAllImageToCMSC(new 
FileInputStream(file), requestContext);
             ch.change(middelFileLocation, styleMap, rowAndSavedImageMap);
+            FileInputStream fileInputStream = new 
FileInputStream(middelFileLocation + ".html");
+            InputStreamReader inputStramReader = new 
InputStreamReader(fileInputStream, "utf-8");
 
-            BufferedReader in = new BufferedReader(new 
FileReader(middelFileLocation + ".html"));
+            BufferedReader in = new BufferedReader(inputStramReader);
             String str;
             while ((str = in.readLine()) != null) {
-                buffer.append(str);
+               String newStr = str.replaceAll("<\\?xml version=\"1.0\" 
encoding=\"UTF-8\"\\?>", "");
+               buffer.append(newStr);                    
             }
             in.close();
         } catch (IOException e) {
@@ -86,7 +86,6 @@
         }
 
         zis.close();
-
         return rawImgeToSavedImgeMaping;
     }
 


Index: Parserfactory.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/Parserfactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Parserfactory.java  21 Jan 2008 07:35:30 -0000      1.1
+++ Parserfactory.java  28 Jan 2008 09:11:25 -0000      1.2
@@ -2,6 +2,7 @@
 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 
 import org.w3c.dom.Attr;
@@ -27,7 +28,7 @@
         return NewNode;
     }
 
-    public void process(Document doc, Node node, HashMap hs) {
+    public void process(Document doc, Node node, HashMap hs,Map mapping) {
         HashMap styleMap = new HashMap();
         String nodeName = node.getNodeName();
         if (nodeName.equals("p")) {
@@ -52,8 +53,7 @@
                 if (style.equals("ol")) {
                     Element ol = doc.createElement("ol");
                     NodeList childs = node.getChildNodes();
-                    for (int i = 0; i < childs.getLength(); i++)
-                    {
+                    for (int i = 0; i < childs.getLength(); i++){
                         ol.appendChild(childs.item(i).cloneNode(true));
                     }
                     node.getParentNode().replaceChild(ol, node);
@@ -74,24 +74,30 @@
             table.setAttributeNode(cellspacing);
             table.setAttributeNode(cellpadding);
             NodeList childs = node.getChildNodes();
-            for (int i = 0; i < childs.getLength(); i++) 
-            {
+            for (int i = 0; i < childs.getLength(); i++) {
                 table.appendChild(childs.item(i).cloneNode(true));
             }
             node.getParentNode().replaceChild(table, node);
         }
+        else if(nodeName.equals("img")){
+                       String oldMapping = 
node.getAttributes().getNamedItem("src").getNodeValue();
+                       String newMapping = mapping.get(oldMapping).toString();
+                       Element image = doc.createElement("img");
+                       Attr src = doc.createAttribute("src");
+                       src.setValue(newMapping);
+                       image.setAttributeNode(src);
+                       node.getParentNode().replaceChild(image, node);
+               }
     }
 
     public HashMap changePnode(Node node, HashMap hs) {
         String classStyle = null;
         HashMap styleHs = new HashMap();
-        if (node.getAttributes().getNamedItem("class") != null) 
-        {
+        if (node.getAttributes().getNamedItem("class") != null) {
             classStyle = 
node.getAttributes().getNamedItem("class").getNodeValue();
         }
         String styleValue = null;
-        if (hs.get(classStyle) != null) 
-        {
+        if (hs.get(classStyle) != null) {
             styleValue = hs.get(classStyle).toString();
             styleHs = getTagFormStyle(styleValue);
         }
@@ -102,13 +108,11 @@
         HashMap styleHs = new HashMap();
         String classStyle = "";
         Node styleNode = node.getAttributes().getNamedItem("class");
-        if (null != styleNode) 
-        {
+        if (null != styleNode) {
             classStyle = styleNode.getNodeValue();
         }
         String styleValue = null;
-        if (hs.get(classStyle) != null) 
-        {
+        if (hs.get(classStyle) != null) {
             styleValue = hs.get(classStyle).toString();
             styleHs = getTagFormStyle(styleValue);
         }
@@ -116,8 +120,7 @@
     }
     public HashMap getTagFormStyle(String style) {
         HashMap tag = new HashMap();
-        if (style != null) 
-        {
+        if (style != null) {
             String bold = String.valueOf(style.charAt(0));
             String italics = String.valueOf(style.charAt(1));
             String underline = String.valueOf(style.charAt(2));


Index: ChangeHtml.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/ChangeHtml.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ChangeHtml.java     21 Jan 2008 07:35:30 -0000      1.1
+++ ChangeHtml.java     28 Jan 2008 09:11:25 -0000      1.2
@@ -44,15 +44,14 @@
                          for(int i=0;i<books.getLength();i++)
                          {
                                  Node childnode = books.item(i);
-                                 getChildNode(doc,childnode,hs);
+                                 getChildNode(doc,childnode,hs,mapping);
                          }
                                FileOutputStream fos = new 
FileOutputStream(xmlUrl+".html");
                            OutputStreamWriter outwriter = new 
OutputStreamWriter(fos);
                            Source sourcea = new DOMSource(doc);                
            
                            Result result = new StreamResult(outwriter);
-                           Transformer xformer = 
TransformerFactory.newInstance()
-                           .newTransformer();
-                           xformer.setOutputProperty(OutputKeys.ENCODING, 
"gb2312");
+                           Transformer xformer = 
TransformerFactory.newInstance().newTransformer();
+                           xformer.setOutputProperty(OutputKeys.ENCODING, 
"UTF-8");
                            xformer.transform(sourcea, result);
                            outwriter.close();
                            fos.close();           
@@ -67,16 +66,16 @@
                        e.printStackTrace();
                }               
        }
-       public void getChildNode(Document doc,Node node,HashMap hs)
+       public void getChildNode(Document doc,Node node,HashMap hs,Map mapping)
        {
-               pf.process(doc,node, hs);
+               pf.process(doc,node, hs,mapping);
                if(node.hasChildNodes())
                {
                        NodeList childNodes = node.getChildNodes();
                         for(int i=0;i<childNodes.getLength();i++)
                          {
                                  Node childnode = childNodes.item(i);
-                                 getChildNode(doc,childnode,hs);
+                                 getChildNode(doc,childnode,hs,mapping);
                          }
                }
        }


Index: ChangeContentXml.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer_Modules/openofficeintegration/src/java/com/finalist/cmsc/openoffice/service/ChangeContentXml.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ChangeContentXml.java       21 Jan 2008 07:35:30 -0000      1.1
+++ ChangeContentXml.java       28 Jan 2008 09:11:25 -0000      1.2
@@ -111,8 +111,9 @@
         String Property = null;
         InputStream in = new BufferedInputStream(new 
FileInputStream(filePath));
         props.load(in);
-        if (props.getProperty(key) != null)
+        if (props.getProperty(key) != null){
             Property = props.getProperty(key);
+        }
         return Property;
     }
 
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to