@Override void resolveDeleteElementStart(String type, Attributes attributes) { otherTarget.doDeleteElementStart(type, attributes.updateWith(update)); ++otherTarget.depth; }
public static String toConciseString(Attributes attributes) { if (attributes.isEmpty()) { return "{}"; } StringBuilder b = new StringBuilder(); b.append("{ "); boolean first = true; for (Map.Entry<String, String> entry : attributes.entrySet()) { if (first) { first = false; } else { b.append(", "); } b.append(entry.getKey()); b.append("="); b.append(literalString(entry.getValue())); } b.append(" }"); return b.toString(); }
private static String extractName(String elementType, Attributes attrs) throws InvalidSchemaException { String name = attrs.get(NAME_ATTRIBUTE_NAME); if (name == null) { throw new InvalidSchemaException( "Missing attribute \"" + NAME_ATTRIBUTE_NAME + "\" in element: " + elementType); } if (attrs.size() != 1) { throw new InvalidSchemaException( "Encountered an attribute other than \"" + NAME_ATTRIBUTE_NAME + "\" in element: " + elementType); } return name; }
assert attrAccu.isEmpty(); attrAccu = pickRandomNonNullMappedElement(r, p.getAttributeNames(), new Mapper<String, Attributes>() { return attrAccu; attrAccu = attrAccu.updateWith( new AttributesUpdateImpl(newAttr.getFirst(), null, newAttr.getSecond()));
@Override public void replaceAttributes(Attributes oldAttributes, Attributes newAttributes) { ProtocolDocumentOperation.Component.ReplaceAttributes.Builder r = ProtocolDocumentOperation.Component.ReplaceAttributes.newBuilder(); if (oldAttributes.isEmpty() && newAttributes.isEmpty()) { r.setEmpty(true); } else { for (String name : oldAttributes.keySet()) { r.addOldAttribute(ProtocolDocumentOperation.Component.KeyValuePair.newBuilder() .setKey(name).setValue(oldAttributes.get(name)).build()); } for (String name : newAttributes.keySet()) { r.addNewAttribute(ProtocolDocumentOperation.Component.KeyValuePair.newBuilder() .setKey(name).setValue(newAttributes.get(name)).build()); } } output.addComponent(newComponentBuilder().setReplaceAttributes(r.build()).build()); }
/** * Validate the given <code>Attributes</code>. * * @param attributes the <code>Attributes</code> to validate * @return information about whether the <code>Attributes</code> is valid and, * if not, why it is not */ AttributeValidationResult validate(Attributes attributes) { for (String name : requiredAttributes) { if (!attributes.containsKey(name)) { return new MissingRequiredAttribute(name); } } for (Map.Entry<String, String> attribute : attributes.entrySet()) { String name = attribute.getKey(); ValueValidator validator = valueValidators.get(name); if (validator == null) { return new AttributeNotAllowed(name); } String value = attribute.getValue(); if (!validator.validate(value)) { return new InvalidAttributeValue(name, value); } } return AttributeValidationResult.VALID; }
@Override public void elementStart(String type, Attributes attrs) { if (elementPart != null) { b.append(elementPart + ">"); elementPart = null; } elementPart = "<" + type + (attrs.isEmpty() ? "" : " " + attributeString(attrs)); tags.add(type); }
private ProtocolDocumentOperation.Component.ElementStart makeElementStart( String type, Attributes attributes) { ProtocolDocumentOperation.Component.ElementStart.Builder e = ProtocolDocumentOperation.Component.ElementStart.newBuilder(); e.setType(type); for (String name : attributes.keySet()) { e.addAttribute(ProtocolDocumentOperation.Component.KeyValuePair.newBuilder() .setKey(name).setValue(attributes.get(name)).build()); } return e.build(); }
@Override public Pair<String, String> map(final String name) { if (finalAttrAccu.containsKey(name)) { return null; } return pickRandomNonNullMappedElement(r, p.getAttributeValues(), new Mapper<String, Pair<String, String>>() { @Override public Pair<String, String> map(String value) { Attributes b = finalAttrAccu.updateWith( new AttributesUpdateImpl(name, null, value)); assert b != finalAttrAccu; // assert non-destructiveness ValidationResult v = checker.check(b); if (valid && !v.isValid() || !valid && v.isIllFormed()) { return null; } else { return Pair.of(name, value); } } }); } });
public static String attributeString(Attributes attributes) { StringBuilder b = new StringBuilder(); boolean first = true; for (Map.Entry<String, String> e : attributes.entrySet()) { if (first) { first = false; } else { b.append(" "); } // We're just writing null with no quotes if the value is null. // This is acceptable since it only occurs in updateAttributes, // which is a processing instruction, so we define the format of it. // // TODO: We should escape ' and " and < and & etc. in the value. b.append(e.getKey() + "=" + (e.getValue() == null ? "null" : "\"" + xmlAttrEscape(e.getValue()) + "\"")); } return b.toString(); }
@Override public void elementStart(String type, Attributes attrs) { if (sb.length() >= maxSnippetLength) { return; } if (DocumentConstants.BLIP.equals(type)) { String blipId = attrs.get(DocumentConstants.BLIP_ID); if (blipId != null) { ReadableBlipData document = wavelet.getDocument(blipId); if (document == null) { // We see this when a blip has been deleted return; } sb.append(collateTextForDocuments(Arrays.asList(document))); sb.append(" "); } } } }));
final void handleText(Attributes attrs) throws InvalidSchemaException { String type = attrs.get(TYPE_ATTRIBUTE_NAME); String chars = attrs.get(CHARACTERS_ATTRIBUTE_NAME); if (type == null) { throw new InvalidSchemaException("Missing attribute: " + TYPE_ATTRIBUTE_NAME); } if (chars == null) { throw new InvalidSchemaException("Missing attribute: " + CHARACTERS_ATTRIBUTE_NAME); } if (attrs.size() != 2) { throw new InvalidSchemaException("Encountered more attributes than the expected two"); } if (type.equals(BLACKLIST_ATTRIBUTE_VALUE)) { characterPattern.blacklistCharacters(extractCodePoints(chars)); } else if (type.equals(WHITELIST_ATTRIBUTE_VALUE)) { characterPattern.whitelistCharacters(extractCodePoints(chars)); } else { throw new InvalidSchemaException( "Invalid value for attribute " + TYPE_ATTRIBUTE_NAME + ": " + type); } }
private <N, E extends N, T extends N> void lcHandleNewLine(RichTextTokenizer tokenizer, Nindo.Builder builder, ReadableDocument<N, E, T> doc, N splitContainer, Attributes attributes) { // TODO(user): Don't create a new paragraph if the attributes are the same, // and is first token. boolean isLastToken = !tokenizer.hasNext(); if ((!isFirstToken && !isLastToken) || !attributes.isEmpty()) { startElement(builder, LineContainers.LINE_TAGNAME, attributes); endElement(builder); } }
public int computeCost(Attributes attrs) { int accu = 0; for (Map.Entry<String, String> attr : attrs.entrySet()) { accu += objectOverhead + computeCost(attr.getKey()) + computeCost(attr.getValue()); } return accu; }
String key = u.getChangeKey(i); String oldValue = u.getOldValue(i); if (!equal(oldValue, oldAttrs.get(key))) { return oldAttributesDifferFromDocument(v); }
@Override void resolveUpdateAttributes(AttributesUpdate update) { doDeleteElementStart(type, attributes.updateWith(update)); ++depth; }
final void handleAttribute(Attributes attrs) throws InvalidSchemaException { String name = attrs.get(NAME_ATTRIBUTE_NAME); String values = attrs.get(VALUES_ATTRIBUTE_NAME); String required = attrs.get(REQUIRED_ATTRIBUTE_NAME); if (name == null) { throw new InvalidSchemaException("Missing attribute: " + NAME_ATTRIBUTE_NAME); } if (values == null) { throw new InvalidSchemaException("Missing attribute: " + VALUES_ATTRIBUTE_NAME); } if (required == null) { throw new InvalidSchemaException("Missing attribute: " + REQUIRED_ATTRIBUTE_NAME); } if (attrs.size() != 3) { throw new InvalidSchemaException("Encountered more attributes than the expected three"); } checkAttributeName(name); if (required.equals(TRUE_ATTRIBUTE_VALUE)) { attributesPattern.addRequired(name); } else if (!required.equals(FALSE_ATTRIBUTE_VALUE)) { throw new InvalidSchemaException( "Invalid value for attribute " + REQUIRED_ATTRIBUTE_NAME + ": " + required); } RegularExpressionChecker.checkRegularExpression(values); attributesPattern.addValuePattern(name, values); }
private ValidationResult validateAttributes(String tag, Attributes attr, ViolationCollector v) { for (Map.Entry<String, String> e : attr.entrySet()) { String key = e.getKey(); String value = e.getValue(); if (!elementAllowsAttribute(tag, key, value)) { return invalidAttribute(v, tag, key, value); } } return ValidationResult.VALID; }
void updateAttributes(AttributesUpdate update) { attrs = attrs.updateWith(update); }