Package org.openoffice.xmerge

Examples of org.openoffice.xmerge.ConvertData


        // create a PalmDB object and ConvertData object.
        //
        Record records[] = encoder.getRecords();

        ConvertData cd = new ConvertData();
        PalmDocument palmDoc = new PalmDocument(docName,
            PdbUtil.intID("WrdS"), PdbUtil.intID("BDOC"), 0,
            PalmDB.PDB_HEADER_ATTR_BACKUP, records);
        cd.addDocument(palmDoc);
        return cd;
    }
View Full Code Here


          }
    }

        // Get the number of sheets in the workbook
        // This will equal the number of PDBs we need
        ConvertData cd = new ConvertData();
    Workbook wb = ((PocketExcelEncoder) encoder).getWorkbook();
    cd.addDocument(wb);

        return cd;
    }
View Full Code Here

            System.out.println("\nFile <" + processFile + "> is not in <" +
                fromMime + "> format");
            throw new IllegalArgumentException();
        }

        ConvertData dataOut = null;

        try {
            dataOut = myConvert.convert();
        } catch (Exception convertExcept) {
            System.out.println("\nThere was an error in the conversion");
            convertExcept.printStackTrace();
        }

        if (dataOut != null ) {

            if (mergeFile == null) {
                Enumeration docEnum = dataOut.getDocumentEnumeration();
                while (docEnum.hasMoreElements()) {
                    Document docOut      = (Document)docEnum.nextElement();
                    String fileName      = docOut.getFileName();
                    try {
                        FileOutputStream fos = new FileOutputStream(fileName);
                        docOut.write(fos);
                        fos.flush();
                        fos.close();
                    } catch (Exception writeExcept) {
                        System.out.println("\nThere was an writing out file <" +
                            fileName + ">");
                        writeExcept.printStackTrace();
                    }
                }
            } else {
                try {
                    FileInputStream mergeIS = new FileInputStream(mergeFile);
                    Document mergeDoc = myConvert.getOfficeDocument(mergeFile, mergeIS);
                    DocumentMerger merger = myConvert.getDocumentMerger(mergeDoc);
                    Enumeration mergeDocEnum = dataOut.getDocumentEnumeration();
                    Document convertedFile = (Document)mergeDocEnum.nextElement();

                    merger.merge(convertedFile);
          mergeIS.close();
View Full Code Here

        boolean bFlat = sFileName.toLowerCase().endsWith(".xml");
        // Determine the type of document by the extension:
        boolean bCalc = sFileName.toLowerCase().endsWith(".sxc");
        boolean bImpress = sFileName.toLowerCase().endsWith(".sxi");

        ConvertData dataOut = null;

        // Create and use the converter
        // No longer uses the XMerge interface
        // Somewhat messy, should be changed if XMerge is discarded
        OfficeDocument oooDoc;
        if (bCalc) {
            oooDoc = new SxcDocument(sFileName);
        }
        else if (bImpress) {
            oooDoc = new SxiDocument(sFileName);
        }
        else {
            oooDoc = new SxwDocument(sFileName);
        }
        File f = new File(sFileName);
        // Make sure the input file actually exists before using it
        try {
            if (!f.exists()) {
                System.out.println("I'm sorry, I can't find "+sFileName);
                System.exit(0);
            }
            FileInputStream fis = new FileInputStream(f);
            oooDoc.read(fis,!bFlat);
        }
        catch (IOException e) {
               System.out.println("Oops, there was an error reading "+sFileName);
               e.printStackTrace();
        }

        try {
            if (toMime.equals(MIMETypes.LATEX)) {
                writer2latex.latex.ConverterPalette converter
                    = new writer2latex.latex.ConverterPalette((SxwDocument)oooDoc,sConfigFileName);
                converter.setOutFileName(sOutFileName);
                dataOut = converter.convert();
            }
            else if (toMime.equals(MIMETypes.BIBTEX)) {
                writer2latex.bibtex.DocumentSerializerImpl converter
                    = new writer2latex.bibtex.DocumentSerializerImpl((SxwDocument)oooDoc);
                converter.setOutFileName(sOutFileName);
                dataOut = converter.serialize();
            }
/* disabled XHTML filter part     
            else if (toMime.equals(MIMETypes.XHTML)) {
                writer2latex.xhtml.DocumentSerializerImpl converter
                    = new writer2latex.xhtml.DocumentSerializerImpl(oooDoc,
                            XhtmlDocument.XHTML10, sConfigFileName);
                converter.setOutFileName(sOutFileName);
                dataOut = converter.serialize();
            }
            else if (toMime.equals(MIMETypes.XHTML_MATHML)) {
                writer2latex.xhtml.DocumentSerializerImpl converter
                    = new writer2latex.xhtml.DocumentSerializerImpl(oooDoc,
                            XhtmlDocument.XHTML_MATHML, sConfigFileName);
                converter.setOutFileName(sOutFileName);
                dataOut = converter.serialize();
            }
            else if (toMime.equals(MIMETypes.XHTML_MATHML_XSL)) {
                writer2latex.xhtml.DocumentSerializerImpl converter
                    = new writer2latex.xhtml.DocumentSerializerImpl(oooDoc,
                            XhtmlDocument.XHTML_MATHML_XSL, sConfigFileName);
                converter.setOutFileName(sOutFileName);
                dataOut = converter.serialize();
            }
      */
        }
        catch (Exception e) {
            System.out.println("Conversion failed");
            e.printStackTrace();
        }

        // TODO: Should do some further checking on the feasability of writing
        // the directory and the files.
        File dir = new File(sOutPathName);
        if (!dir.exists()) { dir.mkdirs(); }

        Enumeration docEnum = dataOut.getDocumentEnumeration();
        while (docEnum.hasMoreElements()) {
            Document docOut      = (Document)docEnum.nextElement();
            String fileName      = sOutPathName+docOut.getFileName();
            try {
                FileOutputStream fos = new FileOutputStream(fileName);
View Full Code Here

     *
     *  @throws  ConvertException  If any conversion error occurs.
     *  @throws  IOException       If any I/O error occurs.
     */
    public ConvertData serialize() throws IOException, ConvertException {     
        ConvertData convertData = new ConvertData();           
        BibTeXDocument bibDoc = new BibTeXDocument(sOutFileName);

        // Collect all text:bibliography-mark elements from content.xml
        org.w3c.dom.Document doc = sxwDoc.getContentDOM();
        NodeList list;
        list = doc.getElementsByTagName(XMLString.TEXT_BIBLIOGRAPHY_MARK);
        int nLen = list.getLength();
        for (int i=0; i<nLen; i++) {
            String sIdentifier = Misc.getAttribute(list.item(i),XMLString.TEXT_IDENTIFIER);
            if (!bibDoc.containsKey(sIdentifier)) {
                bibDoc.put(new BibMark(list.item(i)));
            }           
        }
     
        // Return the converted data
        convertData.addDocument(bibDoc);
        return convertData;
    }
View Full Code Here

     *
     *  @throws  ConvertException  If any conversion error occurs.
     *  @throws  IOException       If any I/O error occurs.
     */
    public ConvertData serialize() throws IOException, ConvertException {     
        ConvertData cd = new ConvertData();
       
        org.w3c.dom.Document doc = sxwDoc.getContentDOM();
       
        // Load any style info before traversing the document content tree
        loadStyles();
       
        NodeList list = doc.getElementsByTagName(TAG_OFFICE_BODY);
       
        int len = list.getLength();
        if (len > 0) {
            Node node = list.item(0);
            traverseBody(node);
        }
       
        cd.addDocument(pswDoc);
       
        return cd;
    }
View Full Code Here

            traverseBody(node);
        }

        // Get the number of sheets in the workbook
        // This will equal the number of PDBs we need
        ConvertData cd = new ConvertData();
        int numSheets = encoder.getNumberOfSheets();

        for (int i = 0; i < numSheets; i++) {

            // Get records for sheet i
            Record records[] = ((MinicalcEncoder) encoder).getRecords(i);

            // Get the sheet name for sheet i
            String fullSheetName = new String(docName
                                              + "-"
                                              + encoder.getSheetName(i));

            // Create a PalmDB object
            PalmDocument palmDoc = new PalmDocument(fullSheetName,
                 MinicalcConstants.CREATOR_ID,
                 MinicalcConstants.TYPE_ID, JMCconstants.AppVersion,
                 PalmDB.PDB_HEADER_ATTR_BACKUP, records);

            cd.addDocument(palmDoc);
        }


        // OutputStream os = new FileOutputStream(docName);
View Full Code Here

        FileInputStream fis = new FileInputStream(srcFile);
        FileOutputStream fos = new FileOutputStream(dstFile);
       
        conv.addInputStream(srcFile, fis);
       
        ConvertData dataOut;
        try {
            dataOut = conv.convert();
        }
        catch (Exception e) {
            return false;
        }
       
        if (dataOut == null) {
            return false;
        }

        // Get the document and write it out.
        Document doc = (Document)dataOut.getDocumentEnumeration().nextElement();     
        if (doc == null) {
            return false;
        }
       
        doc.write(fos);
View Full Code Here

        
       }
       else
       {
           cv.addInputStream(name,(InputStream)xis,false);
           ConvertData dataOut = cv.convert();
        
           Enumeration docEnum = dataOut.getDocumentEnumeration();
        
           if (docEnum.hasMoreElements()){
             Document docOut      = (Document)docEnum.nextElement();
             String fileName      = docOut.getFileName();
             docOut.write(newxos);
            
             newxos.flush();
             newxos.close();
            
         
             int i=1;
             while (docEnum.hasMoreElements() && sURL.startsWith("file:")) {
           //URI uri=new URI(sFileName);
           URI uri=new URI(sURL);
           String  newFileName= getPath(uri);
          
              
           //System.out.println("\nURI: "+uri.getPath());
           File newFile=null;
           if (newFileName.lastIndexOf(".")!=-1){
               newFile =new File(newFileName.substring(0,newFileName.lastIndexOf("."))+String.valueOf(i)+newFileName.substring(newFileName.lastIndexOf(".")));
           }
           else{
              newFile =new File(newFileName.concat(String.valueOf(i)));
           }
              
           FileOutputStream fos = new FileOutputStream(newFile);
           docOut      = (Document)docEnum.nextElement();
           fileName      = docOut.getFileName();
           docOut.write(fos);
           fos.flush();
           fos.close();
           i++;
          
             }
       
           }  
       }
       ConverterInfoMgr.removeByJar(jarName);
     }
     catch (StackOverflowError sOE){
         System.out.println("\nERROR : Stack OverFlow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n");
    
     }
     catch (Exception e) {
         System.out.println("Error:"+e);
          throw new IOException("Xmerge Exception");
         }
       }
       else{
   
     try {
          //Check to see if jar contains a plugin Impl
             ConverterInfoMgr.addPlugIn(ciEnum);
             ConverterFactory cf = new ConverterFactory();
       Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),true);
       if (cv == null) {
           System.out.println("\nNo plug-in exists to convert to <staroffice/sxw> from <specified format>");
       }
       else
       {
                             /*
                             ByteArrayOutputStream bout = new ByteArrayOutputStream();
                             byte[][] buf = new byte[1][4096];
                             int n=0;
                             while ((n=xml.readSomeBytes(buf, 4096))>0)
                                 bout.write(buf[0], 0, n);
                             ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
                             cv.addInputStream(name, bin, false);
                            */
           cv.addInputStream(name,(InputStream)xis,false);
           //System.out.println("\nConverting");
           ConvertData dataIn = cv.convert();
           //System.out.println("\nFinished Converting");
           Enumeration docEnum = dataIn.getDocumentEnumeration();
           while (docEnum.hasMoreElements()) {
         OfficeDocument docIn      = (OfficeDocument)docEnum.nextElement();      
       
         docIn.write(newxos,false);
           }
View Full Code Here

          }
    }

        // Get the number of sheets in the workbook
        // This will equal the number of PDBs we need
        ConvertData cd = new ConvertData();
    Workbook wb = ((PocketExcelEncoder) encoder).getWorkbook();
    cd.addDocument(wb);

        return cd;
    }
View Full Code Here

TOP

Related Classes of org.openoffice.xmerge.ConvertData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.