/** * Removes all the segments from this output document represented by the specified source {@linkplain Segment} objects. * <p> * This is equivalent to the following code:<pre> * for (Iterator i=segments.iterator(); i.hasNext();) * {@link #remove(Segment) remove}((Segment)i.next());</pre> * * @param segments a collection of segments to remove, represented by source {@link Segment} objects. */ public void remove(final Collection<? extends Segment> segments) { for (Segment segment : segments) remove(segment); }
/** * Constructs a new output document based on the specified {@link Segment}. * @param segment the original {@link Segment}. */ public OutputDocument(final Segment segment) { if (segment==null) throw new IllegalArgumentException("segment argument must not be null"); this.segment=segment; Source source=segment.source; this.sourceText=source; if (segment.begin>0) remove(0,segment.begin); if (segment.end<source.end) remove(segment.end,source.end); }
void replaceInOutputDocument(final OutputDocument outputDocument) { if (outputStyle==FormControlOutputStyle.REMOVE) { outputDocument.remove(getElement()); } else { if (outputStyle==FormControlOutputStyle.DISPLAY_VALUE) setDisabled(true); replaceAttributesInOutputDocumentIfModified(outputDocument); } } }
public static String removeSpans(String html) { Source source = new Source(html); source.fullSequentialParse(); OutputDocument outputDocument = new OutputDocument(source); List<Tag> tags = source.getAllTags(); for (Tag tag : tags) { String tagname = tag.getName().toLowerCase(); if (tagname.equals("span")) { //remove the <span> outputDocument.remove(tag); } } return outputDocument.toString(); }
void replaceInOutputDocument(final OutputDocument outputDocument) { if (outputStyle==FormControlOutputStyle.REMOVE) { outputDocument.remove(getElement()); } else if (outputStyle==FormControlOutputStyle.DISPLAY_VALUE) { final StringBuilder sb=new StringBuilder(100); for (int i=0; i<optionElementContainers.length; i++) { if (optionElementContainers[i].getBooleanAttribute(Attribute.SELECTED)) { sb.append(getOptionLabel(optionElementContainers[i].element)); sb.append(FormControlOutputStyle.ConfigDisplayValue.MultipleValueSeparator); } } if (sb.length()>0) sb.setLength(sb.length()-FormControlOutputStyle.ConfigDisplayValue.MultipleValueSeparator.length()); // remove last separator outputDocument.replace(getElement(),getDisplayValueHTML(sb,false)); } else { replaceAttributesInOutputDocumentIfModified(outputDocument); for (int i=0; i<optionElementContainers.length; i++) { optionElementContainers[i].replaceAttributesInOutputDocumentIfModified(outputDocument); } } } private static String getOptionLabel(final Element optionElement) {
void replaceInOutputDocument(final OutputDocument outputDocument) { if (outputStyle==FormControlOutputStyle.REMOVE) { outputDocument.remove(getElement()); } else if (outputStyle==FormControlOutputStyle.DISPLAY_VALUE) { String output=null; if (formControlType!=FormControlType.HIDDEN) { String value=elementContainer.getAttributeValue(Attribute.VALUE); if (formControlType==FormControlType.PASSWORD && value!=null) value=getString(FormControlOutputStyle.ConfigDisplayValue.PasswordChar,value.length()); output=getDisplayValueHTML(value,false); } outputDocument.replace(getElement(),output); } else { replaceAttributesInOutputDocumentIfModified(outputDocument); } } }
document.remove(new Segment(source, attribute.getBegin() - 1, attribute.getEnd())); // 移除属性 String buf = String.format("#if(%s)%s=\"%s\"#end()", expression, oriattr.getName(), oriattr.getValue()); document.replace(new Segment(source, oriattr.getBegin(), oriattr.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除ifattr控制属性 document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除setattr控制属性
document.remove(new Segment(source, attribute.getBegin() - 1, attribute.getEnd())); // 移除属性 String buf = String.format("#if(%s)%s=\"%s\"#end()", expression, oriattr.getName(), oriattr.getValue()); document.replace(new Segment(source, oriattr.getBegin(), oriattr.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除ifattr控制属性 document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除setattr控制属性
void replaceInOutputDocument(final OutputDocument outputDocument) { if (outputStyle==FormControlOutputStyle.REMOVE) { outputDocument.remove(getElement()); } else { if (outputStyle==FormControlOutputStyle.DISPLAY_VALUE) { final String html=isChecked() ? FormControlOutputStyle.ConfigDisplayValue.CheckedHTML : FormControlOutputStyle.ConfigDisplayValue.UncheckedHTML; if (html!=null) { outputDocument.replace(getElement(),html); return; } setDisabled(true); } replaceAttributesInOutputDocumentIfModified(outputDocument); } } }
@Override public String filter(String source, Map<String, Object> properties) { Source sourceHtml = new Source(source); sourceHtml.setLogger(null); sourceHtml.fullSequentialParse(); OutputDocument outputDocument = new OutputDocument(sourceHtml); List<Tag> tags = sourceHtml.getAllTags(); int pos = 0; for (Tag tag : tags) { boolean correctAndAllowedTag = processTag(tag, outputDocument); if (!correctAndAllowedTag) { String elementName = tag.getName().toLowerCase(); if (removedTags.contains(elementName) || allowedTags.contains(elementName)) { outputDocument.remove(tag); } else { outputDocument.replace(tag, StringEscapeUtils.escapeHtml(tag.toString())); } } reencodeTextSegment(sourceHtml, outputDocument, pos, tag.getBegin()); pos = tag.getEnd(); } reencodeTextSegment(sourceHtml, outputDocument, pos, sourceHtml.getEnd()); return correctNewLineSigns(outputDocument.toString(), properties); }
void replaceInOutputDocument(final OutputDocument outputDocument) { if (outputStyle==FormControlOutputStyle.REMOVE) { outputDocument.remove(getElement()); } else if (outputStyle==FormControlOutputStyle.DISPLAY_VALUE) { outputDocument.replace(getElement(),getDisplayValueHTML(getValue(),true)); } else { replaceAttributesInOutputDocumentIfModified(outputDocument); if (value!=UNCHANGED) outputDocument.replace(getElement().getContent(),CharacterReference.encode(value,false)); } } private String getValue() {