1 19 20 package org.netbeans.modules.j2ee.sun.share.plan; 21 22 import org.w3c.dom.*; 23 import org.netbeans.modules.schema2beans.*; 24 25 import java.util.jar.JarOutputStream ; 26 import java.io.InputStream ; 27 28 import java.util.jar.JarEntry ; 29 30 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider; 31 import org.netbeans.modules.j2ee.sun.dd.api.DDException; 32 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 33 34 37 public class Util { 38 39 40 private Util() { 41 } 42 43 52 public static void convert(InputStream plan, JarOutputStream jar) throws java.io.IOException { 53 DeploymentPlan dp = null; 54 Throwable cause = null; 55 56 Document doc = null; 57 try { 59 doc = GraphManager.createXmlDocument(plan, false); 60 } 61 catch (RuntimeException re) { 62 giveUp(re); 63 } 64 65 try { 67 dp = DeploymentPlan.createGraph(doc); 68 } 69 catch (org.netbeans.modules.schema2beans.Schema2BeansException s2be) { 70 cause = s2be; 72 } 73 if (null == dp) { 74 SunWebApp swa = null; 76 try { 77 swa = DDProvider.getDefault().getWebDDRoot(doc); 79 dp = DeploymentPlan.createGraph(); 80 FileEntry fe = new FileEntry(); 81 fe.setName("sun-web.xml"); 82 String s = new String (); 83 java.io.StringWriter strWriter = new java.io.StringWriter (); 84 swa.write(strWriter); 85 fe.setContent(strWriter.toString()); 86 dp.addFileEntry(fe); 87 } catch(DDException ex) { 88 giveUp(ex); 89 } catch (org.netbeans.modules.schema2beans.Schema2BeansException s2bX) { 90 giveUp(s2bX); 91 } catch (java.beans.PropertyVetoException pv) { 92 giveUp(pv); 93 } 94 } 95 96 int index = dp.sizeFileEntry(); 97 for (int i = 0; i < index; i++) { 98 FileEntry fe = dp.getFileEntry(i); 99 String name = fe.getUri(); 100 if (null == name) 101 name = hashify(fe.getName()); 102 else 103 name += "." + hashify(fe.getName()); 104 JarEntry ent = new JarEntry (name); 105 jar.putNextEntry(ent); 106 String content = fe.getContent(); 107 jar.write(content.getBytes()); 108 jar.closeEntry(); 109 } 110 } 111 112 private static void giveUp(Throwable s2be) throws java.io.IOException { 113 java.io.IOException ioe = new java.io.IOException ("plan file issue"); 114 ioe.initCause(s2be); 115 throw ioe; 116 } 117 118 private static String hashify(String path) { 119 return path.replace('/','#'); 120 } 121 122 } 123 | Popular Tags |