Methods Summary |
---|
private org.w3c.dom.Node | getTextNode(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);
}
}
return null;
|
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 | setTextNodeData(org.w3c.dom.Element element, java.lang.String textNodeData)
NodeList children = element.getChildNodes();
for(int index=0; index < children.getLength(); index++){
if(children.item(index).getNodeType() == Node.TEXT_NODE){
children.item(index).setNodeValue(textNodeData);
return;
}
}
|
public void | transform(org.w3c.dom.Element element, org.w3c.dom.Element parentSource, org.w3c.dom.Element parentResult)element - description
parentSource - parent of description
parentResult - result element to which description to be updated
// description is updated if exists, else added if not exists.
NodeList resultDescs = parentResult.getElementsByTagName("description");
Element resultDesc = null;
if(resultDescs.getLength() == 0){
resultDesc = parentResult.getOwnerDocument().createElement("description");
Node textNode = parentResult.getOwnerDocument().createTextNode(this.getTextNodeData(element));
resultDesc.appendChild(textNode);
parentResult.appendChild(resultDesc);
}else {
resultDesc = (Element)resultDescs.item(0);
if((this.getTextNodeData(element)).equals(this.getTextNodeData((Element)resultDesc))){
// If both are same there is nothing to be done, just break.
}else if(this.getTextNode(resultDesc) == null){
Node textNode = parentResult.getOwnerDocument().createTextNode(this.getTextNodeData(element));
resultDesc.appendChild(textNode);
}else{
this.setTextNodeData(resultDesc, this.getTextNodeData(element));
}
}
|