@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(" "); } } } }));
private boolean attributesEqual(Attributes a, Attributes b) { if (a.size() != b.size()) { return false; } for (Map.Entry<String, String> ae : a.entrySet()) { if (!equal(ae.getValue(), b.get(ae.getKey()))) { return false; } } return true; }
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; }
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); }
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 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 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()); }
String key = u.getChangeKey(i); String oldValue = u.getOldValue(i); if (!equal(oldValue, oldAttrs.get(key))) { return oldAttributesDifferFromDocument(v); }