How to search for docx file and unzip it in the given directory using java?

Actually I'm going to convert the .docx file into .xhtml. so I need to find out the doc file in the given directory and unzip it. After getting document.xml from the word file I need that file to process with some xsl files to get final result as .xhtml.

//-------------------------Source--------------------------------------               
simpleTransform(Source+"/"+"filename"+".xml", Source+"/01-W2H.xslt", Source+"/"+"out2.xml");
simpleTransform(Source+"/"+"out2.xml", Source+"/08-xmlns.xslt", Source+"/"+"out22.xml");
simpleTransform(Source+"/"+"out22.xml", Source+"/06-Heading.xslt", Source+"/"+"out3.xml");
simpleTransform(Source+"/"+"out222.xml", Source+"/02-FigureRef.xsl", Source+"/"+"out222.xml");
simpleTransform(Source+"/"+"out3", Source+"/03-Remove-Duplecate.xsl", Source+"/"+"OUT4.xml");
simpleTransform(Source+"/"+"out4.xml", Source+"/04-Return_XML_To_Position.xsl", Source+"/"+"OUT5.xml");
simpleTransform(Source+"/"+"out5.xml", Source+"/05-Final.xsl", Source+"/"+"filename"+".xhtml");       
simpleTransform(Source+"/com.apple.ibooks.display-options.xm", Source+"/07-Combine.xsl", Source+"/"+"del.txt");
simpleTransform(Source+"/"+"merged-html.xml", Source+"/08-xmlns.xslt", Source+"/"+"merged-html2.xml");
simpleTransform(Source+"/"+"merged-html2.xml", Source+"/09-OPF.xsl", Source+"/"+"del2.txt");
simpleTransform(Source+"/merged-html2.xml", Source+"/10-NCX.xsl", Source+"/del3.xml");
simpleTransform(Source+"/toc.ncx", Source+"/10-NCX2.xsl", Source+"/toc.ncx");
simpleTransform(Source+"/toc.ncx", Source+"/11-Heading.xslt", Source+"/toc.ncx");
simpleTransform(Source+"/toc.ncx", Source+"/11-idsequence.xsl",  Source+"/toc.ncx");          
simpleTransform(Source+"/merged-html2.xml", Source+"/12-Contents.xsl",  Source+"/contents.xhtml");

Answers


  1. For search files by extensions you can use Apache Commons IO library:

method:

FileUtils.iterateFiles(File directory, String[] extensions, boolean recursive)
  1. For zip\unzip: Apache Commons Compress

ZipArchiveInputStream class

something like that:

try(ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(fileInputStream)) {
    ZipArchiveEntry zipEntry;

    while ((zipEntry = zipArchiveInputStream.getNextZipEntry()) != null){
        String fileName = zipEntry.getName();

        final File file = new File(fileName);

        FileUtil.createMissingParentDirectories(file);

        try(FileOutputStream fileOutputStream = new FileOutputStream(file.getAbsolutePath())) {(file.read.buffer)
            try(BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream, 1024)) {
                int n = 0;

                byte[] content = new byte[1024];

                while ((n = zipArchiveInputStream.read(content)) != -1) {
                    fileOutputStream.write(content, 0, n);
                }

                bos.flush();
                }
            }
        }
    }
}

Need Your Help

Taxonomy images in Drupal, Is there a way to manually add a thumbnail image?

php drupal

We have the taxonomy image module installed, uploaded some taxonomy images a made a happy dance. Thumbnails where needed so we used the taxonomy_image_display() which does a fairly good job (although

The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

spring transactions spring-transactions

I am trying to configure JSF+Spring+hibernate and I'm tying to run a test but when I use this "tx:annotation-driven" on my application-context.xml file, I get this error: