public static String getParameterValue( Node paramParent,
String parameterName)
throws JahiaException {
if (!paramParent.hasChildNodes()) {
throw new JahiaException("No parameters available on portlet XML tag",
"Parent has no children at all",
JahiaException.CRITICAL_SEVERITY,
JahiaException.CONFIG_ERROR);
}
Node curNode = paramParent.getFirstChild();
while (curNode != null) {
//JahiaConsole.println("XMLParser.getParameterValue", "Looking for param...["+curNode.getNodeName()+"]");
// let's go through all the children nodes
if (curNode.getNodeType() == Node.ELEMENT_NODE) {
if (curNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {
// we have found a parameter tag, let's check further for match of param name
NamedNodeMap attr = curNode.getAttributes();
Node paramAttrNode = attr.getNamedItem(PARAMETER_TAG_NAME_ATTRIBUTE);
if (paramAttrNode != null) {
if (paramAttrNode.getNodeValue().equalsIgnoreCase(parameterName)) {
// we found the parameter
//JahiaConsole.println("XMLParser.getParameterValue", "Found parameter " + parameterName);
// we must now extract value of text node below this node.
Node textNode = curNode.getFirstChild();
if ( textNode == null ){ // check this otherwise nullpointer exception NK
return "";
} else {
if (textNode.getNodeType() == Node.TEXT_NODE) {
return textNode.getNodeValue();
} else {
throw new JahiaException(ERROR_READING_FILE_MSG,
"Value of paramater is not in correct format, should only be text",
JahiaException.CRITICAL_SEVERITY,
JahiaException.CONFIG_ERROR);
}
}
}
} else {
throw new JahiaException(ERROR_READING_FILE_MSG,
"No attribute name found on parameter !",
JahiaException.CRITICAL_SEVERITY,
JahiaException.CONFIG_ERROR);
}
}