List of usage examples for org.xml.sax.helpers AttributesImpl getValue
public String getValue(String qName)
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 .ja v a 2 s. c o m */ 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 input elements that may don't have a "checked" * attributes, e.g. text, password, button. *///from w ww .ja v a 2 s . c o m protected void startNonCheckableElement(String aName, String uri, String name, String raw, AttributesImpl attributes) throws SAXException { // @fixed and this.fixed already considered in startInputElement Object fValue = this.getNextValue(aName); String value = attributes.getValue("value"); if (getLogger().isDebugEnabled()) getLogger() .debug("startNonCheckableElement " + name + " attributes " + this.printAttributes(attributes)); if (fValue != null) { if (getLogger().isDebugEnabled()) getLogger().debug("replacing"); if (value != null) { attributes.setValue(attributes.getIndex("value"), String.valueOf(fValue)); } else { attributes.addAttribute("", "value", "value", "CDATA", String.valueOf(fValue)); } } this.relayStartElement(uri, name, raw, attributes); }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Handle input elements. Calls startCheckableElement or * startNonCheckableElement.//from www .j a v a 2 s . c o m */ protected void startInputElement(String uri, String name, String raw, Attributes attr) throws SAXException { // @value = request.getParameterValues(@name) String aName = getName(attr.getValue("name")); String fixed = attr.getValue(this.fixedName); if (getLogger().isDebugEnabled()) getLogger().debug("startInputElement " + name + " attributes " + this.printAttributes(attr)); if (aName == null || this.fixed || (fixed != null && BooleanUtils.toBoolean(fixed))) { this.relayStartElement(uri, name, raw, attr); } else { if (getLogger().isDebugEnabled()) getLogger().debug("replacing"); attr = this.normalizeAttributes(attr); AttributesImpl attributes = null; if (attr instanceof AttributesImpl) { attributes = (AttributesImpl) attr; } else { attributes = new AttributesImpl(attr); } String type = attributes.getValue("type"); switch (((Integer) inputTypes.get(type, defaultType)).intValue()) { case TYPE_CHECKBOX: case TYPE_RADIO: this.startCheckableElement(aName, uri, name, raw, attributes); break; case TYPE_DEFAULT: this.startNonCheckableElement(aName, uri, name, raw, attributes); break; } this.values = null; } }
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 a2s . c om*/ */ 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.woody.transformation.EffectWidgetReplacingPipe.java
private Attributes translateAttributes(Attributes attributes, String[] names) { AttributesImpl newAtts = new AttributesImpl(attributes); if (names != null) { for (int i = 0; i < names.length; i++) { String name = names[i]; int position = newAtts.getIndex(name); String newValue = pipeContext.translateText(newAtts.getValue(position)); newAtts.setValue(position, newValue); }/*w w w . j av a 2 s . co m*/ } return newAtts; }
From source file:org.apache.slide.webdav.event.NotificationTrigger.java
private void loadSubscribers() { if (filename != null) { synchronized (subscribers) { File file = new File(filename); if (file.exists()) { try { FileInputStream inputStream = new FileInputStream(filename); SimpleImporter importer = new SimpleImporter(); importer.addSimpleImportHandler(new DefaultSimpleImportHandler() { String callback, notificationType, uri; int depth, notificationDelay, subscriptionLifetime, id; List events = new ArrayList(); public void startElement(SimplePath path, String name, AttributesImpl attributes, String leadingCDdata) { if (path.matches(E_SUBSCRIPTION)) { id = ConversionHelpers.getInt(attributes.getValue(A_ID)); } else if (path.matches(E_URI)) { uri = leadingCDdata; } else if (path.matches(E_DEPTH)) { depth = Integer.valueOf(leadingCDdata).intValue(); } else if (path.matches(E_CALLBACK)) { callback = leadingCDdata; } else if (path.matches(E_NOTIFICATION_DELAY)) { notificationDelay = Integer.valueOf(leadingCDdata).intValue(); } else if (path.matches(E_NOTIFICATION_TYPE)) { notificationType = leadingCDdata; } else if (path.matches(E_SUBSCRIPTION_END)) { subscriptionLifetime = (int) (Long.valueOf(leadingCDdata).longValue() - System.currentTimeMillis()); }/*from w ww . j a v a 2 s .c o m*/ } public void endElement(SimplePath path, String name) { if (path.matches(E_SUBSCRIPTION)) { Subscriber subscriber = new Subscriber(uri, callback, notificationType, notificationDelay, subscriptionLifetime, depth); subscribers.add(subscriber); refreshSubscriber(subscriber, false); } } }); importer.parse(new InputSource(inputStream)); } catch (Exception e) { Domain.log("Exception while restoring subscriptions. Skipping..."); } } } } }
From source file:org.apache.tika.gui.TikaGUI.java
/** * Creates and returns a content handler that turns XHTML input to * simplified HTML output that can be correctly parsed and displayed * by {@link JEditorPane}./* w ww . j a v a2 s. c o m*/ * <p> * The returned content handler is set to output <code>html</code> * to the given writer. The XHTML namespace is removed from the output * to prevent the serializer from using the <tag/> empty element * syntax that causes extra ">" characters to be displayed. * The <head> tags are dropped to prevent the serializer from * generating a <META> content type tag that makes * {@link JEditorPane} fail thinking that the document character set * is inconsistent. * <p> * Additionally, it will use ImageSavingParser to re-write embedded:(image) * image links to be file:///(temporary file) so that they can be loaded. * * @param writer output writer * @return HTML content handler * @throws TransformerConfigurationException if an error occurs */ private ContentHandler getHtmlHandler(Writer writer) throws TransformerConfigurationException { SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = factory.newTransformerHandler(); handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html"); handler.setResult(new StreamResult(writer)); return new ContentHandlerDecorator(handler) { @Override public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException { if (XHTMLContentHandler.XHTML.equals(uri)) { uri = null; } if (!"head".equals(localName)) { if ("img".equals(localName)) { AttributesImpl newAttrs; if (atts instanceof AttributesImpl) { newAttrs = (AttributesImpl) atts; } else { newAttrs = new AttributesImpl(atts); } for (int i = 0; i < newAttrs.getLength(); i++) { if ("src".equals(newAttrs.getLocalName(i))) { String src = newAttrs.getValue(i); if (src.startsWith("embedded:")) { String filename = src.substring(src.indexOf(':') + 1); try { File img = imageParser.requestSave(filename); String newSrc = img.toURI().toString(); newAttrs.setValue(i, newSrc); } catch (IOException e) { System.err.println("Error creating temp image file " + filename); // The html viewer will show a broken image too to alert them } } } } super.startElement(uri, localName, name, newAttrs); } else { super.startElement(uri, localName, name, atts); } } } @Override public void endElement(String uri, String localName, String name) throws SAXException { if (XHTMLContentHandler.XHTML.equals(uri)) { uri = null; } if (!"head".equals(localName)) { super.endElement(uri, localName, name); } } @Override public void startPrefixMapping(String prefix, String uri) { } @Override public void endPrefixMapping(String prefix) { } }; }
From source file:org.betaconceptframework.astroboa.engine.jcr.io.Serializer.java
public void openEntity(String elementQName, AttributesImpl atts) throws Exception { if (rootElementAttributes != null) { for (int i = 0; i < atts.getLength(); i++) { IOUtils.addAttribute(rootElementAttributes, atts.getLocalName(i), atts.getValue(i)); }// www .j a v a2 s . c o m exportContentHandler.startElement(elementQName, rootElementAttributes); rootElementAttributes = null; } else { exportContentHandler.startElement(elementQName, atts); } }
From source file:org.orbeon.oxf.xforms.processor.handlers.xhtml.XFormsBaseHandlerXHTML.java
protected void handleLabelHintHelpAlert(LHHAAnalysis lhhaAnalysis, String targetControlEffectiveId, String forEffectiveId, XFormsBaseHandler.LHHAC lhhaType, XFormsControl control, boolean isTemplate, boolean isExternal) throws SAXException { final AttributesImpl staticLHHAAttributes = Dom4jUtils.getSAXAttributes(lhhaAnalysis.element()); final boolean isLabel = lhhaType == LHHAC.LABEL; final boolean isHelp = lhhaType == LHHAC.HELP; final boolean isHint = lhhaType == LHHAC.HINT; final boolean isAlert = lhhaType == LHHAC.ALERT; if (staticLHHAAttributes != null || isAlert) { // If no attributes were found, there is no such label / help / hint / alert if (handlerContext.isNoScript() && isHelp) { if (control != null) { final ContentHandler contentHandler = handlerContext.getController().getOutput(); final String xhtmlPrefix = handlerContext.findXHTMLPrefix(); // <a href="#my-control-id-help"> final AttributesImpl aAttributes = new AttributesImpl(); aAttributes.addAttribute("", "href", "href", XMLReceiverHelper.CDATA, "#" + getLHHACId(containingDocument, targetControlEffectiveId, LHHAC_CODES.get(LHHAC.HELP))); aAttributes.addAttribute("", "class", "class", XMLReceiverHelper.CDATA, "xforms-help-anchor"); final String aQName = XMLUtils.buildQName(xhtmlPrefix, "a"); contentHandler.startElement(XMLConstants.XHTML_NAMESPACE_URI, "a", aQName, aAttributes); contentHandler.endElement(XMLConstants.XHTML_NAMESPACE_URI, "a", aQName); }//from w ww .ja va 2 s . co m } else { final String labelHintHelpAlertValue; final boolean mustOutputHTMLFragment; if (control != null) { // Get actual value from control if (isLabel) { labelHintHelpAlertValue = control.getLabel(); mustOutputHTMLFragment = control.isHTMLLabel(); } else if (isHelp) { // NOTE: Special case here where we get the escaped help to facilitate work below. Help is a special // case because it is stored as escaped HTML within a <label> element. labelHintHelpAlertValue = control.getEscapedHelp(); mustOutputHTMLFragment = false; } else if (isHint) { labelHintHelpAlertValue = control.getHint(); mustOutputHTMLFragment = control.isHTMLHint(); } else if (isAlert) { labelHintHelpAlertValue = control.getAlert(); mustOutputHTMLFragment = control.isHTMLAlert(); } else { throw new IllegalStateException("Illegal type requested"); } } else { // Placeholder labelHintHelpAlertValue = null; mustOutputHTMLFragment = false; } final String elementName; { if (isLabel) { elementName = handlerContext.getLabelElementName(); } else if (isHelp) { elementName = handlerContext.getHelpElementName(); } else if (isHint) { elementName = handlerContext.getHintElementName(); } else if (isAlert) { elementName = handlerContext.getAlertElementName(); } else { throw new IllegalStateException("Illegal type requested"); } } final StringBuilder classes = new StringBuilder(30); // Put user classes first if any if (staticLHHAAttributes != null) { final String userClass = staticLHHAAttributes.getValue("class"); if (userClass != null) classes.append(userClass); } // Mark alert as active if needed if (isAlert) { if (control instanceof XFormsSingleNodeControl) { final XFormsSingleNodeControl singleNodeControl = (XFormsSingleNodeControl) control; final scala.Option<ValidationLevels.ValidationLevel> constraintLevel = singleNodeControl .alertLevel(); if (constraintLevel.isDefined()) { if (classes.length() > 0) classes.append(' '); classes.append("xforms-active"); } // Constraint classes are placed on the control if the alert is not external if (isExternal) addConstraintClasses(classes, constraintLevel); } } // Handle visibility // TODO: It would be great to actually know about the relevance of help, hint, and label. Right now, we just look at whether the value is empty if (control != null) { if (isAlert || isLabel) { // Allow empty labels and alerts if (!control.isRelevant()) { if (classes.length() > 0) classes.append(' '); classes.append("xforms-disabled"); } } else { // For help and hint, consider "non-relevant" if empty final boolean isHintHelpRelevant = control.isRelevant() && StringUtils.isNotEmpty(labelHintHelpAlertValue); if (!isHintHelpRelevant) { if (classes.length() > 0) classes.append(' '); classes.append("xforms-disabled"); } } } else if (!isTemplate || isHelp) { // Null control outside of template OR help within template if (classes.length() > 0) classes.append(' '); classes.append("xforms-disabled"); } // LHHA name if (classes.length() > 0) classes.append(' '); classes.append("xforms-"); classes.append(lhhaType.name().toLowerCase()); // We handle null attributes as well because we want a placeholder for "alert" even if there is no xf:alert final Attributes newAttributes = (staticLHHAAttributes != null) ? staticLHHAAttributes : new AttributesImpl(); lhhaAnalysis.encodeAndAppendAppearances(classes); outputLabelFor(handlerContext, getIdClassXHTMLAttributes(newAttributes, classes.toString(), null), targetControlEffectiveId, forEffectiveId, lhhaType, elementName, labelHintHelpAlertValue, mustOutputHTMLFragment, isExternal); } } }
From source file:org.outerj.daisy.diff.html.dom.DomTreeBuilder.java
private boolean isViewableImage(ImageNode imageNode) { boolean viewable = true; AttributesImpl attrs = imageNode.getAttributes(); String width = attrs.getValue("width"); String height = attrs.getValue("height"); if (StringUtils.isNotBlank(width) && StringUtils.isNotBlank(height)) { int imgWidth = NumberUtils.createInteger(width); int imgHeight = NumberUtils.createInteger(height); if (imgWidth == 0 || imgHeight == 0 || (imgWidth == 1 && imgHeight == 1)) { viewable = false;/*from w w w .j a va 2 s. c o m*/ } } return viewable; }