Package org.openoffice.xmerge

Examples of org.openoffice.xmerge.Convert


     @throws  IllegalArgumentException  If an argument is invalid.
     */
    private void doConversion() throws IllegalArgumentException {

        ConverterFactory cf = new ConverterFactory();
        Convert myConvert   = cf.getConverter(fromMime, toMime);
        String processFile  = null;

        if (myConvert == null) {
            System.out.println("\nNo plug-in exists to convert from <" +
                fromMime + "> to <" + toMime + ">");
            throw new IllegalArgumentException();
        }

        try {
            Enumeration dfEnum = deviceFiles.elements();
            while (dfEnum.hasMoreElements()) {
                processFile = (String)dfEnum.nextElement();
                File f = new File(processFile);
               
                // Make sure the input file actually exists before using it
                if (!f.exists()) {
                    System.out.println(processFile + " does not exist!");
                    System.exit(0);
                }
                FileInputStream fis = new FileInputStream(f);
                myConvert.addInputStream(f.getName(), fis);
            }
        } catch (Exception addExcept) {
            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


         //Check to see if jar contains a plugin Impl
      
             ConverterInfoMgr.addPlugIn(ciEnum);
       ConverterFactory cf = new ConverterFactory();
     
       Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false);
       if (cv == null) {
           System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> ");
        
       }
       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
       {
           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();      
       
View Full Code Here

         //Check to see if jar contains a plugin Impl
      
             ConverterInfoMgr.addPlugIn(ciEnum);
       ConverterFactory cf = new ConverterFactory();
     
       Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false);
       if (cv == null) {
           System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> ");
        
       }
       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();      
       
View Full Code Here

     @throws  IllegalArgumentException  If an argument is invalid.
     */
    private void doConversion() throws IllegalArgumentException {

        ConverterFactory cf = new ConverterFactory();
        Convert myConvert   = cf.getConverter(fromMime, toMime);
        String processFile  = null;

        if (myConvert == null) {
            System.out.println("\nNo plug-in exists to convert from <" +
                fromMime + "> to <" + toMime + ">");
            throw new IllegalArgumentException();
        }

        try {
            Enumeration dfEnum = deviceFiles.elements();
            while (dfEnum.hasMoreElements()) {
                processFile = (String)dfEnum.nextElement();
                File f = new File(processFile);
               
                // Make sure the input file actually exists before using it
                if (!f.exists()) {
                    System.out.println(processFile + " does not exist!");
                    System.exit(0);
                }
                FileInputStream fis = new FileInputStream(f);
                myConvert.addInputStream(f.getName(), fis);
            }
        } catch (Exception addExcept) {
            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

        ConverterInfoReader cirPlugin = new ConverterInfoReader(pluginJar.toURL().toString(), false);    
       
        ConverterInfoMgr.addPlugIn(cirPlugin.getConverterInfoEnumeration());
       
        ConverterFactory cf = new ConverterFactory();
        Convert conv = cf.getConverter(srcMime, dstMime);
               
        if (conv == null) {
            return false;
        }
       
        // Everything is registered so do the conversion
        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;
        }
       
View Full Code Here

        ConverterInfoReader cirPlugin = new ConverterInfoReader(pluginJar.toURL().toString(), false);    
       
        ConverterInfoMgr.addPlugIn(cirPlugin.getConverterInfoEnumeration());
       
        ConverterFactory cf = new ConverterFactory();
        Convert conv = cf.getConverter(srcMime, dstMime);
               
        if (conv == null) {
            return false;
        }
       
        // Everything is registered so do the conversion
        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;
        }
       
View Full Code Here

         //Check to see if jar contains a plugin Impl
      
             ConverterInfoMgr.addPlugIn(ciEnum);
       ConverterFactory cf = new ConverterFactory();
     
       Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false);
       if (cv == null) {
           System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> ");
        
       }
       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();      
       
View Full Code Here

        ConverterInfoReader cirPlugin = new ConverterInfoReader(pluginJar.toURL().toString(), false);    
       
        ConverterInfoMgr.addPlugIn(cirPlugin.getConverterInfoEnumeration());
       
        ConverterFactory cf = new ConverterFactory();
        Convert conv = cf.getConverter(srcMime, dstMime);
               
        if (conv == null) {
            return false;
        }
       
        // Everything is registered so do the conversion
        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;
        }
       
View Full Code Here

     @throws  IllegalArgumentException  If an argument is invalid.
     */
    private void doConversion() throws IllegalArgumentException {

        ConverterFactory cf = new ConverterFactory();
        Convert myConvert   = cf.getConverter(fromMime, toMime);
        String processFile  = null;

        if (myConvert == null) {
            System.out.println("\nNo plug-in exists to convert from <" +
                fromMime + "> to <" + toMime + ">");
            throw new IllegalArgumentException();
        }

        try {
            Enumeration dfEnum = deviceFiles.elements();
            while (dfEnum.hasMoreElements()) {
                processFile = (String)dfEnum.nextElement();
                File f = new File(processFile);
               
                // Make sure the input file actually exists before using it
                if (!f.exists()) {
                    System.out.println(processFile + " does not exist!");
                    System.exit(0);
                }
                FileInputStream fis = new FileInputStream(f);
                myConvert.addInputStream(f.getName(), fis);
            }
        } catch (Exception addExcept) {
            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

         //Check to see if jar contains a plugin Impl
      
             ConverterInfoMgr.addPlugIn(ciEnum);
       ConverterFactory cf = new ConverterFactory();
     
       Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false);
       if (cv == null) {
           System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> ");
        
       }
       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();      
       
View Full Code Here

TOP

Related Classes of org.openoffice.xmerge.Convert

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.