Package org.jdom

Examples of org.jdom.CDATA


    }

    public void writeCData(String data)
        throws XMLStreamException
    {
        currentNode.addContent(new CDATA(data));
    }
View Full Code Here


            Comment c = (Comment) i.next();
            c.setText( ReleaseUtil.normalizeLineEndings( c.getText(), ls ) );
        }
        for ( Iterator<?> i = document.getDescendants( new ContentFilter( ContentFilter.CDATA ) ); i.hasNext(); )
        {
            CDATA c = (CDATA) i.next();
            c.setText( ReleaseUtil.normalizeLineEndings( c.getText(), ls ) );
        }
    }
View Full Code Here

    /**
     * Test the protected CDATA constructor.
     */
    public void test_TCC() {
        new CDATA() {
            // check protected constructor via anonymous class
        };
    }
View Full Code Here

   * Test the CDATA constructor with a valid and an invalid string.
   */
  public void test_TCC___String() {
        final String text = "this is a CDATA section";       

        final CDATA cdata = new CDATA(text);

    assertEquals(
        "incorrect CDATA constructed",
        "[CDATA: " + text + ']',
        cdata.toString());

        try {
            new CDATA("");
        } catch (final IllegalDataException e) {
            fail("CDATA constructor did throw exception on empty string");
        }

        try {
            new CDATA(null);
        } catch (final IllegalDataException e) {
            fail("CDATA constructor did throw exception on null");
        }

        try {
            new CDATA("some valid <text> with a CDATA section ending ]]>");
            fail("CDATA constructor didn't catch invalid comment string");
        } catch (final IllegalDataException e) {
        }
  }
View Full Code Here

    /**
   * Verify a simple object == object test
   */
  public void test_TCM__boolean_equals_Object() {
        final String text = "this is a CDATA section";
      final CDATA cdata = new CDATA(text);

      final Object object = (Object) cdata;

        assertTrue("object not equal to CDATA", cdata.equals(object));
        assertTrue("CDATA not equal to object", object.equals(cdata));
  }
View Full Code Here

   * Test that a real hashcode is returned and that a different one is returned
   * for a different CDATA.
   */
  public void test_TCM__int_hashCode() {
        final String text = "this is a CDATA section";
        final CDATA cdata = new CDATA(text);

    //only an exception would be a problem
        int hash = -1;
        try {
           hash = cdata.hashCode();
        }
        catch(final Exception exception) {
            fail("bad hashCode");
        }

        // same text but created out of parts to avoid object resusal
    final CDATA similarCDATA = new CDATA("this"+ " is" +" a" + " CDATA" + " section");

        //different CDATA sections, same text
    final int similarHash = similarCDATA.hashCode();
    assertTrue("Different comments with same value have same hashcode", hash != similarHash);
       
    final CDATA otherCDATA = new CDATA("this is another CDATA section");

        //only an exception would be a problem
    int otherHash = otherCDATA.hashCode();
        assertTrue("Different comments have same hashcode", otherHash != hash);
        assertTrue("Different comments have same hashcode", otherHash != similarHash);
  }
View Full Code Here

     * Test setting and resetting the text value of this CDATA.
     */
    public void test_TCM__orgJdomText_setText_String() {
        // simple text in CDATA section
        final String text = "this is a CDATA section";       
        final CDATA cdata = new CDATA(text);
        assertEquals("incorrect CDATA text", text, cdata.getText());

      // set it to the empty string
        final String emptyString = "";
      cdata.setText(emptyString);
        assertEquals("incorrect CDATA text", emptyString, cdata.getText());

        // set it to a another string
        final String otherString = "12345qwerty";
        cdata.setText(otherString);
        assertEquals("incorrect CDATA text", otherString, cdata.getText());

        // set it to the null (after it was set to another string so that we
        // are sure comething has changed)
        cdata.setText(null);
        assertEquals("incorrect CDATA text", emptyString, cdata.getText());

      // the following test check for invalid data and transactional behavior
        // means the content must not be change on exceptions so we set a default

        // set text with some special characters
        final String specialText = "this is CDATA section with special characters as < > & &amp; &lt; &gt; [[ ]] > <![![";
        cdata.setText(specialText);   
        assertEquals("incorrect CDATA text", specialText, cdata.getText());
       
       
        cdata.setText(otherString);   
        try {
            final char c= 0x11;
            final StringBuffer buffer = new StringBuffer("hhhh");
            buffer.setCharAt(2, c);

            cdata.setText(buffer.toString());
            fail("Comment setText didn't catch invalid CDATA string");
        } catch (final IllegalDataException exception) {
            assertEquals("incorrect CDATA text after exception", otherString, cdata.getText());
        }
   
        cdata.setText(text);       
        try {
            final String invalidCDATAString = "some valid <text> with an invlaid CDATA section ending ]]>";

            cdata.setText(invalidCDATAString);
            fail("Comment setText didn't catch invalid CDATA string");
        } catch (final IllegalDataException exception) {
            assertEquals("incorrect CDATA text after exception", text, cdata.getText());
        }   
    }
