List of usage examples for org.xml.sax.helpers AttributesImpl addAttribute
public void addAttribute(String uri, String localName, String qName, String type, String value)
From source file:Main.java
/** * Adds attribute with <code>localName</code> to <code>attributes</code> if * value is not null. Follows the same rules as * {@link AttributesImpl#addAttribute(String, String, String, String, String)} * .//w w w . j a va 2 s .c om * * @param attributes * to add to. * @param localName * of attribute to add. * @param value * to add to attribute. * @since 8.1 */ static public void addAttribute(final AttributesImpl attributes, final String localName, final Object value) { if (null != value) { attributes.addAttribute(XMLConstants.NULL_NS_URI, localName, localName, "", value.toString()); } }
From source file:Main.java
/** * Adds attribute with <code>prefix</code> and <code>localName</code> to * <code>attributes</code> if value is not null. Follows the same rules as * {@link AttributesImpl#addAttribute(String, String, String, String, String)} * ./*from ww w. j av a 2s . c om*/ * * @param attributes * to add to. * @param prefix * of the attribute. * @param localName * of attribute to add. * @param value * to add to attribute. * @since 8.1 */ static public void addAttribute(final AttributesImpl attributes, final String prefix, final String localName, final Object value) { if (null != value) { attributes.addAttribute(XMLConstants.NULL_NS_URI, localName, prefix + ":" + localName, "", value.toString()); } }
From source file:no.kantega.commons.util.XMLHelper.java
public static AttributesImpl getAttributesImpl(Attributes attributes) { AttributesImpl impl = new AttributesImpl(); for (int i = 0; i < attributes.getLength(); i++) { impl.addAttribute(attributes.getURI(i), attributes.getLocalName(i), attributes.getQName(i), attributes.getType(i), attributes.getValue(i)); }/*from ww w . jav a 2 s. co m*/ return impl; }
From source file:Main.java
public static void start(final ContentHandler handler, final String... elementAndAttributes) throws SAXException { if (elementAndAttributes == null || elementAndAttributes.length == 0 || elementAndAttributes.length % 2 != 1) { throw new IllegalArgumentException( "elementAndAttributes must contains element name and 0..n pais of attr name-value"); }/*from w w w . j a v a 2s . c o m*/ final String elementName = elementAndAttributes[0]; AttributesImpl attributes = EMPTY_ATTRIBUTES; if (elementAndAttributes.length > 1) { attributes = new AttributesImpl(); for (int i = 1; i + 1 < elementAndAttributes.length;) { String attributeName = elementAndAttributes[i++]; String attributeValue = elementAndAttributes[i++]; attributes.addAttribute("", attributeName, attributeName, NULL_TYPE, attributeValue); } } start(handler, elementName, attributes); }
From source file:IOUtils.java
/** * Helper method to add an attribute./*from www . j a v a 2s .c o m*/ * This implementation adds a new attribute with the given name * and value. Before adding the value is checked for non-null. * @param ai The attributes impl receiving the additional attribute. * @param name The name of the attribute. * @param value The value of the attribute. */ protected static void addAttribute(AttributesImpl ai, String name, Object value) { if (value != null) { ai.addAttribute("", name, name, "CDATA", value.toString()); } }
From source file:com.gargoylesoftware.htmlunit.xml.XmlUtil.java
private static Attributes namedNodeMapToSaxAttributes(final NamedNodeMap attributesMap) { final AttributesImpl attributes = new AttributesImpl(); final int length = attributesMap.getLength(); for (int i = 0; i < length; i++) { final Node attr = attributesMap.item(i); attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getNodeName(), null, attr.getNodeValue());/*w ww . ja v a 2 s . co m*/ } return attributes; }
From source file:net.ontopia.persistence.rdbms.DatabaseProjectReader.java
public static void saveProject(Project project, ContentHandler dh) throws SAXException { AttributesImpl atts = new AttributesImpl(); dh.startDocument();/* ww w.ja v a2 s . c o m*/ dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "dbschema", EMPTY_ATTR_LIST); Iterator<String> platforms = project.getDataTypePlatforms().iterator(); if (platforms.hasNext()) { while (platforms.hasNext()) { String platform = platforms.next(); atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PLATFORM, CDATA, platform); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatypes", atts); Iterator<DataType> datatypes = project.getDataTypes(platform).iterator(); while (datatypes.hasNext()) { // Platform datatypes DataType datatype = datatypes.next(); atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, (datatype.getName())); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, TYPE, CDATA, (datatype.getType())); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, SIZE, CDATA, (datatype.getSize() == null ? "" : datatype.getSize())); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "class", CDATA, (datatype.isVariable() ? "variable" : "constant")); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatype", atts); // Datatype properties Iterator<String> properties = datatype.getProperties().iterator(); while (properties.hasNext()) { String name = properties.next(); String value = datatype.getProperty(name); if (value != null) { atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY); } } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatype"); } } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatypes"); } Iterator<Table> tables = project.getTables().iterator(); while (tables.hasNext()) { Table table = tables.next(); // Table attributes atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, table.getName()); if (table.getShortName() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "short", CDATA, table.getShortName()); if (table.getPrimaryKeys() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "pks", CDATA, StringUtils.join(table.getPrimaryKeys(), " ")); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "table", atts); // Table properties Iterator<String> properties = table.getProperties().iterator(); while (properties.hasNext()) { String name = properties.next(); String value = table.getProperty(name); if (value != null) { atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY); } } Iterator<Column> columns = table.getColumns().iterator(); while (columns.hasNext()) { Column column = columns.next(); // Column attributes atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, column.getName()); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, TYPE, CDATA, column.getType()); if (column.isReference()) { atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "reftab", CDATA, column.getReferencedTable()); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "refcol", CDATA, column.getReferencedColumn()); } if (column.getSize() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, SIZE, CDATA, column.getName()); if (column.isNullable()) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "null", CDATA, "yes"); if (column.getDefault() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "default", CDATA, column.getDefault()); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "column", atts); // Column properties Iterator<String> properties2 = column.getProperties().iterator(); while (properties2.hasNext()) { String name = properties2.next(); String value = column.getProperty(name); if (value != null) { atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY); } } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "column"); } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "table"); } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "dbschema"); dh.endDocument(); }
From source file:it.polito.tellmefirst.web.rest.interfaces.VideoInterface.java
private String produceXML(String videoURL) throws TMFOutputException { LOG.debug("[produceXML] - BEGIN"); String xml;//from www . j av a2s. c o m try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "videoURL", "", videoURL); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Result", atts); hd.endElement("", "", "Result"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:it.polito.tellmefirst.web.rest.interfaces.AbstractInterface.java
private String produceXML(String abstracto) throws TMFOutputException { String xml;/* www. j a va2s. c om*/ LOG.debug("[produceXML] - BEGIN"); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "abstract", "", abstracto); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Result", atts); hd.endElement("", "", "Result"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); System.out.println(xml); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:it.polito.tellmefirst.web.rest.interfaces.ImageInterface.java
private String produceXML(String imageURL) throws TMFOutputException { LOG.debug("[produceXML] - BEGIN"); String xml;/*from w w w. j av a 2 s .co m*/ try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "imageURL", "", imageURL); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Result", atts); hd.endElement("", "", "Result"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }