List of usage examples for org.xml.sax.helpers AttributesImpl getLength
public int getLength()
From source file:com.adobe.acs.commons.rewriter.impl.ResourceResolverMapTransformerFactory.java
protected Attributes rebuildAttributes(final SlingHttpServletRequest slingRequest, final String elementName, final Attributes attrs) { if (slingRequest == null || !attributes.containsKey(elementName)) { // element is not defined as a candidate to rewrite return attrs; }/*from ww w.j a v a2 s . co m*/ final String[] modifiableAttributes = attributes.get(elementName); // clone the attributes final AttributesImpl newAttrs = new AttributesImpl(attrs); final int len = newAttrs.getLength(); for (int i = 0; i < len; i++) { final String attrName = newAttrs.getLocalName(i); if (ArrayUtils.contains(modifiableAttributes, attrName)) { final String attrValue = newAttrs.getValue(i); if (StringUtils.startsWith(attrValue, "/") && !StringUtils.startsWith(attrValue, "//")) { // Only map absolute paths (starting w /), avoid relative-scheme URLs starting w // newAttrs.setValue(i, slingRequest.getResourceResolver().map(slingRequest, attrValue)); } } } return newAttrs; }
From source file:com.adobe.acs.commons.rewriter.impl.StaticReferenceRewriteTransformerFactory.java
@SuppressWarnings("squid:S3776") private Attributes rebuildAttributes(String elementName, Attributes attrs, String[] modifyableAttributes) { // clone the attributes final AttributesImpl newAttrs = new AttributesImpl(attrs); for (int i = 0; i < newAttrs.getLength(); i++) { final String attrName = newAttrs.getLocalName(i); if (ArrayUtils.contains(modifyableAttributes, attrName)) { final String attrValue = newAttrs.getValue(i); String key = elementName + ":" + attrName; if (matchingPatterns.containsKey(key)) { // Find value based on matching pattern Pattern matchingPattern = matchingPatterns.get(key); try { newAttrs.setValue(i, handleMatchingPatternAttribute(matchingPattern, attrValue)); } catch (Exception e) { log.error("Could not perform replacement based on matching pattern", e); }/*from ww w . j av a 2 s .c o m*/ } else { for (String prefix : prefixes) { if (attrValue.startsWith(prefix)) { newAttrs.setValue(i, prependHostName(attrValue)); } } } } } return newAttrs; }
From source file:Writer.java
/** Returns a sorted list of attributes. */ protected Attributes sortAttributes(Attributes attrs) { AttributesImpl attributes = new AttributesImpl(); int len = (attrs != null) ? attrs.getLength() : 0; for (int i = 0; i < len; i++) { String name = attrs.getQName(i); int count = attributes.getLength(); int j = 0; while (j < count) { if (name.compareTo(attributes.getQName(j)) < 0) { break; }//from w w w. j av a2 s . c o m j++; } attributes.insertAttributeAt(j, name, attrs.getType(i), attrs.getValue(i)); } return attributes; }
From source file:nonjsp.application.XmlXulRuleSet.java
/** * This method is invoked when the beginning of the matched * Xml element is encountered ;/*from w w w. j av a 2s.c o m*/ * * @param attributes The element's attribute list */ public void begin(Attributes attributes) throws Exception { UIComponent uic = (UIComponent) digester.peek(); if (log.isTraceEnabled()) { log.trace("component: " + uic.getId()); } AttributesImpl attrs = new AttributesImpl(attributes); for (int i = 0; i < attrs.getLength(); i++) { String qName = attributes.getQName(i); attrs.setLocalName(i, qName); attrs.setValue(i, attributes.getValue(qName)); if (log.isTraceEnabled()) { log.trace("ComponentRule: qName: " + qName + " value: " + attributes.getValue(qName)); } } bc.applyAttributesToComponentInstance(uic, attrs); if (root == null) { root = (UIComponent) digester.peek(digester.getCount() - 1); } root.getChildren().add(uic); //If component is a form, make it the root so that children will be //added to it if (uic instanceof UIForm) { root = uic; } }
From source file:nonjsp.application.XmlXulRuleSet.java
/** * This method is invoked when the beginning of the matched * Xml element is encountered (in this case "property"); * * @param attributes The element's attribute list *///from w w w.java2 s . c o m public void begin(Attributes attributes) throws Exception { UIComponent uic = (UIComponent) digester.peek(); AttributesImpl attrs = new AttributesImpl(attributes); for (int i = 0; i < attrs.getLength(); i++) { String qName = attributes.getQName(i); attrs.setLocalName(i, qName); attrs.setValue(i, attributes.getValue(qName)); } bc.handleNestedComponentTag(uic, "SelectOne_Option", attrs); }
From source file:org.apache.axis.message.MessageElement.java
/** * remove an element/*from www. j a v a2 s . c om*/ * @param attrName name of the element * @return true if the attribute was found and removed. * @see javax.xml.soap.SOAPElement#removeAttribute(javax.xml.soap.Name) */ public boolean removeAttribute(Name attrName) { AttributesImpl attributes = makeAttributesEditable(); boolean removed = false; for (int i = 0; i < attributes.getLength() && !removed; i++) { if (attributes.getURI(i).equals(attrName.getURI()) && attributes.getLocalName(i).equals(attrName.getLocalName())) { attributes.removeAttribute(i); removed = true; } } return removed; }
From source file:org.apache.axis.message.MessageElement.java
/** * remove a named attribute./*from w w w. ja va 2 s. co m*/ * @see org.w3c.dom.Element#removeAttribute(String) * @param attrName name of the attributes * @throws DOMException */ public void removeAttribute(String attrName) throws DOMException { AttributesImpl impl = (AttributesImpl) attributes; int index = impl.getIndex(attrName); if (index >= 0) { AttributesImpl newAttrs = new AttributesImpl(); // copy except the removed attribute for (int i = 0; i < impl.getLength(); i++) { // shift after removal if (i != index) { String uri = impl.getURI(i); String local = impl.getLocalName(i); String qname = impl.getQName(i); String type = impl.getType(i); String value = impl.getValue(i); newAttrs.addAttribute(uri, local, qname, type, value); } } // replace it attributes = newAttrs; } }
From source file:org.apache.axis.message.NodeImpl.java
/** * The internal representation of Attributes cannot help being changed * It is because Attribute is not immutible Type, so if we keep out value and * just return it in another form, the application may chnae it, which we cannot * detect without some kind back track method (call back notifying the chnage.) * I am not sure which approach is better. *//* w w w . ja va 2 s .co m*/ protected NamedNodeMap convertAttrSAXtoDOM(Attributes saxAttr) { try { org.w3c.dom.Document doc = org.apache.axis.utils.XMLUtils.newDocument(); AttributesImpl saxAttrs = (AttributesImpl) saxAttr; NamedNodeMap domAttributes = new NamedNodeMapImpl(); for (int i = 0; i < saxAttrs.getLength(); i++) { String uri = saxAttrs.getURI(i); String qname = saxAttrs.getQName(i); String value = saxAttrs.getValue(i); if (uri != null && uri.trim().length() > 0) { // filterring out the tricky method to differentiate the null namespace // -ware case if (NULL_URI_NAME.equals(uri)) { uri = null; } Attr attr = doc.createAttributeNS(uri, qname); attr.setValue(value); domAttributes.setNamedItemNS(attr); } else { Attr attr = doc.createAttribute(qname); attr.setValue(value); domAttributes.setNamedItem(attr); } } return domAttributes; } catch (Exception ex) { log.error(Messages.getMessage("saxToDomFailed00"), ex); return null; } }
From source file:org.apache.catalina.util.CatalinaDigester.java
/** * Returns an attributes list which contains all the attributes * passed in, with any text of form "${xxx}" in an attribute value * replaced by the appropriate value from the system property. *//* w ww . j ava 2 s . c o m*/ private Attributes updateAttributes(Attributes list) { if (list.getLength() == 0) { return list; } AttributesImpl newAttrs = new AttributesImpl(list); int nAttributes = newAttrs.getLength(); for (int i = 0; i < nAttributes; ++i) { String value = newAttrs.getValue(i); try { String newValue = IntrospectionUtils.replaceProperties(value, null, source); if (value != newValue) { newAttrs.setValue(i, newValue); } } catch (Exception e) { // ignore - let the attribute have its original value } } return newAttrs; }
From source file:org.apache.cocoon.template.script.Parser.java
public void startElement(String namespaceURI, String localName, String qname, Attributes attrs) throws SAXException { Event newEvent = null;/*w ww . j a va2 s .c om*/ AttributesImpl elementAttributes = new AttributesImpl(attrs); int attributeCount = elementAttributes.getLength(); for (int i = 0; i < attributeCount; i++) { String attributeURI = elementAttributes.getURI(i); if (StringUtils.equals(attributeURI, JXTemplateGenerator.NS)) { // TODO: template properties should be allowed only on template // root getStartEvent().getTemplateProperties().put(elementAttributes.getLocalName(i), this.parsingContext .getStringTemplateParser().compileExpr(elementAttributes.getValue(i), null, locator)); elementAttributes.removeAttribute(i--); } } StartElement startElement = new StartElement(this.parsingContext, locator, namespaceURI, localName, qname, elementAttributes); InstructionFactory instructionFactory = this.parsingContext.getInstructionFactory(); if (instructionFactory.isInstruction(startElement)) newEvent = instructionFactory.createInstruction(this.parsingContext, startElement, attrs, stack); else newEvent = startElement; stack.push(newEvent); addEvent(newEvent); }