I am working on SCORE product..and facing some prob in my code...
want to synchronise Msattribute to Score.for that i have build several classes...
I have one class..MSOpenXMLUtil.java class.iwant to add the code for getting the XMLConfigFielLocation XMLDocConfigFileLocation..for that i need to add 2 methods.
1)In getXMLConfigFileLoc do the following,
If the format is “MSWord2007” then return the appropriate path
If the format is “MSExcel2007” then return the appropriate path
If the format is “MSPowerPoint2007” then return the appropriate path
2)In getDocXMLConfigFileLoc do the following
If the format is “MSWord2007” then return the appropriate path of document.xml
If the format is “MSExcel2007” then return the appropriate path of document.xml
If the format is “MSPowerPoint2007” then return the appropriate path of document.xml
Here is the code for the aboce class..
import java.lang.*; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Enumeration; import java.util.UUID; import java.util.zip.Deflater; import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; public class MSOpenXMLUtil { int filePathlength=0; public File unZipFile(File zipFileName) { //String inputFileName = "C:\\SCOREWorkSpace_New\\Test\\Policy - 327"; // "C:\\PPT.zip"; //String desFileName = "C:\\SCOREWorkSpace_New\\Test\\extracted"; // "C:\\TEST\\"; File destDirectory=null; try { //File sourceZipFile = new File(zipFileName); destDirectory = createTempDir(); System.out.println(destDirectory.mkdir()); System.out.println("created directory :"+destDirectory.getAbsolutePath()); /*java.util.zip.GZIPInputStream gzip = new GZIPInputStream(new FileInputStream(zipFileName)); System.out.println(gzip.read()); System.exit(123);*/ //Open the ZIP file for reading ZipFile zipFile = new ZipFile(zipFileName,ZipFile.OPEN_READ); //System.exit(123); //Get the entries Enumeration enum1 = zipFile.entries(); while(enum1.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry)enum1.nextElement(); String currName = zipEntry.getName(); File destFile = new File(destDirectory,currName); // grab file's parent directory structure File destinationParent = destFile.getParentFile(); // create the parent directory structure if needed destinationParent.mkdirs(); if(!zipEntry.isDirectory()) { BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(zipEntry)); int currentByte; // write the current file to disk FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos); // read and write until last byte is encountered while ((currentByte = is.read()) != -1) { dest.write(currentByte); } dest.flush(); dest.close(); is.close(); } } } catch(IOException ioe) { System.out.println("IOException occured====="+ioe); ioe.printStackTrace(); } return destDirectory; } public void zipDir(String zipFileName, String dir) throws Exception { File dirObj = new File(dir); filePathlength = dir.length() + 1; ZipOutputStream out = new ZipOutputStream(new FileOutputStream( zipFileName)); out.setLevel(Deflater.BEST_COMPRESSION); System.out.println("Creating : " + zipFileName); addDir(dirObj, out); out.close(); } private void addDir(File dirObj, ZipOutputStream out) throws IOException { File[] files = dirObj.listFiles(); /*for (int i = 0; i < files.length; i++) { System.out.println(files[i].getPath().substring(filePathlength)); }*/ byte[] tmpBuf = new byte[1024]; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { addDir(files[i], out); continue; } FileInputStream in = new FileInputStream(files[i].getPath()); out.putNextEntry(new ZipEntry(files[i].getPath().substring( filePathlength))); int len; while ((len = in.read(tmpBuf)) > 0) { out.write(tmpBuf, 0, len); } out.closeEntry(); in.close(); } } private File createTempDir() throws IOException{ final File sysTempDir = new File("temp");//System.getProperty("java.io.tmpdir")); File newTempDir; String dirName = UUID.randomUUID().toString(); newTempDir = new File(sysTempDir, dirName); return newTempDir; } public void deleteDirectory(File root) { if (root == null) { return; } if (root.isDirectory()) { File[] files = root.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) { deleteDirectory(file); } else { file.delete(); } } } } root.delete(); } } }
Please help me out!!!