Search in sources :

Example 1 with Namespace

use of org.apache.jackrabbit.webdav.xml.Namespace in project jackrabbit by apache.

the class JcrUserPrivilegesPropertyTest method getExpected.

private Set<Privilege> getExpected(AccessControlManager acMgr, Session s) throws RepositoryException {
    Set<Privilege> expected = new HashSet<Privilege>();
    for (javax.jcr.security.Privilege p : acMgr.getPrivileges(testRoot)) {
        String localName = Text.getLocalName(p.getName());
        String prefix = Text.getNamespacePrefix(p.getName());
        Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, s.getNamespaceURI(prefix));
        expected.add(Privilege.getPrivilege(localName, ns));
    }
    return expected;
}
Also used : Privilege(org.apache.jackrabbit.webdav.security.Privilege) Namespace(org.apache.jackrabbit.webdav.xml.Namespace) HashSet(java.util.HashSet)

Example 2 with Namespace

use of org.apache.jackrabbit.webdav.xml.Namespace in project jackrabbit by apache.

the class JcrUserPrivilegesProperty method asDavProperty.

public CurrentUserPrivilegeSetProperty asDavProperty() throws RepositoryException {
    List<Privilege> davPrivs = new ArrayList<Privilege>();
    for (javax.jcr.security.Privilege privilege : session.getAccessControlManager().getPrivileges(absPath)) {
        String privilegeName = privilege.getName();
        String prefix = Text.getNamespacePrefix(privilegeName);
        Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, session.getNamespaceURI(prefix));
        davPrivs.add(Privilege.getPrivilege(Text.getLocalName(privilegeName), ns));
    }
    return new CurrentUserPrivilegeSetProperty(davPrivs.toArray(new Privilege[davPrivs.size()]));
}
Also used : CurrentUserPrivilegeSetProperty(org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty) ArrayList(java.util.ArrayList) Privilege(org.apache.jackrabbit.webdav.security.Privilege) Namespace(org.apache.jackrabbit.webdav.xml.Namespace)

Example 3 with Namespace

use of org.apache.jackrabbit.webdav.xml.Namespace in project jackrabbit by apache.

the class ExpandPropertyReport method getResponse.

/**
 * Builds a <code>MultiStatusResponse</code> for the given resource respecting
 * the properties specified. Any property that represents a {@link HrefProperty}
 * is expanded: It's name equals the name of a valid {@link HrefProperty}.
 * However the value of that given property (consisting of one or multiple DAV:href elements)
 * is replaced by the Xml representation of a separate
 * {@link MultiStatusResponse multistatus responses} for the
 * resource referenced by the given DAV:href elements. The responses may
 * themselves have properties, which are defined by the separate list.
 *
 * @param res
 * @param propertyElements
 * @return <code>MultiStatusResponse</code> for the given resource.
 * @see ExpandProperty
 */
private MultiStatusResponse getResponse(DavResource res, Iterator<Element> propertyElements) {
    MultiStatusResponse resp = new MultiStatusResponse(res.getHref(), null);
    while (propertyElements.hasNext()) {
        Element propertyElem = propertyElements.next();
        // retrieve the localName present in the "name" attribute
        String nameAttr = propertyElem.getAttribute(ATTR_NAME);
        if (nameAttr == null || "".equals(nameAttr)) {
            // NOTE: this is not valid according to the DTD
            continue;
        }
        // retrieve the namespace present in the "namespace" attribute
        // NOTE: if this attribute is missing the DAV: namespace represents the default.
        String namespaceAttr = propertyElem.getAttribute(ATTR_NAMESPACE);
        Namespace namespace = (namespaceAttr != null) ? Namespace.getNamespace(namespaceAttr) : NAMESPACE;
        DavPropertyName propName = DavPropertyName.create(nameAttr, namespace);
        DavProperty<?> p = res.getProperty(propName);
        if (p != null) {
            if (p instanceof HrefProperty && res instanceof DeltaVResource) {
                ElementIterator it = DomUtil.getChildren(propertyElem, XML_PROPERTY, NAMESPACE);
                resp.add(new ExpandProperty((DeltaVResource) res, (HrefProperty) p, it));
            } else {
                resp.add(p);
            }
        } else {
            resp.add(propName, DavServletResponse.SC_NOT_FOUND);
        }
    }
    return resp;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Element(org.w3c.dom.Element) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) DeltaVResource(org.apache.jackrabbit.webdav.version.DeltaVResource) Namespace(org.apache.jackrabbit.webdav.xml.Namespace) DavPropertyName(org.apache.jackrabbit.webdav.property.DavPropertyName)

