jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r827966 [6/15] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/management/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/...
Date Wed, 21 Oct 2009 11:38:44 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NodePropBundle.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NodePropBundle.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NodePropBundle.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/NodePropBundle.java Wed Oct 21 11:38:31 2009
@@ -32,8 +32,6 @@
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.nodetype.PropDefId;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.slf4j.Logger;
@@ -76,11 +74,6 @@
     private Set<Name> mixinTypeNames;
 
     /**
-     * the nodedef id
-     */
-    private NodeDefId nodeDefId;
-
-    /**
      * the child node entries
      */
     private LinkedList<NodePropBundle.ChildNodeEntry> childNodeEntries = new LinkedList<NodePropBundle.ChildNodeEntry>();
@@ -148,7 +141,6 @@
         parentId = state.getParentId();
         nodeTypeName = state.getNodeTypeName();
         mixinTypeNames = state.getMixinTypeNames();
-        nodeDefId = state.getDefinitionId();
         isReferenceable = state.hasPropertyName(NameConstants.JCR_UUID);
         modCount = state.getModCount();
         List<org.apache.jackrabbit.core.state.ChildNodeEntry> list = state.getChildNodeEntries();
@@ -169,7 +161,6 @@
         state.setParentId(parentId);
         state.setNodeTypeName(nodeTypeName);
         state.setMixinTypeNames(mixinTypeNames);
-        state.setDefinitionId(nodeDefId);
         state.setModCount(modCount);
         for (ChildNodeEntry e : childNodeEntries) {
             state.addChildNodeEntry(e.getName(), e.getId());
@@ -203,7 +194,6 @@
             return null;
         }
         PropertyState ps = pMgr.createNew(new PropertyId(id, name));
-        ps.setDefinitionId(p.getPropDefId());
         ps.setMultiValued(p.isMultiValued());
         ps.setType(p.getType());
         ps.setValues(p.getValues());
@@ -284,22 +274,6 @@
     }
 
     /**
-     * Returns the node def id of this bundle.
-     * @return the node def id.
-     */
-    public NodeDefId getNodeDefId() {
-        return nodeDefId;
-    }
-
-    /**
-     * Sets the node def id.
-     * @param nodeDefId the node def id.
-     */
-    public void setNodeDefId(NodeDefId nodeDefId) {
-        this.nodeDefId = nodeDefId;
-    }
-
-    /**
      * Checks if this bundle is referenceable.
      * @return <code>true</code> if this bundle is referenceable;
      *         <code>false</code> otherwise.
@@ -549,11 +523,6 @@
         private boolean multiValued;
 
         /**
-         * the propedef id
-         */
-        private PropDefId propDefId;
-
-        /**
          * the blob ids
          */
         private String[] blobIds;
@@ -581,7 +550,6 @@
             values = state.getValues();
             type = state.getType();
             multiValued = state.isMultiValued();
-            propDefId = state.getDefinitionId();
             modCount = state.getModCount();
             if (type == PropertyType.BINARY) {
                 blobIds = new String[values.length];
@@ -653,22 +621,6 @@
         }
 
         /**
-         * Returns the propdef id.
-         * @return the propdef id.
-         */
-        public PropDefId getPropDefId() {
-            return propDefId;
-        }
-
-        /**
-         * Sets the propdef id
-         * @param propDefId the propdef id
-         */
-        public void setPropDefId(PropDefId propDefId) {
-            this.propDefId = propDefId;
-        }
-
-        /**
          * Returns the n<sup>th</sup> blob id.
          * @param n the index of the blob id
          * @return the blob id

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/Serializer.java Wed Oct 21 11:38:31 2009
@@ -20,8 +20,6 @@
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.nodetype.PropDefId;
 import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
@@ -82,7 +80,7 @@
             out.write(state.getParentId().getRawBytes());
         }
         // definitionId
-        out.writeUTF(state.getDefinitionId().toString());
+        out.writeUTF("");
         // mixin types
         Collection<Name> c = state.getMixinTypeNames();
         out.writeInt(c.size()); // count
@@ -131,8 +129,7 @@
             state.setParentId(new NodeId(uuidBytes));
         }
         // definitionId
-        s = in.readUTF();
-        state.setDefinitionId(NodeDefId.valueOf(s));
+        in.readUTF();
         // mixin types
         int count = in.readInt();   // count
         Set<Name> set = new HashSet<Name>(count);
@@ -183,7 +180,7 @@
         // multiValued
         out.writeBoolean(state.isMultiValued());
         // definitionId
-        out.writeUTF(state.getDefinitionId().toString());
+        out.writeUTF("");
         // modCount
         out.writeShort(state.getModCount());
         // values
@@ -259,8 +256,7 @@
         boolean multiValued = in.readBoolean();
         state.setMultiValued(multiValued);
         // definitionId
-        String s = in.readUTF();
-        state.setDefinitionId(PropDefId.valueOf(s));
+        in.readUTF();
         // modCount
         short modCount = in.readShort();
         state.setModCount(modCount);
@@ -270,7 +266,7 @@
         for (int i = 0; i < count; i++) {
             InternalValue val;
             if (type == PropertyType.BINARY) {
-                s = in.readUTF();   // value (i.e. blobId)
+                String s = in.readUTF();   // value (i.e. blobId)
                 // special handling required for binary value:
                 // the value stores the id of the BLOB data
                 // in the BLOB store
@@ -302,7 +298,7 @@
                 int len = in.readInt(); // lenght of byte[]
                 byte[] bytes = new byte[len];
                 in.readFully(bytes); // byte[]
-                s = new String(bytes, ENCODING);
+                String s = new String(bytes, ENCODING);
                 val = InternalValue.valueOf(s, type);
             }
             values[i] = val;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/xml/XMLPersistenceManager.java Wed Oct 21 11:38:31 2009
@@ -24,8 +24,6 @@
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
-import org.apache.jackrabbit.core.nodetype.NodeDefId;
-import org.apache.jackrabbit.core.nodetype.PropDefId;
 import org.apache.jackrabbit.core.persistence.AbstractPersistenceManager;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
@@ -87,7 +85,6 @@
     private static final String UUID_ATTRIBUTE = "uuid";
     private static final String NODETYPE_ATTRIBUTE = "nodeType";
     private static final String PARENTUUID_ATTRIBUTE = "parentUUID";
-    private static final String DEFINITIONID_ATTRIBUTE = "definitionId";
     private static final String MODCOUNT_ATTRIBUTE = "modCount";
 
     private static final String MIXINTYPES_ELEMENT = "mixinTypes";
@@ -243,10 +240,6 @@
             state.setParentId(NodeId.valueOf(parentUUID));
         }
 
-        // definition id
-        String definitionId = walker.getAttribute(DEFINITIONID_ATTRIBUTE);
-        state.setDefinitionId(NodeDefId.valueOf(definitionId));
-
         // modification count
         String modCount = walker.getAttribute(MODCOUNT_ATTRIBUTE);
         state.setModCount(Short.parseShort(modCount));
@@ -324,10 +317,6 @@
         String multiValued = walker.getAttribute(MULTIVALUED_ATTRIBUTE);
         state.setMultiValued(Boolean.getBoolean(multiValued));
 
-        // definition id
-        String definitionId = walker.getAttribute(DEFINITIONID_ATTRIBUTE);
-        state.setDefinitionId(PropDefId.valueOf(definitionId));
-
         // modification count
         String modCount = walker.getAttribute(MODCOUNT_ATTRIBUTE);
         state.setModCount(Short.parseShort(modCount));
@@ -567,7 +556,6 @@
                 writer.write("<" + NODE_ELEMENT + " "
                         + UUID_ATTRIBUTE + "=\"" + id + "\" "
                         + PARENTUUID_ATTRIBUTE + "=\"" + parentId + "\" "
-                        + DEFINITIONID_ATTRIBUTE + "=\"" + state.getDefinitionId() + "\" "
                         + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" "
                         + NODETYPE_ATTRIBUTE + "=\"" + encodedNodeType + "\">\n");
 
@@ -650,7 +638,6 @@
                         + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getName().toString()) + "\" "
                         + PARENTUUID_ATTRIBUTE + "=\"" + state.getParentId() + "\" "
                         + MULTIVALUED_ATTRIBUTE + "=\"" + Boolean.toString(state.isMultiValued()) + "\" "
-                        + DEFINITIONID_ATTRIBUTE + "=\"" + state.getDefinitionId().toString() + "\" "
                         + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" "
                         + TYPE_ATTRIBUTE + "=\"" + typeName + "\">\n");
                 // values

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java Wed Oct 21 11:38:31 2009
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import org.apache.commons.io.IOExceptionWithCause;
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.slf4j.Logger;
@@ -36,6 +39,11 @@
     private static final Logger log = LoggerFactory.getLogger(AbstractQueryHandler.class);
 
     /**
+     * Search index file system, or <code>null</code>
+     */
+    protected FileSystem fs;
+
+    /**
      * The context for this query handler.
      */
     private QueryHandlerContext context;
