001package org.nuxeo.template.processors.xdocreport; 002 003import java.io.IOException; 004import java.util.zip.ZipEntry; 005import java.util.zip.ZipInputStream; 006 007import org.nuxeo.ecm.core.api.Blob; 008 009/** 010 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 011 */ 012public class ZipXmlHelper { 013 014 protected static final int BUFFER_SIZE = 1024 * 64; // 64K 015 016 public static final String OOO_MAIN_FILE = "content.xml"; 017 018 public static final String DOCX_MAIN_FILE = "word/document.xml"; 019 020 public static String readXMLContent(Blob blob, String filename) throws IOException { 021 ZipInputStream zIn = new ZipInputStream(blob.getStream()); 022 ZipEntry zipEntry = zIn.getNextEntry(); 023 String xmlContent = null; 024 while (zipEntry != null) { 025 if (zipEntry.getName().equals(filename)) { 026 StringBuilder sb = new StringBuilder(); 027 byte[] buffer = new byte[BUFFER_SIZE]; 028 int read; 029 while ((read = zIn.read(buffer)) != -1) { 030 sb.append(new String(buffer, 0, read)); 031 } 032 xmlContent = sb.toString(); 033 break; 034 } 035 zipEntry = zIn.getNextEntry(); 036 } 037 zIn.close(); 038 return xmlContent; 039 } 040 041}