@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); }
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 <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); } }
@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()); }
assert attrAccu.isEmpty(); attrAccu = pickRandomNonNullMappedElement(r, p.getAttributeNames(), new Mapper<String, Attributes>() {