Search in sources :

Example 76 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.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 77 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.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 78 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.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 79 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.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)

Example 80 with Attribute

use of org.openmuc.jasn1.compiler.pkix1explicit88.Attribute in project mycore by MyCoRe-Org.

the class MCRDynamicURIResolver method resolveVariablesFromElement.

/**
 * This method runs through the whole content of the startElement and
 * tries to resolve all variables in texts and attributes.
 *
 * @param startElement where to start to resolve the variables
 * @param variablesMap a map of all variables
 */
protected void resolveVariablesFromElement(Element startElement, Hashtable<String, String> variablesMap) {
    Iterator<Element> it = startElement.getDescendants(Filters.element());
    MCRTextResolver varResolver = new MCRTextResolver(variablesMap);
    while (it.hasNext()) {
        Element element = it.next();
        // text
        String text = element.getText();
        if (text != null && !text.equals("") && text.contains("{")) {
            element.setText(varResolver.resolve(text));
        }
        // attributes
        for (Attribute attrib : element.getAttributes()) {
            String attribValue = attrib.getValue();
            if (attribValue.contains("{")) {
                attrib.setValue(varResolver.resolve(attribValue));
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) MCRTextResolver(org.mycore.common.MCRTextResolver) Element(org.jdom2.Element)

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