Search in sources :

Example 16 with Namespace

use of org.osate.aadl2.Namespace in project jspwiki by apache.

the class WebContainerAuthorizer method isConstrained.

/**
 * <p>
 * Protected method that identifies whether a particular webapp URL is
 * constrained to a particular Role. The resource is considered constrained
 * if:
 * </p>
 * <ul>
 * <li>the web application deployment descriptor contains a
 * <code>security-constraint</code> with a child
 * <code>web-resource-collection/url-pattern</code> element matching the
 * URL, <em>and</em>:</li>
 * <li>this constraint also contains an
 * <code>auth-constraint/role-name</code> element equal to the supplied
 * Role's <code>getName()</code> method. If the supplied Role is Role.ALL,
 * it matches all roles</li>
 * </ul>
 * @param url the web resource
 * @param role the role
 * @return <code>true</code> if the resource is constrained to the role,
 *         <code>false</code> otherwise
 */
public boolean isConstrained(final String url, final Role role) {
    final Element root = m_webxml.getRootElement();
    final Namespace jeeNs = Namespace.getNamespace("j", J2EE_SCHEMA_25_NAMESPACE);
    // Get all constraints that have our URL pattern
    // (Note the crazy j: prefix to denote the jee schema)
    final String constrainsSelector = "//j:web-app/j:security-constraint[j:web-resource-collection/j:url-pattern=\"" + url + "\"]";
    final List<Element> constraints = XPathFactory.instance().compile(constrainsSelector, Filters.element(), null, jeeNs).evaluate(root);
    // Get all constraints that match our Role pattern
    final String rolesSelector = "//j:web-app/j:security-constraint[j:auth-constraint/j:role-name=\"" + role.getName() + "\"]";
    final List<Element> roles = XPathFactory.instance().compile(rolesSelector, Filters.element(), null, jeeNs).evaluate(root);
    // If we can't find either one, we must not be constrained
    if (constraints.size() == 0) {
        return false;
    }
    // Shortcut: if the role is ALL, we are constrained
    if (role.equals(Role.ALL)) {
        return true;
    }
    // If no roles, we must not be constrained
    if (roles.size() == 0) {
        return false;
    }
    // If a constraint is contained in both lists, we must be constrained
    for (final Element constraint : constraints) {
        for (final Element roleConstraint : roles) {
            if (constraint.equals(roleConstraint)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 17 with Namespace

use of org.osate.aadl2.Namespace in project pom-manipulation-ext by release-engineering.

the class Utils method replaceXpp3DOM.

// -- Element findAndReplaceXpp3DOM( Counter, Element, String, Xpp3Dom )
/**
 * Method replaceXpp3DOM.
 *
 * @param parent
 * @param counter
 * @param parentDom
 */
public static void replaceXpp3DOM(final Element parent, final Xpp3Dom parentDom, final IndentationCounter counter) {
    if (parentDom.getChildCount() > 0) {
        final Xpp3Dom[] childs = parentDom.getChildren();
        final ArrayList<Xpp3Dom> domChilds = new ArrayList<>(Arrays.asList(childs));
        final ListIterator<?> it = parent.getChildren().listIterator();
        while (it.hasNext()) {
            final Element elem = (Element) it.next();
            final Iterator<Xpp3Dom> it2 = domChilds.iterator();
            Xpp3Dom corrDom = null;
            while (it2.hasNext()) {
                final Xpp3Dom dm = it2.next();
                // Elem::getName, unlike getQualifiedName, does not return namespaced names which can fail the comparison
                if (dm.getName().equals(elem.getQualifiedName())) {
                    corrDom = dm;
                    break;
                }
            }
            if (corrDom != null) {
                domChilds.remove(corrDom);
                replaceXpp3DOM(elem, corrDom, new IndentationCounter(counter.getDepth() + 1));
                counter.increaseCount();
            } else {
                it.remove();
            }
        }
        for (Xpp3Dom dm : domChilds) {
            final String rawName = dm.getName();
            final String[] parts = rawName.split(":");
            Element elem;
            if (parts.length > 1) {
                final String nsId = parts[0];
                String nsUrl = dm.getAttribute("xmlns:" + nsId);
                final String name = parts[1];
                if (nsUrl == null) {
                    nsUrl = parentDom.getAttribute("xmlns:" + nsId);
                }
                elem = factory.element(name, Namespace.getNamespace(nsId, nsUrl));
            } else {
                Namespace root = parent.getNamespace();
                for (Namespace n : getNamespacesInherited(parent)) {
                    if (n.getPrefix() == null || n.getPrefix().length() == 0) {
                        root = n;
                        break;
                    }
                }
                elem = factory.element(dm.getName(), root);
            }
            final String[] attributeNames = dm.getAttributeNames();
            for (final String attrName : attributeNames) {
                if (attrName.startsWith("xmlns:")) {
                    continue;
                }
                elem.setAttribute(attrName, dm.getAttribute(attrName));
            }
            insertAtPreferredLocation(parent, elem, counter);
            counter.increaseCount();
            replaceXpp3DOM(elem, dm, new IndentationCounter(counter.getDepth() + 1));
        }
    } else if (parentDom.getValue() != null) {
        List<Content> cl = parent.getContent();
        boolean foundCdata = false;
        for (Content c : cl) {
            if (c instanceof CDATA) {
                foundCdata = true;
                break;
            }
        }
        if (!foundCdata) {
            if (parent.getText().trim().equals(parentDom.getValue())) {
                logger.trace("Ignoring during element update as original of '{}' equals (ignoring trimmed whitespace) '{}'", parent.getText(), parentDom.getValue());
            } else {
                parent.setText(parentDom.getValue());
            }
        }
    }
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Namespace(org.jdom2.Namespace) Content(org.jdom2.Content) ArrayList(java.util.ArrayList) List(java.util.List) CDATA(org.jdom2.CDATA)

Example 18 with Namespace

use of org.osate.aadl2.Namespace in project pom-manipulation-ext by release-engineering.

the class Utils method getNamespacesInherited.

// -- Element findAndReplaceSimpleLists( Counter, Element, java.util.Collection, String, String )
// Copied from JDOM2
static List<Namespace> getNamespacesInherited(Element element) {
    if (element.getParentElement() == null) {
        ArrayList<Namespace> ret = new ArrayList<>(getNamespacesInScope(element));
        for (Iterator<Namespace> it = ret.iterator(); it.hasNext(); ) {
            Namespace ns = it.next();
            if (ns == Namespace.NO_NAMESPACE || ns == Namespace.XML_NAMESPACE) {
                continue;
            }
            it.remove();
        }
        return Collections.unmodifiableList(ret);
    }
    // OK, the things we inherit are the prefixes we have in scope that
    // are also in our parent's scope.
    HashMap<String, Namespace> parents = new HashMap<>();
    for (Namespace ns : getNamespacesInScope(element.getParentElement())) {
        parents.put(ns.getPrefix(), ns);
    }
    ArrayList<Namespace> al = new ArrayList<>();
    for (Namespace ns : getNamespacesInScope(element)) {
        if (ns == parents.get(ns.getPrefix())) {
            // inherited
            al.add(ns);
        }
    }
    return Collections.unmodifiableList(al);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Namespace(org.jdom2.Namespace)

Example 19 with Namespace

use of org.osate.aadl2.Namespace in project OpenOLAT by OpenOLAT.

the class SCORM12_DocumentHandler method canHandle.

protected static boolean canHandle(Document doc) throws DocumentHandlerException {
    // The first thing we do is to see if there is a root Namespace in the Document
    Namespace nameSpace = XMLUtils.getDocumentNamespace(doc);
    // No Namespace, sorry we don't know what it is!
    if (nameSpace == null || nameSpace.equals(Namespace.NO_NAMESPACE)) {
        throw new DocumentHandlerException("No Namespace in Document so cannot determine what it is!");
    }
    // Does it have the correct root Namespace?
    if (SUPPORTED_NAMESPACES.containsKey(nameSpace) == false)
        return false;
    // Now find out if it is a SCORM Document and if so whether we support it
    // We'll search all elements for the ADL Namespace
    Namespace nsSCORM = getSCORM_Namespace(doc);
    if (nsSCORM == null)
        return false;
    // Do we support this version of SCORM?
    return SUPPORTED_SCORM_NAMESPACES.containsKey(nsSCORM);
}
Also used : Namespace(org.jdom2.Namespace)

Example 20 with Namespace

use of org.osate.aadl2.Namespace in project OpenOLAT by OpenOLAT.

the class XMLUtils method containsNamespace.

/**
 * Hunt for a Namespace in the Element searching all sub-Elements in case the Namespace
 * is declared "in-line" at the Element level
 * @param element
 * @param ns
 * @return true if found
 */
private static boolean containsNamespace(Element element, Namespace ns) {
    // Element Namespace?
    if (ns.equals(element.getNamespace())) {
        return true;
    }
    // Additional Namespace?
    Iterator<Namespace> it = element.getAdditionalNamespaces().iterator();
    while (it.hasNext()) {
        Namespace ns1 = it.next();
        if (ns1.equals(ns)) {
            return true;
        }
    }
    // Recurse children
    Iterator<Element> i = element.getChildren().iterator();
    while (i.hasNext()) {
        Element child = i.next();
        boolean found = containsNamespace(child, ns);
        if (found) {
            return true;
        }
    }
    return false;
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Aggregations

Namespace (org.jdom2.Namespace)152 Element (org.jdom2.Element)124 IOException (java.io.IOException)30 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)21 List (java.util.List)21 Document (org.jdom2.Document)21 XConfiguration (org.apache.oozie.util.XConfiguration)19 Attribute (org.jdom2.Attribute)17 Configuration (org.apache.hadoop.conf.Configuration)15 StringReader (java.io.StringReader)14 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)14 Namespace.getNamespace (org.jdom2.Namespace.getNamespace)14 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)13 Map (java.util.Map)12 Path (org.apache.hadoop.fs.Path)12 JDOMException (org.jdom2.JDOMException)12 SAXBuilder (org.jdom2.input.SAXBuilder)11 File (java.io.File)10 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)9