目前我试图使用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;
}
有人能有个主意吗?
谢谢,晚上好!
XMLUtilities是从哪个包来的?它是否以名称空间感知的方法解析XML文档?(setNamespaceAware(true))。
此外,不要在此处使用DavConstants.DEPTH_INFINTY。使用DEPTH_1。