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(); }
Map<String,String> getMap(final boolean convertNamesToLowerCase) { return populateMap(new LinkedHashMap<String,String>(getCount()*2,1.0F),convertNamesToLowerCase); }
/** * Returns a string representation of this object useful for debugging purposes. * @return a string representation of this object useful for debugging purposes. */ public String getDebugInfo() { final StringBuilder sb=new StringBuilder(); sb.append("Attributes ").append(super.getDebugInfo()).append(": "); if (isEmpty()) { sb.append("EMPTY"); } else { sb.append(Config.NewLine); for (Attribute attribute : this) { sb.append(" ").append(attribute.getDebugInfo()); } } return sb.toString(); }
/** * Constructs a new <code>AttributesOutputSegment</code> with the same span * as the specified source {@link Attributes}, using the specified <code>Map</code> to * store the entries. * <p> * This constructor might be used if the <code>Map</code> containing the new attribute values * should not be preloaded with the same entries as the source attributes, or a map implementation * other than <code>LinkedHashMap</code> is required. * * @param attributes the <code>Attributes</code> defining the span of the new <code>AttributesOutputSegment</code>. * @param map the <code>Map</code> containing the name/value entries. * @see #AttributesOutputSegment(Attributes, boolean convertNamesToLowerCase) */ public AttributesOutputSegment(final Attributes attributes, final Map<String,String> map) { if (map==null || attributes==null) throw new IllegalArgumentException("both arguments must be non-null"); begin=attributes.getBegin(); end=attributes.getEnd(); this.map=map; }
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; }
st.getAttributes().populateMap(attributesMap, false), st.isSyntacticalEmptyElementTag())); } else { for ( int i=0; i<attrs.getCount(); i++ ) { String name = attrs.get(i).getName(); if ( name.equals("xmlns") || name.startsWith("xmlns:") ) { String xmlns = st.getAttributeValue(name);
element.getAttributes().populateMap(itemAttributes, true);
/** * Returns the {@linkplain CharacterReference#decode(CharSequence) decoded} value of the attribute with the specified name (case insensitive). * <p> * Returns <code>null</code> if this start tag does not {@linkplain StartTagType#hasAttributes() have attributes}, * no attribute with the specified name exists or the attribute {@linkplain Attribute#hasValue() has no value}. * <p> * This is equivalent to {@link #getAttributes()}<code>.</code>{@link Attributes#getValue(String) getValue(attributeName)}, * except that it returns <code>null</code> if this start tag does not have attributes instead of throwing a * <code>NullPointerException</code>. * * @param attributeName 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}. */ public String getAttributeValue(final String attributeName) { return attributes==null ? null : attributes.getValue(attributeName); }
/** * Register mandatory attributes for Scoped CSS */ private void registerMandatoryAttributes(Attributes attributes) { // see https://sourceforge.net/p/jerichohtml/discussion/350024/thread/501a7d05/ Map<String, String> attrs = context.getMandatoryAttributes(); if (!attrs.isEmpty()) { for (Entry<String, String> i : attrs.entrySet()) { String v = i.getValue(); if (v == null) { outputDocument.insert(attributes.getBegin(), " " + i.getKey() + " "); } else { outputDocument.insert(attributes.getBegin(), " " + i.getKey() + "\"" + v + "\" "); } } } }
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; }
startTag.getAttributes().populateMap(attributeMap, true), attribute.getName())) { case ATTRIBUTE_TRANS: propertyOrTextUnitPlaceholders.add(createPropertyTextUnitPlaceholder(
public String getAttributeValue(final String attributeName) { if (attributesMap!=null) return attributesMap.get(attributeName); else return element.getAttributes().getValue(attributeName); }
public boolean getBooleanAttribute(final String attributeName) { if (attributesMap!=null) return attributesMap.containsKey(attributeName); else return element.getAttributes().get(attributeName)!=null; }
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; }
tag.getAttributes().populateMap(attributeMap, true))) {
StringBuilder appendDebugTag(final StringBuilder sb) { if (startTagType==StartTagType.NORMAL && getAttributes().isEmpty()) { sb.append(this); } else { sb.append('<').append(getNameSegment()).append(' '); if (isSyntacticalEmptyElementTag()) sb.append('/'); sb.append(startTagType.getClosingDelimiter()); } return sb; }
public ElementContainer(final Element element, final boolean loadPredefinedValue) { this.element=element; predefinedValue=loadPredefinedValue ? element.getAttributes().getValue(Attribute.VALUE) : null; }
public boolean includeAttribute(final StartTag startTag, final Attribute attribute) { return startTag.getAttributes().get("name")!=null; } };
attributes = startTag.getAttributes().populateMap(attributes, true); String idValue = null; RULE_TYPE ruleType = getConfig().getConditionalElementRuleType(startTag.getName(),
private void processStartTag( StartTag tag ) { if( "<".equals( tag.getTagType().getStartDelimiter() ) ) { stack.push( new Level( tag ) ); writer.write( "<" ); writer.write( tag.getNameSegment().toString() ); Attributes attributes = tag.getAttributes(); if( !attributes.isEmpty() ) { for( Attribute attribute : attributes ) { processAttribute( attribute ); } } if( tag.toString().trim().endsWith( "/>" ) || tag.isEmptyElementTag() ) { stack.pop(); writer.write( "/>" ); } else { writer.write( ">" ); } } else { writer.write( tag.toString() ); } }