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; }
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(); }
/** * 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); }
/** * 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 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); } }
Element(String name, Iterable<Attribute> attrs) { this.name = name; for (Attribute attr : attrs) { put(attr.getName(), attr.getValue()); } }
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 parseNamespaces() { Attributes attributes = tag.getAttributes(); if( attributes != null ) { for( Attribute attribute : tag.getAttributes() ) { String name = attribute.getName(); if( name.toLowerCase(Locale.ROOT).startsWith( "xmlns" ) ) { int colon = name.indexOf( ":", 5 ); String prefix; if( colon <= 0 ) { prefix = ""; } else { prefix = name.substring( colon ); } namespaces.put( prefix, attribute.getValue() ); } } } }
private void parseNamespaces() { Attributes attributes = tag.getAttributes(); if( attributes != null ) { for( Attribute attribute : tag.getAttributes() ) { String name = attribute.getName(); if( name.toLowerCase(Locale.ROOT).startsWith( "xmlns" ) ) { int colon = name.indexOf( ':', 5 ); String prefix; if( colon <= 0 ) { prefix = ""; } else { prefix = name.substring( colon ); } namespaces.put( prefix, attribute.getValue() ); } } } }
@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) { 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); } } } } }
private CharSequence getStartTagHTML(StartTag startTag) { // tidies and filters out non-approved attributes StringBuilder sb = new StringBuilder(); sb.append('<').append(startTag.getName()); for (Attribute attribute : startTag.getAttributes()) { if (allowedAttributes.contains(attribute.getKey().toLowerCase())) { sb.append(' ').append(attribute.getName()); if (attribute.getValue() != null) { sb.append("=\""); sb.append(CharacterReference.encode(attribute.getValue())); sb.append('"'); } } } if (startTag.getElement().getEndTag() == null && !HTMLElements.getEndTagOptionalElementNames().contains(startTag.getName())) { sb.append(" /"); } sb.append('>'); return sb; }
/** * Populates the specified <code>Map</code> with the name/value pairs from these attributes. * <p> * Both names and values are stored as <code>String</code> objects. * <p> * The entries are added in order of apprearance in the source document. * <p> * An attribute with {@linkplain Attribute#hasValue() no value} is represented by a map entry with a <code>null</code> value. * <p> * Attribute values are automatically {@linkplain CharacterReference#decode(CharSequence) decoded} * before storage in the map. * * @param attributesMap the map to populate, must not be <code>null</code>. * @param convertNamesToLowerCase specifies whether all attribute names are converted to lower case in the map. * @return the same map specified as the argument to the <code>attributesMap</code> parameter, populated with the name/value pairs from these attributes. * @see #generateHTML(Map attributesMap) */ public Map<String,String> populateMap(final Map<String,String> attributesMap, final boolean convertNamesToLowerCase) { for (Attribute attribute : this) { attributesMap.put(convertNamesToLowerCase ? attribute.getKey() : attribute.getName(),attribute.getValue()); } return attributesMap; }
private static String findOpenGraphNamespacePrefix(Element htmlTag) { String prefix = OpenGraphVocabulary.DEFAULT_PREFIX; if (htmlTag != null) { Attributes attributes = htmlTag.getAttributes(); int attributeCount = attributes.size(); for (int i = 0; i < attributeCount; i++) { Attribute attr = attributes.get(i); String value = attr.getValue(); String key = attr.getKey().toLowerCase().trim(); if (key.startsWith(XMLNS_PREFIX)) { if (value.equals(OpenGraphVocabulary.NAMESPACE)) { prefix = key.substring(XMLNS_PREFIX.length()); } } } } return prefix; }
String value1 = StringEscapeUtils.unescapeHtml4(attribute1.getValue()); value2 = StringEscapeUtils.unescapeHtml4(value2);
private TemplateNode parseDomElement(Element elem) { DOMElement templateElem = new DOMElement(elem.getName()); templateElem.setLocation(new Location(elem.getBegin(), elem.getEnd())); for (int i = 0; i < elem.getAttributes().size(); ++i) { Attribute attr = elem.getAttributes().get(i); if (attr.getName().indexOf(':') > 0) { AttributeComponentBinding component = parseAttributeComponent(attr); if (component != null) { templateElem.getAttributeComponents().add(component); } } else { templateElem.setAttribute(attr.getName(), attr.getValue(), new Location(attr.getBegin(), attr.getEnd())); } } Set<String> vars = new HashSet<>(); for (AttributeComponentBinding attrComponent : templateElem.getAttributeComponents()) { for (ComponentVariableBinding var : attrComponent.getVariables()) { vars.add(var.getName()); pushVar(var.getName(), var.getValueType()); } } parseSegment(elem.getEnd(), templateElem.getChildNodes(), child -> true); for (String var : vars) { popVar(var); } return templateElem; }
private TemplateNode parseDomElement(Element elem) { DOMElement templateElem = new DOMElement(elem.getName()); templateElem.setLocation(new Location(elem.getBegin(), elem.getEnd())); for (int i = 0; i < elem.getAttributes().size(); ++i) { Attribute attr = elem.getAttributes().get(i); if (attr.getName().indexOf(':') > 0) { AttributeComponentBinding component = parseAttributeComponent(attr); if (component != null) { templateElem.getAttributeComponents().add(component); } } else { templateElem.setAttribute(attr.getName(), attr.getValue(), new Location(attr.getBegin(), attr.getEnd())); } } Set<String> vars = new HashSet<>(); for (AttributeComponentBinding attrComponent : templateElem.getAttributeComponents()) { for (ComponentVariableBinding var : attrComponent.getVariables()) { vars.add(var.getName()); pushVar(var.getName(), var.getValueType()); } } parseSegment(elem.getEnd(), templateElem.getChildNodes(), child -> true); for (String var : vars) { popVar(var); } return templateElem; }