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);
}
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());
}
}
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);
}
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());
}
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));
}
}
}
}
Aggregations