* with the dlm namespace Constants.NS are added as attributes to the Element.
* Others are added as child parameter Elements.
*/
if (ls.getParameters() != null) {
for (final Iterator itr = ls.getParameters().iterator(); itr.hasNext();) {
final StructureParameter sp = (StructureParameter) itr.next();
String pName = sp.getName();
// handle migration of legacy namespace
if (pName.startsWith(Constants.LEGACY_NS)) {
pName = Constants.NS + sp.getName().substring(Constants.LEGACY_NS.length());
}
if (!ls.isChannel()) { // Folder
if (pName.startsWith(Constants.NS)) {
structure.setAttributeNS(Constants.NS_URI, pName, sp.getValue());
}
else {
structure.setAttribute(pName, sp.getValue());
}
}
else // Channel
{
// if dealing with a dlm namespace param add as attribute
if (pName.startsWith(Constants.NS)) {
structure.setAttributeNS(Constants.NS_URI, pName, sp.getValue());
itr.remove();
}
else {
/*
* do traditional override processing. some explanation is in
* order. The structure element was created by the
* ChannelDefinition and only contains parameter children if the
* definition had defined parameters. These are checked for each
* layout loaded parameter as found in LayoutStructure.parameters.
* If a name match is found then we need to see if overriding is
* allowed and if so we set the value on the child parameter
* element. At that point we are done with that version loaded
* from the layout so we remove it from the in-memory set of
* parameters that are being merged-in. Then, after all such have
* been checked against those added by the channel definition we
* add in any remaining as adhoc, unregulated parameters.
*/
final NodeList nodeListParameters = structure.getElementsByTagName("parameter");
for (int j = 0; j < nodeListParameters.getLength(); j++) {
final Element parmElement = (Element) nodeListParameters.item(j);
final NamedNodeMap nm = parmElement.getAttributes();
final String nodeName = nm.getNamedItem("name").getNodeValue();
if (nodeName.equals(pName)) {
final Node override = nm.getNamedItem("override");
if (override != null && override.getNodeValue().equals("yes")) {
final Node valueNode = nm.getNamedItem("value");
valueNode.setNodeValue(sp.getValue());
}
itr.remove();
break; // found the corresponding one so skip the rest
}
}
}
}
}
// For channels, add any remaining parameter elements loaded with the
// layout as adhoc, unregulated, parameter children that can be overridden.
if (ls.isChannel()) {
for (final Iterator itr = ls.getParameters().iterator(); itr.hasNext();) {
final StructureParameter sp = (StructureParameter) itr.next();
final Element parameter = doc.createElement("parameter");
parameter.setAttribute("name", sp.getName());
parameter.setAttribute("value", sp.getValue());
parameter.setAttribute("override", "yes");
structure.appendChild(parameter);
}
}
}