public void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); if (isEligibleAttribute(attribute)) { String propertyName = attribute.getLocalName().endsWith(REF_SUFFIX) ? attribute.getLocalName() .substring(0, attribute.getLocalName() .length() - REF_SUFFIX.length()) : attribute.getLocalName(); propertyName = Conventions .attributeNameToPropertyName(propertyName); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from" + " 'extractPropertyName(String)': cannot be" + " null or empty."); if (attribute.getLocalName().endsWith(REF_SUFFIX)) { builder.addPropertyReference(propertyName, attribute.getValue()); } else { builder.addPropertyValue(propertyName, attribute.getValue()); } } } }
String namespaceURI0 = attr0.getNamespaceURI(); String namespaceURI1 = attr1.getNamespaceURI(); if (isNamespaceAttr1) { String localname0 = attr0.getLocalName(); String localname1 = attr1.getLocalName(); return attr0.getLocalName().compareTo(attr1.getLocalName());
/** * 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())); }
while (it.hasNext() && successiveOmitted) { Attr n = it.next(); if (n.getLocalName().equals("base") && !e.rendered) { baseAttrs.add(n); } else if (!loa.containsKey(n.getName())) { while (it.hasNext()) { Attr n = it.next(); if (n.getLocalName().equals("base")) { base = n.getValue(); baseAttr = n; break; Attr n = it.next(); if (base == null) { base = n.getValue(); baseAttr = n; } else { try { base = joinURI(n.getValue(), base); } catch (URISyntaxException ue) { if (log.isDebugEnabled()) {
public void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); if (isEligibleAttribute(attribute)) { String propertyName = attribute.getLocalName().endsWith(REF_SUFFIX) ? attribute.getLocalName() .substring(0, attribute.getLocalName() .length() - REF_SUFFIX.length()) : attribute.getLocalName(); propertyName = Conventions .attributeNameToPropertyName(propertyName); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from" + " 'extractPropertyName(String)': cannot be" + " null or empty."); if (attribute.getLocalName().endsWith(REF_SUFFIX)) { builder.addPropertyReference(propertyName, attribute.getValue()); } else { builder.addPropertyValue(propertyName, attribute.getValue()); } } } }
protected Attribute createAttribute(org.w3c.dom.Attr newAttr) { QName qname = null; String name = newAttr.getLocalName(); if (name != null) { String prefix = newAttr.getPrefix(); String uri = newAttr.getNamespaceURI(); qname = getDocumentFactory().createQName(name, prefix, uri); } else { name = newAttr.getName(); qname = getDocumentFactory().createQName(name); } return new DOMAttribute(qname, newAttr.getValue()); }
private static void checkNamespaceDeclaration(Attr attr, Class<? extends AbstractStructuredType> clz) throws XmpParsingException { String prefix = attr.getLocalName(); String namespace = attr.getValue(); String cprefix = clz.getAnnotation(StructuredType.class).preferedPrefix(); String cnamespace = clz.getAnnotation(StructuredType.class).namespace(); // check extension if (cprefix.equals(prefix) && !cnamespace.equals(namespace)) { throw new XmpParsingException(ErrorType.InvalidPdfaSchema, "Invalid PDF/A namespace definition"); } if (cnamespace.equals(namespace) && !cprefix.equals(prefix)) { throw new XmpParsingException(ErrorType.InvalidPdfaSchema, "Invalid PDF/A namespace definition"); } }
public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { AttrImpl newAttrImpl = (AttrImpl) newAttr; if (newAttrImpl.document != this.document) { throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null); } if (newAttrImpl.getOwnerElement() != null) { throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, null); } AttrImpl oldAttrImpl = null; int i = indexOfAttributeNS(newAttr.getNamespaceURI(), newAttr.getLocalName()); if (i != -1) { oldAttrImpl = attributes.get(i); attributes.remove(i); } attributes.add(newAttrImpl); newAttrImpl.ownerElement = this; return oldAttrImpl; }
/** * Parse the supplied {@link Element} and populate the supplied * {@link BeanDefinitionBuilder} as required. * <p>This implementation maps any attributes present on the * supplied element to {@link org.springframework.beans.PropertyValue} * instances, and * {@link BeanDefinitionBuilder#addPropertyValue(String, Object) adds them} * to the * {@link org.springframework.beans.factory.config.BeanDefinition builder}. * <p>The {@link #extractPropertyName(String)} method is used to * reconcile the name of an attribute with the name of a JavaBean * property. * @param element the XML element being parsed * @param builder used to define the {@code BeanDefinition} * @see #extractPropertyName(String) */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); if (isEligibleAttribute(attribute, parserContext)) { String propertyName = extractPropertyName(attribute.getLocalName()); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); builder.addPropertyValue(propertyName, attribute.getValue()); } } postProcess(builder, element); }
public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr newAttr) throws DOMException { Attribute attribute = attribute(newAttr.getNamespaceURI(), newAttr .getLocalName()); if (attribute != null) { attribute.setValue(newAttr.getValue()); } else { attribute = createAttribute(newAttr); add(attribute); } return DOMNodeHelper.asDOMAttr(attribute); }
protected Attribute attribute(org.w3c.dom.Attr attr) { return attribute(DOCUMENT_FACTORY.createQName(attr.getLocalName(), attr .getPrefix(), attr.getNamespaceURI())); }
public void serializeAttributes(Object element, XMLSerializer target) throws SAXException { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); // work defensively String uri = a.getNamespaceURI(); if(uri==null) uri=""; String local = a.getLocalName(); String name = a.getName(); if(local==null) local = name; if (uri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE) && ("nil".equals(local))) { isNilIncluded = true; } if(name.startsWith("xmlns")) continue;// DOM reports ns decls as attributes target.attribute(uri,local,a.getValue()); } }
private void parseDescriptionRootAttr(XMPMetadata xmp, Element description, Attr attr, TypeMapping tm) throws XmpSchemaException, XmpParsingException String namespace = attr.getNamespaceURI(); XMPSchema schema = xmp.getSchema(namespace); if (schema == null && tm.getSchemaFactory(namespace) != null) new QName(attr.getNamespaceURI(), attr.getLocalName())); attr.getLocalName(), attr.getValue(), type.type()); container.addProperty(sp); e.getMessage() + " in " + schema.getPrefix() + ":" + attr.getLocalName(), e);
private void addNamespaces(Node element) { if (element.getParentNode() != null) { addNamespaces(element.getParentNode()); } if (element instanceof Element) { Element el = (Element)element; NamedNodeMap map = el.getAttributes(); for (int x = 0; x < map.getLength(); x++) { Attr attr = (Attr)map.item(x); if ("xmlns".equals(attr.getPrefix())) { namespaceMap.put(attr.getLocalName(), attr.getValue()); } } } } }
/** * {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { if (attribute.getLocalName().equals(LangBearing.XML_LANG_ATTR_LOCAL_NAME) && SAMLConstants.XML_NS.equals(attribute.getNamespaceURI())) { Keywords keywords = (Keywords) samlObject; keywords.setXMLLang(attribute.getValue()); } }
public void run() { Set<String> declaredPrefixes = new HashSet<String>(); for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) { NamedNodeMap atts = n.getAttributes(); if(atts==null) continue; // broken DOM. but be graceful. for( int i=0; i<atts.getLength(); i++ ) { Attr a = (Attr)atts.item(i); String nsUri = a.getNamespaceURI(); if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) continue; // not a namespace declaration String prefix = a.getLocalName(); if(prefix==null) continue; // broken DOM. skip to be safe if(prefix.equals("xmlns")) { prefix = ""; } String value = a.getValue(); if(value==null) continue; // broken DOM. skip to be safe if(declaredPrefixes.add(prefix)) { serializer.addInscopeBinding(value,prefix); } } } } }
/** * {@inheritDoc} */ @Override protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { if (attribute.getLocalName().equals(LangBearing.XML_LANG_ATTR_LOCAL_NAME) && XMLConstants.XML_NS.equals(attribute.getNamespaceURI())) { Keywords keywords = (Keywords) samlObject; keywords.setXMLLang(attribute.getValue()); } }
/** * Parse the supplied {@link Element} and populate the supplied * {@link BeanDefinitionBuilder} as required. * <p>This implementation maps any attributes present on the * supplied element to {@link org.springframework.beans.PropertyValue} * instances, and * {@link BeanDefinitionBuilder#addPropertyValue(String, Object) adds them} * to the * {@link org.springframework.beans.factory.config.BeanDefinition builder}. * <p>The {@link #extractPropertyName(String)} method is used to * reconcile the name of an attribute with the name of a JavaBean * property. * @param element the XML element being parsed * @param builder used to define the {@code BeanDefinition} * @see #extractPropertyName(String) */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); if (isEligibleAttribute(attribute, parserContext)) { String propertyName = extractPropertyName(attribute.getLocalName()); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); builder.addPropertyValue(propertyName, attribute.getValue()); } } postProcess(builder, element); }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { Logo logo = (Logo) samlObject; if (attribute.getLocalName().equals(LangBearing.XML_LANG_ATTR_LOCAL_NAME) && SAMLConstants.XML_NS.equals(attribute.getNamespaceURI())) { logo.setXMLLang(attribute.getValue()); } else if (attribute.getLocalName().equals(Logo.HEIGHT_ATTR_NAME)) { logo.setHeight(Integer.valueOf(attribute.getValue())); } else if (attribute.getLocalName().equals(Logo.WIDTH_ATTR_NAME)) { logo.setWidth(Integer.valueOf(attribute.getValue())); } }
public void serializeURIs(Object element, XMLSerializer target) { NamedNodeMap al = ((Element)element).getAttributes(); int len = al.getLength(); NamespaceContext2 context = target.getNamespaceContext(); for( int i=0; i<len; i++ ) { Attr a = (Attr)al.item(i); if ("xmlns".equals(a.getPrefix())) { context.force(a.getValue(), a.getLocalName()); continue; } if ("xmlns".equals(a.getName())) { if (element instanceof org.w3c.dom.Element) { context.declareNamespace(a.getValue(), null, false); continue; } else { context.force(a.getValue(), ""); continue; } } String nsUri = a.getNamespaceURI(); if(nsUri!=null && nsUri.length()>0) context.declareNamespace( nsUri, a.getPrefix(), true ); } }