You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by lu...@apache.org on 2004/09/26 16:54:55 UTC
cvs commit: jakarta-slide/src/share/org/apache/slide/search SearchToken.java SlideUri.java
luetzkendorf 2004/09/26 07:54:55
Modified: src/share/org/apache/slide/cluster
ClusterCacheRefresher.java
src/share/org/apache/slide/content
NodeRevisionDescriptor.java
NodeRevisionDescriptors.java
src/share/org/apache/slide/structure ObjectNode.java
src/share/org/apache/slide/search SearchToken.java
SlideUri.java
Added: src/share/org/apache/slide/util EmptyEnumeration.java
Log:
merge with release branch
Revision Changes Path
1.5 +2 -0 jakarta-slide/src/share/org/apache/slide/cluster/ClusterCacheRefresher.java
Index: ClusterCacheRefresher.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/cluster/ClusterCacheRefresher.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ClusterCacheRefresher.java 9 Aug 2004 23:27:00 -0000 1.4
+++ ClusterCacheRefresher.java 26 Sep 2004 14:54:54 -0000 1.5
@@ -325,6 +325,8 @@
* @return the stipped uri
*/
private String stripUri(String uri) {
+ // FIXME: if this is intended to remove the servlet path this will
+ // NOT work if the servlet is not default-servlet or is the root servlet
if ( uri.indexOf("/") == 0 ) {
uri = uri.substring(1);
}
1.2 +30 -0 jakarta-slide/src/share/org/apache/slide/util/EmptyEnumeration.java
1.38 +25 -11 jakarta-slide/src/share/org/apache/slide/content/NodeRevisionDescriptor.java
Index: NodeRevisionDescriptor.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeRevisionDescriptor.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- NodeRevisionDescriptor.java 23 Sep 2004 22:52:50 -0000 1.37
+++ NodeRevisionDescriptor.java 26 Sep 2004 14:54:54 -0000 1.38
@@ -34,6 +34,7 @@
import java.util.Vector;
import org.apache.slide.common.ObjectValidationFailedException;
+import org.apache.slide.util.EmptyEnumeration;
import org.apache.slide.util.Messages;
/**
@@ -223,10 +224,9 @@
/**
* Track updated properties
*/
- private Hashtable updatedProperties;
- private Hashtable removedProperties;
+ private Hashtable updatedProperties = null;
+ private Hashtable removedProperties = null;
-
// ------------------------------------------------------------- Properties
@@ -404,6 +404,9 @@
public void setProperty(NodeProperty property) {
String name = getNamespacedPropertyName(property.getNamespace(), property.getName());
properties.put(name, property);
+
+ if (this.updatedProperties == null) this.updatedProperties = new Hashtable();
+ if (this.removedProperties == null) this.removedProperties = new Hashtable();
updatedProperties.put(name, property);
removedProperties.remove(name);
}
@@ -440,6 +443,9 @@
NodeProperty nodeProperty = (NodeProperty )properties.remove(name);
// check if the property existed before
if (nodeProperty != null) {
+ if (this.updatedProperties == null) this.updatedProperties = new Hashtable();
+ if (this.removedProperties == null) this.removedProperties = new Hashtable();
+
removedProperties.put(name, nodeProperty);
updatedProperties.remove(name);
}
@@ -495,19 +501,27 @@
}
public Enumeration enumerateRemovedProperties() {
- return removedProperties.elements();
+ if (this.removedProperties == null) {
+ return EmptyEnumeration.INSTANCE;
+ } else {
+ return removedProperties.elements();
+ }
}
public Enumeration enumerateUpdatedProperties() {
- return updatedProperties.elements();
+ if (this.updatedProperties == null) {
+ return EmptyEnumeration.INSTANCE;
+ } else {
+ return updatedProperties.elements();
+ }
}
public void resetUpdatedProperties() {
- updatedProperties.clear();
+ updatedProperties = null;
}
public void resetRemovedProperties() {
- removedProperties.clear();
+ removedProperties = null;
}
/**
1.18 +6 -4 jakarta-slide/src/share/org/apache/slide/content/NodeRevisionDescriptors.java
Index: NodeRevisionDescriptors.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeRevisionDescriptors.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- NodeRevisionDescriptors.java 28 Jul 2004 09:37:55 -0000 1.17
+++ NodeRevisionDescriptors.java 26 Sep 2004 14:54:54 -0000 1.18
@@ -113,6 +113,8 @@
/**
* Working revisions.
+ *
+ * <p>TODO: <code>workingRevisions</code> are only writen never read!
*/
private Hashtable workingRevisions;
1.29 +41 -26 jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java
Index: ObjectNode.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- ObjectNode.java 20 Sep 2004 22:41:33 -0000 1.28
+++ ObjectNode.java 26 Sep 2004 14:54:55 -0000 1.29
@@ -24,12 +24,14 @@
package org.apache.slide.structure;
import java.io.Serializable;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Set;
import java.util.HashSet;
import org.apache.slide.common.ObjectValidationFailedException;
import org.apache.slide.common.UriPath;
+import org.apache.slide.util.EmptyEnumeration;
import org.apache.slide.util.Messages;
/**
@@ -67,7 +69,7 @@
* wheter {@link #linksShared} is true. In this case clone the vector
* and set the shared state to false.
*/
- private Vector links;
+ private Vector links = null;
/*
* If true then the {@link #links} vector is shared between multiple
@@ -100,7 +102,6 @@
* Default constructor.
*/
public ObjectNode() {
- this.links = new Vector();
this.bindings = new BindingList();
this.parentBindings = new ParentBindingList();
this.updatedBindings = new HashSet();
@@ -135,9 +136,10 @@
this.parentBindings = new ParentBindingList(parentBindings);
this.links = links;
Enumeration e = bindings.elements();
+ if (e.hasMoreElements()) this.updatedBindings = new HashSet();
while(e.hasMoreElements()) {
- updatedBindings.add(((ObjectNode.Binding)e.nextElement()).getUuri());
- }
+ updatedBindings.add(((ObjectNode.Binding)e.nextElement()).getUuri());
+ }
}
/**
@@ -186,14 +188,17 @@
this.uuri = uuri;
}
-
public Set getUpdatedBindings() {
- return updatedBindings;
- }
+ if (this.updatedBindings == null) {
+ return Collections.EMPTY_SET;
+ } else {
+ return Collections.unmodifiableSet(updatedBindings);
+ }
+ }
- public void resetUpdatedBindings() {
- updatedBindings.clear();
- }
+ public void resetUpdatedBindings() {
+ this.updatedBindings = null;
+ }
/**
* Return this object's children
@@ -349,7 +354,11 @@
* @return boolean true if this object has links, false otherwise
*/
public boolean hasLinks() {
- return !( links.isEmpty());
+ if (this.links == null) {
+ return false;
+ } else {
+ return !( links.isEmpty());
+ }
}
/**
* Return this object's inbound links
@@ -357,7 +366,11 @@
* @return Enumeration Inbound links uris
*/
public Enumeration enumerateLinks() {
- return links.elements();
+ if (this.links == null) {
+ return EmptyEnumeration.INSTANCE;
+ } else {
+ return links.elements();
+ }
}
@@ -450,12 +463,7 @@
throw new ObjectValidationFailedException
(uri, Messages.message
(ObjectNode.class.getName() + ".nullBindingsVector"));
-
- if (links == null)
- throw new ObjectValidationFailedException
- (uri, Messages.message
- (ObjectNode.class.getName() + ".nullLinksVector"));
-
+
}
/**
@@ -472,7 +480,8 @@
* @param link an LinkNode
*/
public void addLink( LinkNode link ) {
- links.add(link.getUri());
+ if (this.links == null) this.links = new Vector();
+ links.add(link.getUri());
}
/**
@@ -481,7 +490,9 @@
* @param source the child ObjectNode
*/
public void addBinding( String bindingName, ObjectNode source ) {
- updatedBindings.add(source.getUri());
+ if (this.updatedBindings == null) this.updatedBindings = new HashSet();
+ updatedBindings.add(source.getUri());
+
if (!hasBinding(bindingName)) {
if(bindingsShared) {
// Lazy cloning on first write access
@@ -505,7 +516,9 @@
* @param child The child to remove
*/
public void removeChild(ObjectNode child) {
- updatedBindings.add(child.getUri());
+ if (this.updatedBindings == null) this.updatedBindings = new HashSet();
+ updatedBindings.add(child.getUri());
+
if (child == null) {
return;
}
@@ -527,7 +540,9 @@
* @param link
*/
public void removeLink(LinkNode link) {
- links.remove(link.getUri());
+ if (this.links != null) {
+ links.remove(link.getUri());
+ }
}
/**
1.7 +7 -6 jakarta-slide/src/share/org/apache/slide/search/SearchToken.java
Index: SearchToken.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/SearchToken.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SearchToken.java 28 Jul 2004 09:35:09 -0000 1.6
+++ SearchToken.java 26 Sep 2004 14:54:55 -0000 1.7
@@ -93,8 +93,9 @@
this.contentHelper = content;
this.structureHelper = structure;
this.maxDepth = maxDepth;
- this.slideContext = new SlideUri (requestUri);
- this.namespace = namespace;
+ this.slideContext = SlideUri.createWithRequestUri(
+ (String)token.getParameter("slideContextPath"), requestUri);
+ this.namespace = namespace;
}
/**
1.11 +104 -110 jakarta-slide/src/share/org/apache/slide/search/SlideUri.java
Index: SlideUri.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/SlideUri.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SlideUri.java 14 Jun 2004 12:40:05 -0000 1.10
+++ SlideUri.java 26 Sep 2004 14:54:55 -0000 1.11
@@ -24,10 +24,14 @@
package org.apache.slide.search;
/**
- * The root of an href in slide is the slide servlet. For an external href the
- * root is the server. Example: the host is localhost, the context is slide,
- * the slidePath is /mycoll/myfile.xml
- * http://localhost/slide/mycoll/myfile.xml
+ * A SlideUri contains two parts the <em>context path</em> and the <em>slide uri</em>.
+ *
+ * <p>The context path is determined by the path of the webapp and the path
+ * to which the WebDavServlet is mapped. Samples: <code>/slide</code>,
+ * <code>/webapp/webdav</code> and <code>/</code>.
+ *
+ * <p>The slide uri is an URI as represented by {@link org.apache.slide.common.Uri}.
+ *
*
*/
public class SlideUri {
@@ -36,125 +40,115 @@
private String path;
/**
- * Constructs a SlideUri. If the requestUri is null, paths are regarded
- * as being always slidePaths
+ * Creates a SlideUri.
+ * @param slideContextPath the Context path of the WebDAVServlet
+ * @param requestUri the URI from an WebDAV(HTTP) request
+ *
+ * @return the created SlideUri
*/
- public SlideUri (String requestUri) {
- if (requestUri == null) {
- this.context = null;
- this.path = "";
- }
- else {
- this.context = getContextOfRelPath(requestUri);
- this.path = getPathOfRelPath(requestUri);
- }
- }
-
- /**
- * Method getSlideUri. If the requestUri is null, relpath is regarded to be
- * already a slidePath, it must start with a "/"
- *
- * @param relPath a String
- *
- * @return a String
- *
- * @throws InvalidScopeException
- *
- */
- public String getSlidePath (String relPath) throws InvalidScopeException {
-
- if (context == null) {
- if (!relPath.startsWith("/"))
- throw new InvalidScopeException ("absolute scope is required");
- return relPath;
- }
-
- StringBuffer sb = new StringBuffer ();
- if (relPath.startsWith("/")) {
-
- if (!context.equals ("")) {
-
- String relContext = getContextOfRelPath (relPath);
- if (!relContext.equals (context))
- throw new InvalidScopeException ("Uri \"" + relPath + "\" does not refer to " + context
- + ". If an absolute scope is used, it must start with \""
- + context + "\"");
-
- relPath = getPathOfRelPath (relPath);
- }
- }
-
- else {
- sb.append (path);
- if (!path.endsWith("/"))
- sb.append ("/");
- }
-
- sb.append (relPath);
-
- return sb.toString();
+ public static SlideUri createWithRequestUri(String slideContextPath, String requestUri) {
+ if (slideContextPath.length() == 1) {
+ // this.slideContextPath == "/"
+ return new SlideUri(slideContextPath, requestUri);
+ } else {
+ return new SlideUri(slideContextPath,
+ requestUri.substring(slideContextPath.length()));
+ }
}
/**
- * Method getContextPath
- *
- * @param internalHref a String
- *
- * @return a String
- * @deprecated
+ * Constructs a SlideUri.
+ *
+ * @param slideContextPath Context and ServletPath
+ * @param slideUri uri
*/
- public String getContextPath (String slidePath) {
- if (context == null) {
- throw new RuntimeException ("getContextPath not allowed in this context");
+ private SlideUri (String slideContextPath, String slideUri) {
+ if (slideContextPath == null || slideUri == null) {
+ throw new NullPointerException();
+ }
+ if (slideUri.length() == 0) {
+ slideUri = "/";
+ }
+ if (!slideContextPath.startsWith("/")) {
+ throw new IllegalArgumentException("slideContextPath must be absolute");
+ }
+ if (!slideUri.startsWith("/")) {
+ throw new IllegalArgumentException("slideUri must be absolute");
+ }
+ this.context = slideContextPath;
+ this.path = slideUri;
+
+ // normalize
+ if (this.context.endsWith("/") && this.context.length() > 1) {
+ this.context = this.context.substring(0, this.context.length()-1);
+ }
+ if (this.path.endsWith("/") && this.context.length() > 1) {
+ this.path = this.path.substring(0, this.path.length()-1);
}
- return context + slidePath;
}
-
/**
- * Method getContextOfRelPath
+ * Determines the slidePath from an webdav path.
+ *
+ * @param path relative or absolute webdav path
*
- * @param relPath a String
- *
- * @return a String
+ * @throws InvalidScopeException if the given path is absolute but not
+ * in the scope given by the current slice context path.
*
*/
- private String getContextOfRelPath (String relPath) {
- // FIXME the context may contain slashes too
- // this does not work when the servlet in not the default, e.g. /slide/abc/
- String result = null;
- int posSlash = relPath.indexOf ('/', 1);
- if (posSlash == -1)
- result = relPath.substring (0);
- else
- result = relPath.substring (0, posSlash);
-
- return result;
+ public String getSlidePath (String davPath) throws InvalidScopeException {
+
+ if (davPath.startsWith("/")) {
+ // not a relative path
+ if (!(davPath.startsWith(this.context))) {
+ throw new InvalidScopeException (
+ "Uri \"" + davPath + "\" does not refer to " + context
+ + ". If an absolute scope is used, it must start with \""
+ + context + "\"");
+ }
+ if (davPath.length() == this.context.length()) {
+ return "/";
+ }
+ if (davPath.charAt(this.context.length()) != '/') {
+ throw new InvalidScopeException (
+ "Uri \"" + davPath + "\" does not refer to " + context
+ + ". If an absolute scope is used, it must start with \""
+ + context + "\"");
+ }
+
+ return davPath.substring(this.context.length());
+ } else {
+ // relative path
+ if (path.length() > 1) {
+ return this.path + "/" + davPath;
+ } else {
+ // this.path == "/"
+ return this.path + davPath;
+ }
+ }
}
/**
- * Method getPathOfRelPath
- *
- * @param relPath a String
- *
- * @return a String
- *
+ * Translates a slide uri to an absolute webdav path.
+ *
+ * @param slidePath slide internal uri
*/
- private String getPathOfRelPath (String relPath) {
- // FIXME the context may contain slashes too
- String result = null;
- int posSlash = relPath.indexOf ('/', 1);
- if (posSlash == -1)
- result = "";
- else
- result = relPath.substring (posSlash);
-
- return result;
+ public String getContextPath (String slidePath) {
+ if (slidePath.startsWith("/")) {
+ if (context.length() > 1) {
+ return context + slidePath;
+ } else {
+ // this.context == "/"
+ return slidePath;
+ }
+ } else {
+ if (context.length() > 1) {
+ return context + "/" + slidePath;
+ } else {
+ // this.context == "/"
+ return "/" + slidePath;
+ }
+ }
}
-
-
-
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org