コード例 #1
0
ファイル: XcapService.java プロジェクト: cxb811201/cipango
 private void doDelete(HttpServletRequest request, XcapResourceImpl resource)
     throws XcapException, SAXException, VerifierConfigurationException {
   throwExceptionIfNamespace(resource);
   _dao.delete(resource);
   if (!resource.isAllDocument()) {
     if (_validate) {
       XcapUtil.validate(resource.getDocument().getDom(), resource.getProcessor().getXsdSchema());
     }
     validateSpecificAppResource(resource);
   }
 }
コード例 #2
0
ファイル: XcapService.java プロジェクト: cxb811201/cipango
  private void doPut(HttpServletRequest request, XcapResourceImpl resource)
      throws IOException, XcapException, SAXException, VerifierConfigurationException {
    throwExceptionIfNamespace(resource);
    String content = getContent(request, resource);

    _dao.update(resource, content);

    if (_validate)
      XcapUtil.validate(resource.getDocument().getDom(), resource.getProcessor().getXsdSchema());

    validateSpecificAppResource(resource);
  }
コード例 #3
0
ファイル: XcapService.java プロジェクト: cxb811201/cipango
  public XcapResourceImpl getResource(
      XcapUri xcapUri,
      boolean isPut,
      String requestUrlHead,
      Map<String, String> requestNamespaceContext)
      throws XcapException {
    XcapResourceProcessor processor = _processors.get(xcapUri.getAuid());

    if (processor == null)
      throw new XcapException(
          "Not supported auid: " + xcapUri.getAuid() + " in URI: " + xcapUri,
          HttpServletResponse.SC_NOT_FOUND);

    Document document = null;
    XcapResourceImpl resource = new XcapResourceImpl();

    resource.setXcapUri(xcapUri);
    resource.setProcessor(processor);

    XmlResource xmlResource = _dao.getDocument(xcapUri, isPut && !xcapUri.hasNodeSeparator());

    if (xmlResource == null) {
      if (isPut) {
        locatingParent(xcapUri, requestUrlHead);
        resource.setCreation(true);
        return resource;
      } else {
        XcapException e =
            new XcapException(
                "Resource: " + xcapUri.getDocumentSelector() + " not found",
                HttpServletResponse.SC_NOT_FOUND);
        e.setLevel(Level.INFO);
        throw e;
      }
    }
    resource.setDocument(xmlResource);
    // TODO check rootDirectory is in parent dir.

    // TODO authenticate & authorization

    if (_validateOnGet) {
      try {
        XcapUtil.validate(document, processor.getXsdSchema());
      } catch (XcapException e) {
        _log.warn("Unable to validated document:" + e.getMessage(), e);
      }
    }

    if (resource.isAllDocument()) return resource;

    String nodeSelector =
        XcapUtil.insertDefaultNamespace(
            xcapUri.getNodeSelector(), processor.getDefaultNamespacePrefix());

    if (_log.isDebugEnabled())
      _log.debug("select node " + nodeSelector + " in " + xcapUri.getDocumentSelector());

    if (requestNamespaceContext == null) requestNamespaceContext = new HashMap<String, String>();
    requestNamespaceContext.putAll(processor.getNamespaceContext());

    resource.setNamespaceContext(requestNamespaceContext);

    XmlResource xmlResource2 = _dao.getNode(resource, nodeSelector);

    if (xmlResource2 == null) {
      if (isPut) {
        // XCAP 8.2.1. Locating the Parent
        String parent =
            locatingParent(resource, nodeSelector, xcapUri.getDocumentSelector(), requestUrlHead);
        resource.setCreation(true);
        NodeType nodeType;
        String nodeName = nodeSelector.substring(parent.length());
        // /@id is an attribute and /service[@id="1"] is an
        // element
        if (nodeName.indexOf('@') != -1 && nodeName.indexOf('[') == -1) {
          nodeType = NodeType.ATTRIBUTE;
          nodeName = nodeName.substring(nodeName.indexOf('@') + 1);
        } else nodeType = NodeType.ELEMENT;
        resource.setParent(parent, nodeType, nodeName);
      } else {
        XcapException e =
            new XcapException(
                "Resource: " + xcapUri + " not found (no node selected)",
                HttpServletResponse.SC_NOT_FOUND);
        e.setLevel(Level.INFO);
        throw e;
      }
    } else {
      resource.setCreation(false);
      resource.setSelectedResource(xmlResource2);
    }

    return resource;
  }