private CommandSnippetComment getComment(Document document) { for (Object content : document.getContent()) { if (content instanceof Comment) { return new CommandSnippetTextComment(((Comment) content).getText()); } } return new EmptySnippetComment(); }
/** * This will handle printing of a {@link Comment}. * * @param fstack * the FormatStack * @param basedoc * The org.w3c.dom.Document for creating DOM Nodes * @param comment * <code>Comment</code> to write. * @return The input JDOM Comment converted to a DOM Comment */ protected org.w3c.dom.Comment printComment(final FormatStack fstack, final org.w3c.dom.Document basedoc, final Comment comment) { return basedoc.createComment(comment.getText()); }
/** * This will handle printing of a {@link Comment}. * * @param out * <code>XMLStreamWriter</code> to use. * @param fstack * the FormatStack * @param comment * <code>Comment</code> to write. * @throws XMLStreamException * if the destination XMLStreamWriter fails */ protected void printComment(final XMLStreamWriter out, final FormatStack fstack, final Comment comment) throws XMLStreamException { out.writeComment(comment.getText()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Comment}</code> * to the <code>{@link Document}</code> is illegal. * * @param added <code>Comment</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Comment added, String reason) { super(new StringBuilder() .append("The comment \"") .append(added.getText()) .append("\" could not be added to the top level of the document: ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Comment}</code> * to the <code>{@link Element}</code> is illegal. * * @param base <code>Element</code> that the <code>Comment</code> * couldn't be added to * @param added <code>Comment</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, Comment added, String reason) { super(new StringBuilder() .append("The comment \"") .append(added.getText()) .append("\" could not be added as content to \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * This will handle printing of a {@link Comment}. * * @param out * <code>XMLEventConsumer</code> to use. * @param fstack * the FormatStack * @param eventfactory * The XMLEventFactory for creating XMLEvents * @param comment * <code>Comment</code> to write. * @throws XMLStreamException * if the destination XMLEventConsumer fails */ protected void printComment(final XMLEventConsumer out, final FormatStack fstack, final XMLEventFactory eventfactory, final Comment comment) throws XMLStreamException { out.add(eventfactory.createComment(comment.getText())); }
/** * This will handle printing of a {@link Comment}. * * @param out * <code>SAXTarget</code> to use. * @param fstack * the FormatStack * @param comment * <code>Comment</code> to write. * @throws SAXException * if the destination SAXTarget fails */ protected void printComment(final SAXTarget out, final FormatStack fstack, final Comment comment) throws SAXException { if (out.getLexicalHandler() != null) { char[] c = comment.getText().toCharArray(); out.getLexicalHandler().comment(c, 0, c.length); } }
/** * This will handle printing of a {@link Comment}. * * @param out * <code>Writer</code> to use. * @param fstack * the FormatStack * @param comment * <code>Comment</code> to write. * @throws IOException * if the destination Writer fails */ protected void printComment(final Writer out, final FormatStack fstack, final Comment comment) throws IOException { write(out, "<!--"); write(out, comment.getText()); write(out, "-->"); }
private void normaliseLineEndings( Document document ) { for ( Iterator<?> i = document.getDescendants( new ContentFilter( ContentFilter.COMMENT ) ); i.hasNext(); ) { Comment c = (Comment) i.next(); c.setText( ReleaseUtil.normalizeLineEndings( c.getText(), ls ) ); } for ( Iterator<?> i = document.getDescendants( new ContentFilter( ContentFilter.CDATA ) ); i.hasNext(); ) { CDATA c = (CDATA) i.next(); c.setText( ReleaseUtil.normalizeLineEndings( c.getText(), ls ) ); } }
private IConstructor convertContent(Content content, boolean trim) throws Skip { if (content instanceof Element) { return convertElement((Element)content, trim); } if (content instanceof CDATA) { // CDATA first (is subtype of Text) CDATA cdata = (CDATA)content; return vf.constructor(Factory.Node_cdata, getString(trim, cdata)); } if (content instanceof Text) { Text text = (Text)content; return vf.constructor(Factory.Node_charData, getString(trim, text)); } if (content instanceof Comment) { Comment comment = (Comment)content; IString data = vf.string(comment.getText()); return vf.constructor(Factory.Node_comment, data); } if (content instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction)content; IString data = vf.string(pi.getData()); return vf.constructor(Factory.Node_pi, data); } if (content instanceof EntityRef) { EntityRef er = (EntityRef)content; IString data = vf.string(er.getName()); return vf.constructor(Factory.Node_entityRef, data); } throw new AssertionError("cannot convert JDOM content type " + content.getClass()); }