View Full Code Here

        final String specialText = "> this is a CDATA section with special characters as ]]";
        final String cdataEndText = "this is aCDATA section with a CDATA end marke ]]> somewhere inside";

        {
            // simple text in CDATA section
            final CDATA cdata = new CDATA(text);
            assertEquals("incorrect CDATA text", text, cdata.getText());
            cdata.append(text);
            assertEquals("incorrect CDATA text", text+text, cdata.getText());
            try {
                cdata.append(cdataEndText);
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to the empty string
            final CDATA cdata = new CDATA(emptyString);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append(emptyString);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append(text);
            assertEquals("incorrect CDATA text", text, cdata.getText());
            cdata.append(nullString);
            assertEquals("incorrect CDATA text", text, cdata.getText());
            cdata.append(specialCharactersText);
            assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
            cdata.append(nullString);
            assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
            cdata.append(emptyString);
            assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
            cdata.append(otherString);
            assertEquals("incorrect CDATA text", text + specialCharactersText + otherString, cdata.getText());
            try {
                cdata.append(cdataEndText);
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to a another string
            final CDATA cdata = new CDATA(otherString);
            assertEquals("incorrect CDATA text", otherString, cdata.getText());
            cdata.append(text);
            assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
            cdata.append(nullString);
            assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
            cdata.append(specialCharactersText);
            assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
            cdata.append(nullString);
            assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
            cdata.append(emptyString);
            assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
            try {
                cdata.append(cdataEndText);
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }
       
        {
            // set it to the null (after it was set to another string so that we
            // are sure comething has changed)
            final CDATA cdata = new CDATA(nullString);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append(specialCharactersText);
            assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
            cdata.append(nullString);
            assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
            cdata.append(text);
            assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
            cdata.append(nullString);
            assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
            cdata.append(emptyString);
            assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
            cdata.append(otherString);
            assertEquals("incorrect CDATA text", specialCharactersText + text + otherString, cdata.getText());
            try {
                cdata.append(cdataEndText);
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to the null (after it was set to another string so that we
            // are sure comething has changed)
            final CDATA cdata = new CDATA(null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append((String) null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            try {
                cdata.append(cdataEndText);
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to the null (after it was set to another string so that we
            // are sure comething has changed)
            final CDATA cdata = new CDATA(null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append((Text) null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            try {
                cdata.append(cdataEndText);
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set text with some special characters
            final CDATA cdata = new CDATA(specialCharactersText);
            assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
            cdata.append(specialCharactersText);
            assertEquals("incorrect CDATA text", specialCharactersText + specialCharactersText, cdata.getText());
            try {
                cdata.append(cdataEndText);
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }
       
       
        try {
            // set text with some special characters which sould result into an exception
            final CDATA cdata = new CDATA(specialText);
            assertEquals("incorrect CDATA text", specialText, cdata.getText());
            cdata.append(specialText);
           
            fail("failed to detect CDATA end marker");
        } catch (final IllegalDataException exception) {
        }
    }
View Full Code Here

        final String specialText = "> this is a CDATA section with special characters as ]]";
        final String cdataEndText = "this is aCDATA section with a CDATA end marke ]]> somewhere inside";

        {
            // simple text in CDATA section
            final CDATA cdata = new CDATA(text);
            assertEquals("incorrect CDATA text", text, cdata.getText());
            cdata.append(new Text(text));
            assertEquals("incorrect CDATA text", text+text, cdata.getText());
            try {
                cdata.append(new Text(cdataEndText));
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to the empty string
            final CDATA cdata = new CDATA(emptyString);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append(new Text(emptyString));
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append(new Text(text));
            assertEquals("incorrect CDATA text", text, cdata.getText());
            cdata.append(new Text(nullString));
            assertEquals("incorrect CDATA text", text, cdata.getText());
            cdata.append(new Text(specialCharactersText));
            assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
            cdata.append(new Text(nullString));
            assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
            cdata.append(new Text(emptyString));
            assertEquals("incorrect CDATA text", text + specialCharactersText, cdata.getText());
            cdata.append(new Text(otherString));
            assertEquals("incorrect CDATA text", text + specialCharactersText + otherString, cdata.getText());
            try {
                cdata.append(new Text(cdataEndText));
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to a another string
            final CDATA cdata = new CDATA(otherString);
            assertEquals("incorrect CDATA text", otherString, cdata.getText());
            cdata.append(new Text(text));
            assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
            cdata.append(new Text(nullString));
            assertEquals("incorrect CDATA text", otherString + text, cdata.getText());
            cdata.append(new Text(specialCharactersText));
            assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
            cdata.append(new Text(nullString));
            assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
            cdata.append(new Text(emptyString));
            assertEquals("incorrect CDATA text", otherString + text + specialCharactersText, cdata.getText());
            try {
                cdata.append(new Text(cdataEndText));
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }
       
        {
            // set it to the null (after it was set to another string so that we
            // are sure comething has changed)
            final CDATA cdata = new CDATA(nullString);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append(new Text(specialCharactersText));
            assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
            cdata.append(new Text(nullString));
            assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
            cdata.append(new Text(text));
            assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
            cdata.append(new Text(nullString));
            assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
            cdata.append(new Text(emptyString));
            assertEquals("incorrect CDATA text", specialCharactersText + text, cdata.getText());
            cdata.append(new Text(otherString));
            assertEquals("incorrect CDATA text", specialCharactersText + text + otherString, cdata.getText());
            try {
                cdata.append(new Text(cdataEndText));
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to the null (after it was set to another string so that we
            // are sure comething has changed)
            final CDATA cdata = new CDATA(null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append((String) null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            try {
                cdata.append(new Text(cdataEndText));
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set it to the null (after it was set to another string so that we
            // are sure comething has changed)
            final CDATA cdata = new CDATA(null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            cdata.append((Text) null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
            try {
                cdata.append(new Text(cdataEndText));
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }

        {
            // set text with some special characters
            final CDATA cdata = new CDATA(specialCharactersText);
            assertEquals("incorrect CDATA text", specialCharactersText, cdata.getText());
            cdata.append(new Text(specialCharactersText));
            assertEquals("incorrect CDATA text", specialCharactersText + specialCharactersText, cdata.getText());
            try {
                cdata.append(new Text(cdataEndText));
                fail("failed to detect CDATA end marker");
            } catch (final IllegalDataException exception) {
            }
        }
       
       
        try {
            // set text with some special characters which sould result into an exception
            final CDATA cdata = new CDATA(specialText);
            assertEquals("incorrect CDATA text", specialText, cdata.getText());
            cdata.append(new Text(specialText));
           
            fail("failed to detect CDATA end marker");
        } catch (final IllegalDataException exception) {
        }
    }
View Full Code Here

   */
  public void test_TCM__String_getText() {
        {
            final String text = "this is a CDATA section";       
   
            final CDATA cdata = new CDATA(text);
            assertEquals("incorrect CDATA text", text, cdata.getText());
        }

        {
            //set it to the empty string
            final String emptyString = "";
            final CDATA cdata = new CDATA(emptyString);
            assertEquals("incorrect CDATA text", emptyString, cdata.getText());
        }

        {
            // set it to a another string
            final String otherString = "12345qwerty";
            final CDATA cdata = new CDATA(otherString);
            assertEquals("incorrect CDATA text", otherString, cdata.getText());
        }

        {
            // set it to the null
            final CDATA cdata = new CDATA(null);
            assertEquals("incorrect CDATA text", "", cdata.getText());
        }
  }
View Full Code Here

TOP

Related Classes of org.jdom.CDATA

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.