Esempio n. 1
0
  @Test
  public void testAddOrSetAttributeAttributesImplNode() throws ParserConfigurationException {
    final AttributesImpl atts = new AttributesImpl();
    final DOMImplementation dom =
        DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    final Document doc = dom.createDocument(null, "foo", null);

    doc.getDocumentElement().setAttribute("foo", "foo");
    final Attr att = (Attr) doc.getDocumentElement().getAttributeNode("foo");
    XMLUtils.addOrSetAttribute(atts, att);

    final int i = atts.getIndex(NULL_NS_URI, "foo");
    assertEquals(NULL_NS_URI, atts.getURI(i));
    assertEquals("foo", atts.getQName(i));
    assertEquals("foo", atts.getLocalName(i));
    assertEquals("foo", atts.getValue(i));

    doc.getDocumentElement().setAttributeNS(XML_NS_URI, "xml:lang", "en");
    final Attr lang = (Attr) doc.getDocumentElement().getAttributeNodeNS(XML_NS_URI, "lang");
    XMLUtils.addOrSetAttribute(atts, lang);

    final int l = atts.getIndex(XML_NS_URI, "lang");
    assertEquals(XML_NS_URI, atts.getURI(l));
    assertEquals("xml:lang", atts.getQName(l));
    assertEquals("lang", atts.getLocalName(l));
    assertEquals("en", atts.getValue(l));
  }
Esempio n. 2
0
 @Test
 public void testRemoveAttribute() {
   final AttributesImpl atts = new AttributesImpl();
   XMLUtils.addOrSetAttribute(atts, "foo", "foo", "foo", "CDATA", "foo");
   assertEquals(1, atts.getLength());
   XMLUtils.removeAttribute(atts, "foo");
   assertEquals(0, atts.getLength());
 }
Esempio n. 3
0
 @Test
 public void testAddOrSetAttributeAttributesImplStringString() {
   final AttributesImpl atts = new AttributesImpl();
   XMLUtils.addOrSetAttribute(atts, "foo", "foo");
   assertEquals(1, atts.getLength());
   XMLUtils.addOrSetAttribute(atts, "bar", "bar");
   assertEquals(2, atts.getLength());
   XMLUtils.addOrSetAttribute(atts, "foo", "bar");
   assertEquals(2, atts.getLength());
 }
Esempio n. 4
0
  @Test
  public void testGetStringValue() throws ParserConfigurationException {
    final DOMImplementation dom =
        DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    final Document doc = dom.createDocument(null, "foo", null);

    final Element root = doc.getDocumentElement();
    root.appendChild(doc.createTextNode("foo"));
    assertEquals("foo", XMLUtils.getStringValue(root));
    root.appendChild(doc.createTextNode(" "));
    final Element nested = doc.createElement("ph");
    nested.appendChild(doc.createTextNode("nested"));
    root.appendChild(nested);
    root.appendChild(doc.createTextNode(" bar"));
    assertEquals("foo nested bar", XMLUtils.getStringValue(root));
  }
Esempio n. 5
0
 @Test
 public void testEscapeXMLString() {
   String result = null;
   final String input =
       "<this is test of char update for xml href=\" see link: http://www.ibm.com/download.php?abc=123&def=456\">'test' </test>";
   final String expected =
       "&lt;this is test of char update for xml href=&quot; see link: http://www.ibm.com/download.php?abc=123&amp;def=456&quot;&gt;&apos;test&apos; &lt;/test&gt;";
   result = XMLUtils.escapeXML(input);
   assertEquals(expected, result);
 }