Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplateTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplateTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/ACLTemplateTest.java Wed Jul 8 13:57:13 2009
@@ -16,15 +16,15 @@
*/
package org.apache.jackrabbit.core.security.authorization.principalbased;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.core.SessionImpl;
import org.apache.jackrabbit.core.security.authorization.AbstractACLTemplateTest;
-import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
-import javax.jcr.RepositoryException;
import javax.jcr.PropertyType;
-import java.util.List;
+import javax.jcr.RepositoryException;
import java.util.Arrays;
+import java.util.List;
/**
* <code>ACLTemplateTest</code>...
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EntryTest.java Wed Jul 8 13:57:13 2009
@@ -16,19 +16,19 @@
*/
package org.apache.jackrabbit.core.security.authorization.principalbased;
-import javax.jcr.security.AccessControlException;
-import javax.jcr.security.Privilege;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry;
import org.apache.jackrabbit.core.SessionImpl;
import org.apache.jackrabbit.core.security.authorization.AbstractEntryTest;
-import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlEntry;
-import org.apache.jackrabbit.value.StringValue;
-import org.apache.jackrabbit.value.BooleanValue;
-import org.apache.jackrabbit.test.NotExecutableException;
import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.value.BooleanValue;
+import org.apache.jackrabbit.value.StringValue;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
+import javax.jcr.security.AccessControlException;
+import javax.jcr.security.Privilege;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collections;
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java Wed Jul 8 13:57:13 2009
@@ -16,21 +16,21 @@
*/
package org.apache.jackrabbit.core.security.authorization.principalbased;
-import javax.jcr.security.AccessControlManager;
-import javax.jcr.security.AccessControlPolicy;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager;
import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.security.JackrabbitAccessControlManager;
-import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
import org.apache.jackrabbit.test.NotExecutableException;
import javax.jcr.AccessDeniedException;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.PropertyType;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.AccessControlPolicy;
import java.security.Principal;
import java.util.HashMap;
-import java.util.Map;
import java.util.Iterator;
+import java.util.Map;
/**
* <code>EvaluationTest</code>...
@@ -48,6 +48,12 @@
return true;
}
}
+ policies = ((JackrabbitAccessControlManager) acMgr).getPolicies(princ);
+ for (int i = 0; i < policies.length; i++) {
+ if (policies[i] instanceof ACLTemplate) {
+ return true;
+ }
+ }
} catch (RepositoryException e) {
// ignore
}
@@ -59,6 +65,7 @@
static JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException,
AccessDeniedException, NotExecutableException {
if (acM instanceof JackrabbitAccessControlManager) {
+ // first try applicable policies
AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acM).getApplicablePolicies(principal);
for (int i = 0; i < policies.length; i++) {
if (policies[i] instanceof ACLTemplate) {
@@ -66,6 +73,15 @@
return acl;
}
}
+
+ // second existing policies
+ policies = ((JackrabbitAccessControlManager) acM).getPolicies(principal);
+ for (int i = 0; i < policies.length; i++) {
+ if (policies[i] instanceof ACLTemplate) {
+ ACLTemplate acl = (ACLTemplate) policies[i];
+ return acl;
+ }
+ }
}
throw new NotExecutableException();
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java Wed Jul 8 13:57:13 2009
@@ -16,14 +16,14 @@
*/
package org.apache.jackrabbit.core.security.authorization.principalbased;
-import org.apache.jackrabbit.core.security.authorization.AbstractLockManagementTest;
-import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.core.SessionImpl;
-import javax.jcr.security.AccessControlManager;
+import org.apache.jackrabbit.core.security.authorization.AbstractLockManagementTest;
import org.apache.jackrabbit.test.NotExecutableException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.security.AccessControlManager;
import java.security.Principal;
import java.util.Map;
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java Wed Jul 8 13:57:13 2009
@@ -16,14 +16,14 @@
*/
package org.apache.jackrabbit.core.security.authorization.principalbased;
-import org.apache.jackrabbit.core.security.authorization.AbstractNodeTypeManagementTest;
-import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
import org.apache.jackrabbit.core.SessionImpl;
-import javax.jcr.security.AccessControlManager;
+import org.apache.jackrabbit.core.security.authorization.AbstractNodeTypeManagementTest;
import org.apache.jackrabbit.test.NotExecutableException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.security.AccessControlManager;
import java.security.Principal;
import java.util.Map;
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java Wed Jul 8 13:57:13 2009
@@ -16,21 +16,21 @@
*/
package org.apache.jackrabbit.core.security.authorization.principalbased;
-import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.core.SessionImpl;
import org.apache.jackrabbit.core.security.authorization.AbstractVersionManagementTest;
import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
-import org.apache.jackrabbit.core.SessionImpl;
-import javax.jcr.security.AccessControlManager;
-import javax.jcr.security.Privilege;
import org.apache.jackrabbit.test.NotExecutableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Node;
import javax.jcr.AccessDeniedException;
import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.Privilege;
import java.security.Principal;
import java.util.Map;
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java Wed Jul 8 13:57:13 2009
@@ -16,15 +16,18 @@
*/
package org.apache.jackrabbit.core.security.authorization.principalbased;
-import javax.jcr.security.AccessControlManager;
-import javax.jcr.security.AccessControlPolicy;
-import javax.jcr.security.Privilege;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlManager;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.api.security.user.User;
import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.security.JackrabbitAccessControlManager;
import org.apache.jackrabbit.core.security.authorization.AbstractWriteTest;
-import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
+import org.apache.jackrabbit.core.security.TestPrincipal;
+import org.apache.jackrabbit.core.security.principal.ItemBasedPrincipal;
import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +35,8 @@
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.Privilege;
import java.security.Principal;
import java.util.Map;
@@ -47,16 +52,7 @@
}
protected JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException {
- if (acM instanceof JackrabbitAccessControlManager) {
- AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acM).getApplicablePolicies(principal);
- for (int i = 0; i < policies.length; i++) {
- if (policies[i] instanceof ACLTemplate) {
- ACLTemplate acl = (ACLTemplate) policies[i];
- return acl;
- }
- }
- }
- throw new NotExecutableException();
+ return EvaluationUtil.getPolicy(acM, path, principal);
}
protected Map getRestrictions(Session s, String path) throws RepositoryException, NotExecutableException {
@@ -78,5 +74,77 @@
assertFalse(folder.hasProperty("jcr:created"));
}
+
+ public void testEditor() throws NotExecutableException, RepositoryException {
+ User u = null;
+ try {
+ UserManager uMgr = getUserManager(superuser);
+ u = uMgr.createUser("t", "t");
+ Principal p = u.getPrincipal();
+
+ JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
+ JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p);
+
+ assertEquals(1, acls.length);
+ assertTrue(acls[0] instanceof ACLTemplate);
+
+ // access again
+ acls = acMgr.getApplicablePolicies(p);
+
+ assertEquals(1, acls.length);
+ assertEquals(1, acMgr.getApplicablePolicies(acls[0].getPath()).getSize());
+
+ assertEquals(0, acMgr.getPolicies(p).length);
+ assertEquals(0, acMgr.getPolicies(acls[0].getPath()).length);
+
+ acMgr.setPolicy(acls[0].getPath(), acls[0]);
+
+ assertEquals(0, acMgr.getApplicablePolicies(p).length);
+ assertEquals(1, acMgr.getPolicies(p).length);
+ assertEquals(1, acMgr.getPolicies(acls[0].getPath()).length);
+ } finally {
+ superuser.refresh(false);
+ if (u != null) {
+ u.remove();
+ }
+ }
+ }
+
+ public void testEditor2() throws NotExecutableException, RepositoryException {
+ User u = null;
+ User u2 = null;
+
+ try {
+ UserManager uMgr = getUserManager(superuser);
+
+ u = uMgr.createUser("t", "t");
+ u2 = uMgr.createUser("tt", "tt", new TestPrincipal("tt"), "t/tt");
+
+ Principal p = u.getPrincipal();
+ Principal p2 = u2.getPrincipal();
+
+ if (p instanceof ItemBasedPrincipal && p2 instanceof ItemBasedPrincipal &&
+ Text.isDescendant(((ItemBasedPrincipal) p).getPath(), ((ItemBasedPrincipal) p2).getPath())) {
+
+ JackrabbitAccessControlManager acMgr = (JackrabbitAccessControlManager) getAccessControlManager(superuser);
+
+ JackrabbitAccessControlPolicy[] acls = acMgr.getApplicablePolicies(p2);
+ acMgr.setPolicy(acls[0].getPath(), acls[0]);
+
+ acls = acMgr.getApplicablePolicies(p);
+ String path = acls[0].getPath();
+
+ Node n = superuser.getNode(path);
+ assertEquals("rep:PrincipalAccessControl", n.getPrimaryNodeType().getName());
+ } else {
+ throw new NotExecutableException();
+ }
+ } finally {
+ superuser.refresh(false);
+ if (u2 != null) u2.remove();
+ if (u != null) u.remove();
+ }
+
+ }
// TODO: add specific tests with other restrictions
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupAdministratorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupAdministratorTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupAdministratorTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupAdministratorTest.java Wed Jul 8 13:57:13 2009
@@ -75,7 +75,7 @@
grID = groupAdmin.getID();
// create a session for the grou-admin user.
- uSession = helper.getRepository().login(creds);
+ uSession = getHelper().getRepository().login(creds);
}
protected void tearDown() throws Exception {
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/ImpersonationImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/ImpersonationImplTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/ImpersonationImplTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/ImpersonationImplTest.java Wed Jul 8 13:57:13 2009
@@ -55,7 +55,7 @@
creds = buildCredentials(p.getName(), pw);
UserImpl u = (UserImpl) userMgr.createUser(p.getName(), pw);
uID = u.getID();
- uSession = helper.getRepository().login(creds);
+ uSession = getHelper().getRepository().login(creds);
uMgr = getUserManager(uSession);
// create a second user 'below' the first user.
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NodeResolverTest.java Wed Jul 8 13:57:13 2009
@@ -186,11 +186,12 @@
NodeResolver nr = createNodeResolver(currentUser.getNode().getSession());
NodeIterator result = nr.findNodes(propName, "blub", UserConstants.NT_REP_USER, false);
- assertTrue(result.getSize() == 1);
- assertTrue(result.nextNode().isSame(currentUser.getNode()));
+ assertTrue("expected result", result.hasNext());
+ assertEquals(currentUser.getNode().getPath(), result.nextNode().getPath());
+ assertFalse("expected no more results", result.hasNext());
result = nr.findNodes(propName, "blub", UserConstants.NT_REP_AUTHORIZABLE, false);
- assertTrue(result.getSize() > 1);
+ assertTrue(getSize(result) > 1);
} finally {
currentUser.removeProperty(propertyName1);
@@ -204,7 +205,7 @@
public void testFindNodesWithNonExistingSearchRoot() throws NotExecutableException, RepositoryException {
String searchRoot = nodeResolver.getSearchRoot(UserConstants.NT_REP_AUTHORIZABLE);
- if (((SessionImpl) superuser).nodeExists(searchRoot)) {
+ if (superuser.nodeExists(searchRoot)) {
throw new NotExecutableException();
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NotUserAdministratorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NotUserAdministratorTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NotUserAdministratorTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/NotUserAdministratorTest.java Wed Jul 8 13:57:13 2009
@@ -55,7 +55,7 @@
uPath = u.getNode().getPath();
// create a session for the other user.
- uSession = helper.getRepository().login(new SimpleCredentials(uID, pw.toCharArray()));
+ uSession = getHelper().getRepository().login(new SimpleCredentials(uID, pw.toCharArray()));
uMgr = getUserManager(uSession);
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java Wed Jul 8 13:57:13 2009
@@ -16,6 +16,8 @@
*/
package org.apache.jackrabbit.core.security.user;
+import org.apache.jackrabbit.test.ConcurrentTestSuite;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -28,7 +30,7 @@
* @return a <code>Test</code> suite that executes all test in this package.
*/
public static Test suite() {
- TestSuite suite = new TestSuite("core.security.user tests");
+ TestSuite suite = new ConcurrentTestSuite("core.security.user tests");
suite.addTestSuite(UserManagerImplTest.class);
suite.addTestSuite(AuthorizableImplTest.class);
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserAdministratorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserAdministratorTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserAdministratorTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserAdministratorTest.java Wed Jul 8 13:57:13 2009
@@ -76,7 +76,7 @@
uAdministrators.addMember(other);
// create a session for the other user.
- otherSession = helper.getRepository().login(otherCreds);
+ otherSession = getHelper().getRepository().login(otherCreds);
}
protected void tearDown() throws Exception {
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImplTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImplTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserImplTest.java Wed Jul 8 13:57:13 2009
@@ -54,7 +54,7 @@
creds = new SimpleCredentials(p.getName(), pw.toCharArray());
User u = userMgr.createUser(p.getName(), pw);
uID = u.getID();
- uSession = helper.getRepository().login(creds);
+ uSession = getHelper().getRepository().login(creds);
uMgr = getUserManager(uSession);
}
@@ -95,7 +95,7 @@
}
public void testChangePassword() throws RepositoryException, NotExecutableException, NoSuchAlgorithmException, UnsupportedEncodingException {
- String oldPw = helper.getProperty("javax.jcr.tck.superuser.pwd");
+ String oldPw = getHelper().getProperty("javax.jcr.tck.superuser.pwd");
if (oldPw == null) {
// missing property
throw new NotExecutableException();
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java Wed Jul 8 13:57:13 2009
@@ -390,7 +390,7 @@
}
public void testCleanup() throws RepositoryException, NotExecutableException {
- Session s = helper.getSuperuserSession();
+ Session s = getHelper().getSuperuserSession();
try {
UserManager umgr = getUserManager(s);
s.logout();
@@ -415,7 +415,7 @@
String[] workspaceNames = superuser.getWorkspace().getAccessibleWorkspaceNames();
for (int i = 0; i < workspaceNames.length; i++) {
- Session s = helper.getSuperuserSession(workspaceNames[i]);
+ Session s = getHelper().getSuperuserSession(workspaceNames[i]);
try {
UserManager umgr = getUserManager(s);
s.logout();
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/DocumentViewTest.java Wed Jul 8 13:57:13 2009
@@ -24,19 +24,11 @@
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
-import javax.jcr.Session;
import javax.jcr.ValueFormatException;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
-import org.apache.jackrabbit.core.TestRepository;
-import org.apache.jackrabbit.test.JCRTestResult;
-import org.apache.jackrabbit.test.LogPrintWriter;
-import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-
-import junit.framework.TestCase;
-import junit.framework.TestResult;
+import org.apache.jackrabbit.test.AbstractJCRTest;
/**
* Jackrabbit-specific test cases for the document view XML format.
@@ -44,23 +36,7 @@
* @see org.apache.jackrabbit.test.api.ExportDocViewTest
* @see org.apache.jackrabbit.test.api.DocumentViewImportTest
*/
-public class DocumentViewTest extends TestCase {
-
- /** Logger instance for this class. */
- private static final Logger log = LoggerFactory.getLogger(DocumentViewTest.class);
-
- /** Test session. */
- private Session session;
-
- /**
- * Use a {@link org.apache.jackrabbit.test.JCRTestResult} to suppress test
- * case failures of known issues.
- *
- * @param testResult the test result.
- */
- public void run(TestResult testResult) {
- super.run(new JCRTestResult(testResult, new LogPrintWriter(log)));
- }
+public class DocumentViewTest extends AbstractJCRTest {
/**
* Sets up the test fixture.
@@ -69,9 +45,8 @@
*/
protected void setUp() throws Exception {
super.setUp();
- session = TestRepository.getInstance().login();
JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)
- session.getWorkspace().getNodeTypeManager();
+ superuser.getWorkspace().getNodeTypeManager();
try {
manager.getNodeType("DocViewMultiValueTest");
} catch (NoSuchNodeTypeException e) {
@@ -90,7 +65,6 @@
protected void tearDown() throws Exception {
// TODO: Unregister the MultiValueTestType node type once Jackrabbit
// supports node type removal.
- session.logout();
super.tearDown();
}
@@ -108,7 +82,7 @@
+ " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\""
+ " xmlns:mix=\"http://www.jcp.org/jcr/mix/1.0\"/>";
InputStream input = new ByteArrayInputStream(xml.getBytes("UTF-8"));
- session.importXML(
+ superuser.importXML(
"/", input, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
} catch (ValueFormatException e) {
fail("JCR-369: IllegalNameException when importing document view"
@@ -127,15 +101,15 @@
String message = "JCR-325: docview roundtripping does not work with"
+ " multivalue non-string properties";
- Node root = session.getRootNode();
+ Node root = superuser.getRootNode();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Node node = root.addNode("multi-value-test", "DocViewMultiValueTest");
node.setProperty("test", new String[] {"true", "false"});
- session.exportDocumentView("/multi-value-test", buffer, true, true);
- session.refresh(false); // Discard the transient multi-value-test node
+ superuser.exportDocumentView("/multi-value-test", buffer, true, true);
+ superuser.refresh(false); // Discard the transient multi-value-test node
- session.importXML(
+ superuser.importXML(
"/", new ByteArrayInputStream(buffer.toByteArray()),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
try {
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/WorkspaceImporterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/WorkspaceImporterTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/WorkspaceImporterTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/xml/WorkspaceImporterTest.java Wed Jul 8 13:57:13 2009
@@ -22,32 +22,27 @@
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import org.apache.jackrabbit.core.TestRepository;
import org.apache.jackrabbit.uuid.UUID;
-
-import junit.framework.TestCase;
+import org.apache.jackrabbit.test.AbstractJCRTest;
/**
* Test cases for the {@link WorkspaceImporter} class.
*/
-public class WorkspaceImporterTest extends TestCase {
-
- private Session session;
+public class WorkspaceImporterTest extends AbstractJCRTest {
private Node root;
protected void setUp() throws Exception {
- session = TestRepository.getInstance().login();
- root = session.getRootNode().addNode("WorkspaceImporterTest");
- session.save();
+ super.setUp();
+ root = superuser.getRootNode().addNode("WorkspaceImporterTest");
+ superuser.save();
}
protected void tearDown() throws Exception {
root.remove();
- session.save();
- session.logout();
+ superuser.save();
+ super.tearDown();
}
/**
@@ -81,7 +76,7 @@
+ "<sv:value>" + uuid + "</sv:value></sv:property>"
+ "</sv:node>"
+ "</sv:node>";
- session.getWorkspace().importXML(
+ superuser.getWorkspace().importXML(
root.getPath(),
new ByteArrayInputStream(xml.getBytes("UTF-8")),
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/repository.xml?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/repository.xml (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/repository.xml Wed Jul 8 13:57:13 2009
@@ -29,7 +29,15 @@
<!--
data store configuration
+ -->
<DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
+ <!--
+ sample database data store configuration
+ <DataStore class="org.apache.jackrabbit.core.data.db.DbDataStore">
+ <param name="url" value="jdbc:h2:~/test"/>
+ <param name="user" value="sa"/>
+ <param name="password" value="sa"/>
+ </DataStore>
-->
<!--
@@ -45,7 +53,7 @@
security manager:
class: FQN of class implementing the JackrabbitSecurityManager interface
-->
- <SecurityManager class="org.apache.jackrabbit.core.security.simple.SimpleSecurityManager" workspaceName="security">
+ <SecurityManager class="org.apache.jackrabbit.core.DefaultSecurityManager" workspaceName="security">
<!-- <param name="config" value="${rep.home}/security.xml"/> -->
</SecurityManager>
@@ -53,11 +61,11 @@
access manager:
class: FQN of class implementing the AccessManager interface
-->
- <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
+ <AccessManager class="org.apache.jackrabbit.core.security.DefaultAccessManager">
<!-- <param name="config" value="${rep.home}/access.xml"/> -->
</AccessManager>
- <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
+ <LoginModule class="org.apache.jackrabbit.core.security.authentication.DefaultLoginModule">
<!--
anonymous user name ('anonymous' is the default value)
-->
@@ -66,6 +74,11 @@
administrator user id (default value if param is missing is 'admin')
-->
<param name="adminId" value="admin"/>
+ <!--
+ optional parameter 'principalProvider'.
+ the value refers to the class name of the PrincipalProvider implementation.
+ -->
+ <!-- <param name="principalProvider" value="..."/> -->
</LoginModule>
</Security>
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml Wed Jul 8 13:57:13 2009
@@ -33,6 +33,9 @@
<!--
Search index and the file system it uses.
-->
- <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SlowQueryHandler"/>
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SlowQueryHandler">
+ <param name="path" value="${wsp.home}/index" />
+ <param name="directoryManagerClass" value="org.apache.jackrabbit.core.query.lucene.directory.RAMDirectoryManager"/>
+ </SearchIndex>
</Workspace>
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/nodetype/xml/test_nodetypes.xml Wed Jul 8 13:57:13 2009
@@ -172,6 +172,22 @@
<valueConstraint>/test:testPath</valueConstraint>
</valueConstraints>
</propertyDefinition>
+ <propertyDefinition name="test:pathProperty1"
+ requiredType="Path" autoCreated="false" mandatory="false"
+ isFullTextSearchable="false" isQueryOrderable="true"
+ onParentVersion="IGNORE" protected="false" multiple="false">
+ <valueConstraints>
+ <valueConstraint>/test:testPath/*</valueConstraint>
+ </valueConstraints>
+ </propertyDefinition>
+ <propertyDefinition name="test:pathProperty2"
+ requiredType="Path" autoCreated="false" mandatory="false"
+ isFullTextSearchable="false" isQueryOrderable="true"
+ onParentVersion="IGNORE" protected="false" multiple="false">
+ <valueConstraints>
+ <valueConstraint>test:testPath/*</valueConstraint>
+ </valueConstraints>
+ </propertyDefinition>
<propertyDefinition name="test:referenceProperty"
requiredType="Reference" autoCreated="false" mandatory="false"
isFullTextSearchable="false" isQueryOrderable="true"
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAConnectionRequestInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAConnectionRequestInfo.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAConnectionRequestInfo.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCAConnectionRequestInfo.java Wed Jul 8 13:57:13 2009
@@ -72,7 +72,7 @@
*/
public int hashCode() {
int hash1 = workspace != null ? workspace.hashCode() : 0;
- int hash2 = creds != null ? creds.hashCode() : 0;
+ int hash2 = creds != null ? computeCredsHashCode(creds) : 0;
return hash1 ^ hash2;
}
@@ -170,4 +170,33 @@
return map;
}
+
+ /**
+ * Returns Credentials instance hash code. Handles instances of
+ * SimpleCredentials in a special way.
+ */
+ private int computeCredsHashCode(Credentials c) {
+ if (c instanceof SimpleCredentials) {
+ return computeSimpleCredsHashCode((SimpleCredentials) c);
+ }
+ return c.hashCode();
+ }
+
+ /**
+ * Computes hash code of a SimpleCredentials instance. Ignores its own
+ * hashCode() method because it's not overridden in SimpleCredentials.
+ */
+ private int computeSimpleCredsHashCode(SimpleCredentials c) {
+ String userID = c.getUserID();
+ char[] password = c.getPassword();
+ Map m = getAttributeMap(c);
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((userID == null) ? 0 : userID.hashCode());
+ for (int i = 0; i < password.length; i++) {
+ result = prime * result + password[i];
+ }
+ result = prime * result + ((m == null) ? 0 : m.hashCode());
+ return result;
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/java/org/apache/jackrabbit/jca/JCARepositoryHandle.java Wed Jul 8 13:57:13 2009
@@ -73,6 +73,9 @@
mcf, new JCAConnectionRequestInfo(creds, workspace));
} catch (ResourceException e) {
Throwable cause = e.getCause();
+ if (cause == null) {
+ cause = e.getLinkedException();
+ }
if (cause instanceof LoginException) {
throw (LoginException) cause;
} else if (cause instanceof NoSuchWorkspaceException) {
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/rar/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/rar/repository.xml?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/rar/repository.xml (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/main/rar/repository.xml Wed Jul 8 13:57:13 2009
@@ -35,11 +35,11 @@
access manager:
class: FQN of class implementing the AccessManager interface
-->
- <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager">
+ <AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager">
<!-- <param name="config" value="${rep.home}/access.xml"/> -->
</AccessManager>
- <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
+ <LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
<!-- anonymous user name ('anonymous' is the default value) -->
<param name="anonymousId" value="anonymous"/>
<!--
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/test/java/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/test/java/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/test/java/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jca/src/test/java/org/apache/jackrabbit/jca/test/ConnectionFactoryTest.java Wed Jul 8 13:57:13 2009
@@ -16,17 +16,19 @@
*/
package org.apache.jackrabbit.jca.test;
-import org.apache.jackrabbit.api.XASession;
-import org.apache.jackrabbit.jca.JCAConnectionRequestInfo;
-import org.apache.jackrabbit.jca.JCARepositoryHandle;
-import org.apache.jackrabbit.jca.JCASessionHandle;
+import java.io.Serializable;
+import java.util.HashSet;
+import javax.jcr.NoSuchWorkspaceException;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.naming.Referenceable;
import javax.resource.spi.ManagedConnection;
-import java.io.Serializable;
-import java.util.HashSet;
+
+import org.apache.jackrabbit.api.XASession;
+import org.apache.jackrabbit.jca.JCAConnectionRequestInfo;
+import org.apache.jackrabbit.jca.JCARepositoryHandle;
+import org.apache.jackrabbit.jca.JCASessionHandle;
/**
* This case executes tests on the connection factory.
@@ -118,5 +120,18 @@
assertTrue(session instanceof XASession);
session.logout();
}
+
+ /**
+ * Tests if a NoSuchWorkspaceException is thrown if a wrong workspace name is given to login
+ */
+ public void testExceptionHandling() throws Exception {
+ Object cf = mcf.createConnectionFactory();
+ Repository repository = (Repository) cf;
+ try {
+ repository.login(JCR_SUPERUSER, "xxx");
+ } catch (Exception e) {
+ assertTrue(e instanceof NoSuchWorkspaceException);
+ }
+ }
}
Propchange: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-client/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jul 8 13:57:13 2009
@@ -0,0 +1,5 @@
+*.iml
+*.ipr
+*.iws
+target
+.*
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractProperty.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractProperty.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractProperty.java Wed Jul 8 13:57:13 2009
@@ -218,7 +218,8 @@
public Node getNode() throws RepositoryException {
Session session = getSession();
Value value = getValue();
- if (value.getType() != PropertyType.REFERENCE) {
+ if (value.getType() != PropertyType.REFERENCE
+ && value.getType() != PropertyType.WEAKREFERENCE) {
value = session.getValueFactory().createValue(
value.getString(), PropertyType.REFERENCE);
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractRepository.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractRepository.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractRepository.java Wed Jul 8 13:57:13 2009
@@ -23,7 +23,6 @@
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.Value;
/**
* Abstract base class for implementing the JCR {@link Repository} interface.
@@ -78,6 +77,9 @@
add(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED);
add(Repository.OPTION_XML_EXPORT_SUPPORTED);
add(Repository.OPTION_XML_IMPORT_SUPPORTED);
+ add(Repository.OPTION_ACTIVITIES_SUPPORTED);
+ // add(Repository.OPTION_BASELINES_SUPPORTED);
+
add(Repository.QUERY_FULL_TEXT_SEARCH_SUPPORTED);
add(Repository.QUERY_JOINS);
add(Repository.QUERY_JOINS_INNER);
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java Wed Jul 8 13:57:13 2009
@@ -190,15 +190,6 @@
"Prefix is not a valid XML NCName: " + prefix);
}
- // FIXME Figure out how this should be handled
- // Currently JSR 283 does not specify this exception, but for
- // compatibility with JCR 1.0 TCK it probably should.
- // Note that the solution here also affects the remove() code below
- String previous = namespaces.get(prefix);
- if (previous != null && !previous.equals(uri)) {
- throw new NamespaceException("Namespace already mapped");
- }
-
// Remove existing mapping for the given prefix
namespaces.remove(prefix);
@@ -425,7 +416,7 @@
* {@link Item#remove()} on the item removed by {@link #getItem(String)}.
*
* @see Session#removeItem(String)
- * @param absolute path of the item to be removed
+ * @param absPath An absolute path of the item to be removed
* @throws RepositoryException if the item can not be removed
*/
public void removeItem(String absPath) throws RepositoryException {
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java Wed Jul 8 13:57:13 2009
@@ -151,11 +151,11 @@
* @param pattern property name globs
* @return matching properties of the node
* @throws RepositoryException
- * if the {@link Node#getProperty(String[])} call fails
+ * if the {@link Node#getProperties(String[])} call fails
*/
public static Iterable<Property> getProperties(Node node, String[] globs)
throws RepositoryException {
- return new PropertyIterable(node.getProperty(globs));
+ return new PropertyIterable(node.getProperties(globs));
}
/**
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/EventIteratorAdapter.java Wed Jul 8 13:57:13 2009
@@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.commons.iterator;
-import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -33,24 +32,12 @@
implements EventIterator {
/**
- * Static instance of an empty {@link EventIterator}.
- */
- public static final EventIterator EMPTY =
- new EventIteratorAdapter(RangeIteratorAdapter.EMPTY);
-
- /**
- * Date associated with this iterator.
- */
- private final Calendar date;
-
- /**
* Creates an adapter for the given {@link RangeIterator}.
*
* @param iterator iterator of {@link Event}s
*/
public EventIteratorAdapter(EventIterator iterator) {
super(iterator);
- this.date = iterator.getDate();
}
/**
@@ -60,7 +47,6 @@
*/
public EventIteratorAdapter(RangeIterator iterator) {
super(iterator);
- this.date = null;
}
/**
@@ -70,7 +56,6 @@
*/
public EventIteratorAdapter(Iterator iterator) {
super(new RangeIteratorAdapter(iterator));
- this.date = null;
}
/**
@@ -80,7 +65,6 @@
*/
public EventIteratorAdapter(Collection collection) {
super(new RangeIteratorAdapter(collection));
- this.date = null;
}
//-------------------------------------------------------< EventIterator >
@@ -95,13 +79,4 @@
return (Event) next();
}
- /**
- * Returns the date associated with this iterator.
- *
- * @return date associated with this iterator, or <code>null</code>
- */
- public Calendar getDate() {
- return date;
- }
-
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/iterator/NodeTypeIteratorAdapter.java Wed Jul 8 13:57:13 2009
@@ -60,7 +60,7 @@
*
* @param collection collection of {@link NodeType}s
*/
- public NodeTypeIteratorAdapter(Collection collection) {
+ public NodeTypeIteratorAdapter(Collection<NodeType> collection) {
super(new RangeIteratorAdapter(collection));
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/predicate/NtFilePredicate.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/predicate/NtFilePredicate.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/predicate/NtFilePredicate.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/predicate/NtFilePredicate.java Wed Jul 8 13:57:13 2009
@@ -75,7 +75,7 @@
/**
* @return <code>true</code> if the item is a nt:file or nt:resource property
- * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
+ * @see org.apache.jackrabbit.commons.predicate.Predicate#evaluate(java.lang.Object)
*/
public boolean evaluate(Object item) {
if ( item instanceof Item ) {
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/util/ISO9075.java Wed Jul 8 13:57:13 2009
@@ -16,8 +16,6 @@
*/
package org.apache.jackrabbit.util;
-import org.apache.jackrabbit.name.QName;
-
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -25,11 +23,7 @@
* Implements the encode and decode routines as specified for XML name to SQL
* identifier conversion in ISO 9075-14:2003.<br/>
* If a character <code>c</code> is not valid at a certain position in an XML 1.0
- * NCName it is encoded in the form: '_x' + hexValueOf(c) + '_'
- * <p/>
- * Note that only the local part of a {@link org.apache.jackrabbit.name.QName}
- * is encoded / decoded. A URI namespace will always be valid and does not
- * need encoding.
+ * NCName it is encoded in the form: '_x' + hexValueOf(c) + '_'.
*/
public class ISO9075 {
@@ -46,21 +40,6 @@
private static final String HEX_DIGITS = "0123456789abcdefABCDEF";
/**
- * Encodes the local part of <code>name</code> as specified in ISO 9075.
- * @param name the <code>QName</code> to encode.
- * @return the encoded <code>QName</code> or <code>name</code> if it does
- * not need encoding.
- */
- public static QName encode(QName name) {
- String encoded = encode(name.getLocalName());
- if (encoded == name.getLocalName()) {
- return name;
- } else {
- return new QName(name.getNamespaceURI(), encoded);
- }
- }
-
- /**
* Encodes <code>name</code> as specified in ISO 9075.
* @param name the <code>String</code> to encode.
* @return the encoded <code>String</code> or <code>name</code> if it does
@@ -138,20 +117,6 @@
/**
* Decodes the <code>name</code>.
- * @param name the <code>QName</code> to decode.
- * @return the decoded <code>QName</code>.
- */
- public static QName decode(QName name) {
- String decoded = decode(name.getLocalName());
- if (decoded == name.getLocalName()) {
- return name;
- } else {
- return new QName(name.getNamespaceURI(), decoded);
- }
- }
-
- /**
- * Decodes the <code>name</code>.
* @param name the <code>String</code> to decode.
* @return the decoded <code>String</code>.
*/
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BaseValue.java Wed Jul 8 13:57:13 2009
@@ -20,12 +20,12 @@
import javax.jcr.Binary;
import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.io.IOException;
import java.math.BigDecimal;
import java.util.Calendar;
@@ -223,8 +223,15 @@
public Binary getBinary()
throws ValueFormatException, IllegalStateException,
RepositoryException {
- // TODO
- throw new UnsupportedRepositoryOperationException("JCR-2056");
+ try {
+ // convert via string
+ return new BinaryImpl(new ByteArrayInputStream(getInternalString().getBytes(DEFAULT_ENCODING)));
+ } catch (UnsupportedEncodingException e) {
+ throw new RepositoryException(DEFAULT_ENCODING
+ + " not supported on this platform", e);
+ } catch (IOException e) {
+ throw new RepositoryException("failed to create Binary instance", e);
+ }
}
/**
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BinaryValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BinaryValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BinaryValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BinaryValue.java Wed Jul 8 13:57:13 2009
@@ -19,8 +19,8 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
+import javax.jcr.Binary;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -33,8 +33,7 @@
public static final int TYPE = PropertyType.BINARY;
- // those fields are mutually exclusive, i.e. only one can be non-null
- private byte[] streamData = null;
+ private Binary bin = null;
private String text = null;
/**
@@ -48,23 +47,37 @@
}
/**
+ * Constructs a <code>BinaryValue</code> object based on a <code>Binary</code>.
+ *
+ * @param bin the bytes this <code>BinaryValue</code> should represent
+ */
+ public BinaryValue(Binary bin) {
+ super(TYPE);
+ this.bin = bin;
+ }
+
+ /**
* Constructs a <code>BinaryValue</code> object based on a stream.
*
* @param stream the stream this <code>BinaryValue</code> should represent
*/
public BinaryValue(InputStream stream) {
super(TYPE);
- this.stream = stream;
+ try {
+ bin = new BinaryImpl(stream);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("specified stream cannot be read", e);
+ }
}
/**
- * Constructs a <code>BinaryValue</code> object based on a stream.
+ * Constructs a <code>BinaryValue</code> object based on a byte array.
*
- * @param data the stream this <code>BinaryValue</code> should represent
+ * @param data the bytes this <code>BinaryValue</code> should represent
*/
public BinaryValue(byte[] data) {
super(TYPE);
- streamData = data;
+ bin = new BinaryImpl(data);
}
/**
@@ -85,18 +98,11 @@
if (obj instanceof BinaryValue) {
BinaryValue other = (BinaryValue) obj;
if (text == other.text && stream == other.stream
- && streamData == other.streamData) {
+ && bin == other.bin) {
return true;
}
- // stream, streamData and text are mutually exclusive,
- // i.e. only one of them can be non-null
- if (stream != null) {
- return stream.equals(other.stream);
- } else if (streamData != null) {
- return streamData.equals(other.streamData);
- } else {
- return text.equals(other.text);
- }
+ return (text != null && text.equals(other.text))
+ || (bin != null && bin.equals(other.bin));
}
return false;
}
@@ -124,46 +130,20 @@
public String getInternalString()
throws ValueFormatException, RepositoryException {
// build text value if necessary
- if (streamData != null) {
- try {
- text = new String(streamData, DEFAULT_ENCODING);
- } catch (UnsupportedEncodingException e) {
- throw new RepositoryException(DEFAULT_ENCODING
- + " not supported on this platform", e);
- }
- streamData = null;
- } else if (stream != null) {
+ if (text == null) {
try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buffer = new byte[8192];
- int read;
- while ((read = stream.read(buffer)) > 0) {
- out.write(buffer, 0, read);
- }
- byte[] data = out.toByteArray();
- text = new String(data, DEFAULT_ENCODING);
+ byte[] bytes = new byte[(int) bin.getSize()];
+ bin.read(bytes, 0);
+ text = new String(bytes, DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new RepositoryException(DEFAULT_ENCODING
+ " not supported on this platform", e);
} catch (IOException e) {
- throw new RepositoryException("conversion from stream to string failed", e);
- } finally {
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (IOException e) {
- // ignore
- }
+ throw new RepositoryException("failed to retrieve binary data", e);
}
- stream = null;
}
- if (text != null) {
- return text;
- } else {
- throw new ValueFormatException("empty value");
- }
+ return text;
}
//----------------------------------------------------------------< Value >
@@ -174,20 +154,40 @@
throws IllegalStateException, RepositoryException {
setStreamConsumed();
- // build stream value if necessary
- if (streamData != null) {
- stream = new ByteArrayInputStream(streamData);
- streamData = null;
- } else if (text != null) {
+ if (stream == null) {
+ if (bin != null) {
+ stream = bin.getStream();
+ } else {
+ try {
+ stream = new ByteArrayInputStream(text.getBytes(DEFAULT_ENCODING));
+ } catch (UnsupportedEncodingException e) {
+ throw new RepositoryException(DEFAULT_ENCODING
+ + " not supported on this platform", e);
+ }
+ }
+ }
+
+ return stream;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Binary getBinary()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+
+ if (bin == null) {
try {
- stream = new ByteArrayInputStream(text.getBytes(DEFAULT_ENCODING));
+ bin = new BinaryImpl(new ByteArrayInputStream(text.getBytes(DEFAULT_ENCODING)));
} catch (UnsupportedEncodingException e) {
throw new RepositoryException(DEFAULT_ENCODING
+ " not supported on this platform", e);
+ } catch (IOException e) {
+ throw new RepositoryException("failed to retrieve binary data", e);
}
- text = null;
}
- return super.getStream();
+ return bin;
}
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BooleanValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BooleanValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BooleanValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/BooleanValue.java Wed Jul 8 13:57:13 2009
@@ -20,6 +20,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import java.util.Calendar;
+import java.math.BigDecimal;
/**
* A <code>BooleanValue</code> provides an implementation
@@ -160,4 +161,15 @@
throw new ValueFormatException("conversion to double failed: inconvertible types");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ throw new ValueFormatException("conversion to Decimal failed: inconvertible types");
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DateValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DateValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DateValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DateValue.java Wed Jul 8 13:57:13 2009
@@ -22,6 +22,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import java.util.Calendar;
+import java.math.BigDecimal;
/**
* A <code>DateValue</code> provides an implementation
@@ -191,4 +192,19 @@
throw new ValueFormatException("empty value");
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ if (date != null) {
+ return new BigDecimal(date.getTimeInMillis());
+ } else {
+ throw new ValueFormatException("empty value");
+ }
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DoubleValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DoubleValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DoubleValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/DoubleValue.java Wed Jul 8 13:57:13 2009
@@ -21,6 +21,7 @@
import javax.jcr.ValueFormatException;
import java.util.Calendar;
import java.util.Date;
+import java.math.BigDecimal;
/**
* A <code>DoubleValue</code> provides an implementation
@@ -178,4 +179,19 @@
throw new ValueFormatException("empty value");
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ if (dblNumber != null) {
+ return new BigDecimal(dblNumber.doubleValue());
+ } else {
+ throw new ValueFormatException("empty value");
+ }
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/LongValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/LongValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/LongValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/LongValue.java Wed Jul 8 13:57:13 2009
@@ -21,6 +21,7 @@
import javax.jcr.ValueFormatException;
import java.util.Calendar;
import java.util.Date;
+import java.math.BigDecimal;
/**
* A <code>LongValue</code> provides an implementation
@@ -178,4 +179,19 @@
throw new ValueFormatException("empty value");
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ if (lNumber != null) {
+ return new BigDecimal(lNumber.longValue());
+ } else {
+ throw new ValueFormatException("empty value");
+ }
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java Wed Jul 8 13:57:13 2009
@@ -16,16 +16,11 @@
*/
package org.apache.jackrabbit.value;
-import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
-
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import java.util.Calendar;
+import java.math.BigDecimal;
/**
* A <code>NameValue</code> provides an implementation
@@ -51,61 +46,13 @@
* name.
*/
public static NameValue valueOf(String s) throws ValueFormatException {
- return valueOf(s, true);
- }
-
- /**
- * Returns a new <code>NameValue</code> initialized to the value represented
- * by the specified <code>String</code>.
- * <p/>
- * If <code>checkFormat</code> is <code>true</code> specified
- * <code>String</code> must be a valid JCR name, otherwise the string is
- * used as is.
- *
- * @param s the string to be parsed.
- * @param checkFormat if the format should be checked.
- * @return a newly constructed <code>NameValue</code> representing the
- * specified value.
- * @throws javax.jcr.ValueFormatException If the format should be checked
- * and the <code>String</code> is not
- * a valid name.
- */
- public static NameValue valueOf(String s, boolean checkFormat) throws ValueFormatException {
if (s != null) {
- if (checkFormat) {
- try {
- NameFormat.checkFormat(s);
- } catch (IllegalNameException ine) {
- throw new ValueFormatException(ine.getMessage());
- }
- }
return new NameValue(s);
} else {
throw new ValueFormatException("not a valid name format: " + s);
}
}
- /**
- * Returns a new <code>NameValue</code> initialized to the value represented
- * by the specified <code>QName</code> formatted to a string using the
- * specified <code>resolver</code>.
- *
- * @param name the name to format.
- * @param resolver a namespace resolver the resolve the URI in the name to a
- * prefix.
- * @return a newly constructed <code>NameValue</code> representing the the
- * specified value.
- * @throws ValueFormatException If the <code>QName</code> contains a URI
- * that is not known to <code>resolver</code>.
- */
- public static NameValue valueOf(QName name, NamespaceResolver resolver)
- throws ValueFormatException {
- try {
- return new NameValue(NameFormat.format(name, resolver));
- } catch (NoPrefixDeclaredException e) {
- throw new ValueFormatException(e.getMessage());
- }
- }
/**
* Protected constructor creating a <code>NameValue</code> object
@@ -212,4 +159,15 @@
throw new ValueFormatException("conversion to double failed: inconvertible types");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ throw new ValueFormatException("conversion to Decimal failed: inconvertible types");
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/PathValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/PathValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/PathValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/PathValue.java Wed Jul 8 13:57:13 2009
@@ -16,13 +16,11 @@
*/
package org.apache.jackrabbit.value;
-import org.apache.jackrabbit.name.MalformedPathException;
-import org.apache.jackrabbit.name.PathFormat;
-
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import java.util.Calendar;
+import java.math.BigDecimal;
/**
* A <code>PathValue</code> provides an implementation
@@ -50,11 +48,6 @@
*/
public static PathValue valueOf(String s) throws ValueFormatException {
if (s != null) {
- try {
- PathFormat.checkFormat(s);
- } catch (MalformedPathException mpe) {
- throw new ValueFormatException(mpe.getMessage());
- }
return new PathValue(s);
} else {
throw new ValueFormatException("not a valid path format: " + s);
@@ -166,4 +159,15 @@
throw new ValueFormatException("conversion to double failed: inconvertible types");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ throw new ValueFormatException("conversion to Decimal failed: inconvertible types");
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ReferenceValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ReferenceValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ReferenceValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ReferenceValue.java Wed Jul 8 13:57:13 2009
@@ -24,6 +24,7 @@
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.ValueFormatException;
import java.util.Calendar;
+import java.math.BigDecimal;
/**
* A <code>ReferenceValue</code> provides an implementation
@@ -184,4 +185,15 @@
throw new ValueFormatException("conversion to double failed: inconvertible types");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ throw new ValueFormatException("conversion to Decimal failed: inconvertible types");
+ }
}
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/URIValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/URIValue.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/URIValue.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/URIValue.java Wed Jul 8 13:57:13 2009
@@ -22,6 +22,7 @@
import java.util.Calendar;
import java.net.URI;
import java.net.URISyntaxException;
+import java.math.BigDecimal;
/**
* A <code>URIValue</code> provides an implementation
@@ -162,4 +163,15 @@
throw new ValueFormatException("conversion to double failed: inconvertible types");
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public BigDecimal getDecimal()
+ throws ValueFormatException, IllegalStateException,
+ RepositoryException {
+ setValueConsumed();
+
+ throw new ValueFormatException("conversion to Decimal failed: inconvertible types");
+ }
}
\ No newline at end of file
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImpl.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImpl.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueFactoryImpl.java Wed Jul 8 13:57:13 2009
@@ -16,25 +16,16 @@
*/
package org.apache.jackrabbit.value;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.Calendar;
-
-import javax.jcr.Binary;
-import javax.jcr.Node;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.ValueFormatException;
/**
- * This class implements the <code>ValueFactory</code> interface.
+ * Simple extension of the <code>AbstractValueFactory</code> that omits any
+ * validation checks for path and name values.
*
* @see javax.jcr.Session#getValueFactory()
*/
-public class ValueFactoryImpl implements ValueFactory {
+public class ValueFactoryImpl extends AbstractValueFactory {
private static final ValueFactory valueFactory = new ValueFactoryImpl();
@@ -44,7 +35,6 @@
protected ValueFactoryImpl() {
}
- //--------------------------------------------------------------------------
/**
*
*/
@@ -52,130 +42,17 @@
return valueFactory;
}
- //---------------------------------------------------------< ValueFactory >
/**
- * {@inheritDoc}
+ * @see AbstractValueFactory#checkPathFormat(String)
*/
- public Value createValue(boolean value) {
- return new BooleanValue(value);
+ protected void checkPathFormat(String pathValue) throws ValueFormatException {
+ // ignore
}
/**
- * {@inheritDoc}
+ * @see AbstractValueFactory#checkNameFormat(String)
*/
- public Value createValue(Calendar value) {
- return new DateValue(value);
+ protected void checkNameFormat(String nameValue) throws ValueFormatException {
+ // ignore
}
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(double value) {
- return new DoubleValue(value);
- }
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(InputStream value) {
- return new BinaryValue(value);
- }
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(long value) {
- return new LongValue(value);
- }
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(Node value) throws RepositoryException {
- return createValue(value, false);
- }
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(String value) {
- return new StringValue(value);
- }
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(String value, int type)
- throws ValueFormatException {
- Value val;
- switch (type) {
- case PropertyType.STRING:
- val = new StringValue(value);
- break;
- case PropertyType.BOOLEAN:
- val = BooleanValue.valueOf(value);
- break;
- case PropertyType.DOUBLE:
- val = DoubleValue.valueOf(value);
- break;
- case PropertyType.LONG:
- val = LongValue.valueOf(value);
- break;
- case PropertyType.DECIMAL:
- val = DecimalValue.valueOf(value);
- break;
- case PropertyType.DATE:
- val = DateValue.valueOf(value);
- break;
- case PropertyType.NAME:
- val = NameValue.valueOf(value);
- break;
- case PropertyType.PATH:
- val = PathValue.valueOf(value);
- break;
- case PropertyType.URI:
- val = URIValue.valueOf(value);
- break;
- case PropertyType.REFERENCE:
- val = ReferenceValue.valueOf(value);
- break;
- case PropertyType.WEAKREFERENCE:
- val = WeakReferenceValue.valueOf(value);
- break;
- case PropertyType.BINARY:
- val = new BinaryValue(value);
- break;
- default:
- throw new IllegalArgumentException("Invalid type constant: " + type);
- }
- return val;
- }
-
- public Binary createBinary(InputStream stream) throws RepositoryException {
- throw new UnsupportedRepositoryOperationException("JCR-2056");
- }
-
- public Value createValue(Binary value) {
- throw new UnsupportedOperationException("JCR-2056");
- }
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(BigDecimal value) {
- return new DecimalValue(value);
- }
-
- /**
- * {@inheritDoc}
- */
- public Value createValue(Node node, boolean weak)
- throws RepositoryException {
- if (weak) {
- return new WeakReferenceValue(node);
- } else {
- return new ReferenceValue(node);
- }
- }
-
}
|