public ParserTag getPreviousTag(int i) { Tag encosingTag = fSource.getEnclosingTag(i); Tag parserTag = fSource.getPreviousTag(i); if (parserTag.getBegin() == encosingTag.getBegin()) return makeParserTag(fSource.getPreviousTag(encosingTag.getBegin() - 1)); return makeParserTag(fSource.getPreviousTag(i)); }
for (Tag tag : tags) { if (quickCutTags.contains(tag.getName())) { String cutHtml = source.substring(0, tag.getBegin()); return cutHtml + getClosingTagsBehindElement(tag.getElement()) + SHORTED_FORM_END; if (tag.getBegin() >= maxLength + tagSpace) { return processFirstTagOutOfBounds(source, tag, maxLength, tagSpace); tagSpace += tag.getEnd() - tag.getBegin();
protected Tag constructTagAt(final Source source, final int pos) { final int closingDelimiterPos=source.getParseText().indexOf('>',pos+1); if (closingDelimiterPos==-1) return null; final Tag tag=constructStartTag(source,pos,closingDelimiterPos+1,"",null); if (source.logger.isErrorEnabled()) source.logger.error(source.getRowColumnVector(tag.getBegin()).appendTo(new StringBuilder(200).append("Encountered possible StartTag at ")).append(" whose content does not match a registered StartTagType").toString()); return tag; } }
private String processFirstTagOutOfBounds(String source, Tag tag, int maxLength, int tagSpace) { String cutHtml = null; if (tag.getTagType() == StartTagType.NORMAL) { int whitespacePos = maxLength + tagSpace - 1; while (whitespacePos < source.length() && !Character.isWhitespace(source.charAt(whitespacePos)) && !PUNCTUATION_SIGNS.contains(source.charAt(whitespacePos))) { ++whitespacePos; } cutHtml = (whitespacePos < tag.getBegin()) ? source.substring(0, whitespacePos) : source.substring(0, tag.getBegin()); return cutHtml + getClosingTagsBehindElement(tag.getElement()) + SHORTED_FORM_END; } else { cutHtml = source.substring(0, tag.getEnd()); boolean appendShorteningSign = true; if (tag.getElement() == null) { logger.error("DATA ERROR: No element in tag {}", source); return cutHtml + SHORTED_FORM_END; } else if (tag.getElement().getEnd() == source.length()) { appendShorteningSign = false; } return cutHtml + getClosingTagsBehindElement(tag.getElement()) + ((appendShorteningSign) ? SHORTED_FORM_END : ""); } }
private void parseSegment(int limit, List<TemplateNode> result, Predicate<Element> filter) { while (position < limit) { Tag tag = source.getNextTag(position); if (tag == null || tag.getBegin() > limit) { if (position < limit) { DOMText text = new DOMText(parseText(position, limit)); text.setLocation(new Location(position, limit)); result.add(text); } position = limit; break; } if (position < tag.getBegin()) { DOMText text = new DOMText(parseText(position, tag.getBegin())); text.setLocation(new Location(position, tag.getBegin())); result.add(text); } position = tag.getEnd(); parseTag(tag, result, filter); } }
/** * Create a {@link PropertyTextUnitPlaceholder} given the supplied type, name and Jericho {@link Tag} and * {@link Attribute}. * * @param type * - {@link PlaceholderAccessType} is one of TRANSLATABLE, READ_ONLY_PROPERTY, WRITABLE_PROPERTY * @param name * - attribute name * @param value * - attribute value * @param tag * - Jericho {@link Tag} which contains the attribute * @param attribute * - attribute as a Jericho {@link Attribute} * @return a {@link PropertyTextUnitPlaceholder} representing the attribute */ protected PropertyTextUnitPlaceholder createPropertyTextUnitPlaceholder( PlaceholderAccessType type, String name, String value, Tag tag, Attribute attribute) { // offset of attribute int mainStartPos = attribute.getBegin() - tag.getBegin(); int mainEndPos = attribute.getEnd() - tag.getBegin(); // offset of value of the attribute int valueStartPos = attribute.getValueSegment().getBegin() - tag.getBegin(); int valueEndPos = attribute.getValueSegment().getEnd() - tag.getBegin(); return new PropertyTextUnitPlaceholder(type, normalizeAttributeName(name, value, tag), value, mainStartPos, mainEndPos, valueStartPos, valueEndPos); }
private void parseSegment(int limit, List<TemplateNode> result, Predicate<Element> filter) { while (position < limit) { Tag tag = source.getNextTag(position); if (tag == null || tag.getBegin() > limit) { if (position < limit) { DOMText text = new DOMText(parseText(position, limit)); text.setLocation(new Location(position, limit)); result.add(text); } position = limit; break; } if (position < tag.getBegin()) { DOMText text = new DOMText(parseText(position, tag.getBegin())); text.setLocation(new Location(position, tag.getBegin())); result.add(text); } position = tag.getEnd(); parseTag(tag, result, filter); } }
System.out.println("Tag name mismatch: tag1=" + tag1.getBegin() + "; tag2=" + tag2.getBegin()); System.out.println("Expected: " + tag1.getName() + "; Actual: " + tag2.getName()); return false; System.out.println("Tag not start tag: tag1=" + tag1.getBegin() + "; tag2=" + tag2.getBegin()); return false; System.out.println("Content mismatch: tag1=" + tag1.getBegin() + "; tag2=" + tag2.getBegin()); System.out.println("C1: " + content1); System.out.println("C2: " + content2);
@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); }
final int parentTag = thisTag; tagInfo.add(parentTag); tagInfo.add(tag.getBegin(), tag.getEnd()); tagInfo.add(-1, -1);//these 2 will be populated when we get to the close tag thisTag = tagCounter++; parentChangeOffsets.add(tag.getBegin()); parentChangeIds.add(thisTag); nonTaggableOffsets.add(tag.getBegin()); tagInfo.set(5 * thisTag + 3, tag.getBegin()); tagInfo.set(5 * thisTag + 4, tag.getEnd()); thisTag = getParentTag(thisTag);
final int parentTag = thisTag; tagInfo.add(parentTag); tagInfo.add(tag.getBegin(), tag.getEnd()); tagInfo.add(-1, -1);//these 2 will be populated when we get to the close tag thisTag = tagCounter++; parentChangeOffsets.add(tag.getBegin()); parentChangeIds.add(thisTag); nonTaggableOffsets.add(tag.getBegin()); tagInfo.set(5 * thisTag + 3, tag.getBegin()); tagInfo.set(5 * thisTag + 4, tag.getEnd()); thisTag = getParentTag(thisTag);
if ( tag.getBegin() < prevTagEnd ) {