Methods Summary |
---|
private void | addServletMapping(org.w3c.dom.Element documentElement)
Element sMap = documentElement.getOwnerDocument().createElement("servlet-mapping");
documentElement.appendChild(sMap);
Element sName = documentElement.getOwnerDocument().createElement("servlet-name");
Node sNameTextNode = documentElement.getOwnerDocument().createTextNode("jsp");
sName.appendChild(sNameTextNode);
sMap.appendChild(sName);
Element urlPat = documentElement.getOwnerDocument().createElement("url-pattern");
Node urlTextNode = documentElement.getOwnerDocument().createTextNode("*.jspx");
urlPat.appendChild(urlTextNode);
sMap.appendChild(urlPat);
|
private java.lang.String | getTextNodeData(org.w3c.dom.Element element)
NodeList children = element.getChildNodes();
for(int index=0; index < children.getLength(); index++){
if(children.item(index).getNodeType() == Node.TEXT_NODE){
return children.item(index).getNodeValue();
}
}
return "";
|
private void | modifyContent(java.io.File xmlFile)
UpgradeUtils upgrUtils = UpgradeUtils.getUpgradeUtils(commonInfo);
Document document = upgrUtils.getDomainDocumentElement(xmlFile.toString());
try {
Element docEle = document.getDocumentElement();
// Need to obtain the servlet element named jsp
NodeList servlets = docEle.getElementsByTagName("servlet");
for(int lh =0; lh < servlets.getLength(); lh++){
Element servlet = ((Element)servlets.item(lh));
NodeList ssNames = servlet.getElementsByTagName("servlet-name");
// There should be only one servlet-name
if(this.getTextNodeData((Element)ssNames.item(0)).equals("jsp")){
NodeList ssClNames = servlet.getElementsByTagName("servlet-class");
this.setTextNodeData((Element)ssClNames.item(0),
"org.apache.jasper.servlet.JspServlet");
break;
}
}
this.addServletMapping(docEle);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(new FileOutputStream(xmlFile));
transformer.transform(source, result);
}catch (Exception ex){
// Log error
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.defaultWebXML.startFailureMessage",
ex.getMessage()), ex);
}
|
private void | setTextNodeData(org.w3c.dom.Element element, java.lang.String text)
NodeList children = element.getChildNodes();
for(int index=0; index < children.getLength(); index++){
if(children.item(index).getNodeType() == Node.TEXT_NODE){
children.item(index).setNodeValue(text);
}
}
|
private void | transferFileContents(java.io.File source, java.io.File target)Method to transfer file contents from source to target
BufferedReader reader = new BufferedReader(new InputStreamReader
(new FileInputStream(source)));
PrintWriter writer = new PrintWriter(new FileOutputStream(target));
String readLine = null;
while((readLine = reader.readLine()) != null){
writer.println(readLine);
}
writer.flush();
writer.close();
reader.close();
|
public void | transform(java.lang.String targetFileName)Method to transform default-web.xml file from source to target
logger.log(Level.INFO, stringManager.getString(
"upgrade.configTransfers.defaultWebXML.startMessage"));
File targetFile = new File(targetFileName);
this.modifyContent(targetFile);
|