Search in sources :

Example 96 with Attribute

use of com.android.org.bouncycastle.asn1.x509.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 97 with Attribute

use of com.android.org.bouncycastle.asn1.x509.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 98 with Attribute

use of com.android.org.bouncycastle.asn1.x509.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 99 with Attribute

use of com.android.org.bouncycastle.asn1.x509.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 100 with Attribute

use of com.android.org.bouncycastle.asn1.x509.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)149 Element (org.jdom2.Element)104 IOException (java.io.IOException)31 ArrayList (java.util.ArrayList)27 Document (org.jdom2.Document)18 DataConversionException (org.jdom2.DataConversionException)16 X509Certificate (java.security.cert.X509Certificate)15 Editor (jmri.jmrit.display.Editor)15 GeneralName (org.bouncycastle.asn1.x509.GeneralName)15 Test (org.junit.Test)14 List (java.util.List)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)12 Attribute (org.bouncycastle.asn1.pkcs.Attribute)12 Extensions (org.bouncycastle.asn1.x509.Extensions)12 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)12 CertificateEncodingException (java.security.cert.CertificateEncodingException)11 Attribute (org.bouncycastle.asn1.x509.Attribute)11 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)9