Search in sources :

Example 76 with Attribute

use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.

the class MCRChangeTrackerTest method testAddAttribute.

@Test
public void testAddAttribute() throws JaxenException {
    Document doc = new Document(new MCRNodeBuilder().buildElement("document[title]", null, null));
    MCRChangeTracker tracker = new MCRChangeTracker();
    Attribute id = new Attribute("id", "foo");
    doc.getRootElement().setAttribute(id);
    tracker.track(MCRAddedAttribute.added(id));
    tracker.undoChanges(doc);
    assertNull(doc.getRootElement().getAttribute("id"));
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) Attribute(org.jdom2.Attribute) Document(org.jdom2.Document) Test(org.junit.Test)

Example 77 with Attribute

use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.

the class MCRChangeTrackerTest method testNestedChanges.

@Test
public void testNestedChanges() {
    Element root = new Element("root");
    Document doc = new Document(root);
    MCRChangeTracker tracker = new MCRChangeTracker();
    Element title = new Element("title");
    root.addContent(title);
    tracker.track(MCRAddedElement.added(title));
    Attribute id = new Attribute("type", "main");
    title.setAttribute(id);
    tracker.track(MCRAddedAttribute.added(id));
    Element part = new Element("part");
    title.addContent(part);
    tracker.track(MCRAddedElement.added(part));
    tracker.track(MCRRemoveElement.remove(part));
    tracker.track(MCRRemoveAttribute.remove(id));
    tracker.track(MCRRemoveElement.remove(title));
    tracker.undoChanges(doc);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Document(org.jdom2.Document) Test(org.junit.Test)

Example 78 with Attribute

use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.

the class MCRBinding method bind.

private void bind(String xPath, boolean buildIfNotExists, String initialValue) throws JaxenException {
    this.xPath = xPath;
    Map<String, Object> variables = buildXPathVariables();
    XPathExpression<Object> xPathExpr = XPathFactory.instance().compile(xPath, Filters.fpassthrough(), variables, MCRConstants.getStandardNamespaces());
    boundNodes.addAll(xPathExpr.evaluate(parent.getBoundNodes()));
    for (Object boundNode : boundNodes) if (!(boundNode instanceof Element || boundNode instanceof Attribute || boundNode instanceof Document))
        throw new RuntimeException("XPath MUST only bind either element, attribute or document nodes: " + xPath);
    LOGGER.debug("Bind to {} selected {} node(s)", xPath, boundNodes.size());
    if (boundNodes.isEmpty() && buildIfNotExists) {
        MCRNodeBuilder builder = new MCRNodeBuilder(variables);
        Object built = builder.buildNode(xPath, initialValue, (Parent) (parent.getBoundNode()));
        LOGGER.debug("Bind to {} generated node {}", xPath, MCRXPathBuilder.buildXPath(built));
        boundNodes.add(built);
        trackNodeCreated(builder.getFirstNodeBuilt());
    }
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) MCRRemoveAttribute(org.mycore.frontend.xeditor.tracker.MCRRemoveAttribute) MCRAddedAttribute(org.mycore.frontend.xeditor.tracker.MCRAddedAttribute) Attribute(org.jdom2.Attribute) MCRAddedElement(org.mycore.frontend.xeditor.tracker.MCRAddedElement) MCRRemoveElement(org.mycore.frontend.xeditor.tracker.MCRRemoveElement) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 79 with Attribute

use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.

the class MCRSetAttributeValue method undo.

public void undo(MCRChangeData data) {
    Attribute attribute = data.getAttribute();
    data.getContext().removeAttribute(attribute.getName(), attribute.getNamespace());
    data.getContext().setAttribute(attribute);
}
Also used : Attribute(org.jdom2.Attribute)

Example 80 with Attribute

use of org.omegat.filters3.Attribute in project mycore by MyCoRe-Org.

the class MCRAddedAttribute method undo.

public void undo(MCRChangeData data) {
    Attribute attribute = data.getAttribute();
    data.getContext().removeAttribute(attribute.getName(), attribute.getNamespace());
}
Also used : Attribute(org.jdom2.Attribute)

Aggregations

Attribute (org.jdom2.Attribute)148 Element (org.jdom2.Element)104 Document (org.jdom2.Document)18 ArrayList (java.util.ArrayList)17 DataConversionException (org.jdom2.DataConversionException)16 Editor (jmri.jmrit.display.Editor)15 Test (org.junit.Test)15 IOException (java.io.IOException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 Attribute (org.bouncycastle.asn1.x509.Attribute)11 HashMap (java.util.HashMap)10 List (java.util.List)9 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)7 Attribute (ucar.nc2.Attribute)7 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5