private void digestParameters(Element resourceConfigElement, SmooksResourceConfiguration resourceConfig) { NodeList configNodes = resourceConfigElement.getElementsByTagName("param"); for (int i = 0; i < configNodes.getLength(); i++) { Element paramNode = (Element) configNodes.item(i); String paramName = DomUtils.getAttributeValue(paramNode, "name"); String paramType = DomUtils.getAttributeValue(paramNode, "type"); String paramValue = DomUtils.getAllText(paramNode, true); Parameter paramInstance; paramInstance = resourceConfig.setParameter(paramName, paramType, paramValue); paramInstance.setXML(paramNode); } }
public static boolean isContextObjectElement(Element element) { if(DomUtils.getName(element).equals("context-object") && Namespace.SMOOKS_URI.equals(element.getNamespaceURI())) { return true; } return false; }
public void visitAfter(Element element, ExecutionContext request) { DomUtils.removeElement(element, keepChildContent); } }
private void configureParams(Element configElement, SmooksResourceConfiguration resourceConfig) { Element paramsElement = DomUtils.getElement(configElement, "params", 1); if(paramsElement != null) { NodeList params = paramsElement.getChildNodes(); for(int i = 0; i < params.getLength(); i++) { if(params.item(i).getNodeType() == Node.ELEMENT_NODE) { Element param = (Element) params.item(i); String name = param.getAttribute("name"); String value = DomUtils.getAllText(param, true); resourceConfig.setParameter(name, value); } } } }
/** * Get attribute value, returning <code>null</code> if unset. * <p/> * Some DOM implementations return an empty string for an unset * attribute. * @param element The DOM element. * @param attributeName The attribute to get. * @return The attribute value, or <code>null</code> if unset. */ public static String getAttributeValue(Element element, String attributeName) { return getAttributeValue(element, attributeName, null); }
logger.debug("Cannot remove document root element [" + DomUtils.getName(element) + "] without keeping child content."); } else { if(children != null && children.getLength() > 0) { childElements = DomUtils.getElements(element, "*", null); parent.appendChild((Element)childElements.get(0)); } else { logger.debug("Cannot remove empty document root element [" + DomUtils.getName(element) + "]."); DomUtils.insertBefore(children, element);
private void configureFeatures(Element configElement, SmooksResourceConfiguration resourceConfig) { Element featuresElement = DomUtils.getElement(configElement, "features", 1); if(featuresElement != null) { NodeList features = featuresElement.getChildNodes(); for(int i = 0; i < features.getLength(); i++) { if(features.item(i).getNodeType() == Node.ELEMENT_NODE) { Element feature = (Element) features.item(i); String uri = feature.getAttribute("feature"); if(DomUtils.getName(feature).equals("setOn")) { resourceConfig.setParameter("feature-on", uri); } else { resourceConfig.setParameter("feature-off", uri); } } } } }
public void writeElementStart(Element element, Writer writer, ExecutionContext executionContext) throws IOException { String key = getContextKey(element); if(key != null) { Object object = executionContext.getAttribute(key); if(object != null) { writer.write(object.toString()); } else { logger.debug("Invalid <context-object> specification at '" + DomUtils.getXPath(element) + "'. No Object instance found on context at '" + key + "'."); } } else { logger.warn("Invalid <context-object> specification at '" + DomUtils.getXPath(element) + "'. 'key' attribute not specified."); } }
public static String getText(Element element) { return DomUtils.getAllText(element, false); } }
@SuppressWarnings("unchecked") private void digestImport(Element importElement, URI baseURI) throws SAXException, URISyntaxException, SmooksConfigurationException { String file = DomUtils.getAttributeValue(importElement, "file"); URIResourceLocator resourceLocator; InputStream resourceStream; List<Element> importParams = DomUtils.getElements(importElement, "param", null); if(!importParams.isEmpty()) { String paramName = DomUtils.getAttributeValue(importParam, "name"); String paramValue = XmlUtil.serialize(importParam.getChildNodes());
/** * Rename element. * @param element The element to be renamed. * @param replacementElement The tag name of the replacement element. * @param keepChildContent <code>true</code> if the target element's child content * is to be copied to the replacement element, false if not. Default <code>true</code>. * @param keepAttributes <code>true</code> if the target element's attributes * are to be copied to the replacement element, false if not. Default <code>true</code>. * @return The renamed element. */ public static Element renameElement(Element element, String replacementElement, boolean keepChildContent, boolean keepAttributes) { return renameElementNS(element, replacementElement, null, keepChildContent, keepAttributes); }
List nodeList = DomUtils.copyNodeList(newNodes); List elements = DomUtils.getElements(newNodes, "*", null);
/** * Get the child element having the supplied localname, position * and namespace. * <p/> * Can be used instead of XPath. * @param parent Parent element to be searched. * @param localname Localname of the element required. * @param position The position of the element relative to other sibling * elements having the same name (and namespace if specified) e.g. if * searching for the 2nd <input> element, this param needs to * have a value of 2. * @return The element at the requested position, or null if no such child * element exists on the parent element. */ public static Element getElement(Element parent, String localname, int position) { return getElement(parent, localname, position, null); }
/** * Get the child element having the supplied localname, position * and namespace. * <p/> * Can be used instead of XPath. * @param parent Parent element to be searched. * @param localname Localname of the element required. * @param position The position of the element relative to other sibling * elements having the same name (and namespace if specified) e.g. if * searching for the 2nd <input> element, this param needs to * have a value of 2. * @param namespaceURI Namespace URI of the required element, or null * if a namespace comparison is not to be performed. * @return The element at the requested position, or null if no such child * element exists on the parent element. */ public static Element getElement(Element parent, String localname, int position, String namespaceURI) { List elements = getElements(parent, localname, namespaceURI); position = Math.max(position, 1); if(position > elements.size()) { return null; } return (Element)elements.get(position - 1); }
public int getDepth() { if(element instanceof Element) { return DomUtils.getDepth((Element) element); } else if(element instanceof SAXElement) { return SAXUtil.getDepth((SAXElement) element); } return 0; } }
element.appendChild(node); } else if(action == Action.INSERT_BEFORE) { DomUtils.insertBefore(node, element); } else if(action == Action.INSERT_AFTER) { Node nextSibling = element.getNextSibling(); } else { DomUtils.insertBefore(node, nextSibling);
/** * Get attribute value, returning <code>null</code> if unset. * <p/> * Some DOM implementations return an empty string for an unset * attribute. * @param element The DOM element. * @param attributeName The attribute to get. * @return The attribute value, or <code>null</code> if unset. */ public static String getAttributeValue(Element element, String attributeName) { return getAttributeValue(element, attributeName, null); }
logger.debug("Cannot remove document root element [" + DomUtils.getName(element) + "] without keeping child content."); } else { if(children != null && children.getLength() > 0) { childElements = DomUtils.getElements(element, "*", null); parent.appendChild((Element)childElements.get(0)); } else { logger.debug("Cannot remove empty document root element [" + DomUtils.getName(element) + "]."); DomUtils.insertBefore(children, element);
private void configureParams(Element configElement, SmooksResourceConfiguration resourceConfig) { Element paramsElement = DomUtils.getElement(configElement, "params", 1); if(paramsElement != null) { NodeList params = paramsElement.getChildNodes(); for(int i = 0; i < params.getLength(); i++) { if(params.item(i).getNodeType() == Node.ELEMENT_NODE) { Element param = (Element) params.item(i); String name = param.getAttribute("name"); String value = DomUtils.getAllText(param, true); resourceConfig.setParameter(name, value); } } } }
private void configureFeatures(Element configElement, SmooksResourceConfiguration resourceConfig) { Element featuresElement = DomUtils.getElement(configElement, "features", 1); if(featuresElement != null) { NodeList features = featuresElement.getChildNodes(); for(int i = 0; i < features.getLength(); i++) { if(features.item(i).getNodeType() == Node.ELEMENT_NODE) { Element feature = (Element) features.item(i); String uri = feature.getAttribute("feature"); if(DomUtils.getName(feature).equals("setOn")) { resourceConfig.setParameter("feature-on", uri); } else { resourceConfig.setParameter("feature-off", uri); } } } } }