jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1576690 [2/10] - in /jackrabbit/trunk: examples/jackrabbit-firsthops/ examples/jackrabbit-firsthops/src/main/resources/ jackrabbit-aws-ext/ jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ jackrabbit-aws-ext/src/main/java/or...
Date Wed, 12 Mar 2014 11:05:08 GMT
Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
Wed Mar 12 11:05:06 2014
@@ -1,225 +1,225 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jackrabbit.core.config;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.Context;
-
-/**
- * This class contains list of definitions for {@code DataSource} instances.
- */
-public class DataSourceConfig {
-
-    public static final String DRIVER = "driver";
-
-    public static final String URL = "url";
-
-    public static final String USER = "user";
-
-    public static final String PASSWORD = "password";
-
-    public static final String DB_TYPE = "databaseType";
-
-    public static final String VALIDATION_QUERY = "validationQuery";
-
-    public static final String MAX_POOL_SIZE = "maxPoolSize";
-
-    private final List<DataSourceDefinition> defs = new ArrayList<DataSourceDefinition>();
-
-    /**
-     * Adds a DataSourceDefinition from the given properties.
-     * 
-     * @param props the properties (key and values must be strings)
-     * @throws ConfigurationException on error
-     */
-    public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException
{
-        DataSourceDefinition def = new DataSourceDefinition(name, props);
-        for (DataSourceDefinition existing : defs) {
-            if (existing.getLogicalName().equals(def.getLogicalName())) {
-                throw new ConfigurationException("Duplicate logicalName for a DataSource:
"
-                        + def.getLogicalName());
-            }
-        }
-        defs.add(def);
-    }
-
-    /**
-     * @return the unmodifiable list of the current {@link DataSourceDefinition}s
-     */
-    public List<DataSourceDefinition> getDefinitions() {
-        return Collections.unmodifiableList(defs);
-    }
-
-    /**
-     * The definition of a DataSource. 
-     */
-    public static final class DataSourceDefinition {
-
-        private static final List<String> allPropNames =
-            Arrays.asList(DRIVER, URL, USER, PASSWORD, DB_TYPE, VALIDATION_QUERY, MAX_POOL_SIZE);
-
-        private static final List<String> allJndiPropNames =
-            Arrays.asList(DRIVER, URL, USER, PASSWORD, DB_TYPE);
-
-        private final String logicalName;
-
-        private final String driver;
-
-        private final String url;
-
-        private final String user;
-
-        private final String password;
-
-        private final String dbType;
-
-        private final String validationQuery;
-
-        private final int maxPoolSize;
-
-        /**
-         * Creates a DataSourceDefinition from the given properties and 
-         * throws a {@link ConfigurationException} when the set of properties does not
-         * satisfy some validity constraints.
-         * 
-         * @param name the logical name of the data source
-         * @param props the properties (string keys and values)
-         * @throws ConfigurationException on error
-         */
-        public DataSourceDefinition(String name, Properties props) throws ConfigurationException
{
-            this.logicalName = name;
-            this.driver = (String) props.getProperty(DRIVER);
-            this.url = (String) props.getProperty(URL);
-            this.user = (String) props.getProperty(USER);
-            this.password = (String) props.getProperty(PASSWORD);
-            this.dbType = (String) props.getProperty(DB_TYPE);
-            this.validationQuery = (String) props.getProperty(VALIDATION_QUERY);
-            try {
-                this.maxPoolSize = Integer.parseInt((String) props.getProperty(MAX_POOL_SIZE,
"-1"));
-            } catch (NumberFormatException e) {
-                throw new ConfigurationException("failed to parse " + MAX_POOL_SIZE
-                        + " property for DataSource " + logicalName);
-            }
-            verify(props);
-        }
-
-        private void verify(Properties props) throws ConfigurationException {
-            // Check required properties
-            if (logicalName == null || "".equals(logicalName.trim())) {
-                throw new ConfigurationException("DataSource logical name must not be null
or empty");
-            }
-            if (driver == null || "".equals(driver)) {
-                throw new ConfigurationException("DataSource driver must not be null or empty");
-            }
-            if (url == null || "".equals(url)) {
-                throw new ConfigurationException("DataSource URL must not be null or empty");
-            }
-            if (dbType == null || "".equals(dbType)) {
-                throw new ConfigurationException("DataSource databaseType must not be null
or empty");
-            }
-            // Check unknown properties
-            for (Object propName : props.keySet()) {
-                if (!allPropNames.contains((String) propName)) {
-                    throw new ConfigurationException("Unknown DataSource property: " + propName);
-                }
-            }
-            // Check JNDI config:
-            if (isJndiConfig()) {
-                for (Object propName : props.keySet()) {
-                    if (!allJndiPropNames.contains((String) propName)) {
-                        throw new ConfigurationException("Property " + propName
-                                + " is not allowed for a DataSource obtained through JNDI"
-                                + ", DataSource logicalName = " + logicalName);
-                    }
-                }
-            }
-        }
-
-        private boolean isJndiConfig() throws ConfigurationException {
-            Class<?> driverClass = null;
-            try {
-                if (driver.length() > 0) {
-                    driverClass = Class.forName(driver);
-                }
-            } catch (ClassNotFoundException e) {
-                throw new ConfigurationException("Could not load JDBC driver class " + driver,
e);
-            }
-            return driverClass != null && Context.class.isAssignableFrom(driverClass);
-        }
-
-        /**
-         * @return the logicalName
-         */
-        public String getLogicalName() {
-            return logicalName;
-        }
-
-        /**
-         * @return the driver
-         */
-        public String getDriver() {
-            return driver;
-        }
-
-        /**
-         * @return the url
-         */
-        public String getUrl() {
-            return url;
-        }
-
-        /**
-         * @return the user
-         */
-        public String getUser() {
-            return user;
-        }
-
-        /**
-         * @return the dbType
-         */
-        public String getDbType() {
-            return dbType;
-        }
-
-        /**
-         * @return the password
-         */
-        public String getPassword() {
-            return password;
-        }
-
-        /**
-         * @return the validationQuery
-         */
-        public String getValidationQuery() {
-            return validationQuery;
-        }
-
-        /**
-         * @return the maxPoolSize
-         */
-        public int getMaxPoolSize() {
-            return maxPoolSize;
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.config;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+
+/**
+ * This class contains list of definitions for {@code DataSource} instances.
+ */
+public class DataSourceConfig {
+
+    public static final String DRIVER = "driver";
+
+    public static final String URL = "url";
+
+    public static final String USER = "user";
+
+    public static final String PASSWORD = "password";
+
+    public static final String DB_TYPE = "databaseType";
+
+    public static final String VALIDATION_QUERY = "validationQuery";
+
+    public static final String MAX_POOL_SIZE = "maxPoolSize";
+
+    private final List<DataSourceDefinition> defs = new ArrayList<DataSourceDefinition>();
+
+    /**
+     * Adds a DataSourceDefinition from the given properties.
+     * 
+     * @param props the properties (key and values must be strings)
+     * @throws ConfigurationException on error
+     */
+    public void addDataSourceDefinition(String name, Properties props) throws ConfigurationException
{
+        DataSourceDefinition def = new DataSourceDefinition(name, props);
+        for (DataSourceDefinition existing : defs) {
+            if (existing.getLogicalName().equals(def.getLogicalName())) {
+                throw new ConfigurationException("Duplicate logicalName for a DataSource:
"
+                        + def.getLogicalName());
+            }
+        }
+        defs.add(def);
+    }
+
+    /**
+     * @return the unmodifiable list of the current {@link DataSourceDefinition}s
+     */
+    public List<DataSourceDefinition> getDefinitions() {
+        return Collections.unmodifiableList(defs);
+    }
+
+    /**
+     * The definition of a DataSource. 
+     */
+    public static final class DataSourceDefinition {
+
+        private static final List<String> allPropNames =
+            Arrays.asList(DRIVER, URL, USER, PASSWORD, DB_TYPE, VALIDATION_QUERY, MAX_POOL_SIZE);
+
+        private static final List<String> allJndiPropNames =
+            Arrays.asList(DRIVER, URL, USER, PASSWORD, DB_TYPE);
+
+        private final String logicalName;
+
+        private final String driver;
+
+        private final String url;
+
+        private final String user;
+
+        private final String password;
+
+        private final String dbType;
+
+        private final String validationQuery;
+
+        private final int maxPoolSize;
+
+        /**
+         * Creates a DataSourceDefinition from the given properties and 
+         * throws a {@link ConfigurationException} when the set of properties does not
+         * satisfy some validity constraints.
+         * 
+         * @param name the logical name of the data source
+         * @param props the properties (string keys and values)
+         * @throws ConfigurationException on error
+         */
+        public DataSourceDefinition(String name, Properties props) throws ConfigurationException
{
+            this.logicalName = name;
+            this.driver = (String) props.getProperty(DRIVER);
+            this.url = (String) props.getProperty(URL);
+            this.user = (String) props.getProperty(USER);
+            this.password = (String) props.getProperty(PASSWORD);
+            this.dbType = (String) props.getProperty(DB_TYPE);
+            this.validationQuery = (String) props.getProperty(VALIDATION_QUERY);
+            try {
+                this.maxPoolSize = Integer.parseInt((String) props.getProperty(MAX_POOL_SIZE,
"-1"));
+            } catch (NumberFormatException e) {
+                throw new ConfigurationException("failed to parse " + MAX_POOL_SIZE
+                        + " property for DataSource " + logicalName);
+            }
+            verify(props);
+        }
+
+        private void verify(Properties props) throws ConfigurationException {
+            // Check required properties
+            if (logicalName == null || "".equals(logicalName.trim())) {
+                throw new ConfigurationException("DataSource logical name must not be null
or empty");
+            }
+            if (driver == null || "".equals(driver)) {
+                throw new ConfigurationException("DataSource driver must not be null or empty");
+            }
+            if (url == null || "".equals(url)) {
+                throw new ConfigurationException("DataSource URL must not be null or empty");
+            }
+            if (dbType == null || "".equals(dbType)) {
+                throw new ConfigurationException("DataSource databaseType must not be null
or empty");
+            }
+            // Check unknown properties
+            for (Object propName : props.keySet()) {
+                if (!allPropNames.contains((String) propName)) {
+                    throw new ConfigurationException("Unknown DataSource property: " + propName);
+                }
+            }
+            // Check JNDI config:
+            if (isJndiConfig()) {
+                for (Object propName : props.keySet()) {
+                    if (!allJndiPropNames.contains((String) propName)) {
+                        throw new ConfigurationException("Property " + propName
+                                + " is not allowed for a DataSource obtained through JNDI"
+                                + ", DataSource logicalName = " + logicalName);
+                    }
+                }
+            }
+        }
+
+        private boolean isJndiConfig() throws ConfigurationException {
+            Class<?> driverClass = null;
+            try {
+                if (driver.length() > 0) {
+                    driverClass = Class.forName(driver);
+                }
+            } catch (ClassNotFoundException e) {
+                throw new ConfigurationException("Could not load JDBC driver class " + driver,
e);
+            }
+            return driverClass != null && Context.class.isAssignableFrom(driverClass);
+        }
+
+        /**
+         * @return the logicalName
+         */
+        public String getLogicalName() {
+            return logicalName;
+        }
+
+        /**
+         * @return the driver
+         */
+        public String getDriver() {
+            return driver;
+        }
+
+        /**
+         * @return the url
+         */
+        public String getUrl() {
+            return url;
+        }
+
+        /**
+         * @return the user
+         */
+        public String getUser() {
+            return user;
+        }
+
+        /**
+         * @return the dbType
+         */
+        public String getDbType() {
+            return dbType;
+        }
+
+        /**
+         * @return the password
+         */
+        public String getPassword() {
+            return password;
+        }
+
+        /**
+         * @return the validationQuery
+         */
+        public String getValidationQuery() {
+            return validationQuery;
+        }
+
+        /**
+         * @return the maxPoolSize
+         */
+        public int getMaxPoolSize() {
+            return maxPoolSize;
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/config/DataSourceConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
Wed Mar 12 11:05:06 2014
@@ -1,94 +1,94 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jackrabbit.core.data;
-
-
-/**
- * Abstract data record base class. This base class contains only
- * a reference to the data identifier of the record and implements
- * the standard {@link Object} equality, hash code, and string
- * representation methods based on the identifier.
- */
-public abstract class AbstractDataRecord implements DataRecord {
-
-    /**
-     * The data store that contains this record.
-     */
-    private final AbstractDataStore store;
-
-    /**
-     * The binary identifier;
-     */
-    private final DataIdentifier identifier;
-
-    /**
-     * Creates a data record with the given identifier.
-     *
-     * @param identifier data identifier
-     */
-    public AbstractDataRecord(
-            AbstractDataStore store, DataIdentifier identifier) {
-        this.store = store;
-        this.identifier = identifier;
-    }
-
-    /**
-     * Returns the data identifier.
-     *
-     * @return data identifier
-     */
-    public DataIdentifier getIdentifier() {
-        return identifier;
-    }
-
-    public String getReference() {
-        return store.getReferenceFromIdentifier(identifier);
-    }
-
-    /**
-     * Returns the string representation of the data identifier.
-     *
-     * @return string representation
-     */
-    public String toString() {
-        return identifier.toString();
-    }
-
-    /**
-     * Checks if the given object is a data record with the same identifier
-     * as this one.
-     *
-     * @param object other object
-     * @return <code>true</code> if the other object is a data record and has
-     *         the same identifier as this one, <code>false</code> otherwise
-     */
-    public boolean equals(Object object) {
-        return (object instanceof DataRecord)
-            && identifier.equals(((DataRecord) object).getIdentifier());
-    }
-
-    /**
-     * Returns the hash code of the data identifier.
-     *
-     * @return hash code
-     */
-    public int hashCode() {
-        return identifier.hashCode();
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.core.data;
+
+
+/**
+ * Abstract data record base class. This base class contains only
+ * a reference to the data identifier of the record and implements
+ * the standard {@link Object} equality, hash code, and string
+ * representation methods based on the identifier.
+ */
+public abstract class AbstractDataRecord implements DataRecord {
+
+    /**
+     * The data store that contains this record.
+     */
+    private final AbstractDataStore store;
+
+    /**
+     * The binary identifier;
+     */
+    private final DataIdentifier identifier;
+
+    /**
+     * Creates a data record with the given identifier.
+     *
+     * @param identifier data identifier
+     */
+    public AbstractDataRecord(
+            AbstractDataStore store, DataIdentifier identifier) {
+        this.store = store;
+        this.identifier = identifier;
+    }
+
+    /**
+     * Returns the data identifier.
+     *
+     * @return data identifier
+     */
+    public DataIdentifier getIdentifier() {
+        return identifier;
+    }
+
+    public String getReference() {
+        return store.getReferenceFromIdentifier(identifier);
+    }
+
+    /**
+     * Returns the string representation of the data identifier.
+     *
+     * @return string representation
+     */
+    public String toString() {
+        return identifier.toString();
+    }
+
+    /**
+     * Checks if the given object is a data record with the same identifier
+     * as this one.
+     *
+     * @param object other object
+     * @return <code>true</code> if the other object is a data record and has
+     *         the same identifier as this one, <code>false</code> otherwise
+     */
+    public boolean equals(Object object) {
+        return (object instanceof DataRecord)
+            && identifier.equals(((DataRecord) object).getIdentifier());
+    }
+
+    /**
+     * Returns the hash code of the data identifier.
+     *
+     * @return hash code
+     */
+    public int hashCode() {
+        return identifier.hashCode();
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
Wed Mar 12 11:05:06 2014
@@ -1,135 +1,135 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jackrabbit.core.data;
-
-import java.security.SecureRandom;
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
-
-public abstract class AbstractDataStore implements DataStore {
-
-    private static final String ALGORITHM = "HmacSHA1";
-
-    /**
-     * Array of hexadecimal digits.
-     */
-    private static final char[] HEX = "0123456789abcdef".toCharArray();
-
-    /**
-     * Cached copy of the reference key of this data store. Initialized in
-     * {@link #getReferenceKey()} when the key is first accessed.
-     */
-    private byte[] referenceKey = null;
-
-    //---------------------------------------------------------< DataStore >--
-
-    public DataRecord getRecord(DataIdentifier identifier)
-            throws DataStoreException {
-        DataRecord record = getRecordIfStored(identifier);
-        if (record != null) {
-            return record;
-        } else {
-            throw new DataStoreException(
-                    "Record " + identifier + " does not exist");
-        }
-    }
-
-    public DataRecord getRecordFromReference(String reference)
-            throws DataStoreException {
-        if (reference != null) {
-            int colon = reference.indexOf(':');
-            if (colon != -1) {
-                DataIdentifier identifier =
-                        new DataIdentifier(reference.substring(0, colon));
-                if (reference.equals(getReferenceFromIdentifier(identifier))) {
-                    return getRecordIfStored(identifier);
-                }
-            }
-        }
-        return null;
-    }
-
-    //---------------------------------------------------------< protected >--
-
-    /**
-     * Returns the hex encoding of the given bytes.
-     *
-     * @param value value to be encoded
-     * @return encoded value
-     */
-    protected static String encodeHexString(byte[] value) {
-        char[] buffer = new char[value.length * 2];
-        for (int i = 0; i < value.length; i++) {
-            buffer[2 * i] = HEX[(value[i] >> 4) & 0x0f];
-            buffer[2 * i + 1] = HEX[value[i] & 0x0f];
-        }
-        return new String(buffer);
-    }
-
-    protected String getReferenceFromIdentifier(DataIdentifier identifier) {
-        try {
-            String id = identifier.toString();
-
-            Mac mac = Mac.getInstance(ALGORITHM);
-            mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM));
-            byte[] hash = mac.doFinal(id.getBytes("UTF-8"));
-
-            return id + ':' + encodeHexString(hash);
-        } catch (Exception e) {
-            // TODO: log a warning about this exception
-        }
-        return null;
-    }
-
-    /**
-     * Returns the reference key of this data store. If one does not already
-     * exist, it is automatically created in an implementation-specific way.
-     * The default implementation simply creates a temporary random key that's
-     * valid only until the data store gets restarted. Subclasses can override
-     * and/or decorate this method to support a more persistent reference key.
-     * <p>
-     * This method is called only once during the lifetime of a data store
-     * instance and the return value is cached in memory, so it's no problem
-     * if the implementation is slow.
-     *
-     * @return reference key
-     * @throws DataStoreException if the key is not available
-     */
-    protected byte[] getOrCreateReferenceKey() throws DataStoreException {
-        byte[] referenceKeyValue = new byte[256];
-        new SecureRandom().nextBytes(referenceKeyValue);
-        return referenceKeyValue;
-    }
-
-    //-----------------------------------------------------------< private >--
-
-    /**
-     * Returns the reference key of this data store. Synchronized to
-     * control concurrent access to the cached {@link #referenceKey} value.
-     *
-     * @return reference key
-     * @throws DataStoreException if the key is not available
-     */
-    private synchronized byte[] getReferenceKey() throws DataStoreException {
-        if (referenceKey == null) {
-            referenceKey = getOrCreateReferenceKey();
-        }
-        return referenceKey;
-    }
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.data;
+
+import java.security.SecureRandom;
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+
+public abstract class AbstractDataStore implements DataStore {
+
+    private static final String ALGORITHM = "HmacSHA1";
+
+    /**
+     * Array of hexadecimal digits.
+     */
+    private static final char[] HEX = "0123456789abcdef".toCharArray();
+
+    /**
+     * Cached copy of the reference key of this data store. Initialized in
+     * {@link #getReferenceKey()} when the key is first accessed.
+     */
+    private byte[] referenceKey = null;
+
+    //---------------------------------------------------------< DataStore >--
+
+    public DataRecord getRecord(DataIdentifier identifier)
+            throws DataStoreException {
+        DataRecord record = getRecordIfStored(identifier);
+        if (record != null) {
+            return record;
+        } else {
+            throw new DataStoreException(
+                    "Record " + identifier + " does not exist");
+        }
+    }
+
+    public DataRecord getRecordFromReference(String reference)
+            throws DataStoreException {
+        if (reference != null) {
+            int colon = reference.indexOf(':');
+            if (colon != -1) {
+                DataIdentifier identifier =
+                        new DataIdentifier(reference.substring(0, colon));
+                if (reference.equals(getReferenceFromIdentifier(identifier))) {
+                    return getRecordIfStored(identifier);
+                }
+            }
+        }
+        return null;
+    }
+
+    //---------------------------------------------------------< protected >--
+
+    /**
+     * Returns the hex encoding of the given bytes.
+     *
+     * @param value value to be encoded
+     * @return encoded value
+     */
+    protected static String encodeHexString(byte[] value) {
+        char[] buffer = new char[value.length * 2];
+        for (int i = 0; i < value.length; i++) {
+            buffer[2 * i] = HEX[(value[i] >> 4) & 0x0f];
+            buffer[2 * i + 1] = HEX[value[i] & 0x0f];
+        }
+        return new String(buffer);
+    }
+
+    protected String getReferenceFromIdentifier(DataIdentifier identifier) {
+        try {
+            String id = identifier.toString();
+
+            Mac mac = Mac.getInstance(ALGORITHM);
+            mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM));
+            byte[] hash = mac.doFinal(id.getBytes("UTF-8"));
+
+            return id + ':' + encodeHexString(hash);
+        } catch (Exception e) {
+            // TODO: log a warning about this exception
+        }
+        return null;
+    }
+
+    /**
+     * Returns the reference key of this data store. If one does not already
+     * exist, it is automatically created in an implementation-specific way.
+     * The default implementation simply creates a temporary random key that's
+     * valid only until the data store gets restarted. Subclasses can override
+     * and/or decorate this method to support a more persistent reference key.
+     * <p>
+     * This method is called only once during the lifetime of a data store
+     * instance and the return value is cached in memory, so it's no problem
+     * if the implementation is slow.
+     *
+     * @return reference key
+     * @throws DataStoreException if the key is not available
+     */
+    protected byte[] getOrCreateReferenceKey() throws DataStoreException {
+        byte[] referenceKeyValue = new byte[256];
+        new SecureRandom().nextBytes(referenceKeyValue);
+        return referenceKeyValue;
+    }
+
+    //-----------------------------------------------------------< private >--
+
+    /**
+     * Returns the reference key of this data store. Synchronized to
+     * control concurrent access to the cached {@link #referenceKey} value.
+     *
+     * @return reference key
+     * @throws DataStoreException if the key is not available
+     */
+    private synchronized byte[] getReferenceKey() throws DataStoreException {
+        if (referenceKey == null) {
+            referenceKey = getOrCreateReferenceKey();
+        }
+        return referenceKey;
+    }
+
 }
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/AbstractDataStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/Backend.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/Backend.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/Backend.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/Backend.java
Wed Mar 12 11:05:06 2014
@@ -1,124 +1,124 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jackrabbit.core.data;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.Iterator;
-import java.util.List;
-
-
-
-/**
- * The interface defines the backend which can be plugged into
- * {@link CachingDataStore}.
- */
-public interface Backend {
-
-    /**
-     * This method initialize backend with the configuration.
-     * 
-     * @param store {@link CachingDataStore}
-     * @param homeDir path of repository home dir.
-     * @param config path of config property file.
-     * @throws DataStoreException
-     */
-    void init(CachingDataStore store, String homeDir, String config)
-            throws DataStoreException;
-
-    /**
-     * Return inputstream of record identified by identifier.
-     * 
-     * @param identifier identifier of record.
-     * @return inputstream of the record.
-     * @throws DataStoreException if record not found or any error.
-     */
-    InputStream read(DataIdentifier identifier) throws DataStoreException;
-
-    /**
-     * Return length of record identified by identifier.
-     * 
-     * @param identifier identifier of record.
-     * @return length of the record.
-     * @throws DataStoreException if record not found or any error.
-     */
-    long getLength(DataIdentifier identifier) throws DataStoreException;
-
-    /**
-     * Return lastModified of record identified by identifier.
-     * 
-     * @param identifier identifier of record.
-     * @return lastModified of the record.
-     * @throws DataStoreException if record not found or any error.
-     */
-    long getLastModified(DataIdentifier identifier) throws DataStoreException;
-
-    /**
-     * Stores file to backend with identifier used as key. If key pre-exists, it
-     * updates the timestamp of the key.
-     * 
-     * @param identifier key of the file 
-     * @param file file that would be stored in backend.
-     * @throws DataStoreException for any error.
-     */
-    void write(DataIdentifier identifier, File file) throws DataStoreException;
-
-    /**
-     * Returns identifiers of all records that exists in backend. 
-     * @return iterator consisting of all identifiers
-     * @throws DataStoreException
-     */
-    Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException;
-
-    /**
-     * Update timestamp of record identified by identifier if minModifiedDate is
-     * greater than record's lastModified else no op.
-     * 
-     * @throws DataStoreException if record not found.
-     */
-    void touch(DataIdentifier identifier, long minModifiedDate)
-            throws DataStoreException;
-    /**
-     * This method check the existence of record in backend. 
-     * @param identifier identifier to be checked. 
-     * @return true if records exists else false.
-     * @throws DataStoreException
-     */
-    boolean exists(DataIdentifier identifier) throws DataStoreException;
-
-    /**
-     * Close backend and release resources like database connection if any.
-     * @throws DataStoreException
-     */
-    void close() throws DataStoreException;
-
-    /**
-     * Delete all records which are older than timestamp.
-     * @param timestamp
-     * @return list of identifiers which are deleted. 
-     * @throws DataStoreException
-     */
-    List<DataIdentifier> deleteAllOlderThan(long timestamp) throws DataStoreException;
-
-    /**
-     * Delete record identified by identifier. No-op if identifier not found.
-     * @param identifier
-     * @throws DataStoreException
-     */
-    void deleteRecord(DataIdentifier identifier) throws DataStoreException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.core.data;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+
+
+
+/**
+ * The interface defines the backend which can be plugged into
+ * {@link CachingDataStore}.
+ */
+public interface Backend {
+
+    /**
+     * This method initialize backend with the configuration.
+     * 
+     * @param store {@link CachingDataStore}
+     * @param homeDir path of repository home dir.
+     * @param config path of config property file.
+     * @throws DataStoreException
+     */
+    void init(CachingDataStore store, String homeDir, String config)
+            throws DataStoreException;
+
+    /**
+     * Return inputstream of record identified by identifier.
+     * 
+     * @param identifier identifier of record.
+     * @return inputstream of the record.
+     * @throws DataStoreException if record not found or any error.
+     */
+    InputStream read(DataIdentifier identifier) throws DataStoreException;
+
+    /**
+     * Return length of record identified by identifier.
+     * 
+     * @param identifier identifier of record.
+     * @return length of the record.
+     * @throws DataStoreException if record not found or any error.
+     */
+    long getLength(DataIdentifier identifier) throws DataStoreException;
+
+    /**
+     * Return lastModified of record identified by identifier.
+     * 
+     * @param identifier identifier of record.
+     * @return lastModified of the record.
+     * @throws DataStoreException if record not found or any error.
+     */
+    long getLastModified(DataIdentifier identifier) throws DataStoreException;
+
+    /**
+     * Stores file to backend with identifier used as key. If key pre-exists, it
+     * updates the timestamp of the key.
+     * 
+     * @param identifier key of the file 
+     * @param file file that would be stored in backend.
+     * @throws DataStoreException for any error.
+     */
+    void write(DataIdentifier identifier, File file) throws DataStoreException;
+
+    /**
+     * Returns identifiers of all records that exists in backend. 
+     * @return iterator consisting of all identifiers
+     * @throws DataStoreException
+     */
+    Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException;
+
+    /**
+     * Update timestamp of record identified by identifier if minModifiedDate is
+     * greater than record's lastModified else no op.
+     * 
+     * @throws DataStoreException if record not found.
+     */
+    void touch(DataIdentifier identifier, long minModifiedDate)
+            throws DataStoreException;
+    /**
+     * This method check the existence of record in backend. 
+     * @param identifier identifier to be checked. 
+     * @return true if records exists else false.
+     * @throws DataStoreException
+     */
+    boolean exists(DataIdentifier identifier) throws DataStoreException;
+
+    /**
+     * Close backend and release resources like database connection if any.
+     * @throws DataStoreException
+     */
+    void close() throws DataStoreException;
+
+    /**
+     * Delete all records which are older than timestamp.
+     * @param timestamp
+     * @return list of identifiers which are deleted. 
+     * @throws DataStoreException
+     */
+    List<DataIdentifier> deleteAllOlderThan(long timestamp) throws DataStoreException;
+
+    /**
+     * Delete record identified by identifier. No-op if identifier not found.
+     * @param identifier
+     * @throws DataStoreException
+     */
+    void deleteRecord(DataIdentifier identifier) throws DataStoreException;
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/Backend.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataRecord.java?rev=1576690&r1=1576689&r2=1576690&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataRecord.java
Wed Mar 12 11:05:06 2014
@@ -1,56 +1,56 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jackrabbit.core.data;
-
-import java.io.InputStream;
-
-
-/**
- * CachingDataRecord which stores reference to {@link CachingDataStore}. This
- * class doesn't store any references to attributes but attributes are fetched
- * on demand from {@link CachingDataStore}.
- */
-public class CachingDataRecord extends AbstractDataRecord {
-
-    private final CachingDataStore store;
-
-    public CachingDataRecord(CachingDataStore store, DataIdentifier identifier) {
-        super(store, identifier);
-        this.store = store;
-    }
-
-    @Override
-    public long getLastModified() {
-        try {
-            return store.getLastModified(getIdentifier());
-        } catch (DataStoreException dse) {
-            return 0;
-        }
-    }
-
-    @Override
-    public long getLength() throws DataStoreException {
-        return store.getLength(getIdentifier());
-    }
-
-    @Override
-    public InputStream getStream() throws DataStoreException {
-        return store.getStream(getIdentifier());
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.core.data;
+
+import java.io.InputStream;
+
+
+/**
+ * CachingDataRecord which stores reference to {@link CachingDataStore}. This
+ * class doesn't store any references to attributes but attributes are fetched
+ * on demand from {@link CachingDataStore}.
+ */
+public class CachingDataRecord extends AbstractDataRecord {
+
+    private final CachingDataStore store;
+
+    public CachingDataRecord(CachingDataStore store, DataIdentifier identifier) {
+        super(store, identifier);
+        this.store = store;
+    }
+
+    @Override
+    public long getLastModified() {
+        try {
+            return store.getLastModified(getIdentifier());
+        } catch (DataStoreException dse) {
+            return 0;
+        }
+    }
+
+    @Override
+    public long getLength() throws DataStoreException {
+        return store.getLength(getIdentifier());
+    }
+
+    @Override
+    public InputStream getStream() throws DataStoreException {
+        return store.getStream(getIdentifier());
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/CachingDataRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message