@Override public void writeConfig(ConfigWriter cw) { final String name = "data-source"; String klass = getClass().getName(); AttributeListImpl attribs = new AttributeListImpl(); attribs.addAttribute("class", "CDATA", klass); cw.writeStartElement(name, attribs); cw.writeParam("server-address", getServerAddress()); cw.writeParam("port-number", getPortNumber()); cw.writeParam("user-name", getUserName()); cw.writeParam("password", getPassword()); cw.writeParam("db-auth", getDbAuth()); cw.writeParam("database", getDatabase()); cw.writeParam("cursor-notimeout", getCursorNotimeout()); cw.writeParam("collection", getCollection()); cw.writeParam("query", getQuery()); cw.writeParam("projection", getProjection()); cw.writeEndElement(name); }
private void writeProperty(Property prop) { AttributeListImpl atts = new AttributeListImpl(); if (prop.isIdProperty()) atts.addAttribute("type", "CDATA", "id"); else if (prop.isIgnoreProperty()) atts.addAttribute("type", "CDATA", "ignore"); if (!prop.isIdProperty() && prop.getLookupBehaviour() != Property.Lookup.DEFAULT) { String value = prop.getLookupBehaviour().toString().toLowerCase(); atts.addAttribute("lookup", "CDATA", value); } pp.startElement("property", atts); writeElement("name", prop.getName()); if (prop.getComparator() != null) writeElement("comparator", prop.getComparator().getClass().getName()); if (prop.getLowProbability() != 0.0) writeElement("low", "" + prop.getLowProbability()); if (prop.getHighProbability() != 0.0) writeElement("high", "" + prop.getHighProbability()); pp.endElement("property"); }
protected void writeColumnsConfig(ConfigWriter cw) { // FIXME: this breaks the order... for (Column col : getColumns()) { AttributeListImpl atts = new AttributeListImpl(); atts.addAttribute("name", "CDATA", col.getName()); atts.addAttribute("property", "CDATA", col.getProperty()); if (col.getPrefix() != null) atts.addAttribute("prefix", "CDATA", col.getPrefix()); // FIXME: cleaner really requires object support ... :-( if (col.getCleaner() != null) atts.addAttribute("cleaner", "CDATA", col.getCleaner().getClass().getName()); if (col.isSplit()) atts.addAttribute("split-on", "CDATA", col.getSplitOn()); cw.writeStartElement("column", atts); cw.writeEndElement("column"); } }
@TestTargetNew( level = TestLevel.COMPLETE, method = "startElement", args = { String.class, AttributeList.class } ) public void testStartElement() { AttributeListImpl atts = new AttributeListImpl(); atts.addAttribute("john:doe", "int", "42"); try { adapter.startDocument(); adapter.startElement("foo:bar", atts); } catch (SAXException e) { throw new RuntimeException("Unexpected exception", e); } assertEquals("startElement", logger.getMethod()); assertEquals("", logger.getArgs()[0]); assertEquals("", logger.getArgs()[1]); assertEquals("foo:bar", logger.getArgs()[2]); assertEquals("john:doe", ((Attributes)logger.getArgs()[3]).getQName(0)); }
@TestTargetNew( level = TestLevel.COMPLETE, method = "endElement", args = { String.class } ) public void testEndElement() { AttributeListImpl atts = new AttributeListImpl(); atts.addAttribute("john:doe", "int", "42"); try { adapter.startDocument(); adapter.startElement("foo:bar", atts); adapter.endElement("foo:bar"); } catch (SAXException e) { throw new RuntimeException("Unexpected exception", e); } assertEquals("endElement", logger.getMethod()); assertEquals(new String[] { "", "", "foo:bar" }, logger.getArgs()); }
public void writeParam(String name, String value) { if (value == null) return; AttributeListImpl atts = new AttributeListImpl(); atts.addAttribute("name", "CDATA", name); atts.addAttribute("value", "CDATA", value); pp.startElement("param", atts); pp.endElement("param"); }
/** * Handles a subtree of the parsed XML data structure. * * @exception org.xml.sax.SAXException * if one of the handlers throw such exception */ private void handleSubTree(XMLElement element, SAXLocator locator) throws SAXException { AttributeListImpl attrList = new AttributeListImpl(); locator.setLineNr(element.getLineNr()); Enumeration enum2 = element.enumeratePropertyNames(); while (enum2.hasMoreElements()) { String key = (String)(enum2.nextElement()); String value = element.getProperty(key); attrList.addAttribute(key, "CDATA", value); } this.documentHandler.startElement(element.getTagName(), attrList); if (element.getContents() == null) { enum2 = element.enumerateChildren(); while (enum2.hasMoreElements()) { this.handleSubTree((XMLElement)(enum2.nextElement()), locator); } } else { char[] chars = element.getContents().toCharArray(); this.documentHandler.characters(chars, 0, chars.length); } locator.setLineNr(-1); this.documentHandler.endElement(element.getTagName()); }
@TestTargetNew( level = TestLevel.COMPLETE, method = "setAttributeList", args = { AttributeList.class } ) public void testSetAttributeList() { // Ordinary cases AttributeListImpl attrs = new AttributeListImpl(); attrs.addAttribute("doe", "boolean", "false"); attrs.setAttributeList(empty); assertEquals(0, attrs.getLength()); attrs.setAttributeList(multi); assertEquals(multi.getLength(), attrs.getLength()); for (int i = 0; i < multi.getLength(); i++) { assertEquals(multi.getName(i), attrs.getName(i)); assertEquals(multi.getType(i), attrs.getType(i)); assertEquals(multi.getValue(i), attrs.getValue(i)); } // null case try { attrs.setAttributeList(null); fail("NullPointerException expected"); } catch (NullPointerException e) { // Expected, must still have old elements assertEquals(3, attrs.getLength()); } }
@TestTargetNew( level = TestLevel.COMPLETE, method = "startElement", args = { String.class, AttributeList.class } ) public void testStartElement() { try { h.startElement("name", new AttributeListImpl()); } catch (SAXException e) { throw new RuntimeException(e); } }
/** * Sets the attributes for the wrapped element. * * @param attributes List of attributes defined in the XML for this * element. May be <code>null</code>. * @deprecated since 1.6.x. */ @Deprecated public synchronized void setAttributes(AttributeList attributes) { this.attributes = new AttributeListImpl(attributes); for (int i = 0; i < attributes.getLength(); i++) { setAttribute(attributes.getName(i), attributes.getValue(i)); } }
public void writeStartElement(String name, AttributeListImpl atts) { pp.startElement(name, atts); }