@@ -60,13 +68,27 @@
      * Initializes this query handler by setting all properties in this class
      * with appropriate parameter values.
      *
+     * @param fs search index file system, or <code>null</code>
      * @param context the context for this query handler.
      */
-    public final void init(QueryHandlerContext context) throws IOException {
+    public final void init(FileSystem fs, QueryHandlerContext context)
+            throws IOException {
+        this.fs = fs;
         this.context = context;
         doInit();
     }
 
+    public void close() throws IOException {
+        if (fs != null) {
+            try {
+                fs.close();
+            } catch (FileSystemException e) {
+                throw new IOExceptionWithCause(
+                        "Unable to close search index file system: " + fs, e);
+            }
+        }
+    }
+
     /**
      * This method must be implemented by concrete sub classes and will be
      * called from {@link #init}.
@@ -172,5 +194,5 @@
     public String getIdleTime() {
         return idleTime;
     }
-        
+
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyTypeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyTypeRegistry.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyTypeRegistry.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyTypeRegistry.java Wed Oct 21 11:38:31 2009
@@ -16,11 +16,11 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import org.apache.jackrabbit.core.nodetype.NodeTypeDef;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistryListener;
-import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
+import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -86,10 +86,10 @@
 
     public void nodeTypeRegistered(Name ntName) {
         try {
-            NodeTypeDef def = registry.getNodeTypeDef(ntName);
-            PropDef[] propDefs = def.getPropertyDefs();
+            QNodeTypeDefinition def = registry.getNodeTypeDef(ntName);
+            QPropertyDefinition[] propDefs = def.getPropertyDefs();
             synchronized (typeMapping) {
-                for (PropDef propDef : propDefs) {
+                for (QPropertyDefinition propDef : propDefs) {
                     int type = propDef.getRequiredType();
                     if (!propDef.definesResidual() && type != PropertyType.UNDEFINED) {
                         Name name = propDef.getName();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QOMQueryFactory.java Wed Oct 21 11:38:31 2009
@@ -25,7 +25,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFactory;
 
-import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilderRegistry;
+import org.apache.jackrabbit.commons.query.QueryObjectModelBuilderRegistry;
 
 /**
  * <code>QOMQueryFactory</code> implements a query factory that creates QOM

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java Wed Oct 21 11:38:31 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
@@ -39,11 +40,16 @@
     /**
      * Initializes this query handler. This method is called after the
      * <code>QueryHandler</code> is instantiated.
+     * <p>
+     * If a file system has been configured (i.e. the fs argument is not
+     * <code>null</code>), then the query handler is expected to close
+     * the given file system when the {@link #close()} method is called.
      *
+     * @param fs the configured search index file system, or <code>null</code>
      * @param context the context for this query handler.
      * @throws IOException if an error occurs during initialization.
      */
-    void init(QueryHandlerContext context) throws IOException;
+    void init(FileSystem fs, QueryHandlerContext context) throws IOException;
 
     /**
      * Returns the query handler context that passed in {@link

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java Wed Oct 21 11:38:31 2009
@@ -16,15 +16,16 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import org.apache.jackrabbit.core.fs.FileSystem;
+import java.util.concurrent.Executor;
+
+import org.apache.jackrabbit.core.CachingHierarchyManager;
+import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.NamespaceRegistryImpl;
+import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
-import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.NamespaceRegistryImpl;
-import org.apache.jackrabbit.core.HierarchyManager;
-import org.apache.jackrabbit.core.CachingHierarchyManager;
-import org.apache.jackrabbit.core.persistence.PersistenceManager;
 
 /**
  * Acts as an argument for the {@link QueryHandler} to keep the interface
@@ -34,11 +35,6 @@
 public class QueryHandlerContext {
 
     /**
-     * A <code>FileSystem</code> to store the search index
-     */
-    private final FileSystem fs;
-
-    /**
      * The persistent <code>ItemStateManager</code>
      */
     private final SharedItemStateManager stateMgr;
@@ -84,12 +80,13 @@
     private final NodeId excludedNodeId;
 
     /**
+     * Background task executor.
+     */
+    private final Executor executor;
+
+    /**
      * Creates a new context instance.
      *
-     * @param fs               a {@link FileSystem} this <code>QueryHandler</code>
-     *                         may use to store its index. If no
-     *                         <code>FileSystem</code> has been configured
-     *                         <code>fs</code> is <code>null</code>.
      * @param stateMgr         provides persistent item states.
      * @param pm               the underlying persistence manager.
      * @param rootId           the id of the root node.
@@ -100,16 +97,16 @@
      * @param excludedNodeId   id of the node that should be excluded from
      *                         indexing. Any descendant of that node is also
      *                         excluded from indexing.
+     * @param executor         background task executor
      */
-    public QueryHandlerContext(FileSystem fs,
-                               SharedItemStateManager stateMgr,
+    public QueryHandlerContext(SharedItemStateManager stateMgr,
                                PersistenceManager pm,
                                NodeId rootId,
                                NodeTypeRegistry ntRegistry,
                                NamespaceRegistryImpl nsRegistry,
                                QueryHandler parentHandler,
-                               NodeId excludedNodeId) {
-        this.fs = fs;
+                               NodeId excludedNodeId,
+                               Executor executor) {
         this.stateMgr = stateMgr;
         this.hmgr = new CachingHierarchyManager(rootId, stateMgr);
         this.stateMgr.addListener(hmgr);
@@ -120,6 +117,7 @@
         propRegistry = new PropertyTypeRegistry(ntRegistry);
         this.parentHandler = parentHandler;
         this.excludedNodeId = excludedNodeId;
+        this.executor =  executor;
         ntRegistry.addListener(propRegistry);
     }
 
@@ -152,18 +150,6 @@
     }
 
     /**
-     * Returns the {@link FileSystem} instance this <code>QueryHandler</code>
-     * may use to store its index. If no <code>FileSystem</code> has been
-     * configured this method returns <code>null</code>.
-     *
-     * @return the <code>FileSystem</code> instance for this
-     *         <code>QueryHandler</code>.
-     */
-    public FileSystem getFileSystem() {
-        return fs;
-    }
-
-    /**
      * Returns the id of the root node.
      * @return the idof the root node.
      */
@@ -219,4 +205,14 @@
     public void destroy() {
         ntRegistry.removeListener(propRegistry);
     }
+
+    /**
+     * Returns the background task executor.
+     *
+     * @return background task executor
+     */
+    public Executor getExecutor() {
+        return executor;
+    }
+
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java Wed Oct 21 11:38:31 2009
@@ -25,10 +25,10 @@
 import javax.jcr.query.qom.QueryObjectModel;
 import javax.jcr.query.qom.Source;
 
+import org.apache.jackrabbit.commons.query.QueryObjectModelBuilderRegistry;
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
-import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilderRegistry;
 
 /**
  * <code>QueryObjectModelImpl</code> implements the query object model.

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JoinQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JoinQuery.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JoinQuery.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JoinQuery.java Wed Oct 21 11:38:31 2009
@@ -18,12 +18,12 @@
 
 import java.io.IOException;
 
-import org.apache.lucene.search.SortComparatorSource;
-import org.apache.lucene.index.IndexReader;
-import org.apache.jackrabbit.core.query.lucene.join.Join;
+import org.apache.jackrabbit.commons.query.qom.JoinType;
 import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.query.lucene.join.Join;
 import org.apache.jackrabbit.spi.commons.query.qom.JoinConditionImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.JoinType;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.SortComparatorSource;
 
 /**
  * <code>JoinQuery</code> implements a query that performs a join.

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyTextExtractorField.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyTextExtractorField.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyTextExtractorField.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LazyTextExtractorField.java Wed Oct 21 11:38:31 2009
@@ -16,15 +16,22 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.concurrent.Executor;
+
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.document.AbstractField;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.analysis.TokenStream;
-import org.apache.commons.io.IOUtils;
-import org.slf4j.LoggerFactory;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field.TermVector;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.Parser;
+import org.apache.tika.sax.BodyContentHandler;
 import org.slf4j.Logger;
-
-import java.io.Reader;
-import java.io.IOException;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.ContentHandler;
 
 /**
  * <code>LazyTextExtractorField</code> implements a Lucene field with a String
@@ -37,24 +44,16 @@
 public class LazyTextExtractorField extends AbstractField {
 
     /**
-     * The serial version UID.
-     */
-    private static final long serialVersionUID = -2707986404659820071L;
-
-    /**
      * The logger instance for this class.
      */
-    private static final Logger log = LoggerFactory.getLogger(LazyTextExtractorField.class);
+    private static final Logger log =
+        LoggerFactory.getLogger(LazyTextExtractorField.class);
 
     /**
-     * The reader from where to read the text extract.
+     * The extracted text content of the given binary value.
+     * Set to non-null when the text extraction task finishes.
      */
-    private final Reader reader;
-
-    /**
-     * The extract as obtained lazily from {@link #reader}.
-     */
-    private String extract;
+    private volatile String extract = null;
 
     /**
      * Creates a new <code>LazyTextExtractorField</code> with the given
@@ -62,84 +61,114 @@
      *
      * @param name the name of the field.
      * @param reader the reader where to obtain the string from.
-     * @param store when set <code>true</code> the string value is stored in the
-     *          index.
-     * @param withOffsets when set <code>true</code> a term vector with offsets
-     *          is written into the index.
-     */
-    public LazyTextExtractorField(String name,
-                                  Reader reader,
-                                  boolean store,
-                                  boolean withOffsets) {
-        super(name,
-                store ? Field.Store.YES : Field.Store.NO,
+     * @param highlighting set to <code>true</code> to
+     *                     enable result highlighting support
+     */
+    public LazyTextExtractorField(
+            Parser parser, InternalValue value, Metadata metadata,
+            Executor executor, boolean highlighting) {
+        super(FieldNames.FULLTEXT,
+                highlighting ? Store.YES : Store.NO,
                 Field.Index.ANALYZED,
-                withOffsets ? Field.TermVector.WITH_OFFSETS : Field.TermVector.NO);
-        this.reader = reader;
+                highlighting ? TermVector.WITH_OFFSETS : TermVector.NO);
+        executor.execute(new ParsingTask(parser, value, metadata));
     }
 
     /**
-     * @return the string value of this field.
+     * Returns the extracted text. This method blocks until the text
+     * extraction task has been completed.
+     *
+     * @return the string value of this field
      */
-    public String stringValue() {
-        if (extract == null) {
-            StringBuffer textExtract = new StringBuffer();
-            char[] buffer = new char[1024];
-            int len;
-            try {
-                while ((len = reader.read(buffer)) > -1) {
-                    textExtract.append(buffer, 0, len);
-                }
-            } catch (IOException e) {
-                log.warn("Exception reading value for field: "
-                        + e.getMessage());
-                log.debug("Dump:", e);
-            } finally {
-                IOUtils.closeQuietly(reader);
+    public synchronized String stringValue() {
+        try {
+            while (!isExtractorFinished()) {
+                wait();
             }
-            extract = textExtract.toString();
+            return extract;
+        } catch (InterruptedException e) {
+            log.error("Text extraction thread was interrupted", e);
+            return "";
         }
-        return extract;
     }
 
     /**
-     * @return always <code>null</code>.
+     * @return always <code>null</code>
      */
     public Reader readerValue() {
         return null;
     }
 
     /**
-     * @return always <code>null</code>.
+     * @return always <code>null</code>
      */
     public byte[] binaryValue() {
         return null;
     }
 
     /**
-     * @return always <code>null</code>.
+     * @return always <code>null</code>
      */
     public TokenStream tokenStreamValue() {
         return null;
     }
 
     /**
-     * @return <code>true</code> if the underlying reader is ready to provide
-     *          extracted text.
+     * Checks whether the text extraction task has finished.
+     *
+     * @return <code>true</code> if the extracted text is available
      */
     public boolean isExtractorFinished() {
-        if (reader instanceof TextExtractorReader) {
-            return ((TextExtractorReader) reader).isExtractorFinished();
-        }
-        return true;
+        return extract != null;
+    }
+
+    private synchronized void setExtractedText(String value) {
+        extract = value;
+        notify();
     }
 
     /**
-     * Disposes this field and closes the underlying reader.
-     *
-     * @throws IOException if an error occurs while closing the reader.
+     * Releases all resources associated with this field.
+     */
+    public void dispose() {
+        // TODO: Cause the ContentHandler below to throw an exception
+    }
+
+    /**
+     * The background task for extracting text from a binary value.
      */
-    public void dispose() throws IOException {
-        reader.close();
+    private class ParsingTask implements Runnable {
+
+        private final Parser parser;
+
+        private final InternalValue value;
+
+        private final Metadata metadata;
+
+        public ParsingTask(
+                Parser parser, InternalValue value, Metadata metadata) {
+            this.parser = parser;
+            this.value = value;
+            this.metadata = metadata;
+        }
+
+        public void run() {
+            ContentHandler handler = new BodyContentHandler();
+            try {
+                InputStream stream = value.getStream();
+                try {
+                    parser.parse(stream, handler, metadata);
+                } finally {
+                    stream.close();
+                }
+            } catch (Throwable t) {
+                log.warn("Failed to extract text from a binary property", t);
+            } finally {
+                value.discard();
+            }
+            setExtractedText(handler.toString());
+        }
+
     }
+
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java Wed Oct 21 11:38:31 2009
@@ -609,8 +609,17 @@
             return data;
         }
         LocationStepQueryNode[] steps = relPath.getPathSteps();
-        Name propertyName = steps[steps.length - 1].getNameTest();
-        
+        Name propertyName;
+        if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) {
+            // this is a bit ugly:
+            // use the name of a dummy property because relPath actually
+            // references a property. whereas the relPath of the similar
+            // operation references a node
+            propertyName = NameConstants.JCR_PRIMARYTYPE;
+        } else {
+            propertyName = steps[steps.length - 1].getNameTest();
+        }
+
         Query query;
         String[] stringValues = new String[1];
         switch (node.getValueType()) {
@@ -658,13 +667,6 @@
             }
         }, null);
 
-        if (node.getOperation() == QueryConstants.OPERATION_SIMILAR) {
-            // this is a bit ugly:
-            // use the name of a dummy property because relPath actually
-            // references a property. whereas the relPath of the similar
-            // operation references a node
-            propertyName = NameConstants.JCR_PRIMARYTYPE;
-        }
         String field = "";
         try {
             field = resolver.getJCRName(propertyName);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java Wed Oct 21 11:38:31 2009
@@ -1293,7 +1293,7 @@
 
         // now update index with the remaining ones if there are any
         if (!finished.isEmpty()) {
-            log.info("updating index with {} nodes from indexing queue.",
+            log.debug("updating index with {} nodes from indexing queue.",
                     finished.size());
 
             // remove documents from the queue

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java Wed Oct 21 11:38:31 2009
@@ -16,39 +16,39 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import org.apache.jackrabbit.core.id.PropertyId;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.Executor;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
 import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.id.PropertyId;
+import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.state.ChildNodeEntry;
 import org.apache.jackrabbit.core.value.InternalValue;
-import org.apache.jackrabbit.extractor.TextExtractor;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.Fieldable;
-
-import javax.jcr.NamespaceException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.Calendar;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Date;
-import java.net.URI;
-import java.math.BigDecimal;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.Parser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Creates a lucene <code>Document</code> object from a {@link javax.jcr.Node}.
@@ -87,9 +87,15 @@
     protected final NamePathResolver resolver;
 
     /**
-     * Content extractor.
+     * Background task executor used for full text extraction.
      */
-    protected final TextExtractor extractor;
+    private final Executor executor;
+
+    /**
+     * Parser used for extracting text content from binary properties
+     * for full text indexing.
+     */
+    private final Parser parser;
 
     /**
      * The indexing configuration or <code>null</code> if none is available.
@@ -119,17 +125,18 @@
      * @param node          the node state to index.
      * @param stateProvider the persistent item state manager to retrieve properties.
      * @param mappings      internal namespace mappings.
-     * @param extractor     content extractor
+     * @param executor      background task executor for text extraction
+     * @param parser        parser for binary properties
      */
-    public NodeIndexer(NodeState node,
-                       ItemStateManager stateProvider,
-                       NamespaceMappings mappings,
-                       TextExtractor extractor) {
+    public NodeIndexer(
+            NodeState node, ItemStateManager stateProvider,
+            NamespaceMappings mappings, Executor executor, Parser parser) {
         this.node = node;
         this.stateProvider = stateProvider;
         this.mappings = mappings;
         this.resolver = NamePathResolverImpl.create(mappings);
-        this.extractor = extractor;
+        this.executor = executor;
+        this.parser = parser;
     }
 
     /**
@@ -413,20 +420,19 @@
                 return;
             }
 
-            InternalValue typeValue = getValue(NameConstants.JCR_MIMETYPE);
-            if (typeValue != null) {
-                String type = typeValue.getString();
+            InternalValue type = getValue(NameConstants.JCR_MIMETYPE);
+            if (type != null) {
+                Metadata metadata = new Metadata();
+                metadata.set(Metadata.CONTENT_TYPE, type.getString());
 
                 // jcr:encoding is not mandatory
-                String encoding = null;
-                InternalValue encodingValue = getValue(NameConstants.JCR_ENCODING);
-                if (encodingValue != null) {
-                    encoding = encodingValue.getString();
+                InternalValue encoding = getValue(NameConstants.JCR_ENCODING);
+                if (encoding != null) {
+                    metadata.set(
+                            Metadata.CONTENT_ENCODING, encoding.getString());
                 }
 
-                InputStream stream = internalValue.getStream();
-                Reader reader = extractor.extractText(stream, type, encoding);
-                doc.add(createFulltextField(reader));
+                doc.add(createFulltextField(internalValue, metadata));
             }
         } catch (Throwable t) {
             // TODO: How to recover from a transient indexing failure?
@@ -805,15 +811,14 @@
     /**
      * Creates a fulltext field for the reader <code>value</code>.
      *
-     * @param value the reader value.
+     * @param value the binary value
+     * @param metadata document metatadata
      * @return a lucene field.
      */
-    protected Fieldable createFulltextField(Reader value) {
-        if (supportHighlighting) {
-            return new LazyTextExtractorField(FieldNames.FULLTEXT, value, true, true);
-        } else {
-            return new LazyTextExtractorField(FieldNames.FULLTEXT, value, false, false);
-        }
+    protected Fieldable createFulltextField(
+            InternalValue value, Metadata metadata) {
+        return new LazyTextExtractorField(
+                parser, value, metadata, executor, supportHighlighting);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java Wed Oct 21 11:38:31 2009
@@ -28,10 +28,10 @@
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
-import org.apache.jackrabbit.core.nodetype.PropertyDefinitionImpl;
 import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.query.AndQueryNode;
@@ -43,6 +43,7 @@
 import org.apache.jackrabbit.spi.commons.query.QueryParser;
 import org.apache.jackrabbit.spi.commons.query.QueryRootNode;
 import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
 import org.apache.lucene.search.Query;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -174,9 +175,9 @@
             NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
             PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
             for (PropertyDefinition pd : propDefs) {
-                PropertyDefinitionImpl propDef = (PropertyDefinitionImpl) pd;
+                QPropertyDefinition propDef = ((PropertyDefinitionImpl) pd).unwrap();
                 if (!propDef.definesResidual() && !propDef.isMultiple()) {
-                    columns.put(propDef.getQName(), columnForName(propDef.getQName()));
+                    columns.put(propDef.getName(), columnForName(propDef.getName()));
                 }
             }
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java Wed Oct 21 11:38:31 2009
@@ -29,7 +29,6 @@
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
-import org.apache.jackrabbit.core.nodetype.PropertyDefinitionImpl;
 import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
 import org.apache.jackrabbit.core.query.lucene.constraint.Constraint;
 import org.apache.jackrabbit.core.query.lucene.constraint.ConstraintBuilder;
@@ -39,6 +38,7 @@
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
 
 /**
  * <code>QueryObjectModelImpl</code>...
@@ -123,7 +123,7 @@
                 NodeTypeImpl nt = ntMgr.getNodeType(selector.getNodeTypeQName());
                 for (PropertyDefinition pd : nt.getPropertyDefinitions()) {
                     PropertyDefinitionImpl propDef = (PropertyDefinitionImpl) pd;
-                    if (!propDef.definesResidual() && !propDef.isMultiple()) {
+                    if (!propDef.unwrap().definesResidual() && !propDef.isMultiple()) {
                         String sn = selector.getSelectorName();
                         String pn = propDef.getName();
                         columns.add((ColumnImpl) qomFactory.column(sn, pn, sn + "." + pn));

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Wed Oct 21 11:38:31 2009
@@ -16,73 +16,73 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.InvalidQueryException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.fs.FileSystemException;
+import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
+import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.query.AbstractQueryHandler;
 import org.apache.jackrabbit.core.query.ExecutableQuery;
 import org.apache.jackrabbit.core.query.QueryHandler;
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 import org.apache.jackrabbit.core.query.lucene.directory.DirectoryManager;
 import org.apache.jackrabbit.core.query.lucene.directory.FSDirectoryManager;
-import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
+import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
-import org.apache.jackrabbit.core.state.ItemStateException;
-import org.apache.jackrabbit.extractor.DefaultTextExtractor;
-import org.apache.jackrabbit.extractor.TextExtractor;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeFactory;
-import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.Token;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Fieldable;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
+import org.apache.lucene.search.HitCollector;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortComparatorSource;
-import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.HitCollector;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.document.Fieldable;
-import org.xml.sax.SAXException;
+import org.apache.tika.parser.Parser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.query.InvalidQueryException;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
-import java.io.File;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Collection;
+import org.xml.sax.SAXException;
 
 /**
  * Implements a {@link org.apache.jackrabbit.core.query.QueryHandler} using
@@ -207,20 +207,12 @@
     /**
      * The analyzer we use for indexing.
      */
-    private JackrabbitAnalyzer analyzer;
+    private final JackrabbitAnalyzer analyzer = new JackrabbitAnalyzer();
 
     /**
-     * List of text extractor and text filter class names. The configured
-     * classes will be instantiated and used to extract text content from
-     * binary properties.
+     * The parser for extracting text content from binary properties.
      */
-    private String textFilterClasses =
-        DefaultTextExtractor.class.getName();
-
-    /**
-     * Text extractor for extracting text content of binary properties.
-     */
-    private TextExtractor extractor;
+    private final JackrabbitParser parser = new JackrabbitParser();
 
     /**
      * The namespace mappings used internally.
@@ -476,13 +468,6 @@
     private boolean closed = false;
 
     /**
-     * Default constructor.
-     */
-    public SearchIndex() {
-        this.analyzer = new JackrabbitAnalyzer();
-    }
-
-    /**
      * Initializes this <code>QueryHandler</code>. This implementation requires
      * that a path parameter is set in the configuration. If this condition
      * is not met, a <code>IOException</code> is thrown.
@@ -500,7 +485,6 @@
             excludedIDs.add(context.getExcludedNodeId());
         }
 
-        extractor = createTextExtractor();
         synProvider = createSynonymProvider();
         directoryManager = createDirectoryManager();
         redoLogFactory = createRedoLogFactory();
@@ -784,7 +768,7 @@
      * Closes this <code>QueryHandler</code> and frees resources attached
      * to this handler.
      */
-    public void close() {
+    public void close() throws IOException {
         if (synonymProviderConfigFs != null) {
             try {
                 synonymProviderConfigFs.close();
@@ -792,15 +776,12 @@
                 log.warn("Exception while closing FileSystem", e);
             }
         }
-        // shutdown extractor
-        if (extractor instanceof PooledTextExtractor) {
-            ((PooledTextExtractor) extractor).shutdown();
-        }
         if (spellChecker != null) {
             spellChecker.close();
         }
         index.close();
         getContext().destroy();
+        super.close();
         closed = true;
         log.info("Index closed: " + path);
     }
@@ -910,12 +891,13 @@
     }
 
     /**
-     * Returns the text extractor in use for indexing.
+     * Returns the parser used for extracting text content
+     * from binary properties for full text indexing.
      *
-     * @return the text extractor in use for indexing.
+     * @return the configured parser
      */
-    public TextExtractor getTextExtractor() {
-        return extractor;
+    public Parser getParser() {
+        return parser;
     }
 
     /**
@@ -1114,8 +1096,9 @@
                                       NamespaceMappings nsMappings,
                                       IndexFormatVersion indexFormatVersion)
             throws RepositoryException {
-        NodeIndexer indexer = new NodeIndexer(node,
-                getContext().getItemStateManager(), nsMappings, extractor);
+        NodeIndexer indexer = new NodeIndexer(
+                node, getContext().getItemStateManager(), nsMappings,
+                getContext().getExecutor(), parser);
         indexer.setSupportHighlighting(supportHighlighting);
         indexer.setIndexingConfiguration(indexingConfig);
         indexer.setIndexFormatVersion(indexFormatVersion);
@@ -1141,21 +1124,6 @@
     }
 
     /**
-     * Factory method to create the <code>TextExtractor</code> instance.
-     *
-     * @return the <code>TextExtractor</code> instance this index should use.
-     */
-    protected TextExtractor createTextExtractor() {
-        TextExtractor txtExtr = new JackrabbitTextExtractor(textFilterClasses);
-        if (extractorPoolSize > 0) {
-            // wrap with pool
-            txtExtr = new PooledTextExtractor(txtExtr, extractorPoolSize,
-                    extractorBackLog, extractorTimeout);
-        }
-        return txtExtr;
-    }
-
-    /**
      * @param namespaceMappings The namespace mappings
      * @return the fulltext indexing configuration or <code>null</code> if there
      *         is no configuration.
@@ -1262,7 +1230,6 @@
                         "Invalid synonymProviderConfigPath: "
                         + synonymProviderConfigPath);
             }
-            FileSystem fs = getContext().getFileSystem();
             if (fs == null) {
                 fs = new LocalFileSystem();
                 int lastSeparator = synonymProviderConfigPath.lastIndexOf(
@@ -1881,9 +1848,10 @@
      * constructor.
      *
      * @param filterClasses comma separated list of class names
+     * @deprecated 
      */
     public void setTextFilterClasses(String filterClasses) {
-        this.textFilterClasses = filterClasses;
+        parser.setTextFilterClasses(filterClasses);
     }
 
     /**
@@ -1891,9 +1859,10 @@
      * currently in use. The names are comma separated.
      *
      * @return class names of the text filters in use.
+     * @deprecated 
      */
     public String getTextFilterClasses() {
-        return textFilterClasses;
+        return "deprectated";
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ComparisonConstraint.java Wed Oct 21 11:38:31 2009
@@ -21,10 +21,10 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 
+import org.apache.jackrabbit.commons.query.qom.Operator;
 import org.apache.jackrabbit.core.query.lucene.ScoreNode;
 import org.apache.jackrabbit.core.query.lucene.Util;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
 
 /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java Wed Oct 21 11:38:31 2009
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.core.query.lucene.constraint;
 
-import java.util.Map;
 import java.net.URLDecoder;
+import java.util.Map;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -26,6 +26,7 @@
 import javax.jcr.ValueFormatException;
 import javax.jcr.query.InvalidQueryException;
 
+import org.apache.jackrabbit.commons.query.qom.Operator;
 import org.apache.jackrabbit.core.query.lucene.LuceneQueryFactory;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.query.qom.AndImpl;
@@ -33,6 +34,7 @@
 import org.apache.jackrabbit.spi.commons.query.qom.ChildNodeImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.ComparisonImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.ConstraintImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.DefaultQOMTreeVisitor;
 import org.apache.jackrabbit.spi.commons.query.qom.DescendantNodeImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.DynamicOperandImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchImpl;
@@ -43,7 +45,6 @@
 import org.apache.jackrabbit.spi.commons.query.qom.NodeLocalNameImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.NodeNameImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.NotImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 import org.apache.jackrabbit.spi.commons.query.qom.OrImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.PropertyExistenceImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.PropertyValueImpl;
@@ -51,7 +52,6 @@
 import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.StaticOperandImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.UpperCaseImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.DefaultQOMTreeVisitor;
 
 /**
  * <code>ConstraintBuilder</code> builds a {@link Constraint} from a tree of

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LikeConstraint.java Wed Oct 21 11:38:31 2009
@@ -21,8 +21,8 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 
+import org.apache.jackrabbit.commons.query.qom.Operator;
 import org.apache.jackrabbit.core.query.lucene.Util;
-import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
 
 /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java Wed Oct 21 11:38:31 2009
@@ -21,6 +21,7 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.jackrabbit.commons.query.qom.JoinType;
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.query.lucene.HierarchyResolver;
 import org.apache.jackrabbit.core.query.lucene.MultiColumnQueryHits;
@@ -32,7 +33,6 @@
 import org.apache.jackrabbit.spi.commons.query.qom.DescendantNodeJoinConditionImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.EquiJoinConditionImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.JoinConditionImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.JoinType;
 import org.apache.jackrabbit.spi.commons.query.qom.SameNodeJoinConditionImpl;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.SortComparatorSource;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.java Wed Oct 21 11:38:31 2009
@@ -66,12 +66,31 @@
     private static final String KEY_CREDENTIALS = "org.apache.jackrabbit.credentials";
     private static final String KEY_LOGIN_NAME = "javax.security.auth.login.name";
 
+    /**
+     * The name of the login module configuration option providing the name
+     * of the SimpleCredentials attribute used to identify a pre-authenticated
+     * login.
+     *
+     * @see #isPreAuthenticated(Credentials)
+     */
+    private static final String PRE_AUTHENTICATED_ATTRIBUTE_OPTION = "trust_credentials_attribute";
+
     private String principalProviderClassName;
-    private boolean initialized; 
+    private boolean initialized;
 
     protected String adminId;
     protected String anonymousId;
 
+    /**
+     * The name of the credentials attribute providing a hint that the
+     * credentials should be taken as is and the user requesting access
+     * has already been authenticated outside of this LoginModule.
+     *
+     * @see #getTrustedCredentialsAttributeName()
+     */
+    private String preAuthAttributeName;
+
+
     protected CallbackHandler callbackHandler;
 
     protected Principal principal;
@@ -154,6 +173,14 @@
             if (anonymousId == null) {
                 anonymousId = repositoryCb.getAnonymousId();
             }
+            // trusted credentials attribute name (may be missing to not
+            // support) (normalized to null aka missing aka unset if an empty
+            // string)
+            preAuthAttributeName = (String) options.get(PRE_AUTHENTICATED_ATTRIBUTE_OPTION);
+            if (preAuthAttributeName != null
+                && preAuthAttributeName.length() == 0) {
+                preAuthAttributeName = null;
+            }
 
             //log config values for debug
             if (log.isDebugEnabled()) {
@@ -221,12 +248,15 @@
      * be used.<p/>
      *
      * <b>3) Verfication</b><br>
-     * There are two cases, how the User-ID can be verfied:
-     * Either the login is the result of an impersonation request (see
-     * {@link javax.jcr.Session#impersonate(Credentials)} or of a login to the Repository ({@link
-     * javax.jcr.Repository#login(Credentials)}). The concrete implementation
-     * of the LoginModule is responsible for both impersonation and login:
+     * There are four cases, how the User-ID can be verfied:
+     * The login is anonymous, preauthenticated or the login is the result of
+     * an impersonation request (see {@link javax.jcr.Session#impersonate(Credentials)}
+     * or of a login to the Repository ({@link javax.jcr.Repository#login(Credentials)}).
+     * The concrete implementation of the LoginModule is responsible for all
+     * four cases:
      * <ul>
+     * <li>{@link #isAnonymous(Credentials)}</li>
+     * <li>{@link #isPreAuthenticated(Credentials)}</li>
      * <li>{@link #authenticate(Principal, Credentials)}</li>
      * <li>{@link #impersonate(Principal, Credentials)}</li>
      * </ul>
@@ -276,8 +306,8 @@
                 return false;
             }
             boolean authenticated;
-            // test for anonymous, impersonation or common authentication.
-            if (isAnonymous(creds)) {
+            // test for anonymous, pre-authentication, impersonation or common authentication.
+            if (isAnonymous(creds) || isPreAuthenticated(creds)) {
                 authenticated = true;
             } else if (isImpersonation(creds)) {
                 authenticated = impersonate(userPrincipal, creds);
@@ -705,4 +735,44 @@
     public void setPrincipalProvider(String principalProvider) {
         this.principalProviderClassName = principalProvider;
     }
+
+    /**
+     * The name of the credentials attribute providing a hint that the
+     * credentials should be taken as is and the user requesting access
+     * has already been authenticated outside of this LoginModule.
+     * <p>
+     * This name is configured as the value of the LoginModule configuration
+     * parameter <code>trust_credentials_attribute</code>. If the configuration
+     * parameter is missing (or empty) the name is not set and this method
+     * returns <code>null</code>.
+     *
+     * @see #isPreAuthenticated(Credentials)
+     */
+    protected final String getPreAuthAttributeName() {
+        return preAuthAttributeName;
+    }
+
+    /**
+     * Returns <code>true</code> if the credentials should be considered as
+     * pre-authenticated and a password check is not required.
+     * <p>
+     * This base class implementation returns <code>true</code> if the
+     * <code>creds</code> object is a SimpleCredentials instance and the
+     * configured {@link #getTrustedCredentialsAttributeName() trusted
+     * credentials property} is set to a non-<code>null</code> value in the
+     * credentials attributes.
+     * <p>
+     * Extensions of this class may overwrite this method to apply more or
+     * different checks to the credentials.
+     *
+     * @param creds The Credentials to check
+     *
+     * @see #getPreAuthAttributeName()
+     */
+    protected boolean isPreAuthenticated(final Credentials creds) {
+        final String preAuthAttrName = getPreAuthAttributeName();
+        return preAuthAttrName != null
+            && (creds instanceof SimpleCredentials)
+            && ((SimpleCredentials) creds).getAttribute(preAuthAttrName) != null;
+    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java Wed Oct 21 11:38:31 2009
@@ -101,9 +101,17 @@
             pGroupName = "rep:groups";
             pPrincipalName = "rep:principalName";
         }
+
+        // find common ancestor of all user and group nodes.
+        String userPath = userManager.getUsersPath();
+        String groupPath = userManager.getGroupsPath();
+        String obsPath = userPath;
+        while (!Text.isDescendant(obsPath, groupPath)) {
+            obsPath = Text.getRelativeParent(obsPath, 1);
+        }       
         securitySession.getWorkspace().getObservationManager().addEventListener(this,
                 Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED,
-                UserManagerImpl.SECURITY_ROOT_PATH,
+                obsPath,
                 true,
                 null,
                 ntNames,

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java Wed Oct 21 11:38:31 2009
@@ -16,28 +16,8 @@
  */
 package org.apache.jackrabbit.core.security.user;
 
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.PropertyType;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.PropertyDefinition;
-
 import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal;
-import org.apache.jackrabbit.api.security.principal.PrincipalIterator;
-import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.Authorizable;
-import org.apache.jackrabbit.api.security.user.AuthorizableExistsException;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.core.NodeImpl;
@@ -45,11 +25,24 @@
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
 import org.apache.jackrabbit.core.security.principal.PrincipalImpl;
-import org.apache.jackrabbit.core.security.principal.PrincipalIteratorAdapter;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.PropertyDefinition;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * AuthorizableImpl
  */
@@ -61,7 +54,7 @@
     private final NodeImpl node;
 
     /**
-     * @param node    the Authorizable is persisted to.
+     * @param node The node this Authorizable is persisted to.
      * @param userManager UserManager that created this Authorizable.
      * @throws IllegalArgumentException if the given node isn't of node type
      * {@link #NT_REP_AUTHORIZABLE}.
@@ -78,65 +71,13 @@
 
     //-------------------------------------------------------< Authorizable >---
     /**
-     * @see Authorizable#getPrincipals()
-     */
-    public PrincipalIterator getPrincipals() throws RepositoryException {
-        Collection<Principal> coll = new ArrayList<Principal>();
-        // the first element is the main principal of this user.
-        coll.add(getPrincipal());
-        // in addition add all referees.
-        PrincipalManager prMgr = getSession().getPrincipalManager();
-        for (Object o : getRefereeValues()) {
-            String refName = ((Value) o).getString();
-            Principal princ = prMgr.getPrincipal(refName);
-            if (princ == null) {
-                log.warn("Principal " + refName + " unknown to PrincipalManager.");
-                princ = new PrincipalImpl(refName);
-            }
-            coll.add(princ);
-        }
-        return new PrincipalIteratorAdapter(coll);
-    }
-
-    /**
-     * @see Authorizable#addReferee(Principal)
-     */
-    public synchronized boolean addReferee(Principal principal) throws RepositoryException {
-        String principalName = principal.getName();
-        Value princValue = getSession().getValueFactory().createValue(principalName);
-
-        List<Value> refereeValues = getRefereeValues();
-        if (refereeValues.contains(princValue) || getPrincipal().getName().equals(principalName)) {
-            return false;
-        }
-        if (userManager.hasAuthorizableOrReferee(principal)) {
-            throw new AuthorizableExistsException("Another authorizable already represented by or refeering to " +  principalName);
-        }
-        refereeValues.add(princValue);
-
-        userManager.setProtectedProperty(node, P_REFEREES, refereeValues.toArray(new Value[refereeValues.size()]));
-        return true;
-    }
-
-    /**
-     * @see Authorizable#removeReferee(Principal)
+     * Returns the unescaped name of the node that defines this <code>Authorizable</code>.
+     *
+     * @return the unescaped name of the node that defines this <code>Authorizable</code>.
+     * @see Authorizable#getID()
      */
-    public synchronized boolean removeReferee(Principal principal) throws RepositoryException {
-        Value princValue = getSession().getValueFactory().createValue(principal.getName());
-        List<Value> existingValues = getRefereeValues();
-
-        if (existingValues.remove(princValue))  {
-            PropertyImpl prop = node.getProperty(P_REFEREES);
-            if (existingValues.isEmpty()) {
-                userManager.removeProtectedItem(prop, node);
-            } else {
-                userManager.setProtectedProperty(node, P_REFEREES, existingValues.toArray(new Value[existingValues.size()]));
-            }
-            return true;
-        }
-
-        // specified principal was not referee of this authorizable.
-        return false;
+    public String getID() throws RepositoryException {
+        return Text.unescapeIllegalJcrChars(getNode().getName());
     }
 
     /**
@@ -211,7 +152,9 @@
         checkProtectedProperty(name);
         try {
             node.setProperty(name, value);
-            node.save();
+            if (!userManager.batchModus) {
+                node.save();
+            }
         } catch (RepositoryException e) {
             log.warn("Failed to set Property " + name + " for Authorizable " + getID());
             node.refresh(false);
@@ -234,7 +177,9 @@
         checkProtectedProperty(name);
         try {
             node.setProperty(name, values);
-            node.save();
+            if (!userManager.batchModus) {
+                node.save();
+            }
         } catch (RepositoryException e) {
             log.warn("Failed to set Property " + name + " for Authorizable " + getID());
             node.refresh(false);
@@ -255,7 +200,9 @@
                 } else {
                     p.setValue((Value) null);
                 }
-                node.save();
+                if (!userManager.batchModus) {
+                    node.save();
+                }
                 return true;
             } else {
                 return false;
@@ -415,8 +362,8 @@
      */
     private boolean isProtectedProperty(String propertyName) throws RepositoryException {
         Name pName = getSession().getQName(propertyName);
-        return P_PRINCIPAL_NAME.equals(pName) || P_USERID.equals(pName)
-                || P_REFEREES.equals(pName) || P_GROUPS.equals(pName)
+        return P_PRINCIPAL_NAME.equals(pName)
+                || P_GROUPS.equals(pName)
                 || P_IMPERSONATORS.equals(pName) || P_PASSWORD.equals(pName);
     }
 
@@ -435,19 +382,6 @@
         }
     }
 
-    private List<Value> getRefereeValues() throws RepositoryException {
-        List<Value> principalNames = new ArrayList<Value>();
-        if (node.hasProperty(P_REFEREES)) {
-            try {
-                principalNames.addAll(Arrays.asList(
-                        node.getProperty(P_REFEREES).getValues()));
-            } catch (PathNotFoundException e) {
-                // ignore. should never occur.
-            }
-        }
-        return principalNames;
-    }
-
     //--------------------------------------------------------------------------
     /**
      *

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java Wed Oct 21 11:38:31 2009
@@ -35,7 +35,6 @@
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.NoSuchElementException;
 import java.util.Set;
 
 /**
@@ -55,7 +54,7 @@
         if (node == null || !node.isNodeType(NT_REP_GROUP)) {
             throw new IllegalArgumentException();
         }
-        if (!Text.isDescendant(GROUPS_PATH, node.getPath())) {
+        if (!Text.isDescendant(userManager.getGroupsPath(), node.getPath())) {
             throw new IllegalArgumentException("Group has to be within the Group Path");
         }
         return new GroupImpl(node, userManager);
@@ -64,19 +63,6 @@
 
     //-------------------------------------------------------< Authorizable >---
     /**
-     * Returns the name of the node that defines this <code>Group</code>, that
-     * has been used taking the principal name as hint, unescaping any chars
-     * that have been escaped to circumvent incompatitibilities with JCR name
-     * limitations.
-     *
-     * @return name of the node that defines this <code>Group</code>.
-     * @see Authorizable#getID()
-     */
-    public String getID() throws RepositoryException {
-        return Text.unescapeIllegalJcrChars(getNode().getName());
-    }
-
-    /**
      * @see Authorizable#isGroup()
      */
     public boolean isGroup() {
@@ -213,54 +199,6 @@
     }
 
     //------------------------------------------------------< inner classes >---
-    private class MemberIterator implements Iterator {
-
-        private final Iterator ids;
-        private Authorizable next;
-
-        private MemberIterator(Iterator ids) {
-            this.ids = ids;
-            next = seekNext();
-        }
-
-        public boolean hasNext() {
-            return next != null;
-        }
-
-        public Object next() {
-            if (next == null) {
-                throw new NoSuchElementException();
-            }
-
-            Authorizable n = next;
-            next = seekNext();
-            return n;
-        }
-
-        public void remove() {
-            throw new UnsupportedOperationException();
-        }
-
-        private Authorizable seekNext() {
-            Authorizable auth = null;
-            while (auth == null && ids.hasNext()) {
-                String uuid = (String) ids.next();
-                try {
-                    NodeImpl mem = (NodeImpl) getSession().getNodeByUUID(uuid);
-                    if (mem.isNodeType(NT_REP_GROUP)) {
-                        auth = userManager.createGroup(mem);
-                    } else {
-                        auth = userManager.createUser(mem);
-                    }
-                } catch (RepositoryException e) {
-                    log.warn("Internal error while building next member.", e.getMessage());
-                    // ignore and try next
-                }
-            }
-            return auth;
-        }
-    }
-
     /**
      *
      */
@@ -345,8 +283,6 @@
                 try {
                     for (Iterator it = GroupImpl.this.getMembers(); it.hasNext();) {
                         Authorizable authrz = (Authorizable) it.next();
-                        // NOTE: only add main principal, since 'referees' belong
-                        // to a different provider and should not be exposed here
                         members.add(authrz.getPrincipal());
                     }
                 } catch (RepositoryException e) {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ImpersonationImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ImpersonationImpl.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ImpersonationImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ImpersonationImpl.java Wed Oct 21 11:38:31 2009
@@ -97,12 +97,9 @@
 
         String pName = principal.getName();
         // make sure user does not impersonate himself
-        for (PrincipalIterator it = user.getPrincipals(); it.hasNext();) {
-            Principal p = it.nextPrincipal();
-            if (p.getName().equals(pName)) {
-                log.debug("Cannot grant impersonation to oneself.");
-                return false;
-            }
+        if (user.getPrincipal().getName().equals(pName)) {
+            log.debug("Cannot grant impersonation to oneself.");
+            return false;
         }
 
         boolean granted = false;

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/IndexNodeResolver.java Wed Oct 21 11:38:31 2009
@@ -27,7 +27,6 @@
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.Set;
 
 /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java?rev=827966&r1=827965&r2=827966&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/NodeResolver.java Wed Oct 21 11:38:31 2009
@@ -26,6 +26,7 @@
 
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.util.Text;
 
 /**
  * Resolver: searches for Principals stored in Nodes of a {@link javax.jcr.Workspace}
@@ -37,6 +38,10 @@
     private final Session session;
     private final NamePathResolver resolver;
 
+    private String userSearchRoot = UserConstants.USERS_PATH;
+    private String groupSearchRoot = UserConstants.GROUPS_PATH;
+    private String authorizableSearchRoot = UserConstants.AUTHORIZABLES_PATH;
+
     /**
      * Create a new <code>NodeResolver</code>.
      *
@@ -49,6 +54,16 @@
         this.resolver = resolver;
     }
 
+    void setSearchRoots(String userSearchRoot, String groupSearchRoot) {
+        this.userSearchRoot = userSearchRoot;
+        this.groupSearchRoot = groupSearchRoot;
+
+        authorizableSearchRoot = userSearchRoot;
+        while (!Text.isDescendant(authorizableSearchRoot, groupSearchRoot)) {
+            authorizableSearchRoot = Text.getRelativeParent(authorizableSearchRoot, 1);
+        }
+    }
+
     /**
      * Get the first node that matches <code>ntName</code> and whose name
      * exactly matches the given <code>nodeName</code>.
@@ -133,11 +148,11 @@
     String getSearchRoot(Name ntName) {
         String searchRoot;
         if (UserConstants.NT_REP_USER.equals(ntName)) {
-            searchRoot = UserConstants.USERS_PATH;
+            searchRoot = userSearchRoot;
         } else if (UserConstants.NT_REP_GROUP.equals(ntName)) {
-            searchRoot = UserConstants.GROUPS_PATH;
+            searchRoot = groupSearchRoot;
         } else {
-            searchRoot = UserConstants.AUTHORIZABLES_PATH;
+            searchRoot = authorizableSearchRoot;
         }
         return searchRoot;
     }



Mime
View raw message