public void testDeleteTagByName() throws Exception { doc.addTag("new-tag"); doc.deleteTag("new-tag"); doc.processInitialState(); assertTrue(listener.addedTags.isEmpty()); }
/** * Adds a tag to the document. * * @param tagName The name of the tag. * @param i The index at which to insert the tag. */ public void addTag(String tagName, int i) { E node = getNthTagNode(i); El<N> point = Point.<N>inElement(doc.getDocumentElement(), node); XmlStringBuilder xml = getXmlFor(tagName); doc.insertXml(point, xml); }
/** * Called when an element has been removed from the document. * * @param e The removed element. */ public void handleDeletedElement(E e) { int i = tagElements.indexOf(e); if (i == -1) { return; } tagElements.remove(i); notifyRemoveTag(i); } }
public void testAddTag() throws Exception { doc.addTag("new-tag"); doc.processInitialState(); assertTrue(listener.addedTags.contains("new-tag")); }
TagsDocument tags = new TagsDocument(wavelet.getDocument(IdConstants.TAGS_DOC_ID)); tags.addListener(new TagsDocument.Listener() { @Override public void onAdd(String tagName) { tags.processInitialState();
@Override protected void setUp() throws Exception { listener = new TestListener(); doc = createDocument(""); doc.addListener(listener); }
private TagsDocument<?,?,?> createDocument(String xmlContent) { MutableDocumentImpl<Node, Element, Text> baseDocument = DocProviders.MOJO.parse(xmlContent); return new TagsDocument<Node, Element, Text>(baseDocument); }
/** * Called when an element has been inserted into the document. * * @param e The inserted element. */ public void handleInsertedElement(E e) { tagElements.add(e); String addedTagText = doc.getData(doc.asText(doc.getFirstChild(e))); notifyAddTag(addedTagText); }
/** * Deletes a tag from the document by index. * * @param index The index of the tag to delete. */ public void deleteTag(int index) { E nthTagNode = getNthTagNode(index); doc.deleteNode(nthTagNode); }
/** * Adds a tag to the document. * * @param tagName The name of the tag to add. */ public void addTag(String tagName) { if (tagName == null) { return; } tagElements.add(doc.appendXml(getXmlFor(tagName))); }
public void testAddTag() throws Exception { doc.addTag("new-tag"); doc.processInitialState(); assertTrue(listener.addedTags.contains("new-tag")); }
@Override protected void setUp() throws Exception { listener = new TestListener(); doc = createDocument(""); doc.addListener(listener); }
private TagsDocument<?,?,?> createDocument(String xmlContent) { MutableDocumentImpl<Node, Element, Text> baseDocument = DocProviders.MOJO.parse(xmlContent); return new TagsDocument<Node, Element, Text>(baseDocument); }
/** * Reads the document and sets up the initial state. If a node without text * is found, it is deleted and reported as a non-fatal error. */ public void processInitialState() { List<N> emptyNodes = new ArrayList<N>(); for (N node = doc.getFirstChild(doc.getDocumentElement()); node != null; node = doc.getNextSibling(node)) { T textNode = doc.asText(doc.getFirstChild(node)); if (textNode == null) { emptyNodes.add(node); } else { notifyAddTag(doc.getData(textNode)); tagElements.add(doc.asElement(node)); } } for (N emptyNode : emptyNodes) { doc.deleteNode(doc.asElement(emptyNode)); } }
public void testDeleteTag() throws Exception { doc.addTag("new-tag"); doc.deleteTag(0); doc.processInitialState(); assertTrue(listener.addedTags.isEmpty()); }
public void testAddTagPosition() throws Exception { doc.addTag("new-tag"); doc.addTag("second-tag", 0); doc.processInitialState(); assertEquals(CollectionUtils.newArrayList("second-tag", "new-tag"), listener.addedTags); } }
public void testDeleteTagByName() throws Exception { doc.addTag("new-tag"); doc.deleteTag("new-tag"); doc.processInitialState(); assertTrue(listener.addedTags.isEmpty()); }
public void testAddTagPosition() throws Exception { doc.addTag("new-tag"); doc.addTag("second-tag", 0); doc.processInitialState(); assertEquals(CollectionUtils.newArrayList("second-tag", "new-tag"), listener.addedTags); } }
public void testDeleteTag() throws Exception { doc.addTag("new-tag"); doc.deleteTag(0); doc.processInitialState(); assertTrue(listener.addedTags.isEmpty()); }