Search in sources :

Example 6 with ElementIterator

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

the class OptionsInfo method createFromXml.

/**
 * Build an <code>OptionsInfo</code> object from the root element present
 * in the request body.
 *
 * @param optionsElement
 * @return
 * @throws DavException if the optionsElement is <code>null</code>
 * or not a DAV:options element.
 */
public static OptionsInfo createFromXml(Element optionsElement) throws DavException {
    if (!DomUtil.matches(optionsElement, DeltaVConstants.XML_OPTIONS, DeltaVConstants.NAMESPACE)) {
        log.warn("DAV:options element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    OptionsInfo oInfo = new OptionsInfo();
    ElementIterator it = DomUtil.getChildren(optionsElement);
    while (it.hasNext()) {
        // todo: not correct since assuming its the deltaV-namespace
        oInfo.entriesLocalNames.add(it.nextElement().getLocalName());
    }
    return oInfo;
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException)

Example 7 with ElementIterator

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

the class RepositoryServiceImpl method getRegisteredNamespaces.

@Override
public Map<String, String> getRegisteredNamespaces(SessionInfo sessionInfo) throws RepositoryException {
    ReportInfo info = new ReportInfo(JcrRemotingConstants.REPORT_REGISTERED_NAMESPACES, ItemResourceConstants.NAMESPACE);
    HttpReport request = null;
    try {
        request = new HttpReport(uriResolver.getWorkspaceUri(sessionInfo.getWorkspaceName()), info);
        HttpResponse response = executeRequest(sessionInfo, request);
        request.checkSuccess(response);
        Document doc = request.getResponseBodyAsDocument(response.getEntity());
        Map<String, String> namespaces = new HashMap<String, String>();
        if (doc != null) {
            Element rootElement = doc.getDocumentElement();
            ElementIterator nsElems = DomUtil.getChildren(rootElement, JcrRemotingConstants.XML_NAMESPACE, ItemResourceConstants.NAMESPACE);
            while (nsElems.hasNext()) {
                Element elem = nsElems.nextElement();
                String prefix = DomUtil.getChildText(elem, JcrRemotingConstants.XML_PREFIX, ItemResourceConstants.NAMESPACE);
                String uri = DomUtil.getChildText(elem, JcrRemotingConstants.XML_URI, ItemResourceConstants.NAMESPACE);
                // default namespace
                if (prefix == null && uri == null) {
                    prefix = uri = "";
                }
                // any other uri must not be null
                if (uri != null) {
                    namespaces.put(prefix, uri);
                    // TODO: not correct since nsRegistry is retrieved from each session
                    nsCache.add(prefix, uri);
                } else {
                    log.error("Invalid prefix / uri pair: " + prefix + " -> " + uri);
                }
            }
        }
        return namespaces;
    } catch (IOException e) {
        throw new RepositoryException(e);
    } catch (DavException e) {
        throw ExceptionConverter.generate(e);
    } finally {
        if (request != null) {
            request.releaseConnection();
        }
    }
}
Also used : HttpReport(org.apache.jackrabbit.webdav.client.methods.HttpReport) ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element) ReportInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo) HttpResponse(org.apache.http.HttpResponse) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Document(org.w3c.dom.Document)

Example 8 with ElementIterator

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

the class RepositoryServiceImpl method retrieveQNodeTypeDefinitions.

/**
 * @param sessionInfo
 * @param reportDoc
 * @return
 * @throws RepositoryException
 */
private Iterator<QNodeTypeDefinition> retrieveQNodeTypeDefinitions(SessionInfo sessionInfo, Document reportDoc) throws RepositoryException {
    ElementIterator it = DomUtil.getChildren(reportDoc.getDocumentElement(), NodeTypeConstants.NODETYPE_ELEMENT, null);
    List<QNodeTypeDefinition> ntDefs = new ArrayList<QNodeTypeDefinition>();
    NamePathResolver resolver = getNamePathResolver(sessionInfo);
    while (it.hasNext()) {
        ntDefs.add(DefinitionUtil.createQNodeTypeDefinition(it.nextElement(), resolver, getQValueFactory()));
    }
    // refresh node type definitions map
    synchronized (nodeTypeDefinitions) {
        nodeTypeDefinitions.clear();
        for (Object ntDef : ntDefs) {
            QNodeTypeDefinition def = (QNodeTypeDefinition) ntDef;
            nodeTypeDefinitions.put(def.getName(), def);
        }
    }
    return ntDefs.iterator();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) ArrayList(java.util.ArrayList)

Example 9 with ElementIterator

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

the class DefinitionUtil method createQPropertyDefinition.

/**
 * @param declaringNodeType
 * @param pdefElement
 * @param resolver
 * @param qValueFactory
 * @return
 * @throws RepositoryException
 */
