@Override public int getLastOffset() { return e.getEnd(); }
@Override public int getLastOffset() { return e.getEnd(); }
/** * Constructs a new <code>BlankOutputSegment</code> with the same span as the specified {@link Segment}. * @param segment a {@link Segment} defining the begin and end character positions of the new <code>OutputSegment</code>. */ public BlankOutputSegment(final Segment segment) { this(segment.getBegin(),segment.getEnd()); }
/** * Constructs a new Attribute, called from Attributes class. * <p> * The resulting Attribute segment begins at the start of the nameSegment * and finishes at the end of the valueSegmentIncludingQuotes. If this attribute * has no value, it finishes at the end of the nameSegment. * <p> * If this attribute has no value, the <code>valueSegment</code> and <code>valueSegmentIncludingQuotes</code> must be null. * The <valueSegmentIncludingQuotes</code> parameter must not be null if the <code>valueSegment</code> is not null, and vice versa * * @param source the {@link Source} document. * @param key the name of this attribute in lower case. * @param nameSegment the segment spanning the name. * @param valueSegment the segment spanning the value. * @param valueSegmentIncludingQuotes the segment spanning the value, including quotation marks if any. */ Attribute(final Source source, final String key, final Segment nameSegment, final Segment valueSegment, final Segment valueSegmentIncludingQuotes) { super(source,nameSegment.getBegin(),(valueSegmentIncludingQuotes==null ? nameSegment.getEnd() : valueSegmentIncludingQuotes.getEnd())); this.key=key; this.nameSegment=nameSegment; this.valueSegment=valueSegment; this.valueSegmentIncludingQuotes=valueSegmentIncludingQuotes; }
private void error(Segment segment, String message) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), message)); } }
private void error(Segment segment, String message) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), message)); } }
private void error(String message) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), message)); }
private GenericMethod findSetter(Segment segment, GenericClass cls, String name) { String methodName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1); GenericMethod[] candidates = typeNavigator.findMethods(cls, methodName, 1); if (candidates.length == 0) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Setter not found for key: " + name)); return null; } else if (candidates.length > 1) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Ambiguous key: " + name)); return null; } else { return candidates[0]; } }
private GenericMethod findSetter(Segment segment, GenericClass cls, String name) { String methodName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1); GenericMethod[] candidates = typeNavigator.findMethods(cls, methodName, 1); if (candidates.length == 0) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Setter not found for key: " + name)); return null; } else if (candidates.length > 1) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Ambiguous key: " + name)); return null; } else { return candidates[0]; } }
private void error(String message) { diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), message)); }
/** * 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); }
public static Span getSpan(Segment e) { return new Span(e.getBegin(), e.getEnd()); }
private void processCurrentSegment() { Segment segment = parser.getCurrentSegment(); // If this tag is inside the previous tag (e.g. a server tag) then // ignore it as it was already output along with the previous tag. if( segment.getEnd() <= lastSegEnd ) { return; } lastSegEnd = segment.getEnd(); if( segment instanceof Tag ) { if( segment instanceof StartTag ) { processStartTag( (StartTag)segment ); } else if ( segment instanceof EndTag ) { processEndTag( (EndTag)segment ); } else { writer.write( segment.toString() ); } } else { processText( segment ); } }
private void processCurrentSegment() { Segment segment = parser.getCurrentSegment(); // If this tag is inside the previous tag (e.g. a server tag) then // ignore it as it was already output along with the previous tag. if( segment.getEnd() <= lastSegEnd ) { return; } lastSegEnd = segment.getEnd(); if( segment instanceof Tag ) { if( segment instanceof StartTag ) { processStartTag( (StartTag)segment ); } else if ( segment instanceof EndTag ) { processEndTag( (EndTag)segment ); } else { writer.write( segment.toString() ); } } else { processText( segment ); } }
@Override public int getLastLine() { return e.getSource().getRowColumnVector(e.getEnd()).getRow(); }
@Override public int getLastLine() { return e.getSource().getRowColumnVector(e.getEnd()).getRow(); }
public static List<Segment> getStyleURISegments(final Segment segment) { if (segment==null || segment.length()==0) return Collections.emptyList(); if (segment.getFirstStartTag()==null) { // no start tags in this segment, assume the segment is a style attribute value int urlDelimiterStartPos=segment.getSource().getParseText().indexOf("url(",segment.getBegin(),segment.getEnd()); if (urlDelimiterStartPos==-1) return Collections.emptyList(); return addURLSegmentsFromCSS(new ArrayList<Segment>(),new Segment(segment.getSource(),urlDelimiterStartPos,segment.getEnd())); } List<Segment> uriSegments=new ArrayList<Segment>(); for (StartTag startTag : segment.getAllStartTags("style",null)) { addURLSegmentsFromCSS(uriSegments,startTag.getAttributes().get("style").getValueSegment()); } for (Element element : segment.getAllElements(HTMLElementName.STYLE)) { addURLSegmentsFromCSS(uriSegments,element.getContent()); } Collections.sort(uriSegments); return uriSegments; }
private static Appendable appendDecode(final Appendable appendable, final Segment segment, final int searchBegin, final boolean insideAttributeValue, final boolean convertNonBreakingSpaces) throws IOException { final Config.UnterminatedCharacterReferenceSettings unterminatedCharacterReferenceSettings=Config.CurrentCompatibilityMode.getUnterminatedCharacterReferenceSettings(insideAttributeValue); final Source source=segment.source; final ParseText parseText=source.getParseText(); final int end=segment.getEnd(); int begin=segment.getBegin(); int pos=parseText.indexOf('&',begin+searchBegin,end); while (pos!=-1) { final CharacterReference characterReference=CharacterReference.construct(source,pos,unterminatedCharacterReferenceSettings); if (characterReference!=null) { appendable.append(source.substring(begin,pos)); // Don't use appendable.append(source,begin,pos) as it checks source.length() which may throw an exception when using StreamedSource. characterReference.appendCharTo(appendable,convertNonBreakingSpaces); begin=characterReference.getEnd(); pos=parseText.indexOf('&',begin,end); } else { pos=parseText.indexOf('&',pos+1,end); } } appendable.append(source.substring(begin,end)); return appendable; }
private static List<Segment> addURLSegmentsFromCSS(final List<Segment> uriSegments, final Segment cssSegment) { final Source source=cssSegment.getSource(); final ParseText parseText=source.getParseText(); final int breakAtIndex=cssSegment.getEnd(); for (int pos=cssSegment.getBegin(); (pos=parseText.indexOf("url(",pos,breakAtIndex))!=-1;) { pos+=4; while (pos<breakAtIndex && Segment.isWhiteSpace(parseText.charAt(pos))) pos++; if (pos>=breakAtIndex) break; if (isQuote(parseText.charAt(pos))) { pos++; if (pos>=breakAtIndex) break; } final int uriBegin=pos; final int closingBracketPos=parseText.indexOf(')',uriBegin,breakAtIndex); if (closingBracketPos==-1) break; pos=closingBracketPos; while (Segment.isWhiteSpace(parseText.charAt(pos-1))) pos--; if (isQuote(parseText.charAt(pos-1))) pos--; final int uriEnd=pos; if (uriEnd<=uriBegin) break; uriSegments.add(new Segment(source,uriBegin,uriEnd)); pos=closingBracketPos; } return uriSegments; }
/** * 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); }