@Test public void testNoteShortening() throws Exception { NoteShortener shortener = new NoteShortener(4, 75, 47, 6); Assert.assertNull(shortener.processNoteContent("<p>Line1</p>"), "There must be no shortening if the text is short enough"); Assert.assertNull(shortener.processNoteContent("<p>Line 1</p><p>Line 2</p>" + "<p>Line 3</p><p>Line 4</p>"), "There must be no shortening if the text is short enough"); testContent(shortener, "<p>Line 1</p><p>Line 2</p><p>Line 3</p><p>Line 4</p><p>Line 5</p>", "<p>Line 1</p><p>Line 2</p><p>Line 3</p><p>Line 4<rml/></p>"); testContent(shortener, "<p>Line 1</p><p></p><p></p><p></p><p>Line 5</p>", "<p>Line 1</p><p></p><p></p><p><rml/></p>"); testContent(shortener, "<p>Line 1</p><ul><li>Line 2</li>" + "<li>Line 3</li><li>Line 4</li><li>Line 5</li></ul>", "<p>Line 1</p><ul><li>Line 2</li><li>Line 3</li><li>Line 4<rml/></li></ul>"); testContent(shortener, "<p>Line 1</p><ol><li>Line 2</li>" + "<li>Line 3</li><li>Line 4</li><li>Line 5</li></ol>", "<p>Line 1</p><ol><li>Line 2</li><li>Line 3</li><li>Line 4<rml/></li></ol>"); testContent(shortener, "<p>Line 1</p><ul><li>Line 2</li>" + "<ol><li>Line 3</li><li>Line 4</li></ol><li>Line 5</li></ul>", "<p>Line 1</p><ul><li>Line 2</li><ol><li>Line 3</li><li>Line 4<rml/></li></ol></ul>"); testContent(shortener, "<p>Line 1</p><p>Line 2<br/>Line 3<br/>Line 4<br/>Line 5</p>", "<p>Line 1</p><p>Line 2<br/>Line 3<br/>Line 4<rml/></p>"); testContent(shortener, "Line1<br/>Line2<br/>Line3<br/>Line4<br/>Line5", "Line1<br/>Line2<br/>Line3<br/>Line4<rml/>"); testContent(shortener, "<br/>Line2<br/>Line3<br/>Line4<br/>Line5", "<br/>Line2<br/>Line3<br/>Line4<rml/>"); testContent(shortener, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod" + " tempor invidunt ut labore et Lorem ipsum dolor sit amet, consetetur " + "sadipscing elitr, sed diam nonumy Lorem ipsum dolor sit amet, " + "consetetur sadipscing elitr, sed diam nonumy Lorem ipsum dolor <b>sit" + " amet, consetetur sadipscing elitr, sed diam nonumy</b>", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod" + " tempor invidunt ut labore et Lorem ipsum dolor sit amet, consetetur " + "sadipscing elitr, sed diam nonumy Lorem ipsum dolor sit amet, " + "consetetur sadipscing elitr, sed diam nonumy Lorem ipsum dolor <rml/>"); }
public String processNoteContent(String content) throws NoteStoringPreProcessorException { charsOnLine = 0; curLine = 1; indentLevel = 0; lastProcessedNode = null; try { content = "<root>" + content + "</root>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(content)); Document document = builder.parse(src); Node rootNode = document.getFirstChild(); if (!processChildNodes(rootNode, "root")) { Element e = document.createElement(READ_MORE_LINK_TAG); Node textContainingNode = getTextContainingNode(lastProcessedNode); Node placeHolderContainer = textContainingNode != null ? textContainingNode : rootNode; placeHolderContainer.appendChild(e); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); t.transform(new DOMSource(rootNode), new StreamResult(sw)); String shortenedContent = sw.toString(); shortenedContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(shortenedContent); return extraxtContentOfBodyTag(shortenedContent); } else { return null; } } catch (ParserConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (SAXException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerFactoryConfigurationError e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (DOMException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (RuntimeException e) { LOGGER.error("Unexpected error processing Content: " + content, e); throw e; } }
NoteShortener { public String processNoteContent(String content) throws NoteStoringPreProcessorException { charsOnLine = 0; curLine = 1; indentLevel = 0; lastProcessedNode = null; try { content = "<root>" + content + "</root>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(content)); Document document = builder.parse(src); Node rootNode = document.getFirstChild(); if (!processChildNodes(rootNode, "root")) { Element e = document.createElement(READ_MORE_LINK_TAG); Node textContainingNode = getTextContainingNode(lastProcessedNode); Node placeHolderContainer = textContainingNode != null ? textContainingNode : rootNode; placeHolderContainer.appendChild(e); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); t.transform(new DOMSource(rootNode), new StreamResult(sw)); String shortenedContent = sw.toString(); shortenedContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(shortenedContent); return extraxtContentOfBodyTag(shortenedContent); } else { return null; } } catch (ParserConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (SAXException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerFactoryConfigurationError e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (DOMException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (RuntimeException e) { LOGGER.error("Unexpected error processing Content: " + content, e); throw e; } } }
NoteShortener { public String processNoteContent(String content) throws NoteStoringPreProcessorException { charsOnLine = 0; curLine = 1; indentLevel = 0; lastProcessedNode = null; try { content = "<root>" + content + "</root>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(content)); Document document = builder.parse(src); Node rootNode = document.getFirstChild(); if (!processChildNodes(rootNode, "root")) { Element e = document.createElement(READ_MORE_LINK_TAG); Node textContainingNode = getTextContainingNode(lastProcessedNode); Node placeHolderContainer = textContainingNode != null ? textContainingNode : rootNode; placeHolderContainer.appendChild(e); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); t.transform(new DOMSource(rootNode), new StreamResult(sw)); String shortenedContent = sw.toString(); shortenedContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(shortenedContent); return extraxtContentOfBodyTag(shortenedContent); } else { return null; } } catch (ParserConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (SAXException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerFactoryConfigurationError e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (DOMException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (RuntimeException e) { LOGGER.error("Unexpected error processing Content: " + content, e); throw e; } } NoteShortener();  NoteShortener(int maxShownLines, int maxCharsOnLine, int maxCharsOnLastLine,
            int indentCharsWidth); }
NoteShortener { public String processNoteContent(String content) throws NoteStoringPreProcessorException { charsOnLine = 0; curLine = 1; indentLevel = 0; lastProcessedNode = null; try { content = "<root>" + content + "</root>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(content)); Document document = builder.parse(src); Node rootNode = document.getFirstChild(); if (!processChildNodes(rootNode, "root")) { Element e = document.createElement(READ_MORE_LINK_TAG); Node textContainingNode = getTextContainingNode(lastProcessedNode); Node placeHolderContainer = textContainingNode != null ? textContainingNode : rootNode; placeHolderContainer.appendChild(e); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); t.transform(new DOMSource(rootNode), new StreamResult(sw)); String shortenedContent = sw.toString(); shortenedContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(shortenedContent); return extraxtContentOfBodyTag(shortenedContent); } else { return null; } } catch (ParserConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (SAXException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerFactoryConfigurationError e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (DOMException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (RuntimeException e) { LOGGER.error("Unexpected error processing Content: " + content, e); throw e; } } NoteShortener();  NoteShortener(int maxShownLines, int maxCharsOnLine, int maxCharsOnLastLine,
            int indentCharsWidth); static String replaceReadMorePlaceHolder(String content, String replacement); String processNoteContent(String content); }
NoteShortener { public String processNoteContent(String content) throws NoteStoringPreProcessorException { charsOnLine = 0; curLine = 1; indentLevel = 0; lastProcessedNode = null; try { content = "<root>" + content + "</root>"; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(content)); Document document = builder.parse(src); Node rootNode = document.getFirstChild(); if (!processChildNodes(rootNode, "root")) { Element e = document.createElement(READ_MORE_LINK_TAG); Node textContainingNode = getTextContainingNode(lastProcessedNode); Node placeHolderContainer = textContainingNode != null ? textContainingNode : rootNode; placeHolderContainer.appendChild(e); Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter sw = new StringWriter(); t.transform(new DOMSource(rootNode), new StreamResult(sw)); String shortenedContent = sw.toString(); shortenedContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(shortenedContent); return extraxtContentOfBodyTag(shortenedContent); } else { return null; } } catch (ParserConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (SAXException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerConfigurationException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerFactoryConfigurationError e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (TransformerException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (DOMException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } catch (RuntimeException e) { LOGGER.error("Unexpected error processing Content: " + content, e); throw e; } } NoteShortener();  NoteShortener(int maxShownLines, int maxCharsOnLine, int maxCharsOnLastLine,
            int indentCharsWidth); static String replaceReadMorePlaceHolder(String content, String replacement); String processNoteContent(String content);  }