static final String PROJECT_CONFIGURATION_NAMESPACE = "http://www.netbeans.org/ns/web-project/3"; //NOI18N
static final String JSPC_CLASSPATH = "jspc.classpath";
static FileObject createProjectFromTemplate(final FileObject template, File projectLocation, final String name) throws IOException {
assert template != null && projectLocation != null && name != null;
FileObject prjLoc = FileUtil.createFolder(projectLocation);
if (template.getExt().endsWith("zip")) { //NOI18N
unzip(template.getInputStream(), prjLoc);
// update project.xml
try {
File projXml = FileUtil.toFile(prjLoc.getFileObject(AntProjectHelper.PROJECT_XML_PATH));
Document doc = XMLUtil.parse(new InputSource(projXml.toURI().toString()), false, true, null, null);
NodeList nlist = doc.getElementsByTagNameNS(PROJECT_CONFIGURATION_NAMESPACE, "name"); //NOI18N
if (nlist != null) {
for (int i=0; i < nlist.getLength(); i++) {
Node n = nlist.item(i);
if (n.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element e = (Element)n;
replaceText(e, name);
}
saveXml(doc, prjLoc, AntProjectHelper.PROJECT_XML_PATH);
}
// clean up the project.properties, too.
FileObject projPropsFO = prjLoc.getFileObject(AntProjectHelper.PROJECT_PROPERTIES_PATH);
if (null != projPropsFO) {
java.util.Properties p = new java.util.Properties();
InputStream in = projPropsFO.getInputStream();
OutputStream out = null;
try {
p.load(in);
// this is a hack
// make sure these two keys match keys in the sip-app
// template's project.properties file....
//
p.setProperty("war.name", name+".war");
p.setProperty("war.ear.name", name+".war");
in.close();
out = projPropsFO.getOutputStream();
p.store(out, "Altered war.name property");
} catch (java.io.IOException ioe) {
// this might be a read or a write
Logger.getLogger(ProjectGenerator.class.getName()).log(Level.FINER,
null, ioe);