boolean hasAttribute(final String attributeName, final Pattern valueRegexPattern) { if (attributes==null) return false; final Attribute attribute=attributes.get(attributeName); if (attribute==null) return false; if (valueRegexPattern==null) return true; final String attributeValue=attribute.getValue(); return attributeValue!=null && valueRegexPattern.matcher(attributeValue).matches(); }
public boolean getBooleanAttribute(final String attributeName) { if (attributesMap!=null) return attributesMap.containsKey(attributeName); else return element.getAttributes().get(attributeName)!=null; }
public boolean includeAttribute(final StartTag startTag, final Attribute attribute) { return startTag.getAttributes().get("name")!=null; } };
/** * Returns the {@linkplain CharacterReference#decode(CharSequence) decoded} value of the attribute with the specified name (case insensitive). * <p> * Returns <code>null</code> if no attribute with the specified name exists or * the attribute {@linkplain Attribute#hasValue() has no value}. * <p> * This is equivalent to {@link #get(String) get(name)}<code>.</code>{@link Attribute#getValue() getValue()}, * except that it returns <code>null</code> if no attribute with the specified name exists instead of throwing a * <code>NullPointerException</code>. * * @param name the name of the attribute to get. * @return the {@linkplain CharacterReference#decode(CharSequence) decoded} value of the attribute with the specified name, or <code>null</code> if the attribute does not exist or {@linkplain Attribute#hasValue() has no value}. * @see Attribute#getValue() */ public String getValue(final String name) { final Attribute attribute=get(name); return attribute==null ? null : attribute.getValue(); }
private static boolean isScopedStyleElement(Element element) { return element != null && "style".equalsIgnoreCase(element.getName()) && element.getAttributes() != null && element.getAttributes().get("scoped") != null; }
public static List<Attribute> getList(final Segment segment) { if (segment==null || segment.getFirstStartTag()==null) return Collections.emptyList(); List<Attribute> attributes=new ArrayList<Attribute>(); for (String uriAttributeName : uriAttributeNames) { for (StartTag startTag : segment.getAllStartTags(uriAttributeName,null)) { Attribute attribute=startTag.getAttributes().get(uriAttributeName); attribute.startTag=startTag; attributes.add(attribute); } } for (StartTag startTag : segment.getAllStartTags(HTMLElementName.OBJECT)) { for (String uriAttributeName : objectURIAttributeNames) { Attribute attribute=startTag.getAttributes().get(uriAttributeName); if (attribute==null) continue; attribute.startTag=startTag; attributes.add(attribute); } } Collections.sort(attributes); return attributes; }
/** * 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(); }
@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); } } } }
public SelectFormControl(final Element element) { super(element,element.getAttributes().get(Attribute.MULTIPLE)!=null ? FormControlType.SELECT_MULTIPLE : FormControlType.SELECT_SINGLE,false); final List<Element> optionElements=element.getAllElements(HTMLElementName.OPTION); optionElementContainers=new ElementContainer[optionElements.size()]; int x=0; for (Element optionElement : optionElements) { final ElementContainer optionElementContainer=new ElementContainer(optionElement,true); if (optionElementContainer.predefinedValue==null) // use the content of the element if it has no value attribute optionElementContainer.predefinedValue=CharacterReference.decodeCollapseWhiteSpace(optionElementContainer.element.getContent()); optionElementContainers[x++]=optionElementContainer; } } public String getPredefinedValue() {
@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 Attributes attributes = element.getAttributes(); if (attributes == null) { return; } final Attribute debugAttr = attributes.get(CF.DEBUG); if (debugAttr != null) { if(!debugAttr.hasValue() || (!debugAttr.getValue().equalsIgnoreCase("no") && !debugAttr.getValue().equalsIgnoreCase("false"))) context.addMessage("AVOID_USING_DEBUG_ATTR", null); } if (element.getName().equalsIgnoreCase(CF.CFSETTING)) { final Attribute showDebugOutputAttr = element.getAttributes().get("showDebugOutput"); if (showDebugOutputAttr != null) { if ("Yes".equalsIgnoreCase(showDebugOutputAttr.getValue()) || "true".equalsIgnoreCase(showDebugOutputAttr.getValue())) { context.addMessage("AVOID_USING_CFSETTING_DEBUG", null); } } } } }
@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; } } }
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; }
/** * 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); } }