Fix: 55060 - propagating context root to sun-web.xml BLD200502271900
authoryutayoshida@netbeans.org
Sat, 26 Feb 2005 01:11:29 +0000
changeset 5861ae99e5757fc5
parent 5860 992ca9baa4b0
child 5862 2bd685f3ff83
Fix: 55060 - propagating context root to sun-web.xml
j2ee.blueprints/src/org/netbeans/modules/j2ee/blueprints/ui/projects/J2eeSampleProjectGenerator.java
     1.1 --- a/j2ee.blueprints/src/org/netbeans/modules/j2ee/blueprints/ui/projects/J2eeSampleProjectGenerator.java	Fri Feb 25 16:26:31 2005 +0000
     1.2 +++ b/j2ee.blueprints/src/org/netbeans/modules/j2ee/blueprints/ui/projects/J2eeSampleProjectGenerator.java	Sat Feb 26 01:11:29 2005 +0000
     1.3 @@ -42,11 +42,13 @@
     1.4      
     1.5      private J2eeSampleProjectGenerator() {}
     1.6  
     1.7 -    public static final String PROJECT_CONFIGURATION_NAMESPACE = "http://www.netbeans.org/ns/web-project/1";    //NOI18N
     1.8 +    public static final String PROJECT_CONFIGURATION_NAMESPACE = "http://www.netbeans.org/ns/web-project/3";    //NOI18N
     1.9      public static final String EAR_NAMESPACE = "http://www.netbeans.org/ns/j2ee-earproject/1";
    1.10 +    public static final String SUN_WEB_XMLLOC = "web/WEB-INF/sun-web.xml";
    1.11  
    1.12      public static FileObject createProjectFromTemplate(final FileObject template, File projectLocation, final String name) throws IOException {
    1.13          FileObject prjLoc = null;
    1.14 +        String slashname = "/"+name;
    1.15          if (template.getExt().endsWith("zip")) {  //NOI18N
    1.16              unzip(template.getInputStream(), projectLocation);
    1.17                  String extra = (String)template.getAttribute("extrazip");
    1.18 @@ -58,11 +60,10 @@
    1.19                      }
    1.20                  }
    1.21                  
    1.22 -
    1.23 -        
    1.24 -            // update project.xml
    1.25              try {
    1.26                  prjLoc = FileUtil.toFileObject(projectLocation);
    1.27 +                
    1.28 +                //update project.xml
    1.29                  File projXml = FileUtil.toFile(prjLoc.getFileObject(AntProjectHelper.PROJECT_XML_PATH));
    1.30                  Document doc = XMLUtil.parse(new InputSource(projXml.toURI().toString()), false, true, null, null);
    1.31                  NodeList nlist = doc.getElementsByTagNameNS(PROJECT_CONFIGURATION_NAMESPACE, "name");      //NOI18N
    1.32 @@ -82,6 +83,30 @@
    1.33                          saveXml(doc, prjLoc, AntProjectHelper.PROJECT_XML_PATH);
    1.34                      }
    1.35                  }
    1.36 +                
    1.37 +                // update sun-web.xml
    1.38 +                
    1.39 +                FileObject sunwebfile = prjLoc.getFileObject(SUN_WEB_XMLLOC);
    1.40 +                // WebTier entry must have web/WEB-INF/sun-web.xml.
    1.41 +                // If there isn't, assuming it's in other categories like SOA.
    1.42 +                if (sunwebfile!=null) {
    1.43 +                    File sunwebXml = FileUtil.toFile(sunwebfile);
    1.44 +                    Document swdoc = XMLUtil.parse(new InputSource(sunwebXml.toURI().toString()), false, true, null, null);
    1.45 +                    NodeList swnlist = swdoc.getElementsByTagName("context-root");      //NOI18N
    1.46 +                    // NodeList should contain only one, but just incase
    1.47 +                    if (swnlist != null) {
    1.48 +                        for (int i=0; i < swnlist.getLength(); i++) {
    1.49 +                            Node n = swnlist.item(i);
    1.50 +                            if (n.getNodeType() != Node.ELEMENT_NODE) {
    1.51 +                                continue;
    1.52 +                            }
    1.53 +                            Element e = (Element)n;
    1.54 +                            replaceText(e, slashname);
    1.55 +                            saveXml(swdoc, prjLoc, SUN_WEB_XMLLOC);
    1.56 +                        }
    1.57 +                    }
    1.58 +                }
    1.59 +                 
    1.60              } catch (Exception e) {
    1.61                  throw new IOException(e.toString());
    1.62              }