unico 2004/07/22 07:57:25
Modified: src/webdav/server/org/apache/slide/webdav/method
PropPatchMethod.java
Log:
convert absolute href property values to context-path-relative ones.
Thanks to Johan Stuyts ([EMAIL PROTECTED])
Revision Changes Path
1.82 +109 -7
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java
Index: PropPatchMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- PropPatchMethod.java 24 Jun 2004 13:18:52 -0000 1.81
+++ PropPatchMethod.java 22 Jul 2004 14:57:25 -0000 1.82
@@ -29,19 +29,20 @@
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
+
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.PropertyParseException;
import org.apache.slide.common.RequestedPropertiesImpl;
import org.apache.slide.common.RequestedProperty;
import org.apache.slide.common.RequestedPropertyImpl;
import org.apache.slide.common.ServiceAccessException;
-import org.apache.slide.common.SlideToken;
import org.apache.slide.content.NodeProperty;
-import org.apache.slide.content.NodeProperty.NamespaceCache;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.content.NodeRevisionNumber;
import org.apache.slide.content.RevisionDescriptorNotFoundException;
+import org.apache.slide.content.NodeProperty.NamespaceCache;
+import org.apache.slide.event.EventDispatcher;
import org.apache.slide.structure.LinkedObjectNotFoundException;
import org.apache.slide.util.Configuration;
import org.apache.slide.util.XMLValue;
@@ -58,13 +59,17 @@
import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
import org.apache.slide.webdav.util.resourcekind.ResourceKind;
-import org.apache.slide.event.EventDispatcher;
import org.apache.util.WebdavStatus;
+import org.jdom.CDATA;
+import org.jdom.Comment;
import org.jdom.Document;
import org.jdom.Element;
+import org.jdom.EntityRef;
import org.jdom.JDOMException;
import org.jdom.Namespace;
+import org.jdom.ProcessingInstruction;
import org.jdom.Text;
+import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
/**
@@ -283,9 +288,44 @@
currentProperty = (PropPatchProperty)propertyIterator.next();
if (checkPropertyModification(currentProperty, revisionDescriptor,
resourceKind)) {
+ // Convert absolute URIs to relative ones, because Slide
+ // converts them to absolute ones in the result of queries.
+ String finalValue = currentProperty.getValue();
+ Element property = new Element(currentProperty.getName(),
currentProperty.getNamespace());
+ String propertyValue = currentProperty.getValue();
+ if ( (propertyValue != null) &&
(propertyValue.toString().length() > 0)) {
+ if( propertyValue.toString().indexOf('<') >= 0 ) {
+ try {
+ XMLValue xmlValue = new
XMLValue(propertyValue.toString(),
Namespace.getNamespace(currentProperty.getNamespace()));
+ if
(AbstractResourceKind.isLiveProperty(currentProperty.getName())) {
+ convertHrefValueToRelativeURL (xmlValue,
getSlideContextPath(), config);
+ }
+ Iterator iterator = xmlValue.iterator();
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if( o instanceof Element )
+ property.addContent((Element)o);
+ else if( o instanceof Text )
+ property.addContent((Text)o);
+ else if( o instanceof Comment )
+ property.addContent((Comment)o);
+ else if( o instanceof ProcessingInstruction )
+
property.addContent((ProcessingInstruction)o);
+ else if( o instanceof CDATA )
+ property.addContent((CDATA)o);
+ else if( o instanceof EntityRef )
+ property.addContent((EntityRef)o);
+ }
+ finalValue = new
XMLOutputter(Format.getRawFormat()).outputString(property.getContent());
+ }
+ catch (JDOMException e) {
+ // Fallback to original value
+ }
+ }
+ }
NodeProperty newProperty =
new NodeProperty(currentProperty.getName(),
- currentProperty.getValue(),
+ finalValue,
currentProperty.getNamespace());
revisionDescriptor.setProperty(newProperty);
@@ -641,6 +681,68 @@
// ...is there any property to check here yet ?
return null;
+ }
+
+
+
+ /**
+ * If the given <code>xmlValue</code> contains <code><href></code>
+ * elements (at any depth), absolute URIs are converted to relative ones.
+ *
+ * This method modifies <code>xmlValue</code> (and its children).
+ *
+ * @param xmlValue The XMLValue that might contain
+ * <code><href></code> values to convert.
+ * @param servletContextPath The prefix which when added to a relative URI
+ * makes it an absolute one.
+ * @param config Configuration of the WebDAV servlet.
+ */
+ private static void convertHrefValueToRelativeURL (XMLValue xmlValue,
+ String servletContextPath,
+ WebdavServletConfig config) {
+ if (xmlValue != null) {
+ Iterator iterator = xmlValue.iterator();
+ Element element = null;
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if( o instanceof Element ) {
+ element = (Element)o;
+ convertHrefValueToRelativeURL(element, servletContextPath,
config);
+ }
+ }
+ }
+ }
+
+
+
+ /**
+ * If the given <code>Element</code> contains <code><href></code>
+ * elements (at any depth), the absolute URI is converted to a relative
+ * one.
+ *
+ * This method modifies the <code>Element</code> (and its children).
+ *
+ * @param element The <code>Element</code> that might contain
+ * <code><href></code> values to convert.
+ * @param servletContextPath The prefix which when added to a relative URI
+ * makes it an absolute one.
+ * @param config Configuration of the WebDAV servlet.
+ */
+ private static void convertHrefValueToRelativeURL (Element element,
+ String servletContextPath,
+ WebdavServletConfig config) {
+ if (element.getChildren().size() > 0) {
+ Iterator i = element.getChildren().iterator();
+ while (i.hasNext()) {
+ Element child = (Element) i.next();
+ convertHrefValueToRelativeURL(child, servletContextPath, config);
+ }
+ }
+ if ( E_HREF.equals(element.getName()) && (element.getText() != null) ) {
+ if ( PropertyHelper.isAbsoluteURL(servletContextPath,
element.getText()) ) {
+
element.setText(element.getText().substring(servletContextPath.length()));
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]