/** Note that an element was started. */ protected void afterStartElement() { afterMarkup(); ++depth; scopeState.push(EnumSet.noneOf(StackState.class)); }
/** Prepare to start an element, by allocating stack space. */ protected void beforeStartElement() { beforeMarkup(); }
afterData(); return; beforeStartElement(); wrappedWriter.add(event); afterStartElement(); return; beforeEndElement(); wrappedWriter.add(event); afterEndElement(); return; case XMLStreamConstants.DTD: beforeMarkup(); wrappedWriter.add(event); afterMarkup(); return; afterEndDocument(); break;
/** Prepare to write markup, by writing a new line and indentation. */ protected void beforeMarkup() { final Set<StackState> state = scopeState.getFirst(); if (!state.contains(StackState.WROTE_DATA) && (depth > 0 || !state.isEmpty())) { final String indent = getIndent(this.depth, this.indentSize); final Characters indentEvent = xmlEventFactory.createCharacters(indent); try { wrappedWriter.add(indentEvent); } catch (XMLStreamException e) { // Ignore exceptions caused by indentation } afterMarkup(); // indentation was written } }
/** Prepare to end an element, by writing a new line and indentation. */ protected void beforeEndElement() { final Set<StackState> state = scopeState.getFirst(); // but not data if (depth > 0 && state.contains(StackState.WROTE_MARKUP) && !state.contains(StackState.WROTE_DATA)) { final String indent = this.getIndent(depth - 1, indentSize); final Characters indentEvent = xmlEventFactory.createCharacters(indent); try { wrappedWriter.add(indentEvent); } catch (XMLStreamException e) { // Ignore exceptions caused by indentation } } }
@Override public String serializeXMLEvents(List<XMLEvent> xmlEvents, boolean isHtml) { final XMLOutputFactory outputFactory; if (isHtml) { outputFactory = this.getHtmlOutputFactory(); } else { outputFactory = this.getXmlOutputFactory(); } final StringWriter writer = new StringWriter(); final XMLEventWriter xmlEventWriter; try { xmlEventWriter = new IndentingXMLEventWriter(outputFactory.createXMLEventWriter(writer)); } catch (XMLStreamException e) { throw new RuntimeException("Failed to create XMLEventWriter", e); } try { for (final XMLEvent bufferedEvent : xmlEvents) { xmlEventWriter.add(bufferedEvent); } xmlEventWriter.flush(); xmlEventWriter.close(); } catch (XMLStreamException e) { throw new RuntimeException("Failed to write XMLEvents to XMLEventWriter", e); } return writer.toString(); }
afterData(); return; beforeStartElement(); wrappedWriter.add(event); afterStartElement(); return; beforeEndElement(); wrappedWriter.add(event); afterEndElement(); return; case XMLStreamConstants.DTD: beforeMarkup(); wrappedWriter.add(event); afterMarkup(); return; afterEndDocument(); break;
/** Prepare to write markup, by writing a new line and indentation. */ protected void beforeMarkup() { final Set<StackState> state = scopeState.getFirst(); if (!state.contains(StackState.WROTE_DATA) && (depth > 0 || !state.isEmpty())) { final String indent = getIndent(this.depth, this.indentSize); final Characters indentEvent = xmlEventFactory.createCharacters(indent); try { wrappedWriter.add(indentEvent); } catch (XMLStreamException e) { // Ignore exceptions caused by indentation } afterMarkup(); // indentation was written } }
/** Prepare to end an element, by writing a new line and indentation. */ protected void beforeEndElement() { final Set<StackState> state = scopeState.getFirst(); // but not data if (depth > 0 && state.contains(StackState.WROTE_MARKUP) && !state.contains(StackState.WROTE_DATA)) { final String indent = this.getIndent(depth - 1, indentSize); final Characters indentEvent = xmlEventFactory.createCharacters(indent); try { wrappedWriter.add(indentEvent); } catch (XMLStreamException e) { // Ignore exceptions caused by indentation } } }
@Override public String serializeXMLEvents(List<XMLEvent> xmlEvents, boolean isHtml) { final XMLOutputFactory outputFactory; if (isHtml) { outputFactory = this.getHtmlOutputFactory(); } else { outputFactory = this.getXmlOutputFactory(); } final StringWriter writer = new StringWriter(); final XMLEventWriter xmlEventWriter; try { xmlEventWriter = new IndentingXMLEventWriter(outputFactory.createXMLEventWriter(writer)); } catch (XMLStreamException e) { throw new RuntimeException("Failed to create XMLEventWriter", e); } try { for (final XMLEvent bufferedEvent : xmlEvents) { xmlEventWriter.add(bufferedEvent); } xmlEventWriter.flush(); xmlEventWriter.close(); } catch (XMLStreamException e) { throw new RuntimeException("Failed to write XMLEvents to XMLEventWriter", e); } return writer.toString(); }
/** Note that an element was started. */ protected void afterStartElement() { afterMarkup(); ++depth; scopeState.push(EnumSet.noneOf(StackState.class)); }
/** Prepare to start an element, by allocating stack space. */ protected void beforeStartElement() { beforeMarkup(); }