List of usage examples for org.xml.sax.helpers AttributesImpl removeAttribute
public void removeAttribute(int index)
From source file:org.apache.axis.encoding.ser.JAFDataHandlerSerializer.java
/** * Serialize a JAF DataHandler quantity. *//*from ww w .j av a2 s . co m*/ public void serialize(QName name, Attributes attributes, Object value, SerializationContext context) throws IOException { DataHandler dh = (DataHandler) value; //Add the attachment content to the message. Attachments attachments = context.getCurrentMessage().getAttachmentsImpl(); if (attachments == null) { // Attachments apparently aren't supported. // Instead of throwing NullPointerException like // we used to do, throw something meaningful. throw new IOException(Messages.getMessage("noAttachments")); } SOAPConstants soapConstants = context.getMessageContext().getSOAPConstants(); Part attachmentPart = attachments.createAttachmentPart(dh); AttributesImpl attrs = new AttributesImpl(); if (attributes != null && 0 < attributes.getLength()) attrs.setAttributes(attributes); //copy the existing ones. int typeIndex = -1; if ((typeIndex = attrs.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI, "type")) != -1) { //Found a xsi:type which should not be there for attachments. attrs.removeAttribute(typeIndex); } if (attachments.getSendType() == Attachments.SEND_TYPE_MTOM) { context.setWriteXMLType(null); context.startElement(name, attrs); AttributesImpl attrs2 = new AttributesImpl(); attrs2.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), "CDATA", attachmentPart.getContentIdRef()); context.startElement(new QName(Constants.URI_XOP_INCLUDE, Constants.ELEM_XOP_INCLUDE), attrs2); context.endElement(); context.endElement(); } else { boolean doTheDIME = false; if (attachments.getSendType() == Attachments.SEND_TYPE_DIME) doTheDIME = true; attrs.addAttribute("", soapConstants.getAttrHref(), soapConstants.getAttrHref(), "CDATA", doTheDIME ? attachmentPart.getContentId() : attachmentPart.getContentIdRef()); context.startElement(name, attrs); context.endElement(); //There is no data to so end the element. } }
From source file:org.apache.axis.message.MessageElement.java
/** * Set an attribute, adding the attribute if it isn't already present * in this element, and changing the value if it is. Passing null as the * value will cause any pre-existing attribute by this name to go away. *///from ww w .j a va2 s . c o m public void setAttribute(String namespace, String localName, String value) { AttributesImpl attributes = makeAttributesEditable(); int idx = attributes.getIndex(namespace, localName); if (idx > -1) { // Got it, so replace it's value. if (value != null) { attributes.setValue(idx, value); } else { attributes.removeAttribute(idx); } return; } addAttribute(namespace, localName, value); }
From source file:org.apache.axis.message.MessageElement.java
/** * remove an element/*from www . j a va 2 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.cocoon.template.script.Parser.java
public void startElement(String namespaceURI, String localName, String qname, Attributes attrs) throws SAXException { Event newEvent = null;//from w w w .j a va 2 s. c o m 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); }
From source file:org.apache.cocoon.transformation.JPathTransformer.java
/** * Helper method to check for the existance of an attribute named * jpath:action. If existing the string 'id' is replaced with the * continuation id.//from ww w.ja v a2 s. c om * * @param a an {@link AttributesImpl} instance */ private void checkJPathAction(final AttributesImpl a) { // check for jpath:action attribute int idx = a.getIndex(JPATH_ACTION); if (idx != -1 && JPATH_NAMESPACE_URI.equals(a.getURI(idx))) { if (getLogger().isDebugEnabled()) { getLogger().debug("found jpath:action, adjusting"); } String value = a.getValue(idx); // REVISIT(MC): support for continuation level String id = m_kont.getContinuation(0).getId(); a.removeAttribute(idx); a.addAttribute("", "action", "action", "CDATA", m_re.subst(value, id)); } }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Handle input elements that may have a "checked" attributes, * i.e. checkbox and radio.//w w w . j a v a2s. c om */ protected void startCheckableElement(String aName, String uri, String name, String raw, AttributesImpl attributes) throws SAXException { // @fixed and this.fixed already considered in startInputElement this.values = this.getValues(aName); String checked = attributes.getValue("checked"); String value = attributes.getValue("value"); boolean found = false; if (getLogger().isDebugEnabled()) getLogger().debug("startCheckableElement " + name + " attributes " + this.printAttributes(attributes)); if (this.values != null) { if (getLogger().isDebugEnabled()) getLogger().debug("replacing"); for (int i = 0; i < this.values.length; i++) { if (this.values[i].equals(value)) { found = true; if (checked == null) { attributes.addAttribute("", "checked", "checked", "CDATA", ""); } break; } } if (!found && checked != null) { attributes.removeAttribute(attributes.getIndex("checked")); } } this.relayStartElement(uri, name, raw, attributes); }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Handle option elements. Uses instance variables set up by * startSelectElement. Relies on option having a "value" * attribute, i.e. does not check following characters if "value" * is not present.//from w w w. j a v a 2 s. c o m */ protected void startOptionElement(String uri, String name, String raw, Attributes attr) throws SAXException { // add @selected if @value in request.getParameterValues(@name) if (getLogger().isDebugEnabled()) getLogger().debug("startOptionElement " + name + " attributes " + this.printAttributes(attr)); if (this.values == null || this.fixed) { this.relayStartElement(uri, name, raw, attr); } else { if (getLogger().isDebugEnabled()) getLogger().debug("replacing"); AttributesImpl attributes = null; if (attr instanceof AttributesImpl) { attributes = (AttributesImpl) attr; } else { attributes = new AttributesImpl(attr); } String selected = attributes.getValue("selected"); String value = attributes.getValue("value"); boolean found = false; for (int i = 0; i < this.values.length; i++) { if (this.values[i].equals(value)) { found = true; if (selected == null) { attributes.addAttribute("", "selected", "selected", "CDATA", ""); } break; } } if (!found && selected != null) { attributes.removeAttribute(attributes.getIndex("selected")); } this.relayStartElement(uri, name, raw, attributes); } }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Handle error elements. If validation results are available, * compares validation result for parameter with the same name as * the "name" attribute with the result names is "when" and * "when-ge". Drops element and all nested events when error * condition is not met./* w ww.j av a 2 s. c o m*/ */ protected void startErrorElement(String uri, String name, String raw, Attributes attr) throws SAXException { if (getLogger().isDebugEnabled()) getLogger().debug("startErrorElement " + name + " attributes " + this.printAttributes(attr)); if (this.ignoreValidation) { this.relayStartElement(uri, name, raw, attr); } else if (this.validationResults == null || this.fixed) { this.relayStartElement(true, false, uri, name, raw, attr); } else { String aName = attr.getValue("name"); if (aName == null) { this.relayStartElement(uri, name, raw, attr); } else { ValidatorActionResult validation = FormValidatorHelper.getParamResult(this.objectModel, aName); String when = attr.getValue("when"); String when_ge = attr.getValue("when-ge"); if ((when != null && when.equals(validatorResults.get(validation))) || (when_ge != null && validation.ge((ValidatorActionResult) validatorResultLabel .get(when_ge, ValidatorActionResult.MAXERROR)))) { AttributesImpl attributes = null; if (attr instanceof AttributesImpl) { attributes = (AttributesImpl) attr; } else { attributes = new AttributesImpl(attr); } // remove attributes not meant for client attributes.removeAttribute(attributes.getIndex("name")); if (when != null) attributes.removeAttribute(attributes.getIndex("when")); if (when_ge != null) attributes.removeAttribute(attributes.getIndex("when-ge")); this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes)); } else { this.relayStartElement(true, true, uri, name, raw, attr); } } } }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Start processing a form element. Sets protection indicator if attribute * "fixed" is present and either "true" or "yes". Removes attribute "fixed" * if present./*from w w w . j av a2s. c o m*/ * @param uri The namespace of the element. * @param name The local name of the element. * @param raw The qualified name of the element. * @param attr The attributes of the element. */ protected void startFormElement(String uri, String name, String raw, Attributes attr) throws SAXException { String fixed = attr.getValue(this.fixedName); if (this.useFormName) { this.formName = attr.getValue("name"); } if (fixed == null) { this.relayStartElement(uri, name, raw, attr); } else { if (!this.fixed && BooleanUtils.toBoolean(fixed)) { this.fixed = true; } // remove attributes not meant for client AttributesImpl attributes = null; if (attr instanceof AttributesImpl) { attributes = (AttributesImpl) attr; } else { attributes = new AttributesImpl(attr); } attributes.removeAttribute(attributes.getIndex(this.fixedName)); this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes)); } }
From source file:org.apache.cocoon.woody.transformation.WidgetReplacingPipe.java
public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { elementNestingCounter++;// w w w . j a va 2s . co m if (inWidgetElement) { if (elementNestingCounter == widgetElementNesting + 1 && Constants.WI_NS.equals(namespaceURI) && STYLING_EL.equals(localName)) { gotStylingElement = true; } saxBuffer.startElement(namespaceURI, localName, qName, attributes); } else if (Constants.WT_NS.equals(namespaceURI)) { if (localName.equals(WIDGET) || localName.equals(REPEATER_WIDGET)) { checkContextWidgetAvailable(qName); inWidgetElement = true; widgetElementNesting = elementNestingCounter; gotStylingElement = false; saxBuffer = new SaxBuffer(); // retrieve widget here, but its XML will only be streamed in the endElement call widget = getWidget(attributes); repeaterWidget = localName.equals(REPEATER_WIDGET); if (repeaterWidget && !(widget instanceof Repeater)) { throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-widget\" can only be used for repeater widgets."); } } else if (localName.equals(WIDGET_LABEL)) { checkContextWidgetAvailable(qName); Widget widget = getWidget(attributes); widget.generateLabel(contentHandler); } else if (localName.equals(REPEATER_WIDGET_LABEL)) { checkContextWidgetAvailable(qName); Widget widget = getWidget(attributes); if (!(widget instanceof Repeater)) { throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-widget-label\" can only be used for repeater widgets."); } String widgetId = attributes.getValue("widget-id"); if (widgetId == null || widgetId.length() == 0) { throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-widget-label\" requires a \"widget-id\" attribute."); } ((Repeater) widget).generateWidgetLabel(widgetId, contentHandler); } else if (localName.equals(REPEATER_SIZE)) { checkContextWidgetAvailable(qName); Widget widget = getWidget(attributes); if (!(widget instanceof Repeater)) throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-size\" can only be used for repeater widgets."); contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS); ((Repeater) widget).generateSize(contentHandler); contentHandler.endPrefixMapping(Constants.WI_PREFIX); } else if (localName.equals(FORM_TEMPLATE_EL)) { if (contextWidget != null) { throw new SAXException("Detected nested wt:form-template elements, this is not allowed."); } contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS); // ====> Retrieve the form // first look for the form using the location attribute, if any String formJXPath = attributes.getValue(LOCATION); if (formJXPath != null) { // remove the location attribute AttributesImpl attrsCopy = new AttributesImpl(attributes); attrsCopy.removeAttribute(attributes.getIndex(LOCATION)); attributes = attrsCopy; } contextWidget = pipeContext.findForm(formJXPath); // ====> Determine the Locale //TODO pull this locale stuff also up in the Config object? String localeAttr = attributes.getValue("locale"); if (localeAttr != null) { // first use value of locale attribute if any localeAttr = pipeContext.translateText(localeAttr); pipeContext.setLocale(I18nUtils.parseLocale(localeAttr)); } else if (pipeContext.getLocaleParameter() != null) { // then use locale specified as transformer parameter, if any pipeContext.setLocale(pipeContext.getLocaleParameter()); } else { // use locale specified in bizdata supplied for form Object locale = null; try { locale = pipeContext.evaluateExpression("/locale"); } catch (JXPathException e) { } if (locale != null) { pipeContext.setLocale((Locale) locale); } else { // final solution: use locale defined in the server machine pipeContext.setLocale(Locale.getDefault()); } } String[] namesToTranslate = { "action" }; Attributes transAtts = translateAttributes(attributes, namesToTranslate); contentHandler.startElement(Constants.WI_NS, FORM_TEMPLATE_EL, Constants.WI_PREFIX_COLON + FORM_TEMPLATE_EL, transAtts); } else if (localName.equals(CONTINUATION_ID)) { // Insert the continuation id // FIXME(SW) we could avoid costly JXPath evaluation if we had the objectmodel here. Object idObj = pipeContext.evaluateExpression("$continuation/id"); if (idObj == null) { throw new SAXException("No continuation found"); } String id = idObj.toString(); contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS); contentHandler.startElement(Constants.WI_NS, CONTINUATION_ID, Constants.WI_PREFIX_COLON + CONTINUATION_ID, attributes); contentHandler.characters(id.toCharArray(), 0, id.length()); contentHandler.endElement(Constants.WI_NS, CONTINUATION_ID, Constants.WI_PREFIX_COLON + CONTINUATION_ID); contentHandler.endPrefixMapping(Constants.WI_PREFIX); } else { throw new SAXException("WoodyTemplateTransformer: Unsupported element: " + localName); } } else { super.startElement(namespaceURI, localName, qName, attributes); } }