Example 4 with Namespace

use of org.apache.jackrabbit.webdav.xml.Namespace in project jackrabbit by apache.

the class SubscriptionImpl method serializeInfoMap.

protected static void serializeInfoMap(Element eventElem, Session session, Map<?, ?> map) {
    // info
    Element info = DomUtil.addChildElement(eventElem, XML_EVENTINFO, NAMESPACE);
    Map<?, ?> m = map;
    for (Map.Entry<?, ?> entry : m.entrySet()) {
        try {
            String key = entry.getKey().toString();
            Namespace ns = Namespace.EMPTY_NAMESPACE;
            int colon = key.indexOf(':');
            if (colon >= 0) {
                String prefix = key.substring(0, colon);
                String localname = key.substring(colon + 1);
                ns = Namespace.getNamespace(prefix, session.getNamespaceURI(prefix));
                key = localname;
            }
            Object value = entry.getValue();
            if (value != null) {
                DomUtil.addChildElement(info, key, ns, value.toString());
            } else {
                DomUtil.addChildElement(info, key, ns);
            }
        } catch (RepositoryException nse) {
            log.error("Internal error while getting namespaceUri, info map field skipped for {}", entry.getKey());
        }
    }
}
Also used : Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) Namespace(org.apache.jackrabbit.webdav.xml.Namespace)

Example 5 with Namespace

use of org.apache.jackrabbit.webdav.xml.Namespace in project jackrabbit by apache.

the class JcrSupportedPrivilegesProperty method createSupportedPrivilege.

private SupportedPrivilege createSupportedPrivilege(Privilege privilege) throws RepositoryException {
    String privilegeName = privilege.getName();
    String localName = Text.getLocalName(privilegeName);
    String prefix = Text.getNamespacePrefix(privilegeName);
    Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, session.getNamespaceURI(prefix));
    org.apache.jackrabbit.webdav.security.Privilege davPrivilege = org.apache.jackrabbit.webdav.security.Privilege.getPrivilege(localName, ns);
    SupportedPrivilege[] aggregates = (privilege.isAggregate()) ? getDeclaredAggregates(privilege) : null;
    SupportedPrivilege sp = new SupportedPrivilege(davPrivilege, null, null, privilege.isAbstract(), aggregates);
    if (!aggregated.contains(privilegeName)) {
        supportedPrivileges.put(privilegeName, sp);
    }
    return sp;
}
Also used : SupportedPrivilege(org.apache.jackrabbit.webdav.security.SupportedPrivilege) Namespace(org.apache.jackrabbit.webdav.xml.Namespace)

Aggregations

Namespace (org.apache.jackrabbit.webdav.xml.Namespace)7 DavPropertyName (org.apache.jackrabbit.webdav.property.DavPropertyName)2 Privilege (org.apache.jackrabbit.webdav.security.Privilege)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 RepositoryException (javax.jcr.RepositoryException)1 NamespaceHelper (org.apache.jackrabbit.commons.NamespaceHelper)1 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)1 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)1 CurrentUserPrivilegeSetProperty (org.apache.jackrabbit.webdav.security.CurrentUserPrivilegeSetProperty)1 SupportedPrivilege (org.apache.jackrabbit.webdav.security.SupportedPrivilege)1 DeltaVResource (org.apache.jackrabbit.webdav.version.DeltaVResource)1 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)1