Esempio n. 1
0
 public Map<String, String> loadHeaders(String uri, String[] headerNames)
     throws IOException, RepositoryException {
   HeadMethod method = new HeadMethod(uri);
   try {
     int statusCode = client.executeMethod(method);
     if (statusCode == DavServletResponse.SC_OK) {
       Map<String, String> headers = new HashMap<String, String>();
       for (String name : headerNames) {
         Header hdr = method.getResponseHeader(name);
         if (hdr != null) {
           headers.put(name, hdr.getValue());
         }
       }
       return headers;
     } else {
       throw ExceptionConverter.generate(
           new DavException(
               statusCode,
               ("Unable to load headers at "
                   + uri
                   + " - Status line = "
                   + method.getStatusLine().toString())));
     }
   } finally {
     method.releaseConnection();
   }
 }
Esempio n. 2
0
  int loadType(String uri) throws RepositoryException, IOException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);

    DavMethodBase method = null;
    try {
      method = new PropFindMethod(uri, nameSet, DavConstants.DEPTH_0);
      client.executeMethod(method);
      method.checkSuccess();

      MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
      if (responses.length == 1) {
        DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
        DavProperty<?> type =
            props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
        if (type != null) {
          return PropertyType.valueFromName(type.getValue().toString());
        } else {
          throw new RepositoryException("Internal error. Cannot retrieve property type at " + uri);
        }
      } else {
        throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + uri);
      }
    } catch (DavException e) {
      throw ExceptionConverter.generate(e);
    } finally {
      if (method != null) {
        method.releaseConnection();
      }
    }
  }
Esempio n. 3
0
 void loadBinary(String uri, int index, Target target) throws RepositoryException, IOException {
   GetMethod method = new GetMethod(uri);
   try {
     int statusCode = client.executeMethod(method);
     if (statusCode == DavServletResponse.SC_OK) {
       target.setStream(method.getResponseBodyAsStream());
     } else {
       throw ExceptionConverter.generate(
           new DavException(
               statusCode,
               ("Unable to load binary at "
                   + uri
                   + " - Status line = "
                   + method.getStatusLine().toString())));
     }
   } finally {
     method.releaseConnection();
   }
 }