/** * Creates an IndexedDocument from the provided operation, with the provided * handler installed to receive document events. */ public IndexedDocument<N, E, T> build(DocInitialization operation, DocumentSchema schema, DocumentHandler<N, E, T> handler) throws OperationException { ObservableIndexedDocument<N, E, T, ?> doc = new ObservableIndexedDocument<N, E, T, Void>(handler, substrateProvider.create("doc", Attributes.EMPTY_MAP), schema); doc.consume(operation); return doc; } }
private void event(DocumentEvent<N, E, T> event) { currentEvent().addComponent(event); }
@Override protected void onDeleteElementStart(int location, E element) { assert (deletion == null) == (depth == 0); if (depth == 0) { deletion = new ContentDeleted.Builder<N, E, T>(location, element); } depth++; // Save the element about to be deleted. deleted(element); deletion.addElementStart(getTagName(element), getAttributes(element)); }
private void create(String xml) { RawDocumentImpl raw = DocProviders.ROJO.parse("<d>" + xml + "</d>"); RawDocumentImpl raw2 = DocProviders.ROJO.parse("<d>" + xml + "</d>"); indexed = new ObservableIndexedDocument<Node, Element, Text, Void>(handler, raw, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); indexedCopy = new ObservableIndexedDocument<Node, Element, Text, Void>( handler2, raw2, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); doc = new MutableDocumentImpl<Node, Element, Text>( new OperationSequencer<Nindo>() { @Override public void begin() { } @Override public void consume(Nindo op) { try { consumeNindo(op); } catch (OperationException e) { throw new OperationRuntimeException("Bug!", e); } } @Override public void end() { } }, testNindoConsume ? indexed : indexedCopy); root = doc.getDocumentElement(); }
@Override protected void onModifyAttributes(E element, Attributes oldAttributes, Attributes newAttributes) { event(new AttributesModified<N, E, T>(element, oldAttributes, newAttributes)); }
@Override protected void beforeBegin() { assert depth == 0; assert events.isEmpty(); assert splitElementStack.isEmpty(); push(); }
private void create(String xml) { RawDocumentImpl raw = DocProviders.ROJO.parse("<d>" + xml + "</d>"); RawDocumentImpl raw2 = DocProviders.ROJO.parse("<d>" + xml + "</d>"); indexed = new ObservableIndexedDocument<Node, Element, Text, Void>(handler, raw, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); indexedCopy = new ObservableIndexedDocument<Node, Element, Text, Void>( handler2, raw2, null, DocumentSchema.NO_SCHEMA_CONSTRAINTS); doc = new MutableDocumentImpl<Node, Element, Text>( new OperationSequencer<Nindo>() { @Override public void begin() { } @Override public void consume(Nindo op) { try { consumeNindo(op); } catch (OperationException e) { throw new OperationRuntimeException("Bug!", e); } } @Override public void end() { } }, testNindoConsume ? indexed : indexedCopy); root = doc.getDocumentElement(); }
@Override protected void onCharacters(int location, String characters) { if (depth == 0) { event(new TextInserted<N, E, T>(location, characters)); } }
@Override protected void onModifyAttributes(E element, AttributesUpdate update) { event(new AttributesModified<N, E, T>(element, update)); }
private void inserted(E element) { currentEvent().addInsertedElement(element); }
@Override protected void onDeleteCharacters(int location, String characters) { if (depth == 0) { // TODO(danilatos): Drop the TextDeleted event altogether. event(new TextDeleted<N, E, T>(location, characters)); } if (deletion != null) { deletion.addText(characters); } }
private void deleted(E element) { currentEvent().addDeletedElement(element); }
@Override protected void onDeleteElementEnd() { assert deletion != null; deletion.addElementEnd(); depth--; if (depth == 0) { event(deletion.build()); deletion = null; } }