jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1095338 [2/2] - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ jackrabbit-...
Date Wed, 20 Apr 2011 09:29:04 GMT
Copied: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/ParseException.java
(from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/ParseException.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/ParseException.java?p2=jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/ParseException.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/ParseException.java&r1=1095335&r2=1095338&rev=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/ParseException.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/ParseException.java
Wed Apr 20 09:29:02 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.commons.privilege;
+package org.apache.jackrabbit.spi.commons.privilege;
 
 /**
  * <code>ParseException</code>...

Copied: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinition.java
(from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinition.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinition.java?p2=jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinition.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinition.java&r1=1095335&r2=1095338&rev=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinition.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinition.java
Wed Apr 20 09:29:02 2011
@@ -14,26 +14,29 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.commons.privilege;
+package org.apache.jackrabbit.spi.commons.privilege;
 
-import java.util.Arrays;
+import org.apache.jackrabbit.spi.Name;
+
+import java.util.Collections;
+import java.util.Set;
 
 /**
  * <code>PrivilegeDefinition</code>
  */
 public class PrivilegeDefinition {
 
-    private final String name;
+    private final Name name;
     private final boolean isAbstract;
-    private final String[] declaredAggregateNames;
+    private final Set<Name> declaredAggregateNames;
 
-    public PrivilegeDefinition(String name, boolean isAbstract, String[] declaredAggregateNames)
{
+    public PrivilegeDefinition(Name name, boolean isAbstract, Set<Name> declaredAggregateNames)
{
         this.name = name;
         this.isAbstract = isAbstract;
-        this.declaredAggregateNames = declaredAggregateNames == null ? new String[0] : declaredAggregateNames;
+        this.declaredAggregateNames = declaredAggregateNames == null ? Collections.<Name>emptySet()
: Collections.unmodifiableSet(declaredAggregateNames);
     }
 
-    public String getName() {
+    public Name getName() {
         return name;
     }
 
@@ -41,7 +44,7 @@ public class PrivilegeDefinition {
         return isAbstract;
     }
 
-    public String[] getDeclaredAggregateNames() {
+    public Set<Name> getDeclaredAggregateNames() {
         return declaredAggregateNames;
     }
 
@@ -53,17 +56,16 @@ public class PrivilegeDefinition {
         PrivilegeDefinition that = (PrivilegeDefinition) o;
 
         if (isAbstract != that.isAbstract) return false;
-        if (!Arrays.equals(declaredAggregateNames, that.declaredAggregateNames)) return false;
         if (name != null ? !name.equals(that.name) : that.name != null) return false;
+        return declaredAggregateNames.equals(that.declaredAggregateNames);
 
-        return true;
     }
 
     @Override
     public int hashCode() {
         int result = name != null ? name.hashCode() : 0;
         result = 31 * result + (isAbstract ? 1 : 0);
-        result = 31 * result + (declaredAggregateNames != null ? Arrays.hashCode(declaredAggregateNames)
: 0);
+        result = 31 * result + (declaredAggregateNames != null ? declaredAggregateNames.hashCode()
: 0);
         return result;
     }
 }
\ No newline at end of file

Copied: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionReader.java
(from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionReader.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionReader.java?p2=jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionReader.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionReader.java&r1=1095335&r2=1095338&rev=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionReader.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionReader.java
Wed Apr 20 09:29:02 2011
@@ -14,9 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.commons.privilege;
+package org.apache.jackrabbit.spi.commons.privilege;
 
 import java.io.InputStream;
+import java.io.Reader;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -52,6 +53,28 @@ public class PrivilegeDefinitionReader {
     }
 
     /**
+     * Creates a new <code>PrivilegeDefinitionReader</code> for the given
+     * input stream. The specified content type is used in order to determine
+     * the type of privilege serialization.
+     *
+     * @param reader The reader to read the privilege definitions from.
+     * @param contentType Currently only types supported by
+     * {@link PrivilegeXmlHandler#isSupportedContentType(String)PrivilegeXmlHandler}
+     * are allowed.
+     * @throws ParseException If an error occurs.
+     * @throws IllegalArgumentException if the specified content type is not supported.
+     */
+    public PrivilegeDefinitionReader(Reader reader, String contentType) throws ParseException
{
+        if (PrivilegeXmlHandler.isSupportedContentType(contentType)) {
+            PrivilegeHandler pxh = new PrivilegeXmlHandler();
+            privilegeDefinitions = pxh.readDefinitions(reader, namespaces);
+        } else {
+            // not yet supported
+            throw new IllegalArgumentException("Unsupported content type " + contentType);
+        }
+    }
+
+    /**
      * Returns the privilege definitions retrieved from the input stream.
      *
      * @return an array of <code>PrivilegeDefinition</code>

Copied: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionWriter.java
(from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionWriter.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionWriter.java?p2=jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionWriter.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionWriter.java&r1=1095335&r2=1095338&rev=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionWriter.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionWriter.java
Wed Apr 20 09:29:02 2011
@@ -14,10 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.commons.privilege;
+package org.apache.jackrabbit.spi.commons.privilege;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.Writer;
 import java.util.Map;
 
 /**
@@ -57,4 +58,18 @@ public class PrivilegeDefinitionWriter {
     public void writeDefinitions(OutputStream out, PrivilegeDefinition[] privilegeDefinitions,
Map<String, String> namespaces) throws IOException {
         ph.writeDefinitions(out, privilegeDefinitions, namespaces);
     }
+
+    /**
+     * Writes the privilege definitions to the specified output stream.
+     *
+     * @param writer The writer.
+     * @param privilegeDefinitions The privilege definitions to write to the
+     * given output stream.
+     * @param namespaces The namespace mapping (prefix to uri) used by the
+     * specified definitions.
+     * @throws IOException If an error occurs.
+     */
+    public void writeDefinitions(Writer writer, PrivilegeDefinition[] privilegeDefinitions,
Map<String, String> namespaces) throws IOException {
+        ph.writeDefinitions(writer, privilegeDefinitions, namespaces);
+    }
 }
\ No newline at end of file

Copied: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandler.java
(from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandler.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandler.java?p2=jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandler.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandler.java&r1=1095335&r2=1095338&rev=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandler.java
Wed Apr 20 09:29:02 2011
@@ -14,11 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.commons.privilege;
+package org.apache.jackrabbit.spi.commons.privilege;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
 import java.util.Map;
 
 /**
@@ -37,6 +39,16 @@ public interface PrivilegeHandler {
     PrivilegeDefinition[] readDefinitions(InputStream in, Map<String, String> namespaces)
throws ParseException;
 
     /**
+     * Read the privilege definitions and update the specified namespace mapping.
+     *
+     * @param reader
+     * @param namespaces
+     * @return the privilege definitions contained in the specified stream.
+     * @throws ParseException
+     */
+    PrivilegeDefinition[] readDefinitions(Reader reader, Map<String, String> namespaces)
throws ParseException;
+
+    /**
      * Write the specified privilege definitions to the given output stream.
      * 
      * @param out
@@ -45,4 +57,14 @@ public interface PrivilegeHandler {
      * @throws IOException
      */
     void writeDefinitions(OutputStream out, PrivilegeDefinition[] definitions, Map<String,
String> namespaces) throws IOException;
+
+    /**
+     * Write the specified privilege definitions to the given writer.
+     *
+     * @param writer
+     * @param definitions
+     * @param namespaces
+     * @throws IOException
+     */
+    void writeDefinitions(Writer writer, PrivilegeDefinition[] definitions, Map<String,
String> namespaces) throws IOException;
 }
\ No newline at end of file

Copied: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeXmlHandler.java
(from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeXmlHandler.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeXmlHandler.java?p2=jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeXmlHandler.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeXmlHandler.java&r1=1095335&r2=1095338&rev=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeXmlHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeXmlHandler.java
Wed Apr 20 09:29:02 2011
@@ -14,14 +14,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.commons.privilege;
+package org.apache.jackrabbit.spi.commons.privilege;
 
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.util.Text;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
@@ -29,6 +34,7 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Result;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
@@ -36,11 +42,14 @@ import javax.xml.transform.stream.Stream
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-
-import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+import java.util.Set;
 
 /**
  * The <code>PrivilegeXmlHandler</code> loads and stores privilege definitions
from a XML document using the
@@ -72,6 +81,8 @@ class PrivilegeXmlHandler implements Pri
 
     private static final String LICENSE_HEADER = createLicenseHeader();
 
+    private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance();
+
     private static String createLicenseHeader() {
         return "\n" +                
                     "   Licensed to the Apache Software Foundation (ASF) under one or more\n"
+
@@ -131,11 +142,23 @@ class PrivilegeXmlHandler implements Pri
      * @see PrivilegeHandler#readDefinitions(java.io.InputStream, java.util.Map)
      */
     public PrivilegeDefinition[] readDefinitions(InputStream in, Map<String, String>
namespaces) throws ParseException {
+        return readDefinitions(new InputSource(in), namespaces);
+
+    }
+
+    /**
+     * @see PrivilegeHandler#readDefinitions(java.io.Reader, java.util.Map)
+     */
+    public PrivilegeDefinition[] readDefinitions(Reader reader, Map<String, String>
namespaces) throws ParseException {
+        return readDefinitions(new InputSource(reader), namespaces);
+    }
+
+    private PrivilegeDefinition[] readDefinitions(InputSource input, Map<String, String>
namespaces) throws ParseException {
         try {
             List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
 
             DocumentBuilder builder = createDocumentBuilder();
-            Document doc = builder.parse(in);
+            Document doc = builder.parse(input);
             Element root = doc.getDocumentElement();
             if (!XML_PRIVILEGES.equals(root.getNodeName())) {
                 throw new IllegalArgumentException("root element must be named 'privileges'");
@@ -160,38 +183,51 @@ class PrivilegeXmlHandler implements Pri
         } catch (ParserConfigurationException e) {
             throw new ParseException(e);
         }
-
     }
 
     /**
-     * @see PrivilegeHandler#writeDefinitions(java.io.OutputStream, PrivilegeDefinition[],
java.util.Map) 
+     * @see PrivilegeHandler#writeDefinitions(java.io.OutputStream, PrivilegeDefinition[],
java.util.Map)
      */
     public void writeDefinitions(OutputStream out, PrivilegeDefinition[] definitions, Map<String,
String> namespaces) throws IOException {
+        writeDefinitions(new StreamResult(out), definitions, namespaces);
+    }
+
+    /**
+     * @see PrivilegeHandler#writeDefinitions(java.io.Writer, PrivilegeDefinition[], java.util.Map)
+     */
+    public void writeDefinitions(Writer writer, PrivilegeDefinition[] definitions, Map<String,
String> namespaces) throws IOException {
+        writeDefinitions(new StreamResult(writer), definitions, namespaces);
+    }
+
+    private void writeDefinitions(Result result, PrivilegeDefinition[] definitions, Map<String,
String> namespaces) throws IOException {
         try {
+            Map<String, String> uriToPrefix = new HashMap<String, String>(namespaces.size());
             DocumentBuilder builder = createDocumentBuilder();
             Document doc = builder.newDocument();
             doc.appendChild(doc.createComment(LICENSE_HEADER));
             Element privileges = (Element) doc.appendChild(doc.createElement(XML_PRIVILEGES));
 
             for (String prefix : namespaces.keySet()) {
-                privileges.setAttribute(ATTR_XMLNS + prefix, namespaces.get(prefix));
+                String uri = namespaces.get(prefix);
+                privileges.setAttribute(ATTR_XMLNS + prefix, uri);
+                uriToPrefix.put(uri, prefix);
             }
 
             for (PrivilegeDefinition def : definitions) {
                 Element priv = (Element) privileges.appendChild(doc.createElement(XML_PRIVILEGE));
-                priv.setAttribute(ATTR_NAME, def.getName());
+                priv.setAttribute(ATTR_NAME, getQualifiedName(def.getName(), uriToPrefix));
                 priv.setAttribute(ATTR_ABSTRACT, Boolean.valueOf(def.isAbstract()).toString());
 
-                for (String aggrName : def.getDeclaredAggregateNames()) {
+                for (Name aggrName : def.getDeclaredAggregateNames()) {
                     Element contains = (Element) priv.appendChild(doc.createElement(XML_CONTAINS));
-                    contains.setAttribute(ATTR_NAME, aggrName);
+                    contains.setAttribute(ATTR_NAME, getQualifiedName(aggrName, uriToPrefix));
                 }
             }
 
             Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
             transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
-            transformer.transform(new DOMSource(doc), new StreamResult(out));
+            transformer.transform(new DOMSource(doc), result);
 
         } catch (Exception e) {
             IOException io = new IOException(e.getMessage());
@@ -213,21 +249,21 @@ class PrivilegeXmlHandler implements Pri
 
             updateNamespaceMapping(elem, namespaces);
 
-            String name = elem.getAttribute(ATTR_NAME);
+            Name name = getName(elem.getAttribute(ATTR_NAME), namespaces);
             boolean isAbstract = Boolean.parseBoolean(elem.getAttribute(ATTR_ABSTRACT));
 
-            List<String> aggrNames = new ArrayList<String>();
+            Set<Name> aggrNames = new HashSet<Name>();
             NodeList nodeList = elem.getChildNodes();
             for (int i = 0; i < nodeList.getLength(); i++) {
                 Node contains = nodeList.item(i);
                 if (isElement(n) && XML_CONTAINS.equals(contains.getNodeName()))
{
                     String aggrName = ((Element) contains).getAttribute(ATTR_NAME);
                     if (aggrName != null) {
-                        aggrNames.add(aggrName);
+                        aggrNames.add(getName(aggrName, namespaces));
                     }
                 }
             }
-            return new PrivilegeDefinition(name, isAbstract, aggrNames.toArray(new String[aggrNames.size()]));
+            return new PrivilegeDefinition(name, isAbstract, aggrNames);
         }
 
         // could not parse into privilege definition
@@ -274,4 +310,16 @@ class PrivilegeXmlHandler implements Pri
     private static boolean isElement(Node n) {
         return n.getNodeType() == Node.ELEMENT_NODE;
     }
+
+    private Name getName(String jcrName, Map<String,String> namespaces) {
+       String prefix = Text.getNamespacePrefix(jcrName);
+        String uri = (Name.NS_EMPTY_PREFIX.equals(prefix)) ? Name.NS_DEFAULT_URI : namespaces.get(prefix);
+        return NAME_FACTORY.create(uri, Text.getLocalName(jcrName));
+    }
+
+    private String getQualifiedName(Name name, Map<String,String> uriToPrefix) {
+        String uri = name.getNamespaceURI();
+        String prefix = (Name.NS_DEFAULT_URI.equals(uri)) ? Name.NS_EMPTY_PREFIX : uriToPrefix.get(uri);
+        return prefix + ":" + name.getLocalName();
+    }
 }

Copied: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandlerTest.java
(from r1092629, jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandlerTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandlerTest.java?p2=jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandlerTest.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandlerTest.java&r1=1092629&r2=1095338&rev=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandlerTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandlerTest.java
Wed Apr 20 09:29:02 2011
@@ -14,20 +14,27 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.commons.privilege;
+package org.apache.jackrabbit.spi.commons.privilege;
 
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Set;
 
 import junit.framework.TestCase;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 
 /**
  * <code>PrivilegeReadTest</code>...
  */
 public class PrivilegeHandlerTest extends TestCase {
 
+    private static final NameFactory NF = NameFactoryImpl.getInstance();
     /*
     <privilege name="foo:testRead"/>
     <privilege name="foo:testWrite"/>
@@ -39,12 +46,20 @@ public class PrivilegeHandlerTest extend
     </privilege>
 
      */
-    public static PrivilegeDefinition DEF_READ = new PrivilegeDefinition("foo:testRead",
false, null);
-    public static PrivilegeDefinition DEF_WRITE = new PrivilegeDefinition("foo:testWrite",
false, null);
-    public static PrivilegeDefinition DEF_ABSTRACT = new PrivilegeDefinition("foo:testAbstract",
true, null);
-    public static PrivilegeDefinition DEF_NON_ABSTRACT = new PrivilegeDefinition("foo:testNonAbstract",
false, null);
-    public static PrivilegeDefinition DEF_ALL = new PrivilegeDefinition("foo:testAll", false,
new String[]{"foo:testRead", "foo:testWrite"});
-    public static PrivilegeDefinition[] DEF_EXPECTED = new PrivilegeDefinition[]{
+    private static final String TEST_PREFIX = "foo";
+    private static final String TEST_URI = "http://www.foo.com/1.0";
+
+    private static PrivilegeDefinition DEF_READ = new PrivilegeDefinition(NF.create(TEST_URI,"testRead"),
false, null);
+    private static PrivilegeDefinition DEF_WRITE = new PrivilegeDefinition(NF.create(TEST_URI,"testWrite"),
false, null);
+    private static PrivilegeDefinition DEF_ABSTRACT = new PrivilegeDefinition(NF.create(TEST_URI,"testAbstract"),
true, null);
+    private static PrivilegeDefinition DEF_NON_ABSTRACT = new PrivilegeDefinition(NF.create(TEST_URI,"testNonAbstract"),
false, null);
+    private static Set<Name> aggr = new LinkedHashSet<Name>();
+    static {
+        aggr.add(DEF_READ.getName());
+        aggr.add(DEF_WRITE.getName());
+    }
+    private static PrivilegeDefinition DEF_ALL = new PrivilegeDefinition(NF.create(TEST_URI,"testAll"),
false, aggr);
+    private static PrivilegeDefinition[] DEF_EXPECTED = new PrivilegeDefinition[]{
             DEF_READ,
             DEF_WRITE,
             DEF_ABSTRACT,
@@ -57,7 +72,7 @@ public class PrivilegeHandlerTest extend
 
         PrivilegeDefinitionReader reader = new PrivilegeDefinitionReader(in, "text/xml");
 
-        Map<String, PrivilegeDefinition> defs = new HashMap<String, PrivilegeDefinition>();
+        Map<Name, PrivilegeDefinition> defs = new HashMap<Name, PrivilegeDefinition>();
         for (PrivilegeDefinition def: reader.getPrivilegeDefinitions()) {
             defs.put(def.getName(), def);
         }
@@ -69,15 +84,15 @@ public class PrivilegeHandlerTest extend
         assertTrue("Not all definitions present", defs.isEmpty());
 
         // check for namespace
-        String fooUri = reader.getNamespaces().get("foo");
-        assertEquals("Namespace included", "http://www.foo.com/1.0", fooUri);
+        String fooUri = reader.getNamespaces().get(TEST_PREFIX);
+        assertEquals("Namespace included", TEST_URI, fooUri);
     }
 
     public void testWrite() throws Exception {
 
         PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter("text/xml");
         Map<String, String> namespaces = new HashMap<String, String>();
-        namespaces.put("foo", "http://www.foo.com/1.0");
+        namespaces.put(TEST_PREFIX, TEST_URI);
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         writer.writeDefinitions(out, DEF_EXPECTED, namespaces);
 

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/TestAll.java?rev=1095338&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/TestAll.java
(added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/TestAll.java
Wed Apr 20 09:29:02 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.spi.commons.privilege;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all testcases for package org.apache.jackrabbit.spi.commons.privilege.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("org.apache.jackrabbit.spi.commons.privilege tests");
+
+        suite.addTestSuite(PrivilegeHandlerTest.class);
+
+        return suite;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/TestAll.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message