/** * Returns the raw (not {@linkplain CharacterReference#decode(CharSequence) decoded}) value of the attribute, or null if the attribute {@linkplain Attribute#hasValue() has no value}. * <p> * This is an internal convenience method. * * @return the raw (not {@linkplain CharacterReference#decode(CharSequence) decoded}) value of the attribute, or null if the attribute {@linkplain Attribute#hasValue() has no value}. */ String getRawValue(final String name) { final Attribute attribute=get(name); return attribute==null || !attribute.hasValue() ? null : attribute.getValueSegment().toString(); }
private void processAttribute( Attribute attribute ) { writer.write( " " ); writer.write( attribute.getName() ); if(attribute.hasValue()) { /* * non decoded value, return the raw value of the attribute as it appears * in the source document, without decoding, see KNOX-791. */ String inputValue = attribute.getValueSegment().toString(); String outputValue = inputValue; try { Level tag = stack.peek(); String name = getRuleName(inputValue); outputValue = filterAttribute( tag.getQName(), tag.getQName( attribute.getName() ), inputValue, name ); if( outputValue == null ) { outputValue = inputValue; } } catch ( Exception e ) { LOG.failedToFilterAttribute( attribute.getName(), e ); } writer.write( "=" ); writer.write( attribute.getQuoteChar() ); writer.write( outputValue ); writer.write( attribute.getQuoteChar() ); } }
private void processAttribute( Attribute attribute ) { writer.write( " " ); writer.write( attribute.getName() ); if(attribute.hasValue()) { /* * non decoded value, return the raw value of the attribute as it appears * in the source document, without decoding, see KNOX-791. */ String inputValue = attribute.getValueSegment().toString(); String outputValue = inputValue; try { Level tag = stack.peek(); String name = getRuleName(inputValue); outputValue = filterAttribute( tag.getQName(), tag.getQName( attribute.getName() ), inputValue, name ); if( outputValue == null ) { outputValue = inputValue; } } catch ( Exception e ) { LOG.failedToFilterAttribute( attribute.getName(), e ); } writer.write( "=" ); writer.write( attribute.getQuoteChar() ); writer.write( outputValue ); writer.write( attribute.getQuoteChar() ); } }
private Map<String, Pair<String, Position>> makeAllAttributes() { Map<String, Pair<String, Position>> result = HashMapFactory.make(); if (innerElement.getStartTag().getAttributes() != null) { for (Attribute a : innerElement.getStartTag().getAttributes()) { result.put( a.getName().toLowerCase(), Pair.make(a.getValue(), getPosition(a.getValueSegment()))); } } return result; }
private Map<String, Pair<String, Position>> makeAllAttributes() { Map<String, Pair<String, Position>> result = HashMapFactory.make(); if (innerElement.getStartTag().getAttributes() != null) { for (Attribute a : innerElement.getStartTag().getAttributes()) { result.put( a.getName().toLowerCase(), Pair.make(a.getValue(), getPosition(a.getValueSegment()))); } } return result; }
@Override public void element(final Element element, final Context context, final BugList bugs) { final String name = element.getName(); final int line = element.getSource().getRow(element.getBegin()); int offset = element.getBegin(); if (name != null && name.trim().length() > 0 && context.isInFunction()) { if (checkNames.contains(name.toLowerCase())) { offset = element.getAttributes().get(CF.NAME) != null ? element.getAttributes().get(CF.NAME).getValueSegment().getBegin() : offset; assertVariable(element, context, bugs, element.getAttributeValue(CF.NAME), line, offset); } if (checkElementAttributes.containsKey(name.toLowerCase())) { for (final String attrName : checkElementAttributes.get(name.toLowerCase())) { offset = element.getAttributes().get(attrName) != null ? element.getAttributes().get(attrName).getValueSegment().getBegin() : offset; assertVariable(element, context, bugs, element.getAttributeValue(attrName), line, offset); } } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { final String name = element.getName(); final int line = element.getSource().getRow(element.getBegin()); int offset = element.getBegin(); if (name != null && name.trim().length() > 0 && context.isInFunction()) { if (checkNames.contains(name.toLowerCase())) { offset = element.getAttributes().get(CF.NAME) != null ? element.getAttributes().get(CF.NAME).getValueSegment().getBegin() : offset; assertVariable(element, context, bugs, element.getAttributeValue(CF.NAME), line, offset); } if (checkElementAttributes.containsKey(name.toLowerCase())) { for (final String attrName : checkElementAttributes.get(name.toLowerCase())) { offset = element.getAttributes().get(attrName) != null ? element.getAttributes().get(attrName).getValueSegment().getBegin() : offset; assertVariable(element, context, bugs, element.getAttributeValue(attrName), line, offset); } } } }
.lastIndexOf("charset=") + "charset=".length(); //$NON-NLS-1$ int valueStartPos = (attribute.getValueSegment().getBegin() + charsetValueOffset) - tag.getBegin(); int valueEndPos = attribute.getValueSegment().getEnd() - tag.getBegin();
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFARGUMENT)) { final String name = element.getAttributeValue(CF.NAME) != null ? element.getAttributeValue(CF.NAME) : ""; ArgInfo argInfo = new ArgInfo(); argInfo.casedName=name; argInfo.argumentLineNo=context.startLine(); argInfo.argumentOffset=element.getAttributeValue(CF.NAME) != null ? element.getAttributes().get(CF.NAME).getValueSegment().getBegin() : element.getBegin(); argInfo.type=element.getAttributeValue(CF.TYPE); currentArgs.put(name.toLowerCase(), argInfo); final String code = element.getParentElement().toString(); if (isUsed(code, name.toLowerCase())) { argInfo.used=true; } } }
@Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFARGUMENT)) { final String name = element.getAttributeValue(CF.NAME) != null ? element.getAttributeValue(CF.NAME) : ""; ArgInfo argInfo = new ArgInfo(); argInfo.casedName=name; argInfo.argumentLineNo=context.startLine(); argInfo.argumentOffset=element.getAttributeValue(CF.NAME) != null ? element.getAttributes().get(CF.NAME).getValueSegment().getBegin() : element.getBegin(); argInfo.type=element.getAttributeValue(CF.TYPE); currentArgs.put(name.toLowerCase(), argInfo); final String code = element.getParentElement().toString(); if (isUsed(code, name.toLowerCase())) { argInfo.used=true; } } }
/** * 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); }
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; }
/** * 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); }
/** * Parse a CF argument tag to see if any of the arguments names are invalid. */ @Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFARGUMENT)) { final int lineNo = context.startLine(); int offset = context.offset(); final String name = element.getAttributeValue(CF.NAME); if (name != null && name.length() > 0) { offset = element.getAttributes().get(CF.NAME).getValueSegment().getBegin(); checkNameForBugs(context, name, context.getFilename(), context.getFunctionName(), lineNo, offset, bugs); } else { context.addMessage("ARGUMENT_MISSING_NAME", null, this, lineNo, offset); } } }
/** * Parse a CF argument tag to see if any of the arguments names are invalid. */ @Override public void element(final Element element, final Context context, final BugList bugs) { if (element.getName().equals(CF.CFARGUMENT)) { final int lineNo = context.startLine(); int offset = context.offset(); final String name = element.getAttributeValue(CF.NAME); if (name != null && name.length() > 0) { offset = element.getAttributes().get(CF.NAME).getValueSegment().getBegin(); checkNameForBugs(context, name, context.getFilename(), context.getFunctionName(), lineNo, offset, bugs); } else { context.addMessage("ARGUMENT_MISSING_NAME", null, this, lineNo, offset); } } }
private void checkCFLoopName(final Element element, final Context context, final BugList bugs, final int begLine, int offset) { if (element.getAttributeValue(CF.INDEX) != null || element.getAttributeValue(CF.ITEM) != null) { String varName = ""; final String index = element.getAttributeValue(CF.INDEX); final String item = element.getAttributeValue(CF.ITEM); if (index != null) { varName = index; offset = element.getAttributes().get(CF.INDEX).getValueSegment().getBegin(); } else if (item != null) { varName = item; offset = element.getAttributes().get(CF.ITEM).getValueSegment().getBegin(); } checkNameForBugs(context, varName, varName, context.getFilename(), context.getFunctionName(), begLine, offset, bugs,null); } }
private void checkCFLoopName(final Element element, final Context context, final BugList bugs, final int begLine, int offset) { if (element.getAttributeValue(CF.INDEX) != null || element.getAttributeValue(CF.ITEM) != null) { String varName = ""; final String index = element.getAttributeValue(CF.INDEX); final String item = element.getAttributeValue(CF.ITEM); if (index != null) { varName = index; offset = element.getAttributes().get(CF.INDEX).getValueSegment().getBegin(); } else if (item != null) { varName = item; offset = element.getAttributes().get(CF.ITEM).getValueSegment().getBegin(); } checkNameForBugs(context, varName, varName, context.getFilename(), context.getFunctionName(), begLine, offset, bugs,null); } }
private void checkCFName(final Element element, final Context context, final BugList bugs, final int begLine, int offset, final String name) { if (element.getAttributeValue(name) != null) { final Attribute attribute = element.getAttributes().get(name); String varName; if (attribute != null) { varName = attribute.getValue(); offset = attribute.getValueSegment().getBegin(); } else { varName = ""; } checkNameForBugs(context, varName, varName, context.getFilename(), context.getFunctionName(), begLine, offset, bugs,null); } }
private void checkCFName(final Element element, final Context context, final BugList bugs, final int begLine, int offset, final String name) { if (element.getAttributeValue(name) != null) { final Attribute attribute = element.getAttributes().get(name); String varName; if (attribute != null) { varName = attribute.getValue(); offset = attribute.getValueSegment().getBegin(); } else { varName = ""; } checkNameForBugs(context, varName, varName, context.getFilename(), context.getFunctionName(), begLine, offset, bugs,null); } }
if (includeAttribute(startTag,attribute)) sb.append(' ').append(attribute.getValueSegment()).append(' ');