The following document contains the results of PMD's CPD 4.3.
File | Line |
---|---|
de\smartics\xml\CopyReader.java | 83 |
de\smartics\xml\DomCopyReader.java | 95 |
} // ****************************** Inner Classes ***************************** // ********************************* Methods ******************************** // --- init ----------------------------------------------------------------- // --- get&set -------------------------------------------------------------- // --- business ------------------------------------------------------------- /** * Copies the XML fragment to the writer. * * @param xmlFragment the XML fragment to read and write to the writer. * @throws XMLStreamException on any problem reading from the fragment. */ public void copy(final String xmlFragment) throws XMLStreamException { final XMLInputFactory factory = XMLInputFactory.newInstance(); final boolean isFragment = isFragment(xmlFragment); final XMLEventReader eventReader; if (isFragment) { eventReader = factory.createXMLEventReader(new StringReader(ARTIFICIAL_START_TAG + xmlFragment + ARTIFICIAL_END_TAG)); boolean run = true; while (run && eventReader.hasNext()) { final XMLEvent event = eventReader.nextEvent(); if (event.getEventType() == XMLEvent.START_ELEMENT) { run = false; } } } else { eventReader = factory.createXMLEventReader(new StringReader(xmlFragment)); } parse(eventReader); } /** * Checks if the given XML fragment is not enclosed within an element. * * @param xmlFragment the XML fragment to check. * @return <code>true</code> if the fragment is not enclosed in an element, * <code>false</code> otherwise. */ private static boolean isFragment(final String xmlFragment) { return xmlFragment.charAt(0) != '<'; } /** * Parses the events from the given event reader. * * @param eventReader the event reader to read the events from. * @throws XMLStreamException on any problem reading the events. */ private void parse(final XMLEventReader eventReader) throws XMLStreamException { int level = 0; // NOPMD while (eventReader.hasNext()) { final XMLEvent event = eventReader.nextEvent(); switch (event.getEventType()) { case XMLEvent.START_ELEMENT: level++; // NOPMD handleStartElement(event); break; case XMLEvent.END_ELEMENT: level--; if (level >= 0) { |