void replaceInOutputDocument(final OutputDocument outputDocument) { for (FormControl formControl : formControls) outputDocument.replace(formControl); } }
public void replaceAttributesInOutputDocumentIfModified(final OutputDocument outputDocument) { if (attributesMap!=null) outputDocument.replace(element.getAttributes(),attributesMap); } }
/** * Replaces the specified {@linkplain Segment segment} in this output document with the specified text. * <p> * Specifying a <code>null</code> argument to the <code>text</code> parameter is exactly equivalent to specifying an empty string, * and results in the segment being completely removed from the output document. * * @param segment the segment to replace. * @param text the replacement text, or <code>null</code> to remove the segment. */ public void replace(final Segment segment, final CharSequence text) { replace(segment.getBegin(),segment.getEnd(),text); }
/** * Process text node to check for {{ }} vue expressions. * * @param textSegment Current segment being processed */ private void processTextNode(Segment textSegment) { context.setCurrentSegment(textSegment); String elementText = textSegment.toString(); Matcher matcher = VUE_MUSTACHE_PATTERN.matcher(elementText); int lastEnd = 0; StringBuilder newText = new StringBuilder(); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); if (start > 0) { newText.append(elementText, lastEnd, start); } currentExpressionReturnType = TypeName.get(String.class); String expressionString = elementText.substring(start + 2, end - 2).trim(); String processedExpression = processExpression(expressionString); newText.append("{{ ").append(processedExpression).append(" }}"); lastEnd = end; } if (lastEnd > 0) { newText.append(elementText.substring(lastEnd)); outputDocument.replace(textSegment, newText.toString()); } }
private void reencodeTextSegment(Source source, OutputDocument outputDocument, int begin, int end) { if (begin >= end) { return; } Segment textSegment = new Segment(source, begin, end); String decodedText = CharacterReference.decode(textSegment); String encodedText = CharacterReference.encode(decodedText); outputDocument.replace(textSegment, encodedText); }
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) {
CharacterReference characterReference = (CharacterReference) segment; } else { outputDocument.replace(segment, doProcessText(segment.toString()));
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() {
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); } } }
outputDocument.replace(childContent, String.valueOf((char)value));
continue; outputDocument.replace(texElement.getStartTag(), TEX_SCRIPT_TAG_START); String content = texElement.getContent().toString().trim(); Pair<Integer, Integer> bounds = getBounds(content); if(bounds.getRight() == 0){ logger.info("Empty source in Tex tag"); outputDocument.replace(texElement.getContent(), StringUtils.EMPTY); } else { String strippedContent = content.substring(bounds.getLeft(), bounds.getRight()); String unescapedContent = StringEscapeUtils.unescapeHtml4(strippedContent); outputDocument.replace(texElement.getContent(), unescapedContent); outputDocument.replace(texElement.getEndTag(), TEX_SCRIPT_TAG_END);
if (oriattr != null) { 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.replace(new Segment(source, attribute.getBegin(), attribute.getEnd()), buf);
if (oriattr != null) { 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.replace(new Segment(source, attribute.getBegin(), attribute.getEnd()), buf);
Map<String, String> attrsUpdate = outputDocument.replace(attrs, true); if (!element.getName().contains("a")) { attrsUpdate.clear();
private boolean processTag(Tag tag, OutputDocument outputDocument) { String elementName = tag.getName().toLowerCase(); if (!allowedTags.contains(elementName)) { return false; } if (tag.getTagType() == StartTagType.NORMAL) { Element element = tag.getElement(); if (HTMLElements.getEndTagRequiredElementNames().contains(elementName)) { if (element.getEndTag() == null) { return false; } } else if (HTMLElements.getEndTagOptionalElementNames().contains(elementName) && element.getEndTag() == null) { outputDocument.insert(element.getEnd(), getEndTagHTML(elementName)); } outputDocument.replace(tag, getStartTagHTML(element.getStartTag())); return true; } if (tag.getTagType() == EndTagType.NORMAL) { if (tag.getElement() == null) { return false; } outputDocument.replace(tag, getEndTagHTML(elementName)); return true; } return false; }
/** * Process v-model expressions. Only @Data fields are allowed in v-model. * * @param vModelAttribute The v-model attribute to process */ private void processVModel(Attribute vModelAttribute) { String vModelValue = vModelAttribute.getValue(); VariableInfo vModelDataField = context.findRootVariable(vModelValue); if (vModelDataField == null) { if (vModelValue.contains(".")) { logger.error("v-model doesn't support dot notation in Vue GWT: \"" + vModelValue + "\". Try using a @Computed with a getter and a setter. Check our documentation on v-model for more information."); } else { logger.error("Couldn't find @Data or @Computed for v-model \"" + vModelValue + "\". V-Model is only supported on @Data and @Computed. Check our documentation on v-model for more information."); } return; } String placeHolderVModelValue = vModelFieldToPlaceHolderField(vModelValue); outputDocument.replace(vModelAttribute.getValueSegment(), placeHolderVModelValue); result.addvModelDataField(vModelDataField); }
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); }