CalDAV按时间范围部分检索事件;命名空间错误

时间:2014-04-16 14:53:46

标签: webdav jackrabbit caldav

目前我尝试使用Jackrabbit Libery和RFC 4791 CalDAV

中的信息来实现CalDAV客户端

基于按时间范围部分检索事件的RFC中的示例,我实现了以下代码来执行ReportMethod。

 public void test(String strUri, String strXMLFile) {
  try {
   Document docXMLRequest = XMLUtilities.loadXMLFile(strXMLFile);           
   ReportInfo repInfo = new ReportInfo(docXMLRequest.getDocumentElement(), DavConstants.DEPTH_INFINITY);

   ReportMethod repMethod = new ReportMethod(strUri, repInfo);
  } catch (DavException | IOException e) {
   e.printStackTrace();
  }
 }

docXMLRequest 中包含的使用过的xml内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:"
              xmlns:C="urn:ietf:params:xml:ns:caldav">
  <D:prop>
    <D:getetag/>
    <C:calendar-data>
      <C:comp name="VCALENDAR">
        <C:prop name="VERSION"/>
        <C:comp name="VEVENT">
          <C:prop name="SUMMARY"/>
          <C:prop name="UID"/>
          <C:prop name="DTSTART"/>
          <C:prop name="DTEND"/>
          <C:prop name="DURATION"/>
          <C:prop name="RRULE"/>
          <C:prop name="RDATE"/>
          <C:prop name="EXRULE"/>
          <C:prop name="EXDATE"/>
          <C:prop name="RECURRENCE-ID"/>
        </C:comp>
        <C:comp name="VTIMEZONE"/>
      </C:comp>
    </C:calendar-data>
  </D:prop>
  <C:filter>
    <C:comp-filter name="VCALENDAR">
      <C:comp-filter name="VEVENT">
        <C:time-range start="20060104T000000Z" end="20060105T000000Z"/>
      </C:comp-filter>
    </C:comp-filter>
  </C:filter>
</C:calendar-query>

当我尝试向服务器发出请求时,我总是会收到以下错误:

Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
    at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.setName(Unknown Source)
    at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.<init>(Unknown Source)
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createElementNS(Unknown Source)
    at org.apache.jackrabbit.webdav.xml.DomUtil.createElement(DomUtil.java:549)
    at org.apache.jackrabbit.webdav.version.report.ReportInfo.toXml(ReportInfo.java:250)
    at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.setRequestBody(DavMethodBase.java:204)
    at org.apache.jackrabbit.webdav.client.methods.ReportMethod.<init>(ReportMethod.java:44)
    at webDAVStuff.ManageWebDAV.test(ManageWebDAV.java:117)
    at mainTestRuns.MainTestSyncCalender.main(MainTestSyncCalender.java:24)

遵循XMLUtilities(相关方法):

static public Document loadXMLFile(String strXMLFile) {
try {
    Status.printStatusToConsole("Load: "+ strXMLFile);

    File fileXMLFile = new File(strXMLFile);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder;

    dBuilder = dbFactory.newDocumentBuilder();
    dbFactory.setNamespaceAware(true);
    Document docXMLFile = dBuilder.parse(fileXMLFile);
    docXMLFile.getDocumentElement().normalize();

    return docXMLFile;
} catch (ParserConfigurationException e) {
    e.printStackTrace();
} catch (SAXException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

return null;
}

愿有人有想法吗?

谢谢,晚上好!

1 个答案:

答案 0 :(得分:0)

哪个包是XMLUtilities的东西?它是否在名称空间感知方法中解析XML文档? (setNamespaceAware(真))。

此外,请勿在此处使用DavConstants.DEPTH_INFINITY。使用DEPTH_1。