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; }
String value2 = st2.getAttributeValue(attribute1.getName()); if(value2 == null) { System.out.println("Attribute not present in stream2: attribute1=" + attribute1.getBegin() + "; tag2=" + st2.getBegin()); return false; String value1 = StringEscapeUtils.unescapeHtml4(attribute1.getValue()); value2 = StringEscapeUtils.unescapeHtml4(value2); System.out.println("Attribute value mismatch: attribute1=" + attribute1.getBegin() + "; tag2=" + st2.getBegin()); return false;
/** * 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; }
/** * 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(); }
for (Attribute attribute : attributes) { if (attribute != null) { String name = attribute.getName(); if (name != null && (isDirective(name) || (attributeNamespace != null && name.startsWith(attributeNamespace)) && isDirective(name.substring(attributeNamespace.length())))) { // 识别名称空间 String directiveName = attributeNamespace != null ? name.substring(attributeNamespace.length()) : name; String value = attribute.getValue(); directiveNames.add(directiveName); directiveValues.add(value); document.remove(new Segment(source, attribute.getBegin() - 1, attribute.getEnd())); // 移除属性 String name = attribute.getName(); if (ifattr.equals(name)) { String val = attribute.getValue(); String[] arr = val.split(","); String attrName = arr[0].trim(); String buf = String.format("#if(%s)%s=\"%s\"#end()", expression, oriattr.getName(), oriattr.getValue()); document.replace(new Segment(source, oriattr.getBegin(), oriattr.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除ifattr控制属性 String name = attribute.getName(); if (setattr.equals(name)) { String val = attribute.getValue(); String[] arr = val.split(","); String attrName = arr[0].trim(); document.replace(new Segment(source, attribute.getBegin(), attribute.getEnd()), buf);
private AttributeComponentBinding parseAttributeComponent(Attribute attr) { int prefixLength = attr.getName().indexOf(':'); String prefix = attr.getName().substring(0, prefixLength); String name = attr.getName().substring(prefixLength + 1); String fullName = prefix + ":" + name; AttributeComponentMetadata componentMeta = resolveAttrComponent(prefix, name); if (componentMeta == null) { error(attr.getNameSegment(), "Undefined component " + fullName); return null; component.setLocation(new Location(attr.getBegin(), attr.getEnd())); if (componentMeta.nameSetter != null) { component.setElementNameMethodName(componentMeta.nameSetter.getName()); switch (componentMeta.type) { case VARIABLE: { String varName = attr.getValue(); ComponentVariableBinding varBinding = new ComponentVariableBinding(setter.getOwner().getName(), getter.getName(), varName, getter.getRawReturnType(), componentMeta.valueType); Expr expr = null; if (isSettingsObject(componentMeta.valueType)) { ObjectExpr objectExpr = parseObject(attr.getValueSegment()); if (objectExpr == null) { break; plan = compileSettingsObject(attr.getValueSegment(), objectExpr, componentMeta.sam.getActualOwner()); if (plan == null) {
/** * 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); }
String processedVForValue = processVForValue(vForAttribute.getValue()); outputDocument.replace(vForAttribute.getValueSegment(), processedVForValue); String processedScopedSlotValue = processSlotScopeValue(slotScopeAttribute.getValue()); outputDocument.replace(slotScopeAttribute.getValueSegment(), processedScopedSlotValue); if (refAttribute != null) { result.addRef( refAttribute.getValue(), localComponent.map(LocalComponent::getComponentType) .orElse(getTypeFromDOMElement(element)), String key = attribute.getKey(); if ("v-for".equals(key) || "slot-scope".equals(key)) { continue; localComponent.flatMap(lc -> lc.getPropForAttribute(attribute.getName())); optionalProp.ifPresent(foundProps::add); currentExpressionReturnType = getExpressionReturnTypeForAttribute(attribute, elementPropertiesType); String processedExpression = processExpression(attribute.getValue()); if (attribute.getValueSegment() != null) { outputDocument.replace(attribute.getValueSegment(), processedExpression);
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() ); } }
|| attrMeta.type == ComponentAttributeType.BIDIRECTIONAL) { if (attrMeta.type == ComponentAttributeType.FUNCTION && isSettingsObject(attrMeta.valueType)) { attrParse.objectExpr = parseObject(attr.getValueSegment()); attrParse.type = attrMeta.valueType; } else { attrParse.expr = parseExpr(attr.getValueSegment()); if (!componentMeta.attributes.containsKey(attr.getName())) { error(attr, "Unknown attribute " + attr.getName() + " for component " + prefix + ":" + name);
@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); } } } }
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; }
@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); } } } } }
/** * 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); }
String name = attrs.get(i).getName(); if ( name.equals("xmlns") || name.startsWith("xmlns:") ) { String xmlns = st.getAttributeValue(name);
private static boolean isEventBinding(Attribute attribute) { String attributeName = attribute.getKey().toLowerCase(); return attributeName.startsWith("@") || attributeName.startsWith("v-on:"); }
/** * 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().append(key).append(super.getDebugInfo()).append(",name=").append(nameSegment.getDebugInfo()); if (hasValue()) sb.append(",value=").append(valueSegment.getDebugInfo()).append('"').append(valueSegment).append('"').append(Config.NewLine); else sb.append(",NO VALUE").append(Config.NewLine); return sb.toString(); }
for (Attribute attribute : attributes) { if (attribute != null) { String name = attribute.getName(); if (name != null && (isDirective(name) || (attributeNamespace != null && name.startsWith(attributeNamespace)) && isDirective(name.substring(attributeNamespace.length())))) { // 识别名称空间 String directiveName = attributeNamespace != null ? name.substring(attributeNamespace.length()) : name; String value = attribute.getValue(); directiveNames.add(directiveName); directiveValues.add(value); document.remove(new Segment(source, attribute.getBegin() - 1, attribute.getEnd())); // 移除属性 String name = attribute.getName(); if (ifattr.equals(name)) { String val = attribute.getValue(); String[] arr = val.split(","); String attrName = arr[0].trim(); String buf = String.format("#if(%s)%s=\"%s\"#end()", expression, oriattr.getName(), oriattr.getValue()); document.replace(new Segment(source, oriattr.getBegin(), oriattr.getEnd()), buf); document.remove(new Segment(source, attribute.getBegin(), attribute.getEnd())); // 移除ifattr控制属性 String name = attribute.getName(); if (setattr.equals(name)) { String val = attribute.getValue(); String[] arr = val.split(","); String attrName = arr[0].trim(); document.replace(new Segment(source, attribute.getBegin(), attribute.getEnd()), buf);