/** * See if there is any element content that needs to be completed. * * @throws RepositoryException if there is a problem writing the content to the repository session */ protected void endContent() throws RepositoryException { // Process the content of the element ... String content = StringUtil.normalize(contentBuilder.toString()); // Null-out builder to setup for subsequent content. // Must be done before call to startElement below to prevent infinite loop. contentBuilder = null; // Skip if nothing in content but whitespace if (content.length() > 0) { // Create separate node for each content entry since entries can be interspersed amongst child elements startNode(XmlLexicon.ELEMENT_CONTENT, XmlLexicon.ELEMENT_CONTENT); currentNode.setProperty(XmlLexicon.ELEMENT_CONTENT, content); endNode(); } }
/** * See if there is any element content that needs to be completed. * * @throws RepositoryException if there is a problem writing the content to the repository session */ protected void endContent() throws RepositoryException { // Process the content of the element ... String content = StringUtil.normalize(contentBuilder.toString()); // Null-out builder to setup for subsequent content. // Must be done before call to startElement below to prevent infinite loop. contentBuilder = null; // Skip if nothing in content but whitespace if (content.length() > 0) { // Create separate node for each content entry since entries can be interspersed amongst child elements startNode(XmlLexicon.ELEMENT_CONTENT, XmlLexicon.ELEMENT_CONTENT); currentNode.setProperty(XmlLexicon.ELEMENT_CONTENT, content); endNode(); } }
@Test( expected = IllegalArgumentException.class ) public void normalizeShouldFailIfTextNull() { StringUtil.normalize(null); }
@Test public void normalizeShouldReduceInternalWhitespace() { assertThat(StringUtil.normalize("test \t\n\r this"), is("test this")); }
@Test public void normalizeShouldRemoveLeadingTrailingWhitespace() { assertThat(StringUtil.normalize(" \t\n test this \t"), is("test this")); }
@Test public void normalizeShouldReturnEqualStringIfNothingToNormalize() { assertThat(StringUtil.normalize("test this"), is("test this")); }