@Test public void testForKENMEI5902() throws NoteStoringPreProcessorException, IOException { String content = "<body><p><ol type=\"1\"><li style=\"disply: block;\">Hello</li></ol></p></body>"; NoteStoringTO noteStoringTO = new NoteStoringTO(); noteStoringTO.setContent(content); new RemoveUnsupportedMarkupNotePreProcessor().process(noteStoringTO); Assert.assertEquals(noteStoringTO.getContent(), "<p><ol><li>Hello</li></ol></p>"); content = "<body><p><ul type=\"1\"><li style=\"mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo1\">Hello</li></ul></p></body>"; noteStoringTO = new NoteStoringTO(); noteStoringTO.setContent(content); new RemoveUnsupportedMarkupNotePreProcessor().process(noteStoringTO); Assert.assertEquals(noteStoringTO.getContent(), "<p><ul><li>Hello</li></ul></p>"); }
@Override public NoteStoringTO process(NoteStoringTO note) throws NoteStoringPreProcessorException { String escapedContent = getHTMLEscapedContent(note.getContent(), note.getContentType()); note.setContentType(NoteContentType.HTML); note.setContent(escapedContent); escapedContent = addRequiredElements(escapedContent); escapedContent = HTMLHelper.removeHeadElement(escapedContent); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(escapedContent)); Document document = builder.parse(src); DOMConfiguration domConfig = document.getDomConfig(); domConfig.setParameter("cdata-sections", false); domConfig.setParameter("comments", false); document.normalizeDocument(); Node bodyNode = getBodyNode(document); Node child = bodyNode.getFirstChild(); while (child != null) { child = processDomNode(child); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(bodyNode), new StreamResult(stringWriter)); String finalContent = stringWriter.toString(); finalContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(finalContent); note.setContent(extraxtContentOfBodyTag(finalContent)); } 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 (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } return note; }
RemoveUnsupportedMarkupNotePreProcessor implements
NoteStoringEditableContentPreProcessor { @Override public NoteStoringTO process(NoteStoringTO note) throws NoteStoringPreProcessorException { String escapedContent = getHTMLEscapedContent(note.getContent(), note.getContentType()); note.setContentType(NoteContentType.HTML); note.setContent(escapedContent); escapedContent = addRequiredElements(escapedContent); escapedContent = HTMLHelper.removeHeadElement(escapedContent); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(escapedContent)); Document document = builder.parse(src); DOMConfiguration domConfig = document.getDomConfig(); domConfig.setParameter("cdata-sections", false); domConfig.setParameter("comments", false); document.normalizeDocument(); Node bodyNode = getBodyNode(document); Node child = bodyNode.getFirstChild(); while (child != null) { child = processDomNode(child); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(bodyNode), new StreamResult(stringWriter)); String finalContent = stringWriter.toString(); finalContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(finalContent); note.setContent(extraxtContentOfBodyTag(finalContent)); } 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 (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } return note; } }
RemoveUnsupportedMarkupNotePreProcessor implements
NoteStoringEditableContentPreProcessor { @Override public NoteStoringTO process(NoteStoringTO note) throws NoteStoringPreProcessorException { String escapedContent = getHTMLEscapedContent(note.getContent(), note.getContentType()); note.setContentType(NoteContentType.HTML); note.setContent(escapedContent); escapedContent = addRequiredElements(escapedContent); escapedContent = HTMLHelper.removeHeadElement(escapedContent); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(escapedContent)); Document document = builder.parse(src); DOMConfiguration domConfig = document.getDomConfig(); domConfig.setParameter("cdata-sections", false); domConfig.setParameter("comments", false); document.normalizeDocument(); Node bodyNode = getBodyNode(document); Node child = bodyNode.getFirstChild(); while (child != null) { child = processDomNode(child); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(bodyNode), new StreamResult(stringWriter)); String finalContent = stringWriter.toString(); finalContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(finalContent); note.setContent(extraxtContentOfBodyTag(finalContent)); } 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 (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } return note; } RemoveUnsupportedMarkupNotePreProcessor(); }
RemoveUnsupportedMarkupNotePreProcessor implements
NoteStoringEditableContentPreProcessor { @Override public NoteStoringTO process(NoteStoringTO note) throws NoteStoringPreProcessorException { String escapedContent = getHTMLEscapedContent(note.getContent(), note.getContentType()); note.setContentType(NoteContentType.HTML); note.setContent(escapedContent); escapedContent = addRequiredElements(escapedContent); escapedContent = HTMLHelper.removeHeadElement(escapedContent); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(escapedContent)); Document document = builder.parse(src); DOMConfiguration domConfig = document.getDomConfig(); domConfig.setParameter("cdata-sections", false); domConfig.setParameter("comments", false); document.normalizeDocument(); Node bodyNode = getBodyNode(document); Node child = bodyNode.getFirstChild(); while (child != null) { child = processDomNode(child); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(bodyNode), new StreamResult(stringWriter)); String finalContent = stringWriter.toString(); finalContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(finalContent); note.setContent(extraxtContentOfBodyTag(finalContent)); } 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 (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } return note; } RemoveUnsupportedMarkupNotePreProcessor(); @Override int getOrder(); @Override boolean isProcessAutosave(); @Override NoteStoringTO process(NoteStoringTO note); @Override NoteStoringTO processEdit(Note noteToEdit, NoteStoringTO noteStoringTO); }
RemoveUnsupportedMarkupNotePreProcessor implements
NoteStoringEditableContentPreProcessor { @Override public NoteStoringTO process(NoteStoringTO note) throws NoteStoringPreProcessorException { String escapedContent = getHTMLEscapedContent(note.getContent(), note.getContentType()); note.setContentType(NoteContentType.HTML); note.setContent(escapedContent); escapedContent = addRequiredElements(escapedContent); escapedContent = HTMLHelper.removeHeadElement(escapedContent); try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource src = new InputSource(new StringReader(escapedContent)); Document document = builder.parse(src); DOMConfiguration domConfig = document.getDomConfig(); domConfig.setParameter("cdata-sections", false); domConfig.setParameter("comments", false); document.normalizeDocument(); Node bodyNode = getBodyNode(document); Node child = bodyNode.getFirstChild(); while (child != null) { child = processDomNode(child); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(bodyNode), new StreamResult(stringWriter)); String finalContent = stringWriter.toString(); finalContent = HTMLHelper.convertXmlSerializedHtmlToLegalHtml(finalContent); note.setContent(extraxtContentOfBodyTag(finalContent)); } 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 (IOException e) { throw new NoteStoringPreProcessorException(e.getMessage()); } return note; } RemoveUnsupportedMarkupNotePreProcessor(); @Override int getOrder(); @Override boolean isProcessAutosave(); @Override NoteStoringTO process(NoteStoringTO note); @Override NoteStoringTO processEdit(Note noteToEdit, NoteStoringTO noteStoringTO);  }