Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: HI all....Need your help on Java coding part...very thankful for your help....

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy HI all....Need your help on Java coding part...very thankful for your help....

    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!!!


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: HI all....Need your help on Java coding part...very thankful for your help....

    Welcome to the forums Nishi. Have you tried writing these methods yet? What are you stuck on?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Java Applet Coding Help?
    By Drag01 in forum Java Applets
    Replies: 1
    Last Post: April 26th, 2012, 07:03 AM
  2. Help me in java coding
    By smallmac in forum Java Theory & Questions
    Replies: 5
    Last Post: August 2nd, 2010, 09:50 AM
  3. How to write to specific part of an html file using java
    By nasi in forum File I/O & Other I/O Streams
    Replies: 12
    Last Post: May 27th, 2010, 11:22 PM
  4. Java coding help
    By Javalover1 in forum The Cafe
    Replies: 0
    Last Post: April 12th, 2010, 08:11 PM
  5. 15, Loves ICT, learning Java coding.
    By Sergant Mitch in forum Member Introductions
    Replies: 1
    Last Post: September 20th, 2008, 09:40 AM