Refine search
static class LoggingErrorListener implements ErrorListener { // See http://www.cafeconleche.org/slides/sd2003west/xmlandjava/346.html boolean strict; public LoggingErrorListener(boolean strict) { } public void warning(TransformerException exception) { log.warn(exception.getMessage(), exception); // Don't throw an exception and stop the processor // just for a warning; but do log the problem } public void error(TransformerException exception) throws TransformerException { log.error(exception.getMessage(), exception); // XSLT is not as draconian as XML. There are numerous errors // which the processor may but does not have to recover from; // e.g. multiple templates that match a node with the same // priority. If I do not want to allow that, I'd throw this // exception here. if (strict) { throw exception; }
protected Element writeBodyElement(Document d) { Element envelopeElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Envelope"); Attr encodingStyleAttr = d.createAttributeNS(Constants.SOAP_NS_ENVELOPE, "s:encodingStyle"); encodingStyleAttr.setValue(Constants.SOAP_URI_ENCODING_STYLE); envelopeElement.setAttributeNode(encodingStyleAttr); d.appendChild(envelopeElement); Element bodyElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Body"); envelopeElement.appendChild(bodyElement); return bodyElement; }
public static Map<String, Object> loadAttributes(Element e) { Map<String, Object> map = new HashMap<String, Object>(); NamedNodeMap nm = e.getAttributes(); for (int j = 0; j < nm.getLength(); j++) { Node n = nm.item(j); if (n instanceof Attr) { Attr attr = (Attr) n; map.put(attr.getName(), attr.getNodeValue()); } } return map; }
/** * Loads the given attribute in the current sequence. * * @param attr The W3C DOM attribute node to load. */ private void load(Attr attr) { handlePrefixMapping(attr.getNamespaceURI(), attr.getPrefix()); load(this.efactory.makeAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getNodeName(), attr.getValue())); }
for (int j = 0; j < nodeMap.getLength(); j++) { Node familyAttr = nodeMap.item(j); if (familyAttr.getNodeType() == Node.ATTRIBUTE_NODE) { Attr attr = (Attr) familyAttr; String name = attr.getName(); String value = attr.getValue(); if (ATTR_NAME.equals(name)) { family.setName(value); familyMap.put(family.getName(), family); for (int k = 0; k < counterAttrMap.getLength(); k++) { Attr attr = (Attr) counterAttr; String name = attr.getName(); String value = attr.getValue(); if (ATTR_NAME.equals(name)) { counter.setName(value); String name = attr.getName(); String value = attr.getValue(); if (ATTR_NAME.equals(name)) { objType.setName(value); String name = attr.getName(); String value = attr.getValue(); if (ATTR_NAME.equals(name)) { counter.setName(value);
protected static void parseBridges(SiteConfig site_config, Node root) throws Exception { NodeList children=root.getChildNodes(); if(children == null || children.getLength() == 0) return; for(int i=0; i < children.getLength(); i++) { Node node=children.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) continue; String node_name=node.getNodeName(); match(BRIDGE, node_name, true); NamedNodeMap attrs=node.getAttributes(); if(attrs == null || attrs.getLength() == 0) continue; Attr name_attr=(Attr)attrs.getNamedItem("name"); Attr config_attr=(Attr)attrs.getNamedItem("config"); String name=name_attr != null? name_attr.getValue() : null; String config=config_attr.getValue(); BridgeConfig bridge_config=new PropertiesBridgeConfig(name, config); site_config.addBridge(bridge_config); } }
trimEmptyTextNodes(actual); if (expected.getNodeType() != actual.getNodeType()) { throw new Exception("Different types of nodes: " + expected + " " + actual); if (!expectedElement.getLocalName().equals(actualElement.getLocalName())) { throw new Exception("Element names do not match: " + expectedElement.getLocalName() + " " + actualElement.getLocalName()); + countNonNamespaceAttributes(expectedAttrs) + " " + countNonNamespaceAttributes(actualAttrs)); for (int i = 0; i < expectedAttrs.getLength(); i++) { Attr expectedAttr = (Attr) expectedAttrs.item(i); if (expectedAttr.getName().startsWith("xmlns")) { continue; actualAttr = (Attr) actualAttrs.getNamedItem(expectedAttr.getName()); if (actualAttr == null) { throw new Exception(elementName + ": No attribute found:" + expectedAttr); if (!expectedAttr.getValue().equals(actualAttr.getValue())) { throw new Exception(elementName + ": Attribute values do not match: " + expectedAttr.getValue() + " " + actualAttr.getValue());
private void writeElement(Element element, Writer writer, int depth) throws IOException { for (int i = 0; i < depth; ++i) { writer.append(' '); } writer.append('<').append(element.getTagName()); NamedNodeMap attrs = element.getAttributes(); for (int i = 0, imax = attrs.getLength(); i < imax; ++i) { Attr attr = (Attr) attrs.item(i); writer.append(' ').append(attr.getName()).append("='").append(attr.getValue()).append("'"); } NodeList nodes = element.getChildNodes(); if (nodes.getLength() == 0) { // no children, so just close off the element and return writer.append("/>").append(lineSeparator); return; } writer.append('>').append(lineSeparator); for (int i = 0, imax = nodes.getLength(); i < imax; ++i) { Node n = nodes.item(i); if (n.getNodeType() == Node.ATTRIBUTE_NODE) { continue; } write(n, writer, depth + indent); } for (int i = 0; i < depth; ++i) { writer.append(' '); } writer.append("</").append(element.getTagName()).append('>').append(lineSeparator); }
private boolean updateApplicationAttribute( Element manifestElement, String attribute, String value, boolean dirty ) { NodeList appElements = manifestElement.getElementsByTagName( ELEM_APPLICATION ); // Update all application nodes. Not sure whether there will ever be // more than one. for ( int i = 0; i < appElements.getLength(); ++i ) { Node node = appElements.item( i ); getLog().info( "Testing if node " + node.getNodeName() + " is application" ); if ( node.getNodeType() == Node.ELEMENT_NODE ) { Element element = (Element) node; Attr labelAttrib = element.getAttributeNode( attribute ); if ( labelAttrib == null || !value.equals( labelAttrib.getValue() ) ) { getLog().info( "Setting " + attribute + " to " + value ); element.setAttribute( attribute, String.valueOf( value ) ); dirty = true; } } } return dirty; }
private ClusteringCacheManagerServiceConfigurationParser.ServerSideConfig processServerSideConfig(Node serverSideConfigElement) { ClusteringCacheManagerServiceConfigurationParser.ServerSideConfig serverSideConfig = new ClusteringCacheManagerServiceConfigurationParser.ServerSideConfig(); serverSideConfig.autoCreate = Boolean.parseBoolean(((Element)serverSideConfigElement).getAttribute("auto-create")); final NodeList serverSideNodes = serverSideConfigElement.getChildNodes(); for (int i = 0; i < serverSideNodes.getLength(); i++) { final Node item = serverSideNodes.item(i); if (Node.ELEMENT_NODE == item.getNodeType()) { String nodeLocalName = item.getLocalName(); if ("default-resource".equals(nodeLocalName)) { serverSideConfig.defaultServerResource = ((Element)item).getAttribute("from"); String poolName = sharedPoolElement.getAttribute("name"); // required Attr fromAttr = sharedPoolElement.getAttributeNode("from"); // optional String fromResource = (fromAttr == null ? null : fromAttr.getValue()); Attr unitAttr = sharedPoolElement.getAttributeNode("unit"); // optional - default 'B' String unit = (unitAttr == null ? "B" : unitAttr.getValue()); MemoryUnit memoryUnit = MemoryUnit.valueOf(unit.toUpperCase(Locale.ENGLISH));
String typeId = propertyElement.getAttribute(PropertyDescriptorField.TYPE.attributeName()); NamedNodeMap atts = propertyElement.getAttributes(); for (int i = 0; i < atts.getLength(); i++) { Attr a = (Attr) atts.item(i); values.put(PropertyDescriptorField.getConstant(a.getName()), a.getValue()); NodeList children = propertyElement.getElementsByTagName(DEFAULT_VALUE.attributeName()); if (children.getLength() == 1) { values.put(DEFAULT_VALUE, children.item(0).getTextContent()); } else { throw new IllegalArgumentException("No value defined!");
for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.item(i); if (!(node instanceof Element)) { continue; Node child = node.getFirstChild(); NamedNodeMap attrs = node.getAttributes(); int lastAttr = attrs.getLength() - 1; for (int j = lastAttr; j--> 0; ) { Attr attr = (Attr) attrs.item(j); attributes.put(attr.getNodeName(), attr.getNodeValue()); child = child.getNextSibling(); continue;
Attr a = (Attr)attributes.item(i); String name = a.getName(); receiver.startPrefixMapping( "", a.getValue() ); } else { String localName = a.getLocalName(); if(localName==null) { receiver.startPrefixMapping( localName, a.getValue() ); String uri = a.getNamespaceURI(); if(uri==null) uri=""; String local = a.getLocalName(); if(local==null) local = a.getName(); uri, local, a.getName(), "CDATA", a.getValue()); Attr a = (Attr)attributes.item(i); String name = a.getName(); if(name.startsWith("xmlns")) { if(name.length()==5) receiver.endPrefixMapping(""); else receiver.endPrefixMapping(a.getLocalName());
parent = ((org.w3c.dom.Node) target).getParentNode(); Document doc = builder.newDocument(); Element temp = doc.createElementNS(null, "temp"); temp.appendChild(doc.createTextNode((String) source)); nl = temp.getChildNodes(); } else if (source == null) { if (nl.getLength() == 0) { throw new RuntimeException("Nothing was selected by the from expression " + from + " on " + sourceExpr); for (int i = 0 ; i < nl.getLength(); i++) { if (nl.item(i) instanceof Attr) { targetElem = ((Attr) nl.item(i)).getValue(); } else if (nl.item(i) instanceof Text) { targetElem = ((Text) nl.item(i)).getWholeText(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.newDocument(); targetElem = doc.importNode(nl.item(i), true); org.w3c.dom.Node n = ((org.w3c.dom.Node) targetElem).getOwnerDocument().importNode(nl.item(i), true); if (n instanceof Attr) { ((Element) targetElem).setAttributeNode((Attr) n); } else { ((org.w3c.dom.Node) targetElem).appendChild(n);
@Override public void decorate(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, RedissonNamespaceParserSupport helper) { NodeList list = element.getElementsByTagNameNS( RedissonNamespaceParserSupport.REDISSON_NAMESPACE, RedissonNamespaceParserSupport.LOCAL_CACHED_MAP_OPTIONS_ELEMENT); Element options = null; String id; if (list.getLength() == 1) { options = (Element) list.item(0); id = invokeOptions(options, parserContext, helper); for (int i = 0; i < options.getAttributes().getLength(); i++) { Attr item = (Attr) options.getAttributes().item(i); if (helper.isEligibleAttribute(item) && !RedissonNamespaceParserSupport.TIME_TO_LIVE_UNIT_ATTRIBUTE .equals(item.getLocalName()) && !RedissonNamespaceParserSupport.MAX_IDLE_UNIT_ATTRIBUTE .equals(item.getLocalName())) { helper.invoker(id, helper.getName(item), new Object[]{item.getValue()}, parserContext);
return defVal; String sizeString = tmpEl.getAttribute("size"); NodeList nodes = tmpEl.getChildNodes(); List<String> strings = new ArrayList<String>(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (n instanceof Element && n.getNodeName().contains("String")) { strings.add(((Element) n).getAttributeNode("value").getValue());
private boolean updateProviderAuthorities( Element manifestElement ) NodeList appElems = manifestElement.getElementsByTagName( ELEM_APPLICATION ); for ( int i = 0; i < appElems.getLength(); ++ i ) Node node = appElems.item( i ); if ( node.getNodeType() == Node.ELEMENT_NODE ) NodeList providerElems = manifestElement.getElementsByTagName( ELEM_PROVIDER ); for ( int j = 0; j < providerElems.getLength(); ++ j ) Node providerNode = providerElems.item( j ); if ( providerNode.getNodeType() == Node.ELEMENT_NODE ) Attr providerName = providerElem.getAttributeNode( ATTR_NAME ); getLog().debug( "Checking provider " + providerName.getValue() ); if ( shouldPerformProviderUpdate( providerName ) ) String name = providerName.getValue(); String newAuthorities = parsedProviderAuthorities.getProperty( name ); getLog().info( "Updating provider " + name + " authorities attr to " + newAuthorities );
if (element.hasAttributes()) { NamedNodeMap attributes = element.getAttributes(); int attributesLength = attributes.getLength(); for (Node child = element.getFirstChild(); child!=null; child = child.getNextSibling()) { if (child.getNodeType() != Node.ELEMENT_NODE) { continue; Attr currentAttr = (Attr) attributes.item(i); if (!namespaceNs.equals(currentAttr.getNamespaceURI())) { continue; if (childElement.hasAttributeNS(namespaceNs, currentAttr.getLocalName())) { continue; childElement.setAttributeNS(namespaceNs, currentAttr.getName(), currentAttr.getNodeValue());
protected void handleParent(Element e, NameSpaceSymbTable ns) { if (!e.hasAttributes() && e.getNamespaceURI() == null) { return; NamedNodeMap attrs = e.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NName = attribute.getLocalName(); String NValue = attribute.getNodeValue(); if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI()) && (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue))) { ns.addMapping(NName, NValue, attribute); Name = XMLNS + ":" + NName; Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name); n.setValue(NValue); ns.addMapping(NName, NValue, n);