static QPropertyDefinition createQPropertyDefinition(Name declaringNodeType, Element pdefElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
    QPropertyDefinitionBuilder builder = new QPropertyDefinitionBuilder();
    buildQItemDefinition(declaringNodeType, pdefElement, resolver, builder);
    if (pdefElement.hasAttribute(REQUIREDTYPE_ATTRIBUTE)) {
        builder.setRequiredType(PropertyType.valueFromName(pdefElement.getAttribute(REQUIREDTYPE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(MULTIPLE_ATTRIBUTE)) {
        builder.setMultiple(Boolean.valueOf(pdefElement.getAttribute(MULTIPLE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)) {
        builder.setFullTextSearchable(Boolean.valueOf(pdefElement.getAttribute(FULL_TEXT_SEARCHABLE_ATTRIBUTE)));
    }
    if (pdefElement.hasAttribute(QUERY_ORDERABLE_ATTRIBUTE)) {
        builder.setQueryOrderable(Boolean.valueOf(pdefElement.getAttribute(QUERY_ORDERABLE_ATTRIBUTE)));
    }
    int requiredType = builder.getRequiredType();
    Element child = DomUtil.getChildElement(pdefElement, DEFAULTVALUES_ELEMENT, null);
    if (child != null) {
        ElementIterator it = DomUtil.getChildren(child, DEFAULTVALUE_ELEMENT, null);
        while (it.hasNext()) {
            String jcrVal = DomUtil.getText(it.nextElement());
            if (jcrVal == null) {
                jcrVal = "";
            }
            QValue qValue;
            if (requiredType == PropertyType.BINARY) {
                // TODO: improve
                Value v = new ValueFactoryQImpl(qValueFactory, resolver).createValue(jcrVal, requiredType);
                qValue = ValueFormat.getQValue(v, resolver, qValueFactory);
            } else {
                qValue = ValueFormat.getQValue(jcrVal, requiredType, resolver, qValueFactory);
            }
            builder.addDefaultValue(qValue);
        }
    }
    // else: no default values defined.
    child = DomUtil.getChildElement(pdefElement, VALUECONSTRAINTS_ELEMENT, null);
    if (child != null) {
        ElementIterator it = DomUtil.getChildren(child, VALUECONSTRAINT_ELEMENT, null);
        while (it.hasNext()) {
            String qValue = DomUtil.getText(it.nextElement());
            // in case of name and path constraint, the value must be
            // converted to SPI values
            // TODO: tobefixed. path-constraint may contain trailing *
            builder.addValueConstraint(ValueConstraint.create(requiredType, qValue, resolver));
        }
    }
    child = DomUtil.getChildElement(pdefElement, AVAILABLE_QUERY_OPERATORS_ELEMENT, null);
    if (child == null) {
        builder.setAvailableQueryOperators(new String[0]);
    } else {
        List<String> names = new ArrayList<String>();
        ElementIterator it = DomUtil.getChildren(child, AVAILABLE_QUERY_OPERATOR_ELEMENT, null);
        while (it.hasNext()) {
            String str = DomUtil.getText(it.nextElement());
            names.add(str);
        }
        builder.setAvailableQueryOperators(names.toArray(new String[names.size()]));
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QValue(org.apache.jackrabbit.spi.QValue) QPropertyDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder) Element(org.w3c.dom.Element) QValue(org.apache.jackrabbit.spi.QValue) Value(javax.jcr.Value) ArrayList(java.util.ArrayList) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl) ValueConstraint(org.apache.jackrabbit.spi.commons.nodetype.constraint.ValueConstraint)

Example 10 with ElementIterator

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

the class BindInfo method createFromXml.

/**
 * Build an <code>BindInfo</code> object from the root element present
 * in the request body.
 *
 * @param root the root element of the request body
 * @return a BindInfo object containing segment and href
 * @throws org.apache.jackrabbit.webdav.DavException if the BIND request is malformed
 */
public static BindInfo createFromXml(Element root) throws DavException {
    if (!DomUtil.matches(root, BindConstants.XML_BIND, BindConstants.NAMESPACE)) {
        log.warn("DAV:bind element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    String href = null;
    String segment = null;
    ElementIterator it = DomUtil.getChildren(root);
    while (it.hasNext()) {
        Element elt = it.nextElement();
        if (DomUtil.matches(elt, BindConstants.XML_SEGMENT, BindConstants.NAMESPACE)) {
            if (segment == null) {
                segment = DomUtil.getText(elt);
            } else {
                log.warn("unexpected multiple occurrence of DAV:segment element");
                throw new DavException(DavServletResponse.SC_BAD_REQUEST);
            }
        } else if (DomUtil.matches(elt, BindConstants.XML_HREF, BindConstants.NAMESPACE)) {
            if (href == null) {
                href = DomUtil.getText(elt);
            } else {
                log.warn("unexpected multiple occurrence of DAV:href element");
                throw new DavException(DavServletResponse.SC_BAD_REQUEST);
            }
        } else {
            log.warn("unexpected element " + elt.getLocalName());
            throw new DavException(DavServletResponse.SC_BAD_REQUEST);
        }
    }
    if (href == null) {
        log.warn("DAV:href element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    if (segment == null) {
        log.warn("DAV:segment element expected");
        throw new DavException(DavServletResponse.SC_BAD_REQUEST);
    }
    return new BindInfo(href, segment);
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) DavException(org.apache.jackrabbit.webdav.DavException) Element(org.w3c.dom.Element)

Aggregations

ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)36 Element (org.w3c.dom.Element)34 ArrayList (java.util.ArrayList)17 DavException (org.apache.jackrabbit.webdav.DavException)13 RepositoryException (javax.jcr.RepositoryException)9 Document (org.w3c.dom.Document)7 IOException (java.io.IOException)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 HttpResponse (org.apache.http.HttpResponse)4 SAXException (org.xml.sax.SAXException)4 Name (org.apache.jackrabbit.spi.Name)3 QValue (org.apache.jackrabbit.spi.QValue)3 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)3 HashMap (java.util.HashMap)2 Event (org.apache.jackrabbit.spi.Event)2 EventBundleImpl (org.apache.jackrabbit.spi.commons.EventBundleImpl)2 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 KeyManagementException (java.security.KeyManagementException)1