DNA SVN: r1131 - branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client.
by dna-commits@lists.jboss.org
Author: elvisisking
Date: 2009-07-24 16:08:32 -0400 (Fri, 24 Jul 2009)
New Revision: 1131
Modified:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
Log:
Added a ServerManager constructor that does not need a IRestClient input. The default IRestClient will be used which is the JsonRestClient.
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-07-24 18:13:16 UTC (rev 1130)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-07-24 20:08:32 UTC (rev 1131)
@@ -47,6 +47,7 @@
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
+import org.jboss.dna.web.jcr.rest.client.json.JsonRestClient;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -168,6 +169,17 @@
this.listeners = new CopyOnWriteArrayList<IServerRegistryListener>();
}
+ /**
+ * This server manager uses the default REST Client.
+ *
+ * @param stateLocationPath the directory where the {@link Server} registry} is persisted (may be <code>null</code> if
+ * persistence is not desired)
+ * @since 0.6
+ */
+ public ServerManager( String stateLocationPath ) {
+ this(stateLocationPath, new JsonRestClient());
+ }
+
// ===========================================================================================================================
// Methods
// ===========================================================================================================================
16 years, 5 months
DNA SVN: r1130 - in branches/eclipse/dna-web-jcr-rest-client: src/main/java/org/jboss/dna/web/jcr/rest/client and 6 other directories.
by dna-commits@lists.jboss.org
Author: elvisisking
Date: 2009-07-24 14:13:16 -0400 (Fri, 24 Jul 2009)
New Revision: 1130
Modified:
branches/eclipse/dna-web-jcr-rest-client/pom.xml
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Utils.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
Log:
Added trace messages, null arg checks, and got publish and unpublish tests working.
Modified: branches/eclipse/dna-web-jcr-rest-client/pom.xml
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/pom.xml 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/pom.xml 2009-07-24 18:13:16 UTC (rev 1130)
@@ -126,7 +126,8 @@
<!-- application to deploy -->
<deployable>
<groupId>org.jboss.dna</groupId>
- <artifactId>dna-web-jcr-rest-war</artifactId>
+ <artifactId>dna-web-jcr-rest-war
+ </artifactId>
<type>war</type>
<properties>
<context>resources</context>
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IJcrConstants.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -55,6 +55,20 @@
* @since 0.6
*/
String FOLDER_NODE_TYPE = "nt:folder"; //$NON-NLS-1$
+
+ /**
+ * The JCR data property name (<code>jcr:lastModified</code>).
+ *
+ * @since 0.6
+ */
+ String LAST_MODIFIED = "jcr:lastModified"; //$NON-NLS-1$
+
+ /**
+ * The JCR data property name (<code>jcr:lastModified</code>).
+ *
+ * @since 0.6
+ */
+ String MIME_TYPE = "jcr:mimeType"; //$NON-NLS-1$
/**
* The JCR primary type property name (<code>jcr:primaryType</code>).
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -41,6 +41,8 @@
String ErrorSavingServerRegistry = "ErrorSavingServerRegistry"; //$NON-NLS-1$
+ String NullArgumentMsg = "NullArgumentMsg"; //$NON-NLS-1$
+
String RepositoryEmptyNameMsg = "RepositoryEmptyNameMsg"; //$NON-NLS-1$
String RepositoryNullServerMsg = "RepositoryNullServerMsg"; //$NON-NLS-1$
@@ -76,17 +78,23 @@
String WorkspaceNullRepositoryMsg = "WorkspaceNullRepositoryMsg"; //$NON-NLS-1$
String WorkspaceShortDescription = "WorkspaceShortDescription"; //$NON-NLS-1$
-
+
// JsonRestClient messages
-
+
+ String ConnectionErrorMsg = "ConnectionErrorMsg"; //$NON-NLS-1$
+
String CreateFileFailedMsg = "CreateFileFailedMsg"; //$NON-NLS-1$
-
+
String CreateFolderFailedMsg = "CreateFolderFailedMsg"; //$NON-NLS-1$
String GetRepositoriesFailedMsg = "GetRepositoriesFailedMsg"; //$NON-NLS-1$
String GetWorkspacesFailedMsg = "GetWorkspacesFailedMsg"; //$NON-NLS-1$
+ String PublishFailedMsg = "PublishFailedMsg"; //$NON-NLS-1$
+
String UnpublishFailedMsg = "UnpublishFailedMsg"; //$NON-NLS-1$
+
+ String UnpublishNeverPublishedMsg = "UnpublishNeverPublishedMsg"; //$NON-NLS-1$
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -25,6 +25,7 @@
import java.io.File;
import java.util.Collection;
+import org.jboss.dna.web.jcr.rest.client.Status.Severity;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
@@ -40,7 +41,7 @@
* @throws Exception if there is a problem obtaining the repositories
* @since 0.6
*/
- public abstract Collection<Repository> getRepositories( Server server ) throws Exception;
+ Collection<Repository> getRepositories( Server server ) throws Exception;
/**
* @param repository the repository whose workspaces are being requested (never <code>null</code>)
@@ -48,28 +49,30 @@
* @throws Exception if there is a problem obtaining the workspaces
* @since 0.6
*/
- public abstract Collection<Workspace> getWorkspaces( Repository repository ) throws Exception;
+ Collection<Workspace> getWorkspaces( Repository repository ) throws Exception;
/**
* @param workspace the workspace where the resource will be published (never <code>null</code>)
- * @param path the path to the folder where the file will be published
+ * @param path the path to the folder where the file will be published (never <code>null</code>)
* @param file the resource being published (never <code>null</code>)
- * @throws Exception if there is a problem publishing
+ * @return a status of the publishing operation outcome (never <code>null</code>)
* @since 0.6
*/
- public abstract void publish( Workspace workspace,
- String path,
- File file ) throws Exception;
+ Status publish( Workspace workspace,
+ String path,
+ File file );
/**
+ * If a file being unpublished is not found in the workspace an {@link Severity#INFO info status} results.
+ *
* @param workspace the workspace where the resource will be unpublished (never <code>null</code>)
* @param path the path to the folder where the file is published (never <code>null</code>)
* @param file the file being unpublished (never <code>null</code>)
- * @throws Exception if there is a problem unpublishing
+ * @return a status of the unpublishing operation outcome (never <code>null</code>)
* @since 0.6
*/
- public abstract void unpublish( Workspace workspace,
- String path,
- File file ) throws Exception;
+ Status unpublish( Workspace workspace,
+ String path,
+ File file );
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -26,7 +26,6 @@
import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
import java.io.File;
import java.io.FileOutputStream;
-import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -161,6 +160,8 @@
*/
public ServerManager( String stateLocationPath,
IRestClient restExecutor ) {
+ Utils.nullArgumentCheck("restExecutor", restExecutor); //$NON-NLS-1$
+
this.servers = new ArrayList<Server>();
this.stateLocationPath = stateLocationPath;
this.restExecutor = restExecutor;
@@ -174,22 +175,24 @@
/**
* Listeners already registered will not be added again.
*
- * @param listener the listener being register to receive events
+ * @param listener the listener being register to receive events (never <code>null</code>)
* @return <code>true</code> if listener was added
* @since 0.6
*/
public boolean addRegistryListener( IServerRegistryListener listener ) {
+ Utils.nullArgumentCheck("listener", listener); //$NON-NLS-1$
return this.listeners.addIfAbsent(listener);
}
/**
* Registers the specified <code>Server</code>.
*
- * @param server the server being added
+ * @param server the server being added (never <code>null</code>)
* @return a status indicating if the server was added to the registry
* @since 0.6
*/
public Status addServer( Server server ) {
+ Utils.nullArgumentCheck("server", server); //$NON-NLS-1$
return internalAddServer(server, true);
}
@@ -221,7 +224,7 @@
}
/**
- * @param server the server whose repositories are being requested
+ * @param server the server whose repositories are being requested (never <code>null</code>)
* @return the server repositories (never <code>null</code>)
* @throws Exception if there is a problem obtaining the repositories or if the server is not registered
* @throws RuntimeException if the server is not registered
@@ -229,6 +232,8 @@
* @since 0.6
*/
public Collection<Repository> getRepositories( Server server ) throws Exception {
+ Utils.nullArgumentCheck("server", server); //$NON-NLS-1$
+
try {
this.serverLock.readLock().lock();
@@ -238,15 +243,14 @@
}
// server must be registered in order to obtain it's repositories
- String pattern = MESSAGES.getString(IMessages.ServerManagerUnregisteredServer);
- throw new RuntimeException(MessageFormat.format(pattern, server.getShortDescription()));
+ throw new RuntimeException(Utils.getMessage(IMessages.ServerManagerUnregisteredServer, server.getShortDescription()));
} finally {
this.serverLock.readLock().unlock();
}
}
/**
- * @param repository the repository whose workspaces are being requested
+ * @param repository the repository whose workspaces are being requested (never <code>null</code>)
* @return the DNA repository workspaces (never <code>null</code>)
* @throws Exception if there is a problem obtaining the workspaces
* @throws RuntimeException if the repository's server is not registered
@@ -254,6 +258,8 @@
* @since 0.6
*/
public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
+ Utils.nullArgumentCheck("repository", repository); //$NON-NLS-1$
+
try {
this.serverLock.readLock().lock();
@@ -263,8 +269,8 @@
}
// a repository's server must be registered in order to obtain it's workspaces
- String pattern = MESSAGES.getString(IMessages.ServerManagerUnregisteredServer);
- throw new RuntimeException(MessageFormat.format(pattern, repository.getServer().getShortDescription()));
+ throw new RuntimeException(Utils.getMessage(IMessages.ServerManagerUnregisteredServer,
+ repository.getServer().getShortDescription()));
} finally {
this.serverLock.readLock().unlock();
}
@@ -302,10 +308,7 @@
}
// server already exists
- String pattern = MESSAGES.getString(IMessages.ServerExistsMsg);
- String msg = MessageFormat.format(pattern, server.getShortDescription());
- Status status = new Status(Severity.ERROR, msg, null);
- return status;
+ return new Status(Severity.ERROR, Utils.getMessage(IMessages.ServerExistsMsg, server.getShortDescription()), null);
}
/**
@@ -342,19 +345,19 @@
}
// server could not be removed
- String pattern = MESSAGES.getString(IMessages.ServerManagerRegistryRemoveUnexpectedError);
- String msg = MessageFormat.format(pattern, server.getShortDescription());
- Status status = new Status(Severity.ERROR, msg, null);
- return status;
+ return new Status(Severity.ERROR, Utils.getMessage(IMessages.ServerManagerRegistryRemoveUnexpectedError,
+ server.getShortDescription()), null);
}
/**
- * @param server the server being tested
+ * @param server the server being tested (never <code>null</code>)
* @return <code>true</code> if the server has been registered
* @see #addServer(Server)
* @since 0.6
*/
public boolean isRegistered( Server server ) {
+ Utils.nullArgumentCheck("server", server); //$NON-NLS-1$
+
try {
this.serverLock.readLock().lock();
@@ -425,20 +428,22 @@
}
/**
- * @param listener the listener being unregistered and will no longer receive events
+ * @param listener the listener being unregistered and will no longer receive events (never <code>null</code>)
* @return <code>true</code> if listener was removed
* @since 0.6
*/
public boolean removeRegistryListener( IServerRegistryListener listener ) {
+ Utils.nullArgumentCheck("listener", listener); //$NON-NLS-1$
return this.listeners.remove(listener);
}
/**
- * @param server the server being removed
- * @return a status indicating if the specified server was removed from the registry
+ * @param server the server being removed (never <code>null</code>)
+ * @return a status indicating if the specified server was removed from the registry (never <code>null</code>)
* @since 0.6
*/
public Status removeServer( Server server ) {
+ Utils.nullArgumentCheck("server", server); //$NON-NLS-1$
return internalRemoveServer(server, true);
}
@@ -474,8 +479,8 @@
}
}
} catch (Exception e) {
- String pattern = MESSAGES.getString(IMessages.ErrorRestoringServerRegistry);
- return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
+ return new Status(Severity.ERROR,
+ Utils.getMessage(IMessages.ErrorRestoringServerRegistry, getStateFileName()), e);
}
}
}
@@ -521,16 +526,15 @@
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$
transformer.transform(source, resultXML);
} catch (Exception e) {
- String pattern = MESSAGES.getString(IMessages.ErrorSavingServerRegistry);
- return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
+ return new Status(Severity.ERROR, Utils.getMessage(IMessages.ErrorSavingServerRegistry, getStateFileName()), e);
}
} else if ((this.stateLocationPath != null) && stateFileExists()) {
// delete current registry file since all servers have been deleted
try {
new File(getStateFileName()).delete();
} catch (Exception e) {
- String pattern = MESSAGES.getString(IMessages.ErrorDeletingServerRegistryFile);
- return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
+ return new Status(Severity.ERROR,
+ Utils.getMessage(IMessages.ErrorDeletingServerRegistryFile, getStateFileName()), e);
}
}
@@ -548,13 +552,16 @@
/**
* Updates the server registry with a new version of a server.
*
- * @param previousServerVersion the version of the server being replaced
- * @param newServerVersion the new version of the server being put in the server registry
- * @return a status indicating if the server was updated in the registry
+ * @param previousServerVersion the version of the server being replaced (never <code>null</code>)
+ * @param newServerVersion the new version of the server being put in the server registry (never <code>null</code>)
+ * @return a status indicating if the server was updated in the registry (never <code>null</code>)
* @since 0.6
*/
public Status updateServer( Server previousServerVersion,
Server newServerVersion ) {
+ Utils.nullArgumentCheck("previousServerVersion", previousServerVersion); //$NON-NLS-1$
+ Utils.nullArgumentCheck("newServerVersion", newServerVersion); //$NON-NLS-1$
+
Status status = null;
try {
@@ -572,20 +579,17 @@
}
// unexpected problem adding new version of server to registry
- String pattern = MESSAGES.getString(IMessages.ServerManagerRegistryUpdateAddError);
- String msg = MessageFormat.format(pattern, status.getMessage());
- status = new Status(Severity.ERROR, msg, status.getException());
- return status;
+ return new Status(Severity.ERROR, Utils.getMessage(IMessages.ServerManagerRegistryUpdateAddError,
+ status.getMessage()), status.getException());
}
} finally {
this.serverLock.writeLock().unlock();
}
// unexpected problem removing server from registry
- String pattern = MESSAGES.getString(IMessages.ServerManagerRegistryUpdateRemoveError);
- String msg = MessageFormat.format(pattern, status.getMessage());
- status = new Status(Severity.ERROR, msg, status.getException());
- return status;
+ return new Status(Severity.ERROR,
+ Utils.getMessage(IMessages.ServerManagerRegistryUpdateRemoveError, status.getMessage()),
+ status.getException());
}
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -68,34 +68,39 @@
// ===========================================================================================================================
/**
- * @param newServer the server that was added to the server registry
- * @return the event
+ * @param newServer the server that was added to the server registry (never <code>null</code>)
+ * @return the event (never <code>null</code>)
* @see Type#NEW
* @since 0.6
*/
public static ServerRegistryEvent createNewEvent( Server newServer ) {
+ Utils.nullArgumentCheck("newServer", newServer); //$NON-NLS-1$
return new ServerRegistryEvent(Type.NEW, newServer);
}
/**
- * @param removedServer the server removed from the server registry
- * @return the event
+ * @param removedServer the server removed from the server registry (never <code>null</code>)
+ * @return the event (never <code>null</code>)
* @see Type#REMOVE
* @since 0.6
*/
public static ServerRegistryEvent createRemoveEvent( Server removedServer ) {
+ Utils.nullArgumentCheck("removedServer", removedServer); //$NON-NLS-1$
return new ServerRegistryEvent(Type.REMOVE, removedServer);
}
/**
- * @param previousServerVersion the server being updated (this instance is no longer found in the server registry)
- * @param newServerVersion the updated version of the server (this is now contained in the server registry)
- * @return the event
+ * @param previousServerVersion the server being updated (never <code>null</code>)
+ * @param newServerVersion the updated version of the server (never <code>null</code>)
+ * @return the event (never <code>null</code>)
* @see Type#UPDATE
* @since 0.6
*/
public static ServerRegistryEvent createUpdateEvent( Server previousServerVersion,
Server newServerVersion ) {
+ Utils.nullArgumentCheck("previousServerVersion", previousServerVersion); //$NON-NLS-1$
+ Utils.nullArgumentCheck("newServerVersion", newServerVersion); //$NON-NLS-1$
+
ServerRegistryEvent event = new ServerRegistryEvent(Type.UPDATE, previousServerVersion);
event.updatedServer = newServerVersion;
return event;
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Utils.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Utils.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Utils.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -23,6 +23,10 @@
*/
package org.jboss.dna.web.jcr.rest.client;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.NullArgumentMsg;
+import java.text.MessageFormat;
+
/**
* @author Dan Florian
* @since 0.6
@@ -34,9 +38,9 @@
// ===========================================================================================================================
/**
- * @param thisObj an object being compared
- * @param thatObj the other object being compared
- * @return <code>true</code> if both objects are null or both are not null and equal
+ * @param thisObj an object being compared (may be <code>null</code>)
+ * @param thatObj the other object being compared (may be <code>null</code>)
+ * @return <code>true</code> if both objects are <code>null</code> or both are not <code>null</code> and equal
* @since 0.6
*/
public static boolean equivalent( Object thisObj,
@@ -50,6 +54,33 @@
return thisObj.equals(thatObj);
}
+ /**
+ * @param key the key of the pattern from the {@link IMessages#MESSAGES} resource bundle (never <code>null</code>)
+ * @param arguments the values being inserted into the pattern
+ * @return the localized text
+ * @since 0.6
+ */
+ public static String getMessage( String key,
+ Object... arguments ) {
+ Utils.nullArgumentCheck("key", key); //$NON-NLS-1$
+ String pattern = MESSAGES.getString(key);
+ return MessageFormat.format(pattern, arguments);
+ }
+
+ /**
+ * @param name the argument name
+ * @param value the argument value
+ * @throws IllegalArgumentException if the value is <code>null</code>
+ * @since 0.6
+ */
+ public static void nullArgumentCheck( String name,
+ Object value ) throws IllegalArgumentException {
+ if (value == null) {
+ String pattern = MESSAGES.getString(NullArgumentMsg);
+ throw new IllegalArgumentException(MessageFormat.format(pattern, name));
+ }
+ }
+
// ===========================================================================================================================
// Constructors
// ===========================================================================================================================
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -23,11 +23,10 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain;
-import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
import static org.jboss.dna.web.jcr.rest.client.IMessages.RepositoryShortDescription;
-import java.text.MessageFormat;
import net.jcip.annotations.Immutable;
import org.jboss.dna.web.jcr.rest.client.Status;
+import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.validation.RepositoryValidator;
import org.jboss.dna.web.jcr.rest.client.json.JsonUtils;
@@ -67,14 +66,17 @@
/**
* Constructs a new <code>Repository</code>.
*
- * @param name the repository name
- * @param server the server where this repository resides
+ * @param name the repository name (never <code>null</code>)
+ * @param server the server where this repository resides (never <code>null</code>)
* @see RepositoryValidator
* @throws RuntimeException if any of the input parameters are invalid
* @since 0.6
*/
public Repository( String name,
Server server ) {
+ Utils.nullArgumentCheck("name", name); //$NON-NLS-1$
+ Utils.nullArgumentCheck("server", server); //$NON-NLS-1$
+
// validate inputs
Status status = RepositoryValidator.isValid(name, server);
@@ -132,8 +134,9 @@
* @since 0.6
*/
public String getShortDescription() {
- String pattern = MESSAGES.getString(RepositoryShortDescription);
- return MessageFormat.format(pattern, JsonUtils.decodeEscaping(this.name), this.server.getShortDescription());
+ return Utils.getMessage(RepositoryShortDescription,
+ JsonUtils.decodeEscaping(this.name),
+ this.server.getShortDescription());
}
/**
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -23,9 +23,7 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain;
-import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerShortDescription;
-import java.text.MessageFormat;
import net.jcip.annotations.Immutable;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.Utils;
@@ -80,9 +78,9 @@
/**
* Constructs on new <code>Server</code>.
*
- * @param url the server URL
- * @param user the server user
- * @param password the server password
+ * @param url the server URL (never <code>null</code>)
+ * @param user the server user (may be <code>null</code>)
+ * @param password the server password (may be <code>null</code>)
* @param persistPassword <code>true</code> if the password should be stored
* @see RepositoryValidator
* @throws RuntimeException if any of the input parameters are invalid
@@ -92,6 +90,8 @@
String user,
String password,
boolean persistPassword ) {
+ Utils.nullArgumentCheck("url", url); //$NON-NLS-1$
+
// valid inputs
Status status = ServerValidator.isValid(url, user, password, persistPassword);
@@ -153,8 +153,7 @@
* @since 0.6
*/
public String getShortDescription() {
- String pattern = MESSAGES.getString(ServerShortDescription);
- return MessageFormat.format(pattern, this.url, this.user);
+ return Utils.getMessage(ServerShortDescription, this.url, this.user);
}
/**
@@ -198,10 +197,11 @@
}
/**
- * @param otherServer the server whose key is being compared
+ * @param otherServer the server whose key is being compared (never <code>null</code>)
* @return <code>true</code> if the servers have the same key
*/
public boolean hasSameKey( Server otherServer ) {
+ Utils.nullArgumentCheck("otherServer", otherServer); //$NON-NLS-1$
return (Utils.equivalent(this.url, otherServer.url) && Utils.equivalent(this.user, otherServer.user));
}
@@ -215,7 +215,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see java.lang.Object#toString()
* @since 0.6
*/
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -23,11 +23,10 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain;
-import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
import static org.jboss.dna.web.jcr.rest.client.IMessages.WorkspaceShortDescription;
-import java.text.MessageFormat;
import net.jcip.annotations.Immutable;
import org.jboss.dna.web.jcr.rest.client.Status;
+import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.validation.WorkspaceValidator;
import org.jboss.dna.web.jcr.rest.client.json.JsonUtils;
@@ -65,14 +64,17 @@
/**
* Constructs a new <code>Workspace</code>.
*
- * @param name the workspace name
- * @param repository the repository where this workspace resides
+ * @param name the workspace name (never <code>null</code>)
+ * @param repository the repository where this workspace resides (never <code>null</code>)
* @see WorkspaceValidator
* @throws RuntimeException if any of the input parameters are invalid
* @since 0.6
*/
public Workspace( String name,
Repository repository ) {
+ Utils.nullArgumentCheck("name", name); //$NON-NLS-1$
+ Utils.nullArgumentCheck("repository", repository); //$NON-NLS-1$
+
// validate inputs
Status status = WorkspaceValidator.isValid(name, repository);
@@ -138,8 +140,9 @@
* @since 0.6
*/
public String getShortDescription() {
- String pattern = MESSAGES.getString(WorkspaceShortDescription);
- return MessageFormat.format(pattern, JsonUtils.decodeEscaping(this.name), this.repository.getShortDescription());
+ return Utils.getMessage(WorkspaceShortDescription,
+ JsonUtils.decodeEscaping(this.name),
+ this.repository.getShortDescription());
}
/**
@@ -158,7 +161,7 @@
/**
* {@inheritDoc}
- *
+ *
* @see java.lang.Object#toString()
* @since 0.6
*/
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -29,9 +29,9 @@
import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerExistsMsg;
import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerInvalidUrlMsg;
import java.net.URL;
-import java.text.MessageFormat;
import org.jboss.dna.web.jcr.rest.client.ServerManager;
import org.jboss.dna.web.jcr.rest.client.Status;
+import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.Status.Severity;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
@@ -67,9 +67,7 @@
try {
new URL(url);
} catch (Exception e) {
- String pattern = MESSAGES.getString(ServerInvalidUrlMsg);
- String msg = MessageFormat.format(pattern, url);
- return new Status(Severity.ERROR, msg, null);
+ return new Status(Severity.ERROR, Utils.getMessage(ServerInvalidUrlMsg, url), null);
}
return Status.OK_STATUS;
@@ -140,9 +138,7 @@
Server newServer = new Server(url, user, password, persistPassword);
if (serverManager.isRegistered(newServer)) {
- String pattern = MESSAGES.getString(ServerExistsMsg);
- String msg = MessageFormat.format(pattern, newServer.getShortDescription());
- status = new Status(Severity.ERROR, msg, null);
+ status = new Status(Severity.ERROR, Utils.getMessage(ServerExistsMsg, newServer.getShortDescription()), null);
}
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -29,11 +29,15 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.List;
+import java.util.TimeZone;
import net.jcip.annotations.Immutable;
import org.codehaus.jettison.json.JSONObject;
import org.jboss.dna.web.jcr.rest.client.IJcrConstants;
+import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
/**
@@ -75,7 +79,7 @@
/**
* @param workspace the workspace being used (never <code>null</code>)
* @param path the path in the workspace (never <code>null</code>)
- * @param file the file on the local file system
+ * @param file the file on the local file system (never <code>null</code>)
* @throws Exception if there is a problem constructing the file node
* @since 0.6
*/
@@ -83,6 +87,10 @@
String path,
File file ) throws Exception {
super(file.getName());
+
+ Utils.nullArgumentCheck("workspace", workspace); //$NON-NLS-1$
+ Utils.nullArgumentCheck("path", path); //$NON-NLS-1$
+
this.file = file;
this.path = path;
this.workspace = workspace;
@@ -105,8 +113,15 @@
kid.put(IJsonConstants.PROPERTIES_KEY, properties);
properties.put(IJcrConstants.PRIMARY_TYPE_PROPERTY, IJcrConstants.RESOURCE_NODE_TYPE);
- // TODO need to figure out how to write out file contents
- properties.put(IJcrConstants.DATA_PROPERTY, readFile(file));
+ // add required jcr:lastModified property
+ Calendar lastModified = Calendar.getInstance();
+ lastModified.setTimeInMillis(file.lastModified());
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); //$NON-NLS-1$
+ formatter.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$
+ properties.put(IJcrConstants.LAST_MODIFIED, formatter.format(lastModified.getTime()));
+
+ // add required jcr:mimeType property (just use a default value)
+ properties.put(IJcrConstants.MIME_TYPE, "application/octet-stream"); //$NON-NLS-1$
}
// ===========================================================================================================================
@@ -120,7 +135,14 @@
* @since 0.6
*/
@Override
- public byte[] getContent() {
+ public byte[] getContent() throws Exception {
+ // TODO need to figure out how to write binary content to JSONObject
+ // add required jcr:data property (do this lazily only when the content is requested)
+ JSONObject children = (JSONObject)get(IJsonConstants.CHILDREN_KEY);
+ JSONObject kid = (JSONObject)children.get(IJcrConstants.CONTENT_PROPERTY);
+ JSONObject props = (JSONObject)kid.get(IJsonConstants.PROPERTIES_KEY);
+ props.put(IJcrConstants.DATA_PROPERTY, readFile());
+
return super.getContent();
}
@@ -148,12 +170,17 @@
return new URL(url.toString());
}
- private Byte[] readFile( File file ) throws Exception {
+ /**
+ * @return the file content
+ * @throws Exception if there is a problem reading the file
+ * @since 0.6
+ */
+ private Byte[] readFile() throws Exception {
DataInputStream is = null;
List<Byte> bytes = new ArrayList<Byte>(1000);
try {
- is = new DataInputStream(new FileInputStream(file.getAbsoluteFile()));
+ is = new DataInputStream(new FileInputStream(this.file.getAbsoluteFile()));
while (true) {
bytes.add(is.readByte());
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -27,6 +27,7 @@
import net.jcip.annotations.Immutable;
import org.codehaus.jettison.json.JSONObject;
import org.jboss.dna.web.jcr.rest.client.IJcrConstants;
+import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
/**
@@ -60,6 +61,10 @@
public FolderNode( Workspace workspace,
String fullPath ) throws Exception {
super(fullPath);
+
+ Utils.nullArgumentCheck("workspace", workspace); //$NON-NLS-1$
+ Utils.nullArgumentCheck("fullPath", fullPath); //$NON-NLS-1$
+
this.workspace = workspace;
// add properties
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -25,6 +25,7 @@
import java.net.URL;
import org.codehaus.jettison.json.JSONObject;
+import org.jboss.dna.web.jcr.rest.client.Utils;
/**
* @author Dan Florian
@@ -52,6 +53,7 @@
* @since 0.6
*/
protected JsonNode( String id ) {
+ Utils.nullArgumentCheck("id", id); //$NON-NLS-1$
this.id = id;
}
@@ -61,9 +63,10 @@
/**
* @return the content that gets published
+ * @throws Exception if there is a problem obtaining the node content
* @since 0.6
*/
- public byte[] getContent() {
+ public byte[] getContent() throws Exception {
return toString().getBytes();
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -23,20 +23,24 @@
*/
package org.jboss.dna.web.jcr.rest.client.json;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.ConnectionErrorMsg;
import static org.jboss.dna.web.jcr.rest.client.IMessages.CreateFileFailedMsg;
import static org.jboss.dna.web.jcr.rest.client.IMessages.CreateFolderFailedMsg;
import static org.jboss.dna.web.jcr.rest.client.IMessages.GetRepositoriesFailedMsg;
import static org.jboss.dna.web.jcr.rest.client.IMessages.GetWorkspacesFailedMsg;
-import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.PublishFailedMsg;
import static org.jboss.dna.web.jcr.rest.client.IMessages.UnpublishFailedMsg;
import java.io.File;
+import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.text.MessageFormat;
import java.util.Collection;
import javax.ws.rs.core.MediaType;
import org.jboss.dna.web.jcr.rest.client.IRestClient;
import org.jboss.dna.web.jcr.rest.client.Logger;
+import org.jboss.dna.web.jcr.rest.client.Status;
+import org.jboss.dna.web.jcr.rest.client.Utils;
+import org.jboss.dna.web.jcr.rest.client.Status.Severity;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
@@ -66,26 +70,33 @@
File file ) throws Exception {
Logger.trace(JsonRestClient.class,
null,
- "createFileNode: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ "createFileNode: workspace=" + workspace.getName() + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileNode fileNode = new FileNode(workspace, path, file);
HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.POST);
try {
- Logger.trace(JsonRestClient.class, null, "createFileNode: file node=" + fileNode); //$NON-NLS-1$
+ Logger.trace(JsonRestClient.class, null, "createFileNode: create node=" + fileNode); //$NON-NLS-1$
connection.getOutputStream().write(fileNode.getContent());
// make sure node was created
if (connection.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
- String pattern = MESSAGES.getString(CreateFileFailedMsg);
- String msg = MessageFormat.format(pattern,
- file.getName(),
- path,
- workspace.getName(),
- connection.getResponseCode());
+ // log
+ Status status = new Status(Severity.ERROR, Utils.getMessage(ConnectionErrorMsg,
+ connection.getResponseCode(),
+ "createFileNode"), null); //$NON-NLS-1$
+ Logger.log(JsonRestClient.class, status);
+
+ // throw exception
+ String msg = Utils.getMessage(CreateFileFailedMsg,
+ file.getName(),
+ path,
+ workspace.getName(),
+ connection.getResponseCode());
throw new RuntimeException(msg);
}
} finally {
if (connection != null) {
+ Logger.trace(JsonRestClient.class, null, "createFileNode: " + connection.getResponseMessage()); //$NON-NLS-1$
connection.disconnect();
}
}
@@ -101,22 +112,29 @@
*/
private void createFolderNode( Workspace workspace,
String path ) throws Exception {
- Logger.trace(JsonRestClient.class, null, "createFolderNode: workspace=" + workspace + ", path=" + path); //$NON-NLS-1$//$NON-NLS-2$
+ Logger.trace(JsonRestClient.class, null, "createFolderNode: workspace=" + workspace.getName() + ", path=" + path); //$NON-NLS-1$//$NON-NLS-2$
FolderNode folderNode = new FolderNode(workspace, path);
HttpURLConnection connection = openConnection(folderNode.getUrl(), RequestMethod.POST);
try {
- Logger.trace(JsonRestClient.class, null, "createFolderNode: folder node=" + folderNode); //$NON-NLS-1$
+ Logger.trace(JsonRestClient.class, null, "createFolderNode: create node=" + folderNode); //$NON-NLS-1$
connection.getOutputStream().write(folderNode.getContent());
// make sure node was created
if (connection.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
- String pattern = MESSAGES.getString(CreateFolderFailedMsg);
- String msg = MessageFormat.format(pattern, path, workspace.getName(), connection.getResponseCode());
+ // log
+ Status status = new Status(Severity.ERROR, Utils.getMessage(ConnectionErrorMsg,
+ connection.getResponseCode(),
+ "createFolderNode"), null); //$NON-NLS-1$
+ Logger.log(JsonRestClient.class, status);
+
+ // throw exception
+ String msg = Utils.getMessage(CreateFolderFailedMsg, path, workspace.getName(), connection.getResponseCode());
throw new RuntimeException(msg);
}
} finally {
if (connection != null) {
+ Logger.trace(JsonRestClient.class, null, "createFolderNode: " + connection.getResponseMessage()); //$NON-NLS-1$
connection.disconnect();
}
}
@@ -132,7 +150,7 @@
*/
private void ensureFolderExists( Workspace workspace,
String folderPath ) throws Exception {
- Logger.trace(JsonRestClient.class, null, "ensureFolderExists: workspace=" + workspace + ", path=" + folderPath); //$NON-NLS-1$//$NON-NLS-2$
+ Logger.trace(JsonRestClient.class, null, "ensureFolderExists: workspace=" + workspace.getName() + ", path=" + folderPath); //$NON-NLS-1$//$NON-NLS-2$
FolderNode folderNode = new FolderNode(workspace, folderPath);
if (!pathExists(folderNode.getUrl())) {
@@ -171,7 +189,9 @@
* @since 0.6
*/
public Collection<Repository> getRepositories( Server server ) throws Exception {
+ Utils.nullArgumentCheck("server", server); //$NON-NLS-1$
Logger.trace(JsonRestClient.class, null, "getRepositories: server=" + server); //$NON-NLS-1$
+
ServerNode serverNode = new ServerNode(server);
HttpURLConnection connection = openConnection(serverNode.getFindRepositoriesUrl(), RequestMethod.GET);
@@ -180,12 +200,18 @@
return serverNode.getRepositories(JsonUtils.readInputStream(connection));
}
+ // log
+ Status status = new Status(Severity.ERROR, Utils.getMessage(ConnectionErrorMsg,
+ connection.getResponseCode(),
+ "getRepositories"), null); //$NON-NLS-1$
+ Logger.log(JsonRestClient.class, status);
+
// not a good response code
- String pattern = MESSAGES.getString(GetRepositoriesFailedMsg);
- String msg = MessageFormat.format(pattern, server.getName(), connection.getResponseCode());
+ String msg = Utils.getMessage(GetRepositoriesFailedMsg, server.getName(), connection.getResponseCode());
throw new RuntimeException(msg);
} finally {
if (connection != null) {
+ Logger.trace(JsonRestClient.class, null, "getRepositories: " + connection.getResponseMessage()); //$NON-NLS-1$
connection.disconnect();
}
}
@@ -198,7 +224,9 @@
* @since 0.6
*/
public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
+ Utils.nullArgumentCheck("repository", repository); //$NON-NLS-1$
Logger.trace(JsonRestClient.class, null, "getWorkspaces: repository=" + repository); //$NON-NLS-1$
+
RepositoryNode repositoryNode = new RepositoryNode(repository);
HttpURLConnection connection = openConnection(repositoryNode.getUrl(), RequestMethod.GET);
@@ -207,15 +235,21 @@
return repositoryNode.getWorkspaces(JsonUtils.readInputStream(connection));
}
+ // log
+ Status status = new Status(Severity.ERROR, Utils.getMessage(ConnectionErrorMsg,
+ connection.getResponseCode(),
+ "getWorkspaces"), null); //$NON-NLS-1$
+ Logger.log(JsonRestClient.class, status);
+
// not a good response code
- String pattern = MESSAGES.getString(GetWorkspacesFailedMsg);
- String msg = MessageFormat.format(pattern,
- repository.getName(),
- repository.getServer().getName(),
- connection.getResponseCode());
+ String msg = Utils.getMessage(GetWorkspacesFailedMsg,
+ repository.getName(),
+ repository.getServer().getName(),
+ connection.getResponseCode());
throw new RuntimeException(msg);
} finally {
if (connection != null) {
+ Logger.trace(JsonRestClient.class, null, "getWorkspaces: " + connection.getResponseMessage()); //$NON-NLS-1$
connection.disconnect();
}
}
@@ -249,10 +283,10 @@
HttpURLConnection connection = openConnection(url, RequestMethod.GET);
try {
- Logger.trace(JsonRestClient.class, null, "pathExists: response code=" + connection.getResponseCode()); //$NON-NLS-1$
return (connection.getResponseCode() == HttpURLConnection.HTTP_OK);
} finally {
if (connection != null) {
+ Logger.trace(JsonRestClient.class, null, "pathExists: " + connection.getResponseMessage()); //$NON-NLS-1$
connection.disconnect();
}
}
@@ -269,9 +303,6 @@
protected boolean pathExists( Workspace workspace,
String path,
File file ) throws Exception {
- Logger.trace(JsonRestClient.class,
- null,
- "pathExists: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
FileNode fileNode = new FileNode(workspace, path, file);
return pathExists(fileNode.getUrl());
}
@@ -283,24 +314,35 @@
* java.lang.String, java.io.File)
* @since 0.6
*/
- public void publish( Workspace workspace,
- String path,
- File file ) throws Exception {
+ public Status publish( Workspace workspace,
+ String path,
+ File file ) {
+ Utils.nullArgumentCheck("workspace", workspace); //$NON-NLS-1$
+ Utils.nullArgumentCheck("path", path); //$NON-NLS-1$
+ Utils.nullArgumentCheck("file", file); //$NON-NLS-1$
Logger.trace(JsonRestClient.class,
null,
- "publish: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "publish: workspace=" + workspace.getName() + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- // see if file exists at that path
- if (pathExists(workspace, path, file)) {
- // must be an update
- updateFileNode(workspace, path, file);
- } else {
- // doesn't exist so make sure the parent path exists
- ensureFolderExists(workspace, path);
+ try {
+ // first delete if file exists at that path
+ if (pathExists(workspace, path, file)) {
+ unpublish(workspace, path, file);
+ } else {
+ // doesn't exist so make sure the parent path exists
+ ensureFolderExists(workspace, path);
+ }
- // publish new file
+ // publish file
createFileNode(workspace, path, file);
+ } catch (Exception e) {
+ return new Status(Severity.ERROR, Utils.getMessage(PublishFailedMsg,
+ file.getAbsolutePath(),
+ path,
+ workspace.getName()), e);
}
+
+ return Status.OK_STATUS;
}
/**
@@ -310,54 +352,55 @@
* java.lang.String, java.io.File)
* @since 0.6
*/
- public void unpublish( Workspace workspace,
- String path,
- File file ) throws Exception {
+ public Status unpublish( Workspace workspace,
+ String path,
+ File file ) {
+ Utils.nullArgumentCheck("workspace", workspace); //$NON-NLS-1$
+ Utils.nullArgumentCheck("path", path); //$NON-NLS-1$
+ Utils.nullArgumentCheck("file", file); //$NON-NLS-1$
Logger.trace(JsonRestClient.class,
null,
- "publish: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- FileNode fileNode = new FileNode(workspace, path, file);
- HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.DELETE);
+ "unpublish: workspace=" + workspace.getName() + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ HttpURLConnection connection = null;
+
try {
- if (connection.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT) {
- String pattern = MESSAGES.getString(UnpublishFailedMsg);
- String msg = MessageFormat.format(pattern,
- file.getName(),
- workspace.getName(),
- path,
- connection.getResponseCode());
+ FileNode fileNode = new FileNode(workspace, path, file);
+ connection = openConnection(fileNode.getUrl(), RequestMethod.DELETE);
+ int responseCode = connection.getResponseCode();
+
+ if (responseCode != HttpURLConnection.HTTP_NO_CONTENT) {
+ // check to see if the file was never published
+ if (!pathExists(fileNode.getUrl())) {
+ return new Status(Severity.INFO, Utils.getMessage(PublishFailedMsg,
+ file.getAbsolutePath(),
+ workspace.getName(),
+ path), null);
+ }
+
+ // unexpected result
+ Status status = new Status(Severity.ERROR, Utils.getMessage(ConnectionErrorMsg, responseCode, "unpublish"), null); //$NON-NLS-1$
+ Logger.log(JsonRestClient.class, status);
+
+ // throw exception
+ String msg = Utils.getMessage(UnpublishFailedMsg, file.getName(), workspace.getName(), path, responseCode);
throw new RuntimeException(msg);
}
+
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ return new Status(Severity.ERROR, Utils.getMessage(PublishFailedMsg,
+ workspace.getName(),
+ path,
+ file.getAbsolutePath()), e);
} finally {
if (connection != null) {
- connection.disconnect();
- }
- }
- }
+ try {
+ Logger.trace(JsonRestClient.class, null, "unpublish: " + connection.getResponseMessage()); //$NON-NLS-1$
+ } catch (IOException e) {
+ Logger.log(JsonRestClient.class, new Status(Severity.ERROR, null, e));
+ }
- /**
- * Updates a file node in the specified workspace. Note: All parent folders are assumed to already exist.
- *
- * @param workspace the workspace where the file node is being updated
- * @param path the path to the folder where the file node is being updated
- * @param file the file whose contents will be contained in the file node being created
- * @throws Exception if there is a problem creating the file
- * @since 0.6
- */
- private void updateFileNode( Workspace workspace,
- String path,
- File file ) throws Exception {
- Logger.trace(JsonRestClient.class,
- null,
- "updateFileNode: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- FileNode fileNode = new FileNode(workspace, path, file);
- HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.PUT);
-
- try {
- connection.getOutputStream().write(fileNode.getContent());
- } finally {
- if (connection != null) {
connection.disconnect();
}
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import org.jboss.dna.web.jcr.rest.client.Utils;
/**
* @author Dan Florian
@@ -38,23 +39,26 @@
// ===========================================================================================================================
/**
- * @param text the text whose escape sequences will be replaced with the actual characters
+ * @param text the text whose escape sequences will be replaced with the actual characters (never <code>null</code>)
* @return the decoded text
* @since 0.6
*/
public static String decodeEscaping( String text ) {
+ Utils.nullArgumentCheck("text", text); //$NON-NLS-1$
return text.replace("%3a", ":"); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Note: The connection is not disconnected during this method.
*
- * @param connection the connection whose input stream is going to be read from
- * @return the data read from the connection input stream
+ * @param connection the connection whose input stream is going to be read from (never <code>null</code>)
+ * @return the data read from the connection input stream (never <code>null</code>)
* @throws IOException if there is a problem reading from the connection
* @since 0.6
*/
public static String readInputStream( HttpURLConnection connection ) throws IOException {
+ Utils.nullArgumentCheck("connection", connection); //$NON-NLS-1$
+
InputStream stream = connection.getInputStream();
int bytesRead;
byte[] bytes = new byte[1024];
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -28,6 +28,7 @@
import java.util.Collection;
import java.util.Iterator;
import org.codehaus.jettison.json.JSONObject;
+import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
@@ -91,6 +92,7 @@
*/
@SuppressWarnings( "unchecked" )
public Collection<Workspace> getWorkspaces( String jsonResponse ) throws Exception {
+ Utils.nullArgumentCheck("jsonResponse", jsonResponse); //$NON-NLS-1$
Collection<Workspace> workspaces = new ArrayList<Workspace>();
JSONObject jsonObj = new JSONObject(jsonResponse);
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -29,6 +29,7 @@
import java.util.Iterator;
import org.codehaus.jettison.json.JSONObject;
import org.jboss.dna.web.jcr.rest.client.Logger;
+import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
@@ -104,6 +105,7 @@
*/
@SuppressWarnings( "unchecked" )
public Collection<Repository> getRepositories( String jsonResponse ) throws Exception {
+ Utils.nullArgumentCheck("jsonResponse", jsonResponse); //$NON-NLS-1$
Collection<Repository> repositories = new ArrayList<Repository>();
Logger.trace(ServerNode.class, null, "getRepositories:jsonResponse=" + jsonResponse); //$NON-NLS-1$
JSONObject jsonObj = new JSONObject(jsonResponse);
@@ -112,7 +114,7 @@
for (Iterator<String> itr = jsonObj.keys(); itr.hasNext();) {
Repository repository = new Repository(itr.next(), this.server);
repositories.add(repository);
- Logger.trace(ServerNode.class, null, "getRepositories:repository=" + repository); //$NON-NLS-1$
+ Logger.trace(ServerNode.class, null, "getRepositories: adding repository=" + repository); //$NON-NLS-1$
}
return repositories;
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties 2009-07-24 18:13:16 UTC (rev 1130)
@@ -25,6 +25,8 @@
ErrorRestoringServerRegistry = Error trying to restore the server registry from file "{0}"
ErrorSavingServerRegistry = Error trying to save the server registry to "{0}"
+NullArgumentMsg = The argument "{0}" may not be null.
+
RepositoryEmptyNameMsg = A repository name cannot be empty
RepositoryNullServerMsg = A repository server cannot be null
RepositoryShortDescription = DNA Repository: Name: {0}, {1}
@@ -49,8 +51,11 @@
# JsonRestClient messages
+ConnectionErrorMsg = response code={0}: {1}
CreateFileFailedMsg = Creating the "{0}" file node in folder "{1}" in workspace "{2}" failed with HTTP response code of "{3}"
CreateFolderFailedMsg = Creating the "{0}" folder node in workspace "{1}" failed with HTTP response code of "{2}"
GetRepositoriesFailedMsg = Obtaining the repositories from server "{0}" failed with HTTP response code of "{1}"
GetWorkspacesFailedMsg = Obtaining the workspaces from repository "{0}" at server "{1}" failed with HTTP response code of "{2}"
-UnpublishFailedMsg = The file "{0}" could not be unpublished in repository "{1}" at path "{2}". The HTTP response code was "{3}".
+PublishFailedMsg = Publishing file "{0}" to path "{1}" in workspace "{2}" failed.
+UnpublishFailedMsg = The file "{0}" could not be unpublished in workspace "{1}" at path "{2}". The HTTP response code was "{3}".
+UnpublishNeverPublishedMsg = The file "{0}" could not be unpublished in workspace "{1}" at path "{2}" because it could not be found.
Modified: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -66,9 +66,10 @@
* java.lang.String, java.io.File)
* @since 0.6
*/
- public void publish( Workspace workspace,
- String path,
- File file ) throws Exception {
+ public Status publish( Workspace workspace,
+ String path,
+ File file ) {
+ return null;
}
/**
@@ -78,9 +79,10 @@
* java.lang.String, java.io.File)
* @since 0.6
*/
- public void unpublish( Workspace workspace,
- String path,
- File file ) throws Exception {
+ public Status unpublish( Workspace workspace,
+ String path,
+ File file ) {
+ return null;
}
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java 2009-07-24 13:42:58 UTC (rev 1129)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java 2009-07-24 18:13:16 UTC (rev 1130)
@@ -61,7 +61,7 @@
private static final String WORKSPACE_PATH = "/myproject/myfolder/"; //$NON-NLS-1$
private static final String FILE_PATH = WORKSPACE_PATH + "document.txt"; //$NON-NLS-1$
-// private static final String BINARY_FILE_PATH = WORKSPACE_PATH + "picture.txt"; //$NON-NLS-1$
+ private static final String BINARY_FILE_PATH = WORKSPACE_PATH + "picture.jpg"; //$NON-NLS-1$
// ===========================================================================================================================
// Fields
@@ -103,22 +103,51 @@
assertThat(workspaces.iterator().next(), is(WORKSPACE1));
}
- // @Test
- public void shouldPublishResource() throws Exception {
+ @Test
+ public void shouldNotUnpublishNonexistentFile() throws Exception {
+ File file = new File("bogusfile"); //$NON-NLS-1$
+ assertThat(this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, file).isInfo(), is(true));
+ }
+
+ @Test
+ public void shouldPublishBinaryResource() throws Exception {
+ URL binaryFile = getClass().getResource(BINARY_FILE_PATH);
+ assertThat(binaryFile, is(notNullValue()));
+
+ // publish
+ File file = new File(binaryFile.toURI());
+ assertThat(this.restClient.publish(WORKSPACE1, WORKSPACE_PATH, file).isOk(), is(true));
+
+ // confirm it exists in repository
+ assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1, WORKSPACE_PATH, file), is(true));
+
+ // TODO: get jcr:data and compare
+ }
+
+ @Test
+ public void shouldPublishTextResource() throws Exception {
URL textFile = getClass().getResource(FILE_PATH);
assertThat(textFile, is(notNullValue()));
// publish
File file = new File(textFile.toURI());
- this.restClient.publish(WORKSPACE1, WORKSPACE_PATH, file);
+ assertThat(this.restClient.publish(WORKSPACE1, WORKSPACE_PATH, file).isOk(), is(true));
// confirm it exists in repository
assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1, WORKSPACE_PATH, file), is(true));
}
- // @Test
+ @Test
public void shouldUnpublish() throws Exception {
- this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, new File(FILE_PATH));
+ // first publish
+ shouldPublishTextResource();
+
+ URL textFile = getClass().getResource(FILE_PATH);
+ File file = new File(textFile.toURI());
+ assertThat(this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, file).isOk(), is(true));
+
+ // confirm it does not exist in repository
+ assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1, WORKSPACE_PATH, file), is(false));
}
}
16 years, 5 months
DNA SVN: r1129 - trunk/docs/reference/src/main/docbook/en-US/content/connectors.
by dna-commits@lists.jboss.org
Author: bcarothers
Date: 2009-07-24 09:42:58 -0400 (Fri, 24 Jul 2009)
New Revision: 1129
Modified:
trunk/docs/reference/src/main/docbook/en-US/content/connectors/file_system.xml
trunk/docs/reference/src/main/docbook/en-US/content/connectors/infinispan.xml
trunk/docs/reference/src/main/docbook/en-US/content/connectors/jboss_cache.xml
Log:
Updated documentation to reflect recent connector changes
Modified: trunk/docs/reference/src/main/docbook/en-US/content/connectors/file_system.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/connectors/file_system.xml 2009-07-24 06:10:33 UTC (rev 1128)
+++ trunk/docs/reference/src/main/docbook/en-US/content/connectors/file_system.xml 2009-07-24 13:42:58 UTC (rev 1129)
@@ -35,7 +35,16 @@
The connector considers a workspace name to be the path to the directory on the file system that represents the root of that
workspace. Each connector can define whether it allows new workspaces can be created, but if so the names of the new workspaces
must represent valid paths to existing directories.
- </para>
+ <note>
+ <para>
+ The file nodes returned by this connector will have a primary type of <code>nt:file</code> and a child node named <code>jcr:content</code>.
+ The <code>jcr:content</code> node will have a primary type of <code>dna:resource</code>. The <code>dna:resource</code> node type is equivalent
+ to the built-in <code>nt:resource</code> node type in all ways except one: it does not extend <code>mix:referenceable</code>. This is because
+ DNA cannot assign a persistent UUID to the files in the file system or guarantee that no other process will not move or delete the files outside of DNA.
+ The <code>mix:referenceable</code> node type cannot be implemented if either of these conditions cannot be met.
+ </para>
+ </note>
+ </para>
<para>
The &FileSystemSource; class provides a number of JavaBean properties that control its behavior:
</para>
@@ -56,16 +65,15 @@
<entry>The name of the repository source, which is used by the &RepositoryService; when obtaining a &RepositoryConnection; by name.</entry>
</row>
<row>
- <entry>directoryForDefaultWorkspace</entry>
- <entry>Optional property that, if used, specifies the file system path to the existing directory that should be used for the
- default workspace. If null (or not specified), the source will use the current working directory of this virtual machine
- (as defined by <code>new File(".").getAbsolutePath()</code>.</entry>
+ <entry>cacheTimeToLiveInMilliseconds</entry>
+ <entry>Optional property that, if used, defines the maximum time in milliseconds that any information returned by this connector
+ is allowed to be cached before being considered invalid. When not used, this source will not define a specific
+ duration for caching information.</entry>
</row>
<row>
- <entry>predefinedWorkspaceNames</entry>
- <entry>Optional property that, if used, defines names of the workspaces that are predefined and need not be created before being used.
- This can be coupled with a "fase" value for the "creatingWorkspaceAllowed" property to allow only the use of only predefined workspaces.
- </entry>
+ <entry>defaultWorkspaceName</entry>
+ <entry>Optional property that is initialized to <code>"default"</code> and which defines the name for the workspace that will be used by default
+ if none is specified.</entry>
</row>
<row>
<entry>creatingWorkspaceAllowed</entry>
@@ -73,21 +81,42 @@
</entry>
</row>
<row>
+ <entry>predefinedWorkspaceNames</entry>
+ <entry>Optional property that, if used, defines names of the workspaces that are predefined and need not be created before being used.
+ This can be coupled with a "false" value for the "creatingWorkspaceAllowed" property to allow only the use of only predefined workspaces.
+ </entry>
+ </row>
+ <row>
<entry>retryLimit</entry>
<entry>Optional property that, if used, defines the number of times that any single operation on a &RepositoryConnection; to this source should be retried
following a communication failure. The default value is '0'.</entry>
</row>
<row>
- <entry>cacheTimeToLiveInMilliseconds</entry>
- <entry>Optional property that, if used, defines the maximum time in milliseconds that any information returned by this connector
- is allowed to be cached before being considered invalid. When not used, this source will not define a specific
- duration for caching information.</entry>
- </row>
+ <entry>rootNodeUuid</entry>
+ <entry>Optional property that, if used, specifies the UUID that should be used for the root node of each workspace. If no value is
+ specified, a random UUID is generated each time that the repository is started.</entry>
+ </row>
+ <row>
+ <entry>workspaceRootPath</entry>
+ <entry>
+ <para>Optional property that, if used, specifies a path on the local file system to the root of all workspaces. The source will will
+ use the name of the workspace as a relative path from the <code>workspaceRootPath</code> to determine the path for a particular workspace.
+ If no value (or a <code>null</code> value) is specified, the source will use the name of the workspace as a relative path from the current working
+ directory of this virtual machine (as defined by <code>new File(".")</code>.
+ </para>
+ <para>As an example for a workspace named <code>"default/foo"</code>,
+ the source will use <code>new File(workspaceRootPath, "default/foo")</code> as the source directory for the connector if <code>workspaceRootPath</code> is set
+ to a non-null value, or <code>new File(".", "default/foo")</code> as the source directory for the connector if <code>workspaceRootPath</code> is
+ set to <code>null</code>.
+ </para>
+ </entry>
+ </row>
+
</tbody>
</tgroup>
</table>
<para>
- Using the file system connector is used by creating in the &JcrConfiguration; a repository source that uses the &InMemoryRepositorySource; class.
+ The file system connector is used by creating in the &JcrConfiguration; a repository source that uses the &InMemoryRepositorySource; class.
For example:
</para>
<programlisting role="JAVA"><![CDATA[
@@ -95,7 +124,10 @@
config.repositorySource("source A")
.usingClass(FileSystemSource.class)
.setDescription("The repository for our content")
- .setProperty("directoryForDefaultWorkspace", "file://some/file/path")
+ .setProperty("workspaceRootPath", "/home/content/someApp")
+ .setProperty("defaultWorkspaceName", "prod")
+ .setProperty("predefinedWorkspaceNames", new String[] { "staging", "dev"})
+ .setProperty("rootNodeUuid", UUID.fromString("fd129c12-81a8-42ed-aa4b-820dba49e6f0")
.setProperty("creatingWorkspaceAllowed", "false");
]]></programlisting>
</chapter>
Modified: trunk/docs/reference/src/main/docbook/en-US/content/connectors/infinispan.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/connectors/infinispan.xml 2009-07-24 06:10:33 UTC (rev 1128)
+++ trunk/docs/reference/src/main/docbook/en-US/content/connectors/infinispan.xml 2009-07-24 13:42:58 UTC (rev 1129)
@@ -67,18 +67,13 @@
when creating a new Infinispan CacheManager instance.</entry>
</row>
<row>
- <entry>retryLimit</entry>
- <entry>Optional property that, if used, defines the number of times that any single operation on a &RepositoryConnection; to this source should be retried
- following a communication failure. The default value is '0'.</entry>
- </row>
- <row>
<entry>defaultCachePolicy</entry>
<entry>Optional property that, if used, defines the default for how long this information provided by this source may to be
cached by other, higher-level components. The default value of null implies that this source does not define a specific
duration for caching information provided by this repository source.</entry>
</row>
<row>
- <entry>nameOfDefaultWorkspace</entry>
+ <entry>defaultWorkspaceName</entry>
<entry>Optional property that is initialized to an empty string and which defines the name for the workspace that will be used by default
if none is specified.</entry>
</row>
@@ -86,8 +81,31 @@
<entry>predefinedWorkspaceNames</entry>
<entry>Optional property that defines the names of the workspaces that exist and that are available for use without having to create them.</entry>
</row>
+ <row>
+ <entry>retryLimit</entry>
+ <entry>Optional property that, if used, defines the number of times that any single operation on a &RepositoryConnection; to this source should be retried
+ following a communication failure. The default value is '0'.</entry>
+ </row>
+ <row>
+ <entry>rootNodeUuid</entry>
+ <entry>Optional property that, if used, specifies the UUID that should be used for the root node of each workspace. If no value is
+ specified, a random UUID is generated each time that the repository is started.</entry>
+ </row>
</tbody>
</tgroup>
</table>
-</chapter>
+ <para>
+ The Infinispan connector is used by creating in the &JcrConfiguration; a repository source that uses the &InfinispanSource; class.
+ For example:
+ </para>
+ <programlisting role="JAVA"><![CDATA[
+JcrConfiguration config = ...
+config.repositorySource("source A")
+ .usingClass(InfinispanSource.class)
+ .setDescription("The repository for our content")
+ .setProperty("defaultWorkspaceName", "prod")
+ .setProperty("rootNodeUuid", UUID.fromString("84b73fc8-81a8-42ed-aa4b-3905094966f0")
+ .setProperty("predefinedWorkspaceNames", new String[] { "staging", "dev"});
+ ]]></programlisting>
+ </chapter>
Modified: trunk/docs/reference/src/main/docbook/en-US/content/connectors/jboss_cache.xml
===================================================================
--- trunk/docs/reference/src/main/docbook/en-US/content/connectors/jboss_cache.xml 2009-07-24 06:10:33 UTC (rev 1128)
+++ trunk/docs/reference/src/main/docbook/en-US/content/connectors/jboss_cache.xml 2009-07-24 13:42:58 UTC (rev 1129)
@@ -73,23 +73,17 @@
a special way.</entry>
</row>
<row>
- <entry>uuidPropertyName</entry>
- <entry>Optional property that, if used, defines the property that should be used to find the UUID value for each node
- in the cache. "<code>dna:uuid</code>" is the default.</entry>
+ <entry>creatingWorkspacesAllowed</entry>
+ <entry>Optional property that is by default 'true' that defines whether clients can create new workspaces.</entry>
</row>
<row>
- <entry>retryLimit</entry>
- <entry>Optional property that, if used, defines the number of times that any single operation on a &RepositoryConnection; to this source should be retried
- following a communication failure. The default value is '0'.</entry>
- </row>
- <row>
<entry>defaultCachePolicy</entry>
<entry>Optional property that, if used, defines the default for how long this information provided by this source may to be
cached by other, higher-level components. The default value of null implies that this source does not define a specific
duration for caching information provided by this repository source.</entry>
</row>
<row>
- <entry>nameOfDefaultWorkspace</entry>
+ <entry>defaultWorkspaceName</entry>
<entry>Optional property that is initialized to an empty string and which defines the name for the workspace that will be used by default
if none is specified.</entry>
</row>
@@ -98,11 +92,36 @@
<entry>Optional property that defines the names of the workspaces that exist and that are available for use without having to create them.</entry>
</row>
<row>
- <entry>creatingWorkspacesAllowed</entry>
- <entry>Optional property that is by default 'true' that defines whether clients can create new workspaces.</entry>
+ <entry>retryLimit</entry>
+ <entry>Optional property that, if used, defines the number of times that any single operation on a &RepositoryConnection; to this source should be retried
+ following a communication failure. The default value is '0'.</entry>
</row>
+ <row>
+ <entry>rootNodeUuid</entry>
+ <entry>Optional property that, if used, specifies the UUID that should be used for the root node of each workspace. If no value is
+ specified, a random UUID is generated each time that the repository is started.</entry>
+ </row>
+ <row>
+ <entry>uuidPropertyName</entry>
+ <entry>Optional property that, if used, defines the property that should be used to find the UUID value for each node
+ in the cache. "<code>dna:uuid</code>" is the default.</entry>
+ </row>
+
</tbody>
</tgroup>
</table>
-</chapter>
+ <para>
+ The JBoss Cache connector is used by creating in the &JcrConfiguration; a repository source that uses the &JBossCacheSource; class.
+ For example:
+ </para>
+ <programlisting role="JAVA"><![CDATA[
+JcrConfiguration config = ...
+config.repositorySource("source A")
+ .usingClass(JBossCacheSource.class)
+ .setDescription("The repository for our content")
+ .setProperty("defaultWorkspaceName", "prod")
+ .setProperty("rootNodeUuid", UUID.fromString("12083e7e-2b55-4c8d-954d-627a9f5c45c2"))
+ .setProperty("predefinedWorkspaceNames", new String[] { "staging", "dev"});
+ ]]></programlisting>
+ </chapter>
16 years, 5 months
DNA SVN: r1128 - in trunk/dna-integration-tests/src/test/resources/tck/filesystem: defaultWorkspace and 3 other directories.
by dna-commits@lists.jboss.org
Author: bcarothers
Date: 2009-07-24 02:10:33 -0400 (Fri, 24 Jul 2009)
New Revision: 1128
Added:
trunk/dna-integration-tests/src/test/resources/tck/filesystem/defaultWorkspace/
trunk/dna-integration-tests/src/test/resources/tck/filesystem/defaultWorkspace/testroot/
trunk/dna-integration-tests/src/test/resources/tck/filesystem/defaultWorkspace/testroot/node1
trunk/dna-integration-tests/src/test/resources/tck/filesystem/otherWorkspace/
trunk/dna-integration-tests/src/test/resources/tck/filesystem/otherWorkspace/testroot/
trunk/dna-integration-tests/src/test/resources/tck/filesystem/otherWorkspace/testroot/nodeInOtherWorkspace
Log:
Added missing repository content for the filesystem TCK test to fix the nightly build.
Added: trunk/dna-integration-tests/src/test/resources/tck/filesystem/defaultWorkspace/testroot/node1
===================================================================
--- trunk/dna-integration-tests/src/test/resources/tck/filesystem/defaultWorkspace/testroot/node1 (rev 0)
+++ trunk/dna-integration-tests/src/test/resources/tck/filesystem/defaultWorkspace/testroot/node1 2009-07-24 06:10:33 UTC (rev 1128)
@@ -0,0 +1 @@
+Test content
Added: trunk/dna-integration-tests/src/test/resources/tck/filesystem/otherWorkspace/testroot/nodeInOtherWorkspace
===================================================================
16 years, 5 months
DNA SVN: r1127 - in trunk/dna-jcr/src/main: resources/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: bcarothers
Date: 2009-07-23 22:38:37 -0400 (Thu, 23 Jul 2009)
New Revision: 1127
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
Log:
DNA-471 Add Messages to JCR Exceptions with No Message
Committed patch (DNA-471_updated.patch) adds messages for all of the non-trivial exceptions that don't already have messages.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -202,7 +202,7 @@
public String getUUID() throws RepositoryException {
// Return "jcr:uuid" only if node is referenceable
if (!isReferenceable()) {
- throw new UnsupportedRepositoryOperationException();
+ throw new UnsupportedRepositoryOperationException(JcrI18n.nodeNotReferenceable.text());
}
PropertyInfo<JcrPropertyPayload> uuidProp = nodeInfo().getProperty(JcrLexicon.UUID);
if (uuidProp == null) {
@@ -361,7 +361,7 @@
return false;
}
- public CorrespondenceId getCorrespondenceId() throws RepositoryException {
+ protected CorrespondenceId getCorrespondenceId() throws RepositoryException {
if (this.isReferenceable()) return new CorrespondenceId(getUUID());
assert !this.isRoot(); // the root must be referenceable
@@ -829,7 +829,7 @@
}
if (!canAddMixin(mixinName)) {
- throw new ConstraintViolationException();
+ throw new ConstraintViolationException(JcrI18n.cannotAddMixin.text(mixinName));
}
this.editor().addMixin(mixinCandidateType);
@@ -864,13 +864,13 @@
Property existingMixinProperty = getProperty(JcrLexicon.MIXIN_TYPES);
if (existingMixinProperty == null) {
- throw new NoSuchNodeTypeException();
+ throw new NoSuchNodeTypeException(JcrI18n.invalidMixinTypeForNode.text(mixinName, getPath()));
}
Value[] existingMixinValues = existingMixinProperty.getValues();
if (existingMixinValues.length == 0) {
- throw new NoSuchNodeTypeException();
+ throw new NoSuchNodeTypeException(JcrI18n.invalidMixinTypeForNode.text(mixinName, getPath()));
}
// ------------------------------------------------------------------------------
@@ -889,7 +889,7 @@
newMixinValues[j++] = existingMixinValues[i];
newMixinNames.add(cache.nameFactory.create(existingMixinValues[i].getString()));
} else {
- throw new NoSuchNodeTypeException();
+ throw new NoSuchNodeTypeException(JcrI18n.invalidMixinTypeForNode.text(mixinName, getPath()));
}
}
}
@@ -922,7 +922,11 @@
}
if (match == null) {
- throw new ConstraintViolationException();
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("property",
+ property.getName(),
+ getPath(),
+ primaryTypeName,
+ newMixinNames));
}
}
}
@@ -946,7 +950,11 @@
true);
if (match == null) {
- throw new ConstraintViolationException();
+ throw new ConstraintViolationException(JcrI18n.noDefinition.text("child node",
+ node.getName(),
+ getPath(),
+ primaryTypeName,
+ newMixinNames));
}
}
}
@@ -1556,13 +1564,15 @@
String destChildRelPath ) throws UnsupportedRepositoryOperationException, RepositoryException {
// This implementation is correct, except for not calling the SessionCache or graph layer to do the re-order
if (!getPrimaryNodeType().hasOrderableChildNodes()) {
- throw new UnsupportedRepositoryOperationException();
+ throw new UnsupportedRepositoryOperationException(
+ JcrI18n.notOrderable.text(getPrimaryNodeType().getName(), getPath()));
}
PathFactory pathFactory = this.cache.pathFactory();
Path srcPath = pathFactory.create(srcChildRelPath);
if (srcPath.isAbsolute() || srcPath.size() != 1) {
- throw new ItemNotFoundException();
+ throw new ItemNotFoundException(JcrI18n.pathNotFound.text(srcPath.getString(cache.context().getNamespaceRegistry()),
+ cache.session().workspace().getName()));
}
// getLastSegment should return the only segment, since we verified that size() == 1
Path.Segment sourceSegment = srcPath.getLastSegment();
@@ -1578,7 +1588,9 @@
if (destChildRelPath != null) {
Path destPath = pathFactory.create(destChildRelPath);
if (destPath.isAbsolute() || destPath.size() != 1) {
- throw new ItemNotFoundException();
+ throw new ItemNotFoundException(
+ JcrI18n.pathNotFound.text(destPath.getString(cache.context().getNamespaceRegistry()),
+ cache.session().workspace().getName()));
}
destSegment = destPath.getLastSegment();
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrContentHandler.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -360,12 +360,18 @@
break;
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
if (existingNodeWithUuid.path().isAtOrAbove(parentStack.firstElement().path())) {
- throw new ConstraintViolationException();
+ throw new ConstraintViolationException(
+ JcrI18n.cannotRemoveParentNodeOfTarget.text(existingNodeWithUuid.getPath(),
+ uuid,
+ parentStack.firstElement().getPath()));
}
existingNodeWithUuid.remove();
break;
case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
- throw new ItemExistsException();
+ throw new ItemExistsException(
+ JcrI18n.itemAlreadyExistsWithUuid.text(uuid,
+ cache().session().workspace().getName(),
+ existingNodeWithUuid.getPath()));
}
} catch (ItemNotFoundException e) {
// there wasn't an existing item, so just continue
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -40,6 +40,7 @@
public static I18n nonInputStreamConsumed;
public static I18n pathNotFound;
public static I18n pathNotFoundRelativeTo;
+ public static I18n pathCannotHaveSameNameSiblingIndex;
public static I18n permissionDenied;
public static I18n repositoryMustBeConfigured;
public static I18n sourceInUse;
@@ -47,6 +48,7 @@
public static I18n fileDoesNotExist;
public static I18n rootNodeHasNoParent;
+ public static I18n childNodeAlreadyExists;
public static I18n noNamespaceWithPrefix;
public static I18n noNamespaceWithUri;
@@ -71,6 +73,7 @@
public static I18n primaryItemNameForPrimaryTypeIsNotValid;
public static I18n primaryItemDoesNotExist;
public static I18n itemNotFoundWithUuid;
+ public static I18n itemAlreadyExistsWithUuid;
public static I18n itemNotFoundAtPath;
public static I18n itemNotFoundAtPathRelativeToReferenceNode;
public static I18n propertyNotFoundOnNode;
@@ -87,11 +90,16 @@
public static I18n unableToSaveNodeThatWasCreatedSincePreviousSave;
public static I18n unableToSetMultiValuedPropertyUsingSingleValue;
public static I18n unableToSetSingleValuedPropertyUsingMultipleValues;
+ public static I18n invalidMethodForSingleValuedProperty;
+ public static I18n invalidMethodForMultiValuedProperty;
public static I18n unableToRefreshBranchBecauseChangesDependOnChangesToNodesOutsideOfBranch;
public static I18n unableToSaveBranchBecauseChangesDependOnChangesToNodesOutsideOfBranch;
public static I18n allPropertyValuesMustHaveSameType;
public static I18n cannotRemoveNodeFromClone;
+ public static I18n cannotRemoveParentNodeOfTarget;
+ public static I18n invalidPropertyType;
+
public static I18n unableToRemoveRootNode;
public static I18n unableToMoveNodeToBeChildOfDecendent;
public static I18n nodeHasAlreadyBeenRemovedFromThisSession;
@@ -146,12 +154,17 @@
public static I18n allNodeTypeTemplatesMustComeFromSameSession;
public static I18n nodeNotReferenceable;
+ public static I18n nodeNotReferenceableUuid;
public static I18n noPendingChangesAllowed;
public static I18n cannotUnregisterSupertype;
public static I18n cannotUnregisterRequiredPrimaryType;
public static I18n cannotUnregisterDefaultPrimaryType;
+ public static I18n cannotAddMixin;
+ public static I18n invalidMixinTypeForNode;
+ public static I18n notOrderable;
+
static {
try {
I18n.initialize(JcrI18n.class);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrMultiValueProperty.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -71,7 +71,7 @@
* @see javax.jcr.Property#getBoolean()
*/
public boolean getBoolean() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -81,7 +81,7 @@
* @see javax.jcr.Property#getDate()
*/
public Calendar getDate() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -91,7 +91,7 @@
* @see javax.jcr.Property#getDouble()
*/
public double getDouble() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -100,7 +100,7 @@
* @see javax.jcr.Property#getNode()
*/
public Node getNode() throws ValueFormatException, RepositoryException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -110,7 +110,7 @@
* @see javax.jcr.Property#getLength()
*/
public long getLength() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -135,7 +135,7 @@
* @see javax.jcr.Property#getLong()
*/
public long getLong() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -145,7 +145,7 @@
* @see javax.jcr.Property#getStream()
*/
public InputStream getStream() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -155,7 +155,7 @@
* @see javax.jcr.Property#getString()
*/
public String getString() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -240,7 +240,7 @@
* @see javax.jcr.Property#getValue()
*/
public Value getValue() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -250,7 +250,7 @@
* @see javax.jcr.Property#setValue(javax.jcr.Value)
*/
public final void setValue( Value value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -260,7 +260,7 @@
* @see javax.jcr.Property#setValue(java.lang.String)
*/
public final void setValue( String value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -270,7 +270,7 @@
* @see javax.jcr.Property#setValue(java.io.InputStream)
*/
public final void setValue( InputStream value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -280,7 +280,7 @@
* @see javax.jcr.Property#setValue(long)
*/
public final void setValue( long value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -290,7 +290,7 @@
* @see javax.jcr.Property#setValue(double)
*/
public final void setValue( double value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -300,7 +300,7 @@
* @see javax.jcr.Property#setValue(java.util.Calendar)
*/
public final void setValue( Calendar value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -310,7 +310,7 @@
* @see javax.jcr.Property#setValue(boolean)
*/
public final void setValue( boolean value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
/**
@@ -320,7 +320,7 @@
* @see javax.jcr.Property#setValue(javax.jcr.Node)
*/
public final void setValue( Node value ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForMultiValuedProperty.text());
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -564,7 +564,7 @@
public Value createValue( Node value ) throws RepositoryException {
if (!value.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(JcrSession.this.namespaces()))) {
- throw new RepositoryException();
+ throw new RepositoryException(JcrI18n.nodeNotReferenceable.text());
}
String uuid = valueFactories.getStringFactory().create(value.getUUID());
return new JcrValue(valueFactories, sessionCache, PropertyType.REFERENCE, uuid);
@@ -772,14 +772,15 @@
Path.Segment newNodeName = destPath.getSegment(destPath.size() - 1);
// Doing a literal test here because the path factory will canonicalize "/node[1]" to "/node"
if (destAbsPath.endsWith("]")) {
- throw new RepositoryException();
+ throw new RepositoryException(JcrI18n.pathCannotHaveSameNameSiblingIndex.text(destAbsPath));
}
AbstractJcrNode sourceNode = getNode(pathFactory.create(srcAbsPath));
AbstractJcrNode newParentNode = getNode(destPath.getParent());
+ String newNodeNameAsString = newNodeName.getString(executionContext.getNamespaceRegistry());
if (newParentNode.hasNode(newNodeName.getString(executionContext.getNamespaceRegistry()))) {
- throw new ItemExistsException();
+ throw new ItemExistsException(JcrI18n.childNodeAlreadyExists.text(newNodeNameAsString, newParentNode.getPath()));
}
newParentNode.editor().moveToBeChild(sourceNode, newNodeName.getName());
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSingleValueProperty.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -116,7 +116,7 @@
* @see javax.jcr.Property#getLengths()
*/
public long[] getLengths() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForSingleValuedProperty.text());
}
/**
@@ -237,7 +237,7 @@
setValue(value.getString());
break;
default:
- throw new RepositoryException();
+ throw new RepositoryException(JcrI18n.invalidPropertyType.text(value.getType()));
}
}
@@ -346,7 +346,7 @@
* @see javax.jcr.Property#getValues()
*/
public Value[] getValues() throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForSingleValuedProperty.text());
}
/**
@@ -355,7 +355,7 @@
* @see javax.jcr.Property#setValue(javax.jcr.Value[])
*/
public void setValue( Value[] values ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForSingleValuedProperty.text());
}
/**
@@ -364,6 +364,6 @@
* @see javax.jcr.Property#setValue(java.lang.String[])
*/
public void setValue( String[] values ) throws ValueFormatException {
- throw new ValueFormatException();
+ throw new ValueFormatException(JcrI18n.invalidMethodForSingleValuedProperty.text());
}
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -279,7 +279,7 @@
case PropertyType.REFERENCE:
return this.getString().equals(that.getString());
default:
- throw new SystemFailureException();
+ throw new SystemFailureException(JcrI18n.invalidPropertyType.text(this.type));
}
} catch (RepositoryException e) {
return false;
@@ -310,7 +310,7 @@
case PropertyType.REFERENCE:
return this.getString().equals(that.getString());
default:
- throw new SystemFailureException();
+ throw new SystemFailureException(JcrI18n.invalidPropertyType.text(this.type));
}
} catch (IOException e) {
return false;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -307,7 +307,7 @@
// Doing a literal test here because the path factory will canonicalize "/node[1]" to "/node"
if (destAbsPath.endsWith("]")) {
- throw new RepositoryException();
+ throw new RepositoryException(JcrI18n.pathCannotHaveSameNameSiblingIndex.text(destAbsPath));
}
try {
@@ -431,7 +431,7 @@
// Doing a literal test here because the path factory will canonicalize "/node[1]" to "/node"
if (destAbsPath.endsWith("]")) {
- throw new RepositoryException();
+ throw new RepositoryException(JcrI18n.pathCannotHaveSameNameSiblingIndex.text(destAbsPath));
}
try {
@@ -538,7 +538,7 @@
// Doing a literal test here because the path factory will canonicalize "/node[1]" to "/node"
if (destAbsPath.endsWith("]")) {
- throw new RepositoryException();
+ throw new RepositoryException(JcrI18n.pathCannotHaveSameNameSiblingIndex.text(destAbsPath));
}
try {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-07-24 02:38:37 UTC (rev 1127)
@@ -937,7 +937,12 @@
true,
skipProtected);
if (definition == null) {
- throw new ConstraintViolationException();
+ throw new ConstraintViolationException(
+ JcrI18n.noDefinition.text("property",
+ readable(name),
+ readable(node.getPath()),
+ readable(payload.getPrimaryTypeName()),
+ readable(payload.getMixinTypeNames())));
}
}
// Create the DNA property ...
@@ -1109,7 +1114,12 @@
newValues,
skipProtected);
if (definition == null) {
- throw new ConstraintViolationException();
+ throw new ConstraintViolationException(
+ JcrI18n.noDefinition.text("property",
+ readable(name),
+ readable(node.getPath()),
+ readable(payload.getPrimaryTypeName()),
+ readable(payload.getMixinTypeNames())));
}
}
// Create the DNA property ...
@@ -1239,8 +1249,8 @@
// The node definition changed, so try to set the property ...
NodeEditor newChildEditor = getEditorFor(existingChild);
try {
- JcrValue value = new JcrValue(factories(), SessionCache.this, PropertyType.STRING, defn.getId()
- .getString());
+ JcrValue value = new JcrValue(factories(), SessionCache.this, PropertyType.STRING,
+ defn.getId().getString());
newChildEditor.setProperty(DnaIntLexicon.NODE_DEFINITON, value);
} catch (ConstraintViolationException e) {
// We can't set this property on the node (according to the node definition).
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-07-24 01:15:00 UTC (rev 1126)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-07-24 02:38:37 UTC (rev 1127)
@@ -30,6 +30,7 @@
nonInputStreamConsumed = This value was already consumed as a non-input stream
pathNotFound = No item exists at path {0} in workspace "{1}"
pathNotFoundRelativeTo = No item exists at path {0} relative to {1} in workspace "{2}"
+pathCannotHaveSameNameSiblingIndex = The path specified by the argument "{0}" cannot have a same-name-sibling index
permissionDenied = Permission denied to perform actions "{1}" on path {0}
repositoryMustBeConfigured = DNA repositories must be configured with either a repository source factory or a repository source
sourceInUse = All sessions must end before a new repository source can be set
@@ -37,6 +38,7 @@
fileDoesNotExist = Unable to find or read the file "{0}"
rootNodeHasNoParent = The root node has no parent node
+childNodeAlreadyExists = A child node named "{0}" already exists at node "{1}"
noNamespaceWithPrefix = There is no namespace with prefix "{0}"
noNamespaceWithUri = There is no namespace with URI "{0}"
@@ -61,6 +63,7 @@
primaryItemNameForPrimaryTypeIsNotValid = The primary type "{0}" for node "{2}" in workspace "{3}" defines an invalid primary item name ("{1}")
primaryItemDoesNotExist = The node "{2}" in workspace "{3}" does not have an item named "{1}" as defined by its primary type "{0}"
itemNotFoundWithUuid = An item with UUID "{0}" could not be found in workspace "{1}": {2}
+itemAlreadyExistsWithUuid = An item with UUID "{0}" already exists in workspace "{1}" at "{2}"
itemNotFoundAtPath = An item at "{0}" could not be found in workspace "{1}"
itemNotFoundAtPathRelativeToReferenceNode = An item at "{0}" relative to "{1}" could not be found in workspace "{2}"
propertyNotFoundOnNode = Property "{0}" does not exist on node "{1}" in workspace "{2}"
@@ -77,10 +80,15 @@
unableToSaveNodeThatWasCreatedSincePreviousSave = Unable to save node "{0}" in workspace "{1}" because it was created since the last save
unableToSetMultiValuedPropertyUsingSingleValue = Unable to set existing multi-valued property "{0}" on node "{1}" in workspace "{2}" using single-value setter methods
unableToSetSingleValuedPropertyUsingMultipleValues = Unable to set existing single-valued property "{0}" on node "{1}" in workspace "{2}" using multi-value setter methods
+invalidMethodForSingleValuedProperty = This method cannot be called on a property with a single value
+invalidMethodForMultiValuedProperty = This method cannot be called on a property with multiple values
unableToRefreshBranchBecauseChangesDependOnChangesToNodesOutsideOfBranch = Unable to refresh "{0}" in workspace "{1}" because it contains changes that depend on changes to nodes outside of this branch
unableToSaveBranchBecauseChangesDependOnChangesToNodesOutsideOfBranch = Unable to save "{0}" in workspace "{1}" because it contains changes that depend on changes to nodes outside of this branch
allPropertyValuesMustHaveSameType = All values of property "{0}" on node "{3}" in workspace "{4}" must all be {2} values (values were: {1})
cannotRemoveNodeFromClone = The node at "{0}" with UUID "{1}" exists in the current workspace but cannot be removed because it is a mandatory child node
+cannotRemoveParentNodeOfTarget = The node at "{0}" with UUID "{1}" is a parent of the target node for this operation "{2}"
+invalidPropertyType = Invalid property type: {0}
+
unableToRemoveRootNode = Unable to remove the root node in workspace "{1}"
unableToMoveNodeToBeChildOfDecendent = Node "{0}" in workspace "{2}" cannot be moved under a decendant node ("{1}")
@@ -131,8 +139,13 @@
allNodeTypeTemplatesMustComeFromSameSession=All node type templates must be created from the same javax.jcr.Session
nodeNotReferenceable=Only referenceable nodes may be the value of reference properties
+nodeNotReferenceableUuid = Only referenceable nodes have a public UUID assigned
noPendingChangesAllowed=This operation cannot be performed when the session has pending changes
cannotUnregisterSupertype=Cannot unregister type '{0}' which is supertype of type '{1}'
cannotUnregisterRequiredPrimaryType=Cannot unregister type '{0}' which is the required primary type for child node '{2}' on type '{1}'
-cannotUnregisterDefaultPrimaryType=Cannot unregister type '{0}' which is the default primary type for child node '{2}' of type '{1}'
\ No newline at end of file
+cannotUnregisterDefaultPrimaryType=Cannot unregister type '{0}' which is the default primary type for child node '{2}' of type '{1}'
+
+cannotAddMixin = This node does not allow adding the mixin type "{0}"
+invalidMixinTypeForNode = "{0}" is not currently a mixin type for node "{1}"
+notOrderable = The primary type "{0}" for this node (at "{1}") does not have orderable children
16 years, 5 months
DNA SVN: r1126 - in trunk: dna-integration-tests/src/test/java/org/jboss/dna/test/integration and 9 other directories.
by dna-commits@lists.jboss.org
Author: bcarothers
Date: 2009-07-23 21:15:00 -0400 (Thu, 23 Jul 2009)
New Revision: 1126
Added:
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/FileSystemRepositoryTckTest.java
trunk/dna-integration-tests/src/test/resources/tck/filesystem/
trunk/dna-integration-tests/src/test/resources/tck/filesystem/configRepository.xml
trunk/dna-integration-tests/src/test/resources/tck/filesystem/repositoryOverlay.properties
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java
trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/AbstractRepositoryTckTest.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaRepositoryStub.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
trunk/dna-jcr/src/test/resources/security/tck_roles.properties
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java
trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorCreateWorkspacesTest.java
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNoCreateWorkspaceTest.java
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNotWritableTest.java
trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadableTest.java
Log:
DNA-476 Add integration test that uses the file system connector
Committed patch that implements a read-only TCK test based on a filesystem connector. This patch implements a few changes as described below:
- Minor JCR bug fixes around UUID properties for connectors that don't support UUID properties and binary handling in JcrValue and the document view exporter
- Minor tweaks to the TCK infrastructure code to support not importing test data into read-only repositories and having a test suite of just the read-only tests
- Less-minor tweaks to the filesystem connector to support a new way of specifying workspace names and locations as described in http://www.jboss.org/index.html?module=bb&op=viewtopic&t=158928. This caused a fair amount of code shuffling within the FS connector classes.
There's also a somewhat dubious change to the filesystem connector that causes the root folder to be returned as type dna:root instead of nt:folder. This is necessary if the root happens to be the root of a repository workspace, as it is in this test. This is not appropriate under some projection scenarios (e.g. /foo => /). This merits some more discussion and thought in the future.
It is also worth noting that our FS connector was modified to return a node with primary type nt:file and a child node of type dna:resource for each file instead of nt:file/nt:resource. We cannot support nt:resource from our FS connector because nt:resource extends mix:referenceable. Instead, we use a node type that is identical to nt:resource but without extending mix:referenceable.
[ Show ?\194?\187 ]
Brian Carothers - 23/Jul/09 09:12 PM Attached patch that implements a read-only TCK test based on a filesystem connector. This patch implements a few changes as described below: - Minor JCR bug fixes around UUID properties for connectors that don't support UUID properties and binary handling in JcrValue and the document view exporter - Minor tweaks to the TCK infrastructure code to support not importing test data into read-only repositories and having a test suite of just the read-only tests - Less-minor tweaks to the filesystem connector to support a new way of specifying workspace names and locations as described in http://www.jboss.org/index.html?module=bb&op=viewtopic&t=158928. This caused a fair amount of code shuffling within the FS connector classes. There's also a somewhat dubious change to the filesystem connector that causes the root folder to be returned as type dna:root instead of nt:folder. This is necessary if the root happens to be the root of a repository wor!
kspace, as it is in this test. This is not appropriate under some projection scenarios (e.g. /foo => /). This merits some more discussion and thought in the future. It is also worth noting that our FS connector was modified to return a node with primary type nt:file and a child node of type dna:resource for each file instead of nt:file/nt:resource. We cannot support nt:resource from our FS connector because nt:resource extends mix:referenceable. Instead, we use a node type that is identical to nt:resource but without extending mix:referenceable.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/DnaLexicon.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -43,6 +43,8 @@
public static final Name NAMESPACES = new BasicName(Namespace.URI, "namespaces");
public static final Name PROJECTION_RULES = new BasicName(Namespace.URI, "projectionRules");
public static final Name READ_ONLY = new BasicName(Namespace.URI, "readOnly");
+ public static final Name RESOURCE = new BasicName(Namespace.URI, "resource");
+ public static final Name ROOT = new BasicName(Namespace.URI, "root");
public static final Name TIME_TO_EXPIRE = new BasicName(Namespace.URI, "timeToExpire");
public static final Name NAMESPACE_URI = new BasicName(Namespace.URI, "uri");
Modified: trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/AbstractRepositoryTckTest.java
===================================================================
--- trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/AbstractRepositoryTckTest.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/AbstractRepositoryTckTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -53,8 +53,8 @@
public static TestSuite readOnlyRepositorySuite( String name ) {
TestSuite suite = new TestSuite("Tests for " + name + "(read-only)");
suite.addTest(new ChangeRepositoryTestCase(name));
- suite.addTest(JcrTckTest.suite());
- suite.addTestSuite(DnaTckTest.class);
+ suite.addTest(JcrTckTest.readOnlySuite());
+ suite.addTest(DnaTckTest.readOnlySuite());
return suite;
}
Added: trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/FileSystemRepositoryTckTest.java
===================================================================
--- trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/FileSystemRepositoryTckTest.java (rev 0)
+++ trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/FileSystemRepositoryTckTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -0,0 +1,33 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.test.integration;
+
+import junit.framework.Test;
+
+public class FileSystemRepositoryTckTest {
+
+ public static Test suite() {
+ return AbstractRepositoryTckTest.readOnlyRepositorySuite("filesystem");
+ }
+}
Property changes on: trunk/dna-integration-tests/src/test/java/org/jboss/dna/test/integration/FileSystemRepositoryTckTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/dna-integration-tests/src/test/resources/tck/filesystem/configRepository.xml
===================================================================
--- trunk/dna-integration-tests/src/test/resources/tck/filesystem/configRepository.xml (rev 0)
+++ trunk/dna-integration-tests/src/test/resources/tck/filesystem/configRepository.xml 2009-07-24 01:15:00 UTC (rev 1126)
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss DNA (http://www.jboss.org/dna)
+ ~
+ ~ See the COPYRIGHT.txt file distributed with this work for information
+ ~ regarding copyright ownership. Some portions may be licensed
+ ~ to Red Hat, Inc. under one or more contributor license agreements.
+ ~ See the AUTHORS.txt file in the distribution for a full listing of
+ ~ individual contributors.
+ ~
+ ~ JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ ~ is licensed to you under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ JBoss DNA is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<configuration xmlns:dna="http://www.jboss.org/dna/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
+ <!--
+ Define the sources for the content. These sources are directly accessible using the DNA-specific Graph API.
+ In fact, this is how the DNA JCR implementation works. You can think of these as being similar to
+ JDBC DataSource objects, except that they expose graph content via the Graph API instead of records via SQL or JDBC.
+ -->
+ <dna:sources jcr:primaryType="nt:unstructured">
+ <!--
+ The 'JCR' repository is a file system source with a single, default workspace (though others could be created, too).
+ In a production release, the dna:rootNodeUuid would be specified here as well to ensure stability over restarts.
+ Since we don't specify a rootNodeUuid, a random UUID will be generated each time that the corresponding test is run.
+ -->
+ <dna:source jcr:name="Store" dna:classname="org.jboss.dna.connector.filesystem.FileSystemSource"
+ dna:workspaceRootPath="./src/test/resources/tck/filesystem"
+ dna:defaultWorkspaceName="defaultWorkspace"
+ dna:predefinedWorkspaceNames="otherWorkspace"
+ dna:creatingWorkspacesAllowed="false"
+ />
+ <!--
+ <dna:source jcr:name="Store" dna:classname="org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource" />
+ -->
+ </dna:sources>
+ <!--
+ Define the mime type detectors. This is an optional section. By default, each engine will use the
+ MIME type detector that uses filename extensions. So we wouldn't need to define the same detector again,
+ but this is how you'd define another extension.
+ -->
+ <dna:mimeTypeDetectors>
+ <dna:mimeTypeDetector jcr:name="Detector">
+ <dna:description>Standard extension-based MIME type detector</dna:description>
+ <!--
+ Specify the implementation class (required), as a child element or attribute on parent element.
+ -->
+ <dna:classname>org.jboss.dna.graph.mimetype.ExtensionBasedMimeTypeDetector</dna:classname>
+ <!--
+ Specify the classpath (optional) as an ordered list of 'names', where each name is significant to
+ the classpath factory. For example, a name could be an OSGI identifier or a Maven coordinate,
+ depending upon the classpath factory being used. If there is only one 'name' in the classpath,
+ it may be specified as an attribute on the 'mimeTypeDetector' element. If there is more than one
+ 'name', then they must be specified as child 'classpath' elements. Blank or empty values are ignored.
+ -->
+ <dna:classpath></dna:classpath>
+ </dna:mimeTypeDetector>
+ </dna:mimeTypeDetectors>
+ <!--
+ Define the JCR repositories
+ -->
+ <dna:repositories>
+ <!--
+ Define a JCR repository that accesses the 'JCR' source directly.
+ This of course is optional, since we could access the same content through 'JCR'.
+ -->
+ <dna:repository jcr:name="Test Repository Source">
+ <!-- Specify the source that should be used for the repository -->
+ <dna:source>Store</dna:source>
+ <!-- Define the options for the JCR repository, using camelcase version of JcrRepository.Option names
+-->
+ <dna:options jcr:primaryType="dna:options">
+ <jaasLoginConfigName jcr:primaryType="dna:option" dna:value="dna-jcr"/>
+ <projectNodeTypes jcr:primaryType="dna:option" dna:value="false"/>
+ </dna:options>
+ <!-- Define any namespaces for this repository, other than those already defined by JCR or DNA
+-->
+ <namespaces jcr:primaryType="dna:namespaces">
+ <dnatest jcr:primaryType="dna:namespace" dna:uri="http://jboss.org/dna/test/1.0"/>
+ </namespaces>
+ </dna:repository>
+ </dna:repositories>
+</configuration>
Property changes on: trunk/dna-integration-tests/src/test/resources/tck/filesystem/configRepository.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Added: trunk/dna-integration-tests/src/test/resources/tck/filesystem/repositoryOverlay.properties
===================================================================
--- trunk/dna-integration-tests/src/test/resources/tck/filesystem/repositoryOverlay.properties (rev 0)
+++ trunk/dna-integration-tests/src/test/resources/tck/filesystem/repositoryOverlay.properties 2009-07-24 01:15:00 UTC (rev 1126)
@@ -0,0 +1,8 @@
+# Placeholder for any overlaid properties for this repo configuration
+
+javax.jcr.tck.dnaSkipImport=true
+
+
+javax.jcr.tck.nodetype=nt\:file
+javax.jcr.tck.nodetype2=nt\:file
+
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/DnaLexicon.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -35,7 +35,6 @@
public static final Name NAMESPACE = new BasicName(Namespace.URI, "namespace");
public static final Name NODE_TYPES = new BasicName(Namespace.URI, "nodeTypes");
public static final Name REPOSITORIES = new BasicName(Namespace.URI, "repositories");
- public static final Name ROOT = new BasicName(Namespace.URI, "root");
public static final Name SYSTEM = new BasicName(Namespace.URI, "system");
public static final Name URI = new BasicName(Namespace.URI, "uri");
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrDocumentViewExporter.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -23,6 +23,7 @@
*/
package org.jboss.dna.jcr;
+import java.io.IOException;
import java.io.OutputStream;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
@@ -39,6 +40,7 @@
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.text.XmlNameEncoder;
+import org.jboss.dna.common.util.Base64;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.property.Name;
import org.jboss.dna.graph.property.ValueFactories;
@@ -56,6 +58,8 @@
@NotThreadSafe
class JcrDocumentViewExporter extends AbstractJcrExporter {
+ private static final int ENCODE_BUFFER_SIZE = 2 << 15;
+
private static final TextEncoder VALUE_ENCODER = new JcrDocumentViewExporter.JcrDocumentViewPropertyEncoder();
JcrDocumentViewExporter( JcrSession session ) {
@@ -99,14 +103,19 @@
while (properties.hasNext()) {
Property prop = properties.nextProperty();
+ Name propName = ((AbstractJcrProperty)prop).name();
+
+ String localPropName = getPrefixedName(propName);
+
if (skipBinary && PropertyType.BINARY == prop.getType()) {
+ atts.addAttribute(propName.getNamespaceUri(),
+ propName.getLocalName(),
+ localPropName,
+ PropertyType.nameFromValue(prop.getType()),
+ "");
continue;
}
- Name propName = ((AbstractJcrProperty)prop).name();
-
- String localPropName = getPrefixedName(propName);
-
Value value;
if (prop instanceof JcrSingleValueProperty) {
value = prop.getValue();
@@ -115,11 +124,31 @@
// 6.4.2.5
value = prop.getValues()[0];
}
+
+ String valueAsString;
+ if (PropertyType.BINARY == prop.getType()) {
+ StringBuffer buff = new StringBuffer(ENCODE_BUFFER_SIZE);
+ try {
+ Base64.InputStream is = new Base64.InputStream(value.getStream(), Base64.ENCODE);
+
+ byte[] bytes = new byte[ENCODE_BUFFER_SIZE];
+ int len;
+ while (-1 != (len = is.read(bytes, 0, ENCODE_BUFFER_SIZE))) {
+ buff.append(new String(bytes, 0, len));
+ }
+ } catch (IOException ioe) {
+ throw new RepositoryException(ioe);
+ }
+ valueAsString = buff.toString();
+ } else {
+ valueAsString = VALUE_ENCODER.encode(value.getString());
+ }
+
atts.addAttribute(propName.getNamespaceUri(),
propName.getLocalName(),
localPropName,
PropertyType.nameFromValue(prop.getType()),
- VALUE_ENCODER.encode(value.getString()));
+ valueAsString);
}
Name name;
@@ -148,8 +177,10 @@
* Indicates whether the current node is an XML text node as per section 6.4.2.3 of the JCR 1.0 specification. XML text nodes
* are nodes that have the name "jcr:xmltext" and only one property (besides the mandatory
* "jcr:primaryType"). The property must have a property name of "jcr:xmlcharacters", a type of
- * <code>String</code>, and does not have multiple values.<p/> In practice, this is handled in DNA by making XML text nodes
- * have a type of "dna:xmltext", which enforces these property characteristics.
+ * <code>String</code>, and does not have multiple values.
+ * <p/>
+ * In practice, this is handled in DNA by making XML text nodes have a type of "dna:xmltext", which enforces these
+ * property characteristics.
*
* @param node the node to test
* @return whether this node is a special xml text node
@@ -224,6 +255,7 @@
* underscore characters that might otherwise suggest an encoding, as defined in {@link XmlNameEncoder}.
*/
protected static class JcrDocumentViewPropertyEncoder extends XmlNameEncoder {
+
private static final Set<Character> MAPPED_CHARACTERS;
static {
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrValue.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -56,6 +56,7 @@
private final ValueFactories valueFactories;
private final int type;
private final Object value;
+ private InputStream asStream = null;
JcrValue( ValueFactories valueFactories,
SessionCache sessionCache,
@@ -187,10 +188,12 @@
throw new IllegalStateException(JcrI18n.nonInputStreamConsumed.text());
}
try {
- Binary binary = valueFactories.getBinaryFactory().create(value);
- InputStream convertedValue = new SelfClosingInputStream(binary);
- state = State.INPUT_STREAM_CONSUMED;
- return convertedValue;
+ if (asStream == null) {
+ Binary binary = valueFactories.getBinaryFactory().create(value);
+ asStream = new SelfClosingInputStream(binary);
+ state = State.INPUT_STREAM_CONSUMED;
+ }
+ return asStream;
} catch (RuntimeException error) {
throw createValueFormatException(InputStream.class);
}
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -2067,43 +2067,7 @@
uuidProperty = propertyFactory.create(JcrLexicon.UUID, uuid);
}
}
- if (uuidProperty == null) {
- org.jboss.dna.graph.session.GraphSession.PropertyInfo<JcrPropertyPayload> uuidInfo = node.getProperty(JcrLexicon.UUID);
- if (uuidInfo != null) {
- uuidProperty = uuidInfo.getProperty();
- }
- if (uuidProperty != null) {
- // Grab the first 'good' UUID value ...
- for (Object uuidValue : uuidProperty) {
- try {
- uuid = factories.getUuidFactory().create(uuidValue);
- break;
- } catch (ValueFormatException e) {
- // Ignore; just continue with the next property value
- }
- }
- }
- if (uuid == null) {
- // Look for the DNA UUID property ...
- uuidInfo = node.getProperty(DnaLexicon.UUID);
- if (uuidInfo != null) {
- uuidProperty = uuidInfo.getProperty();
- }
- if (uuidProperty != null) {
- // Grab the first 'good' UUID value ...
- for (Object uuidValue : uuidProperty) {
- try {
- uuid = factories.getUuidFactory().create(uuidValue);
- break;
- } catch (ValueFormatException e) {
- // Ignore; just continue with the next property value
- }
- }
- }
- }
- }
- if (uuid == null) uuid = UUID.randomUUID();
- if (uuidProperty == null) uuidProperty = propertyFactory.create(JcrLexicon.UUID, uuid);
+ if (uuid != null && uuidProperty == null) uuidProperty = propertyFactory.create(JcrLexicon.UUID, uuid);
// Look for the primary type of the node ...
Map<Name, Property> graphProperties = persistentNode.getPropertiesByName();
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/dna_builtins.cnd 2009-07-24 01:15:00 UTC (rev 1126)
@@ -53,3 +53,8 @@
+ jcr:system (dna:system) = dna:system autocreated mandatory protected ignore
+ * (nt:base) = nt:unstructured multiple version
+[dna:resource] > nt:base
+- jcr:data (binary) primary mandatory
+- jcr:encoding (string) copy
+- jcr:lastModified (date) mandatory ignore
+- jcr:mimeType (string) copy mandatory
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaRepositoryStub.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaRepositoryStub.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaRepositoryStub.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -39,6 +39,9 @@
* Concrete implementation of {@link RepositoryStub} based on DNA-specific configuration.
*/
public class DnaRepositoryStub extends RepositoryStub {
+
+ public static final String DNA_SKIP_IMPORT = "javax.jcr.tck.dnaSkipImport";
+
private static final String REPOSITORY_SOURCE_NAME = "Test Repository Source";
private static String currentConfigurationName = "default";
@@ -46,7 +49,6 @@
private Properties configProps;
private String repositoryConfigurationName;
private JcrRepository repository;
-
static {
@@ -69,7 +71,7 @@
private void configureRepository() {
repositoryConfigurationName = currentConfigurationName;
-
+
// Create the in-memory (DNA) repository
JcrConfiguration configuration = new JcrConfiguration();
try {
@@ -94,7 +96,6 @@
JcrEngine engine = configuration.build();
engine.start();
- // Problems problems = engine.getRepositoryService().getStartupProblems();
Problems problems = engine.getProblems();
// Print all of the problems from the engine configuration ...
for (Problem problem : problems) {
@@ -110,24 +111,27 @@
try {
repository = engine.getRepository(REPOSITORY_SOURCE_NAME);
- // Set up some sample nodes in the graph to match the expected test configuration
- Graph graph = Graph.create(repository.getRepositorySourceName(),
- engine.getRepositoryConnectionFactory(),
- executionContext);
- Path destinationPath = executionContext.getValueFactories().getPathFactory().createRootPath();
+ // This needs to check configProps directly to avoid an infinite loop
+ String skipImport = (String)configProps.get(DNA_SKIP_IMPORT);
+ if (!Boolean.valueOf(skipImport)) {
- InputStream xmlStream = getClass().getResourceAsStream("/tck/repositoryForTckTests.xml");
- graph.importXmlFrom(xmlStream).into(destinationPath);
+ // Set up some sample nodes in the graph to match the expected test configuration
+ Graph graph = Graph.create(repository.getRepositorySourceName(),
+ engine.getRepositoryConnectionFactory(),
+ executionContext);
+ Path destinationPath = executionContext.getValueFactories().getPathFactory().createRootPath();
- graph.createWorkspace().named("otherWorkspace");
+ InputStream xmlStream = getClass().getResourceAsStream("/tck/repositoryForTckTests.xml");
+ graph.importXmlFrom(xmlStream).into(destinationPath);
+ graph.createWorkspace().named("otherWorkspace");
+ }
} catch (Exception ex) {
// The TCK tries to quash this exception. Print it out to be more obvious.
ex.printStackTrace();
throw new IllegalStateException("Failed to initialize the repository with text content.", ex);
}
-
}
public static void setCurrentConfigurationName( String newConfigName ) {
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/DnaTckTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -13,6 +13,8 @@
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.nodetype.ConstraintViolationException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
import org.apache.jackrabbit.test.AbstractJCRTest;
import org.jboss.dna.jcr.nodetype.NodeTypeTemplate;
@@ -23,6 +25,25 @@
Session session;
+ public DnaTckTest( String testName ) {
+ super();
+
+ this.setName(testName);
+ this.isReadOnly = true;
+ }
+
+ public static Test readOnlySuite() {
+ TestSuite suite = new TestSuite("DNA JCR API tests");
+
+ suite.addTest(new DnaTckTest("testShouldAllowAdminSessionToRead"));
+ suite.addTest(new DnaTckTest("testShouldAllowReadOnlySessionToRead"));
+ suite.addTest(new DnaTckTest("testShouldAllowReadWriteSessionToRead"));
+ suite.addTest(new DnaTckTest("testShouldNotSeeWorkspacesWithoutReadPermission"));
+ suite.addTest(new DnaTckTest("testShouldMapReadRolesToWorkspacesWhenSpecified"));
+
+ return suite;
+ }
+
@Override
protected void tearDown() throws Exception {
try {
@@ -254,11 +275,35 @@
*
* @throws Exception
*/
- public void testShouldMapRolesToWorkspacesWhenSpecified() throws Exception {
+ public void testShouldMapReadRolesToWorkspacesWhenSpecified() throws Exception {
Credentials creds = new SimpleCredentials("defaultonly", "defaultonly".toCharArray());
session = helper.getRepository().login(creds);
testRead(session);
+
+ session.logout();
+
+ session = helper.getRepository().login(creds, "otherWorkspace");
+ testRead(session);
+ try {
+ testWrite(session);
+ fail("User 'defaultuser' should not have write access to 'otherWorkspace'");
+ } catch (AccessDeniedException expected) {
+ }
+ session.logout();
+ }
+
+ /**
+ * User defaultuser is configured to have readwrite in "otherWorkspace" and readonly in the default workspace. This test makes
+ * sure both work.
+ *
+ * @throws Exception
+ */
+ public void testShouldMapWriteRolesToWorkspacesWhenSpecified() throws Exception {
+ Credentials creds = new SimpleCredentials("defaultonly", "defaultonly".toCharArray());
+ session = helper.getRepository().login(creds);
+
+ testRead(session);
testWrite(session);
session.logout();
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -107,6 +107,23 @@
}
/**
+ * Wrapper for read-only tests
+ *
+ * @return a new instance of {@link JCRTestSuite}.
+ */
+ public static Test readOnlySuite() {
+ // Uncomment this to execute all tests
+ // return new JCRTestSuite();
+
+ // Or uncomment the following lines to execute the different sets/suites of tests ...
+ TestSuite suite = new TestSuite("JCR 1.0 API tests");
+
+ suite.addTest(new LevelOneFeatureTests());
+
+ return suite;
+ }
+
+ /**
* Test suite that includes the Level 1 JCR TCK API tests from the Jackrabbit project.
*/
private static class LevelOneFeatureTests extends TestSuite {
Modified: trunk/dna-jcr/src/test/resources/security/tck_roles.properties
===================================================================
--- trunk/dna-jcr/src/test/resources/security/tck_roles.properties 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/dna-jcr/src/test/resources/security/tck_roles.properties 2009-07-24 01:15:00 UTC (rev 1126)
@@ -2,6 +2,6 @@
superuser=admin
readwrite=readwrite
readonly=readonly
-# default workspace name is the empty string
-defaultonly=readwrite.Store.default,readonly.Store.otherWorkspace
+# defaultWorkspace is the default workspace name for the filesystem TCK test
+defaultonly=readwrite.Store.default,readonly.Store.otherWorkspace,readwrite.Store.defaultWorkspace
noaccess=readonly.Store.otherWorkspace
Modified: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemConnection.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -25,7 +25,8 @@
import java.io.File;
import java.io.FilenameFilter;
-import java.util.Set;
+import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.transaction.xa.XAResource;
import org.jboss.dna.graph.ExecutionContext;
@@ -44,28 +45,35 @@
public class FileSystemConnection implements RepositoryConnection {
private final String sourceName;
- private final File defaultWorkspace;
+ private final String defaultWorkspaceName;
private final CachePolicy cachePolicy;
- private final Set<String> availableWorkspaceNames;
+ private final Map<String, File> availableWorkspaces;
private final boolean creatingWorkspacesAllowed;
private final FilenameFilter filenameFilter;
+ private final UUID rootNodeUuid;
+ private final String workspaceRootPath;
private final boolean updatesAllowed;
FileSystemConnection( String sourceName,
- File defaultWorkspace,
- Set<String> availableWorkspaceNames,
+ String defaultWorkspaceName,
+ Map<String, File> availableWorkspaces,
boolean creatingWorkspacesAllowed,
CachePolicy cachePolicy,
+ UUID rootNodeUuid,
+ String workspaceRootPath,
FilenameFilter filenameFilter,
boolean updatesAllowed ) {
assert sourceName != null;
assert sourceName.trim().length() != 0;
- assert availableWorkspaceNames != null;
+ assert availableWorkspaces != null;
+ assert rootNodeUuid != null;
this.sourceName = sourceName;
- this.defaultWorkspace = defaultWorkspace;
- this.availableWorkspaceNames = availableWorkspaceNames;
+ this.defaultWorkspaceName = defaultWorkspaceName;
+ this.availableWorkspaces = availableWorkspaces;
this.creatingWorkspacesAllowed = creatingWorkspacesAllowed;
this.cachePolicy = cachePolicy;
+ this.rootNodeUuid = rootNodeUuid;
+ this.workspaceRootPath = workspaceRootPath;
this.filenameFilter = filenameFilter;
this.updatesAllowed = updatesAllowed;
}
@@ -115,8 +123,9 @@
*/
public void execute( ExecutionContext context,
Request request ) throws RepositorySourceException {
- RequestProcessor proc = new FileSystemRequestProcessor(sourceName, defaultWorkspace, availableWorkspaceNames,
- creatingWorkspacesAllowed, context, filenameFilter, updatesAllowed);
+ RequestProcessor proc = new FileSystemRequestProcessor(sourceName, defaultWorkspaceName, availableWorkspaces,
+ creatingWorkspacesAllowed, rootNodeUuid, workspaceRootPath,
+ context, filenameFilter, updatesAllowed);
try {
proc.process(request);
} finally {
Modified: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemI18n.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -40,6 +40,9 @@
public static I18n pathForPredefinedWorkspaceDoesNotExist;
public static I18n pathForPredefinedWorkspaceIsNotDirectory;
public static I18n pathForPredefinedWorkspaceCannotBeRead;
+ public static I18n pathForWorkspaceRootDoesNotExist;
+ public static I18n pathForWorkspaceRootIsNotDirectory;
+ public static I18n pathForWorkspaceRootCannotBeRead;
public static I18n propertyIsRequired;
public static I18n locationInRequestMustHavePath;
public static I18n sameNameSiblingsAreNotAllowed;
Modified: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemRequestProcessor.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -31,8 +31,11 @@
import java.io.InputStream;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.JcrNtLexicon;
@@ -77,43 +80,68 @@
private static final String DEFAULT_MIME_TYPE = "application/octet";
private final String defaultNamespaceUri;
- private final Set<String> availableWorkspaceNames;
+ private final Map<String, File> availableWorkspaces;
private final boolean creatingWorkspacesAllowed;
- private final File defaultWorkspace;
+ private final String defaultWorkspaceName;
+ private final File workspaceRootPath;
private final FilenameFilter filenameFilter;
private final boolean updatesAllowed;
private final MimeTypeDetector mimeTypeDetector;
+ private final UUID rootNodeUuid;
/**
* @param sourceName
- * @param defaultWorkspace
- * @param availableWorkspaceNames
+ * @param defaultWorkspaceName
+ * @param availableWorkspaces
* @param creatingWorkspacesAllowed
* @param context
+ * @param rootNodeUuid the UUID for the root node in this workspace; may be null. If not specified, a random UUID will be
+ * generated each time that the repository is started.
+ * @param workspaceRootPath the path to the workspace root directory; may be null. If specified, all workspace names will be
+ * treated as relative paths from this directory.
* @param filenameFilter the filename filter to use to restrict the allowable nodes, or null if all files/directories are to
* be exposed by this connector
* @param updatesAllowed true if this connector supports updating the file system, or false if the connector is readonly
*/
protected FileSystemRequestProcessor( String sourceName,
- File defaultWorkspace,
- Set<String> availableWorkspaceNames,
+ String defaultWorkspaceName,
+ Map<String, File> availableWorkspaces,
boolean creatingWorkspacesAllowed,
+ UUID rootNodeUuid,
+ String workspaceRootPath,
ExecutionContext context,
FilenameFilter filenameFilter,
boolean updatesAllowed ) {
super(sourceName, context, null);
- assert defaultWorkspace != null;
- assert defaultWorkspace.exists();
- assert defaultWorkspace.canRead();
- assert defaultWorkspace.isDirectory();
- assert availableWorkspaceNames != null;
- this.availableWorkspaceNames = availableWorkspaceNames;
+ assert defaultWorkspaceName != null;
+ assert availableWorkspaces != null;
+ assert rootNodeUuid != null;
+ this.availableWorkspaces = availableWorkspaces;
this.creatingWorkspacesAllowed = creatingWorkspacesAllowed;
this.defaultNamespaceUri = getExecutionContext().getNamespaceRegistry().getDefaultNamespaceUri();
+ this.rootNodeUuid = rootNodeUuid;
this.filenameFilter = filenameFilter;
- this.defaultWorkspace = defaultWorkspace;
+ this.defaultWorkspaceName = defaultWorkspaceName;
this.updatesAllowed = updatesAllowed;
this.mimeTypeDetector = context.getMimeTypeDetector();
+
+ if (workspaceRootPath != null) {
+ this.workspaceRootPath = new File(workspaceRootPath);
+ if (!this.workspaceRootPath.exists()) {
+ throw new IllegalStateException(FileSystemI18n.pathForWorkspaceRootDoesNotExist.text(workspaceRootPath,
+ sourceName));
+ }
+ if (!this.workspaceRootPath.isDirectory()) {
+ throw new IllegalStateException(FileSystemI18n.pathForWorkspaceRootIsNotDirectory.text(workspaceRootPath,
+ sourceName));
+ }
+ if (!this.workspaceRootPath.canRead()) {
+ throw new IllegalStateException(FileSystemI18n.pathForWorkspaceRootCannotBeRead.text(workspaceRootPath,
+ sourceName));
+ }
+ } else {
+ this.workspaceRootPath = null;
+ }
}
/**
@@ -134,6 +162,11 @@
// Find the existing file for the parent ...
Location location = request.of();
Path parentPath = getPathFor(location, request);
+
+ if (parentPath.isRoot()) {
+ if (!location.hasPath()) location = location.with(parentPath);
+ }
+
File parent = getExistingFileFor(workspaceRoot, parentPath, location, request);
if (parent == null) {
// An error was set on the request
@@ -180,13 +213,20 @@
return;
}
+ PropertyFactory factory = getExecutionContext().getPropertyFactory();
+
// Find the existing file for the parent ...
Location location = request.at();
Path path = getPathFor(location, request);
if (path.isRoot()) {
- // There are no properties on the root ...
+ // Root nodes can be requested by UUID, path, or both
+ if (!location.hasPath()) location = location.with(path);
+ if (location.getUuid() == null) location = location.with(rootNodeUuid);
+
+ request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, DnaLexicon.ROOT));
request.setActualLocationOfNode(location);
setCacheableInfo(request);
+
return;
}
@@ -197,7 +237,6 @@
return;
}
// Generate the properties for this File object ...
- PropertyFactory factory = getExecutionContext().getPropertyFactory();
DateTimeFactory dateFactory = getExecutionContext().getValueFactories().getDateFactory();
// Note that we don't have 'created' timestamps, just last modified, so we'll have to use them
if (file.isDirectory()) {
@@ -209,7 +248,9 @@
// It is a file, but ...
if (path.getLastSegment().getName().equals(JcrLexicon.CONTENT)) {
// The request is to get properties of the "jcr:content" child node ...
- request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.RESOURCE));
+ // ... use the dna:resource node type. This is the same as nt:resource, but is not referenceable
+ // since we cannot assume that we control all access to this file and can track its movements
+ request.addProperty(factory.create(JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE));
request.addProperty(factory.create(JcrLexicon.LAST_MODIFIED, dateFactory.create(file.lastModified())));
// Don't really know the encoding, either ...
// request.addProperty(factory.create(JcrLexicon.ENCODED, stringFactory.create("UTF-8")));
@@ -330,23 +371,19 @@
public void process( VerifyWorkspaceRequest request ) {
// If the request contains a null name, then we use the default ...
String workspaceName = request.workspaceName();
- if (workspaceName == null) workspaceName = getCanonicalWorkspaceName(defaultWorkspace);
+ if (workspaceName == null) workspaceName = defaultWorkspaceName;
if (!this.creatingWorkspacesAllowed) {
// Then the workspace name must be one of the available names ...
+
boolean found = false;
- for (String available : this.availableWorkspaceNames) {
+ for (String available : this.availableWorkspaces.keySet()) {
if (workspaceName.equals(available)) {
found = true;
break;
}
- File directory = new File(available);
- if (directory.exists() && directory.isDirectory() && directory.canRead()
- && getCanonicalWorkspaceName(directory).equals(workspaceName)) {
- found = true;
- break;
- }
}
+
if (!found) {
request.setError(new InvalidWorkspaceException(FileSystemI18n.workspaceDoesNotExist.text(workspaceName)));
return;
@@ -354,9 +391,9 @@
// We know it is an available workspace, so just continue ...
}
// Verify that there is a directory at the path given by the workspace name ...
- File directory = new File(workspaceName);
+ File directory = availableWorkspaces.get(workspaceName);
if (directory.exists() && directory.isDirectory() && directory.canRead()) {
- request.setActualWorkspaceName(getCanonicalWorkspaceName(directory));
+ request.setActualWorkspaceName(workspaceName);
request.setActualRootLocation(Location.create(pathFactory().createRootPath()));
} else {
request.setError(new InvalidWorkspaceException(FileSystemI18n.workspaceDoesNotExist.text(workspaceName)));
@@ -372,12 +409,13 @@
public void process( GetWorkspacesRequest request ) {
// Return the set of available workspace names, even if new workspaces can be created ...
Set<String> names = new HashSet<String>();
- for (String name : this.availableWorkspaceNames) {
- File directory = new File(name);
+ for (Map.Entry<String, File> entry : this.availableWorkspaces.entrySet()) {
+ File directory = entry.getValue();
if (directory.exists() && directory.isDirectory() && directory.canRead()) {
- names.add(getCanonicalWorkspaceName(directory));
+ names.add(entry.getKey());
}
}
+
request.setAvailableWorkspaceNames(Collections.unmodifiableSet(names));
}
@@ -389,6 +427,12 @@
*/
protected String getCanonicalWorkspaceName( File directory ) {
try {
+ if (this.workspaceRootPath != null) {
+ String directoryCanonicalPath = directory.getCanonicalPath();
+ String rootCanonicalPath = workspaceRootPath.getCanonicalPath();
+ assert directoryCanonicalPath.startsWith(rootCanonicalPath);
+ return directoryCanonicalPath.substring(rootCanonicalPath.length() + 1);
+ }
return directory.getCanonicalPath();
} catch (IOException e) {
return directory.getAbsolutePath();
@@ -424,7 +468,7 @@
if (directory.exists() && directory.isDirectory() && directory.canRead()) {
request.setActualWorkspaceName(getCanonicalWorkspaceName(directory));
request.setActualRootLocation(Location.create(pathFactory().createRootPath()));
- availableWorkspaceNames.add(workspaceName);
+ availableWorkspaces.put(workspaceName, directory);
recordChange(request);
} else {
request.setError(new InvalidWorkspaceException(FileSystemI18n.workspaceDoesNotExist.text(workspaceName)));
@@ -444,7 +488,7 @@
request.setError(new InvalidRequestException(msg));
}
// This doesn't delete the file/directory; rather, it just remove the workspace from the available set ...
- if (!this.availableWorkspaceNames.remove(workspaceName)) {
+ if (this.availableWorkspaces.remove(workspaceName) == null) {
request.setError(new InvalidWorkspaceException(FileSystemI18n.workspaceDoesNotExist.text(workspaceName)));
} else {
request.setActualRootLocation(Location.create(pathFactory().createRootPath()));
@@ -470,6 +514,11 @@
protected Path getPathFor( Location location,
Request request ) {
Path path = location.getPath();
+
+ if (location.getUuid() != null && rootNodeUuid.equals(location.getUuid())) {
+ return pathFactory().createRootPath();
+ }
+
if (path == null) {
I18n msg = FileSystemI18n.locationInRequestMustHavePath;
throw new RepositorySourceException(getSourceName(), msg.text(getSourceName(), request));
@@ -478,13 +527,11 @@
}
protected File getWorkspaceDirectory( String workspaceName ) {
- File workspace = defaultWorkspace;
- if (workspaceName != null) {
- File directory = new File(workspaceName);
- if (directory.exists() && directory.isDirectory() && directory.canRead()) workspace = directory;
- else return null;
- }
- return workspace;
+ if (workspaceName == null) workspaceName = defaultWorkspaceName;
+
+ File directory = this.workspaceRootPath == null ? new File(workspaceName) : new File(workspaceRootPath, workspaceName);
+ if (directory.exists() && directory.isDirectory() && directory.canRead()) return directory;
+ return null;
}
/**
Modified: trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/main/java/org/jboss/dna/connector/filesystem/FileSystemSource.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -31,7 +31,8 @@
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
import javax.naming.Context;
import javax.naming.RefAddr;
import javax.naming.Reference;
@@ -40,6 +41,7 @@
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;
import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.Logger;
import org.jboss.dna.common.util.StringUtil;
import org.jboss.dna.graph.cache.CachePolicy;
@@ -64,10 +66,16 @@
*/
private static final long serialVersionUID = 1L;
+ /**
+ * The initial {@link #getDefaultWorkspaceName() name of the default workspace} is "{@value} ", unless otherwise specified.
+ */
+ public static final String DEFAULT_NAME_OF_DEFAULT_WORKSPACE = "default";
+
protected static final String SOURCE_NAME = "sourceName";
protected static final String CACHE_TIME_TO_LIVE_IN_MILLISECONDS = "cacheTimeToLiveInMilliseconds";
protected static final String RETRY_LIMIT = "retryLimit";
protected static final String DEFAULT_WORKSPACE = "defaultWorkspace";
+ protected static final String WORKSPACE_ROOT = "workspaceRootPath";
protected static final String PREDEFINED_WORKSPACE_NAMES = "predefinedWorkspaceNames";
protected static final String ALLOW_CREATING_WORKSPACES = "allowCreatingWorkspaces";
@@ -84,7 +92,7 @@
*/
protected static final boolean DEFAULT_SUPPORTS_CREATING_WORKSPACES = true;
/**
- * This source does not support udpates by default, but each instance may be configured to be read-only or updateable}.
+ * This source does not support updates by default, but each instance may be configured to be read-only or updateable}.
*/
public static final boolean DEFAULT_SUPPORTS_UPDATES = false;
@@ -99,8 +107,10 @@
private volatile String name;
private volatile int retryLimit = DEFAULT_RETRY_LIMIT;
private volatile int cacheTimeToLiveInMilliseconds = DEFAULT_CACHE_TIME_TO_LIVE_IN_SECONDS * 1000;
- private volatile String defaultWorkspace;
+ private volatile String defaultWorkspaceName = DEFAULT_NAME_OF_DEFAULT_WORKSPACE;
+ private volatile String workspaceRootPath;
private volatile String[] predefinedWorkspaces = new String[] {};
+ private volatile UUID rootNodeUuid = UUID.randomUUID();
private volatile RepositorySourceCapabilities capabilities = new RepositorySourceCapabilities(
SUPPORTS_SAME_NAME_SIBLINGS,
DEFAULT_SUPPORTS_UPDATES,
@@ -108,7 +118,7 @@
DEFAULT_SUPPORTS_CREATING_WORKSPACES,
SUPPORTS_REFERENCES);
private transient CachePolicy cachePolicy;
- private transient CopyOnWriteArraySet<String> availableWorkspaceNames;
+ private transient Map<String, File> availableWorkspaces;
/**
*
@@ -170,30 +180,64 @@
// }
/**
- * Get the file system path to the existing directory that should be used for the default workspace. If the default is
- * specified as a null String or is not a valid and resolvable path, this source will consider the default to be the current
- * working directory of this virtual machine, as defined by the <code>new File(".")</code>.
+ * Get the relative root directory for the workspaces. If this property is set, workspaces can be given as relative paths from
+ * this directory and all workspace paths must be ancestors of this path.
*
- * @return the file system path to the directory representing the default workspace, or null if the default should be the
- * current working directory
+ * @return the root directory for workspaces
*/
- public String getDirectoryForDefaultWorkspace() {
- return defaultWorkspace;
+ public String getWorkspaceRootPath() {
+ return workspaceRootPath;
}
/**
- * Set the file system path to the existing directory that should be used for the default workspace. If the default is
- * specified as a null String or is not a valid and resolvable path, this source will consider the default to be the current
- * working directory of this virtual machine, as defined by the <code>new File(".")</code>.
+ * Sets the relative root directory for workspaces
*
- * @param pathToDirectoryForDefaultWorkspace the valid and resolvable file system path to the directory representing the
- * default workspace, or null if the current working directory should be used as the default workspace
+ * @param workspaceRootPath the relative root directory for workspaces. If this value is non-null, all workspace paths will be
+ * treated as paths relative to this directory
*/
- public synchronized void setDirectoryForDefaultWorkspace( String pathToDirectoryForDefaultWorkspace ) {
- this.defaultWorkspace = pathToDirectoryForDefaultWorkspace;
+ public synchronized void setWorkspaceRootPath( String workspaceRootPath ) {
+ this.workspaceRootPath = workspaceRootPath;
}
/**
+ * Get the UUID that is used for the root node of each workspace
+ *
+ * @return the UUID that is used for the root node of each workspace
+ */
+ public UUID getRootNodeUuid() {
+ return rootNodeUuid;
+ }
+
+ /**
+ * Set the {@code jcr:uuid} property of the root node in each workspace to the given value.
+ *
+ * @param rootNodeUuid the UUID to use for the root nodes of all workspaces
+ */
+ public synchronized void setRootNodeUuid( String rootNodeUuid ) {
+ CheckArg.isNotNull(rootNodeUuid, "rootNodeUuid");
+ this.rootNodeUuid = UUID.fromString(rootNodeUuid);
+ }
+
+ /**
+ * Get the name of the default workspace.
+ *
+ * @return the name of the workspace that should be used by default; never null
+ */
+ public String getDefaultWorkspaceName() {
+ return defaultWorkspaceName;
+ }
+
+ /**
+ * Set the name of the workspace that should be used when clients don't specify a workspace.
+ *
+ * @param nameOfDefaultWorkspace the name of the workspace that should be used by default, or null if the
+ * {@link #DEFAULT_NAME_OF_DEFAULT_WORKSPACE default name} should be used
+ */
+ public synchronized void setDefaultWorkspaceName( String nameOfDefaultWorkspace ) {
+ this.defaultWorkspaceName = nameOfDefaultWorkspace != null ? nameOfDefaultWorkspace : DEFAULT_NAME_OF_DEFAULT_WORKSPACE;
+ }
+
+ /**
* Gets the names of the workspaces that are available when this source is created. Each workspace name corresponds to a path
* to a directory on the file system.
*
@@ -310,7 +354,7 @@
}
ref.add(new StringRefAddr(CACHE_TIME_TO_LIVE_IN_MILLISECONDS, Integer.toString(getCacheTimeToLiveInMilliseconds())));
ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
- ref.add(new StringRefAddr(DEFAULT_WORKSPACE, getDirectoryForDefaultWorkspace()));
+ ref.add(new StringRefAddr(DEFAULT_WORKSPACE, getDefaultWorkspaceName()));
ref.add(new StringRefAddr(ALLOW_CREATING_WORKSPACES, Boolean.toString(isCreatingWorkspacesAllowed())));
String[] workspaceNames = getPredefinedWorkspaceNames();
if (workspaceNames != null && workspaceNames.length != 0) {
@@ -356,7 +400,7 @@
if (sourceName != null) source.setName(sourceName);
if (cacheTtlInMillis != null) source.setCacheTimeToLiveInMilliseconds(Integer.parseInt(cacheTtlInMillis));
if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
- if (defaultWorkspace != null) source.setDirectoryForDefaultWorkspace(defaultWorkspace);
+ if (defaultWorkspace != null) source.setDefaultWorkspaceName(defaultWorkspace);
if (createWorkspaces != null) source.setCreatingWorkspacesAllowed(Boolean.parseBoolean(createWorkspaces));
if (workspaceNames != null && workspaceNames.length != 0) source.setPredefinedWorkspaceNames(workspaceNames);
return source;
@@ -364,6 +408,18 @@
return null;
}
+ private String pathFor( String workspaceName ) {
+ String path = workspaceName;
+ if (this.workspaceRootPath != null) {
+ if (this.workspaceRootPath.charAt(workspaceRootPath.length() - 1) == File.separatorChar) {
+ path = this.workspaceRootPath + workspaceName;
+ }
+ path = this.workspaceRootPath + File.separatorChar + workspaceName;
+ }
+
+ return path;
+ }
+
/**
* {@inheritDoc}
*
@@ -376,54 +432,42 @@
throw new RepositorySourceException(getName(), msg.text("name"));
}
- boolean reportWarnings = false;
- if (this.availableWorkspaceNames == null) {
+ if (this.availableWorkspaces == null) {
// Set up the predefined workspace names ...
- this.availableWorkspaceNames = new CopyOnWriteArraySet<String>();
+ this.availableWorkspaces = new ConcurrentHashMap<String, File>();
for (String predefined : this.predefinedWorkspaces) {
- this.availableWorkspaceNames.add(predefined);
- }
-
- // Report the warnings for non-existant predefined workspaces
- reportWarnings = true;
- for (String path : this.availableWorkspaceNames) {
// Look for the file at this path ...
- File file = new File(path);
+ File file = new File(pathFor(predefined));
if (!file.exists()) {
- Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceDoesNotExist, path, name);
+ Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceDoesNotExist, predefined, name);
} else if (!file.isDirectory()) {
- Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceIsNotDirectory, path, name);
+ Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceIsNotDirectory, predefined, name);
} else if (!file.canRead()) {
- Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceCannotBeRead, path, name);
+ Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceCannotBeRead, predefined, name);
}
+
+
+ this.availableWorkspaces.put(predefined, file);
}
}
- FilenameFilter filenameFilter = null;
- boolean supportsUpdates = getSupportsUpdates();
- File defaultWorkspace = new File(".");
- String path = getDirectoryForDefaultWorkspace();
- if (path != null) {
+ if (defaultWorkspaceName != null) {
// Look for the file at this path ...
- File file = new File(path);
- I18n warning = null;
+ File file = new File(pathFor(defaultWorkspaceName));
if (!file.exists()) {
- warning = FileSystemI18n.pathForDefaultWorkspaceDoesNotExist;
+ Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceDoesNotExist, defaultWorkspaceName, name);
} else if (!file.isDirectory()) {
- warning = FileSystemI18n.pathForDefaultWorkspaceIsNotDirectory;
+ Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceIsNotDirectory, defaultWorkspaceName, name);
} else if (!file.canRead()) {
- warning = FileSystemI18n.pathForDefaultWorkspaceCannotBeRead;
- } else {
- // good to use!
- defaultWorkspace = file;
+ Logger.getLogger(getClass()).warn(FileSystemI18n.pathForPredefinedWorkspaceCannotBeRead, defaultWorkspaceName, name);
}
- if (reportWarnings && warning != null) {
- Logger.getLogger(getClass()).warn(warning, path, name);
- }
+
+
+ this.availableWorkspaces.put(defaultWorkspaceName, file);
}
- this.availableWorkspaceNames.add(defaultWorkspace.getPath());
- return new FileSystemConnection(name, defaultWorkspace, availableWorkspaceNames, isCreatingWorkspacesAllowed(),
- cachePolicy, filenameFilter, supportsUpdates);
+
+ return new FileSystemConnection(name, defaultWorkspaceName, availableWorkspaces, isCreatingWorkspacesAllowed(),
+ cachePolicy, rootNodeUuid, workspaceRootPath, (FilenameFilter) null, getSupportsUpdates());
}
@Immutable
Modified: trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/main/resources/org/jboss/dna/connector/filesystem/FileSystemI18n.properties 2009-07-24 01:15:00 UTC (rev 1126)
@@ -29,6 +29,9 @@
pathForPredefinedWorkspaceDoesNotExist = The path "{0}" for the predefined workspace for the file system source "{1}" does not represent an existing directory
pathForPredefinedWorkspaceIsNotDirectory = The path "{0}" for the predefined workspace for the file system source "{1}" is actually a path to an existing file
pathForPredefinedWorkspaceCannotBeRead = The path "{0}" for the predefined workspace for the file system source "{1}" cannot be read
+pathForWorkspaceRootDoesNotExist = The path "{0}" for the predefined workspace for the file system source "{1}" does not represent an existing directory
+pathForWorkspaceRootIsNotDirectory = The path "{0}" for the predefined workspace for the file system source "{1}" is actually a path to an existing file
+pathForWorkspaceRootCannotBeRead = The path "{0}" for the predefined workspace for the file system source "{1}" cannot be read
propertyIsRequired = The {0} property is required but has no value
locationInRequestMustHavePath = {0} requires a path in the request: {1}
sameNameSiblingsAreNotAllowed = {0} does not allow same name siblings on nodes: {1}
Modified: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorCreateWorkspacesTest.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorCreateWorkspacesTest.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorCreateWorkspacesTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -25,7 +25,6 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -56,7 +55,7 @@
FileSystemSource source = new FileSystemSource();
source.setName("Test Repository");
source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
- source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setDefaultWorkspaceName(predefinedWorkspaceNames[0]);
source.setCreatingWorkspacesAllowed(true);
return source;
@@ -101,11 +100,8 @@
workspaceNames.add(workspace.getName());
}
// The actual names should be the absolute paths to the directories representing the root ...
- String absolutePathToRepositories = new File("./src/test/resources/repositories/").getCanonicalPath();
+ String absolutePathToRepositories = "./src/test/resources/repositories/";
- // getCanonicalPath strips the trailing separator character, so we need to re-added it for each case
- absolutePathToRepositories += File.separatorChar;
-
assertThat(workspaceNames.remove(absolutePathToRepositories + "airplanes"), is(true));
assertThat(workspaceNames.remove(absolutePathToRepositories + "cars"), is(true));
assertThat(workspaceNames.isEmpty(), is(true));
Modified: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNoCreateWorkspaceTest.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNoCreateWorkspaceTest.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNoCreateWorkspaceTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -49,7 +49,7 @@
FileSystemSource source = new FileSystemSource();
source.setName("Test Repository");
source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
- source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setDefaultWorkspaceName(predefinedWorkspaceNames[0]);
source.setCreatingWorkspacesAllowed(false);
return source;
Modified: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNotWritableTest.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNotWritableTest.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorNotWritableTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -46,7 +46,7 @@
FileSystemSource source = new FileSystemSource();
source.setName("Test Repository");
source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
- source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setDefaultWorkspaceName(predefinedWorkspaceNames[0]);
source.setCreatingWorkspacesAllowed(false);
return source;
Modified: trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadableTest.java
===================================================================
--- trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadableTest.java 2009-07-22 22:41:00 UTC (rev 1125)
+++ trunk/extensions/dna-connector-filesystem/src/test/java/org/jboss/dna/connector/filesystem/FileSystemConnectorReadableTest.java 2009-07-24 01:15:00 UTC (rev 1126)
@@ -26,7 +26,6 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
-import java.io.File;
import java.util.List;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.JcrLexicon;
@@ -50,13 +49,13 @@
@Override
protected RepositorySource setUpSource() {
// Set the connection properties to be use the content of "./src/test/resources/repositories" as a repository ...
- String path = new File(".").getAbsolutePath() + "/src/test/resources/repositories/";
+ String path = "./src/test/resources/repositories/";
String[] predefinedWorkspaceNames = new String[] {path + "airplanes", path + "cars"};
FileSystemSource source = new FileSystemSource();
source.setName("Test Repository");
source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
- source.setDirectoryForDefaultWorkspace(predefinedWorkspaceNames[0]);
- source.setCreatingWorkspacesAllowed(false);
+ source.setDefaultWorkspaceName(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(true);
return source;
}
16 years, 5 months
DNA SVN: r1125 - in branches/eclipse/dna-web-jcr-rest-client: src/main/java/org/jboss/dna/web/jcr/rest/client and 9 other directories.
by dna-commits@lists.jboss.org
Author: elvisisking
Date: 2009-07-22 18:41:00 -0400 (Wed, 22 Jul 2009)
New Revision: 1125
Added:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/WorkspaceNode.java
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/document.txt
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/picture.jpg
Removed:
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestExecutor.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessor.java
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessorTest.java
Modified:
branches/eclipse/dna-web-jcr-rest-client/pom.xml
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Logger.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/RepositoryValidator.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/WorkspaceValidator.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/IJsonConstants.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java
branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java
branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java
branches/eclipse/dna-web-jcr-rest-client/src/test/resources/log4j.properties
Log:
Mostly getting the URLs correct to talk to REST server. JsonRestClientTest is an integration test that starts REST server.
Modified: branches/eclipse/dna-web-jcr-rest-client/pom.xml
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/pom.xml 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/pom.xml 2009-07-22 22:41:00 UTC (rev 1125)
@@ -1,76 +1,165 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.jboss.dna</groupId>
- <artifactId>dna</artifactId>
- <version>0.6-SNAPSHOT</version>
- </parent>
- <!-- The groupId and version values are inherited from parent -->
- <artifactId>dna-web-jcr-rest-client</artifactId>
- <packaging>jar</packaging>
- <name>JBoss DNA JCR REST Client</name>
- <description>JBoss DNA JCR REST client resource publishing</description>
- <url>http://labs.jboss.org/dna</url>
- <!--
- Define the dependencies. Note that all version and scopes default to those
- defined in the dependencyManagement section of the parent pom.
- -->
- <dependencies>
- <!--
- Testing (note the scope)
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna</artifactId>
+ <version>0.6-SNAPSHOT</version>
+ </parent>
+ <!-- The groupId and version values are inherited from parent -->
+ <artifactId>dna-web-jcr-rest-client</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss DNA JCR REST Client</name>
+ <description>JBoss DNA JCR REST client resource publishing
+ </description>
+ <url>http://labs.jboss.org/dna</url>
+ <!--
+ Define the dependencies. Note that all version and scopes default to
+ those defined in the dependencyManagement section of the parent pom.
+ -->
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-web-jcr-rest-war</artifactId>
+ <type>war</type>
+ <version>${pom.version}</version>
+ </dependency>
+
+ <!--
+ Testing (note the scope)
-->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <scope>test</scope>
- </dependency>
- <!--
- Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for testing)
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>integration-test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>integration-test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>integration-test</scope>
+ </dependency>
+ <!--
+ Logging (require SLF4J API for compiling, but use Log4J and its SLF4J
+ binding for testing)
+ -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ <!--
+ Java Concurrency in Practice annotations
-->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
- <!--
- Java Concurrency in Practice annotations
- -->
- <dependency>
- <groupId>net.jcip</groupId>
- <artifactId>jcip-annotations</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <version>1.1.GA</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxb-provider</artifactId>
- <version>1.1.GA</version>
- </dependency>
- </dependencies>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-report-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
+ <dependency>
+ <groupId>net.jcip</groupId>
+ <artifactId>jcip-annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxrs</artifactId>
+ <version>1.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxb-provider</artifactId>
+ <version>1.1.GA</version>
+ </dependency>
+ </dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin
+ </artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <!-- >version>1.0.1-SNAPSHOT</version -->
+ <executions>
+ <execution>
+ <id>start-container</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-container</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <container>
+ <containerId>${cargo.container}</containerId>
+ <home>${cargo.container.home}</home>
+ </container>
+ <configuration>
+ <properties>
+ <cargo.logging>high</cargo.logging>
+ <cargo.servlet.users>
+ dnauser:password:connect,readwrite|unauthorized:password:bogus
+ </cargo.servlet.users>
+ <cargo.servlet.port>8080</cargo.servlet.port>
+ </properties>
+
+ <deployables>
+ <!-- application to deploy -->
+ <deployable>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-web-jcr-rest-war</artifactId>
+ <type>war</type>
+ <properties>
+ <context>resources</context>
+ </properties>
+ </deployable>
+ </deployables>
+ </configuration>
+ <wait>false</wait>
+ </configuration>
+ </plugin>
+ <!--
+ Override the default Surefire behavior to run during
+ integration-test phase
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>surefire-it</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -76,6 +76,12 @@
String WorkspaceNullRepositoryMsg = "WorkspaceNullRepositoryMsg"; //$NON-NLS-1$
String WorkspaceShortDescription = "WorkspaceShortDescription"; //$NON-NLS-1$
+
+ // JsonRestClient messages
+
+ String CreateFileFailedMsg = "CreateFileFailedMsg"; //$NON-NLS-1$
+
+ String CreateFolderFailedMsg = "CreateFolderFailedMsg"; //$NON-NLS-1$
String GetRepositoriesFailedMsg = "GetRepositoriesFailedMsg"; //$NON-NLS-1$
Copied: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java (from rev 1113, branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestExecutor.java)
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -0,0 +1,75 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client;
+
+import java.io.File;
+import java.util.Collection;
+import org.jboss.dna.web.jcr.rest.client.domain.Repository;
+import org.jboss.dna.web.jcr.rest.client.domain.Server;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
+
+/**
+ * @author dan
+ */
+public interface IRestClient {
+
+ /**
+ * @param server the server whose repositories are being requested (never <code>null</code>)
+ * @return the repositories within the specified server (never <code>null</code>)
+ * @throws Exception if there is a problem obtaining the repositories
+ * @since 0.6
+ */
+ public abstract Collection<Repository> getRepositories( Server server ) throws Exception;
+
+ /**
+ * @param repository the repository whose workspaces are being requested (never <code>null</code>)
+ * @return the workspaces within the specified repository (never <code>null</code>)
+ * @throws Exception if there is a problem obtaining the workspaces
+ * @since 0.6
+ */
+ public abstract Collection<Workspace> getWorkspaces( Repository repository ) throws Exception;
+
+ /**
+ * @param workspace the workspace where the resource will be published (never <code>null</code>)
+ * @param path the path to the folder where the file will be published
+ * @param file the resource being published (never <code>null</code>)
+ * @throws Exception if there is a problem publishing
+ * @since 0.6
+ */
+ public abstract void publish( Workspace workspace,
+ String path,
+ File file ) throws Exception;
+
+ /**
+ * @param workspace the workspace where the resource will be unpublished (never <code>null</code>)
+ * @param path the path to the folder where the file is published (never <code>null</code>)
+ * @param file the file being unpublished (never <code>null</code>)
+ * @throws Exception if there is a problem unpublishing
+ * @since 0.6
+ */
+ public abstract void unpublish( Workspace workspace,
+ String path,
+ File file ) throws Exception;
+
+}
Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestClient.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestExecutor.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestExecutor.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IRestExecutor.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -1,76 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.client;
-
-import java.io.File;
-import java.util.Collection;
-import org.jboss.dna.web.jcr.rest.client.domain.Repository;
-import org.jboss.dna.web.jcr.rest.client.domain.Server;
-import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
-
-/**
- * @author dan
- *
- */
-public interface IRestExecutor {
-
- /**
- * @param server the server whose repositories are being requested (never <code>null</code>)
- * @return the repositories within the specified server (never <code>null</code>)
- * @throws Exception if there is a problem obtaining the repositories
- * @since 0.6
- */
- public abstract Collection<Repository> getRepositories( Server server ) throws Exception;
-
- /**
- * @param repository the repository whose workspaces are being requested (never <code>null</code>)
- * @return the workspaces within the specified repository (never <code>null</code>)
- * @throws Exception if there is a problem obtaining the workspaces
- * @since 0.6
- */
- public abstract Collection<Workspace> getWorkspaces( Repository repository ) throws Exception;
-
- /**
- * @param repository the repository where the resource will be published
- * @param parentPath the parent path where the file will be published in the repository
- * @param file the resource being published
- * @throws Exception if there is a problem publishing
- * @since 0.6
- */
- public abstract void publish( Repository repository,
- String parentPath,
- File file ) throws Exception;
-
- /**
- * @param repository the repository where the resource will be unpublished (never <code>null</code>)
- * @param parentPath the path to the parent folder in the repository (never <code>null</code>)
- * @param file the file being unpublished (never <code>null</code>)
- * @throws Exception if there is a problem unpublishing
- * @since 0.6
- */
- public abstract void unpublish( Repository repository,
- String parentPath,
- File file ) throws Exception;
-
-}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Logger.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Logger.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Logger.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -37,18 +37,44 @@
// ===========================================================================================================================
/**
- * @param status the status whose message is a {@link MessageFormat} pattern.
+ * @param clazz the class whose logger will be used
+ * @param message the localized message
+ * @return the message prepended with the class name and a delimiter
+ * @since 0.6
+ */
+ private static String getMessage( Class<?> clazz,
+ String message ) {
+ return (clazz.getSimpleName() + ": " + message); //$NON-NLS-1$
+ }
+
+ /**
+ * @param clazz the class whose logger will be used
+ * @param pattern the {@link MessageFormat} pattern
* @param arguments the arguments being inserted into the pattern
* @return the message
* @since 0.6
*/
- private static String getMessage( Status status,
+ private static String getMessage( Class<?> clazz,
+ String pattern,
Object... arguments ) {
- return MessageFormat.format(status.getMessage(), arguments);
+ return getMessage(clazz, MessageFormat.format(pattern, arguments));
}
/**
* @param clazz the class whose logger will be used
+ * @param status the status whose message is a {@link MessageFormat} pattern
+ * @param arguments the arguments being inserted into the pattern
+ * @return the message
+ * @since 0.6
+ */
+ private static String getMessage( Class<?> clazz,
+ Status status,
+ Object... arguments ) {
+ return getMessage(clazz, status.getMessage(), arguments);
+ }
+
+ /**
+ * @param clazz the class whose logger will be used
* @param status the status being logged
* @since 0.6
*/
@@ -58,30 +84,24 @@
if (status.isError() && delegate.isErrorEnabled()) {
if (status.getException() == null) {
- delegate.error(status.getMessage());
+ delegate.error(getMessage(clazz, status.getMessage()));
} else {
- delegate.error(status.getMessage(), status.getException());
+ delegate.error(getMessage(clazz, status.getMessage()), status.getException());
}
} else if (status.isWarning() && delegate.isWarnEnabled()) {
if (status.getException() == null) {
- delegate.warn(status.getMessage());
+ delegate.warn(getMessage(clazz, status.getMessage()));
} else {
- delegate.warn(status.getMessage(), status.getException());
+ delegate.warn(getMessage(clazz, status.getMessage()), status.getException());
}
} else if (status.isInfo() && delegate.isInfoEnabled()) {
if (status.getException() == null) {
- delegate.info(status.getMessage());
+ delegate.info(getMessage(clazz, status.getMessage()));
} else {
- delegate.info(status.getMessage(), status.getException());
+ delegate.info(getMessage(clazz, status.getMessage()), status.getException());
}
} else {
- if (delegate.isTraceEnabled()) {
- if (status.getException() == null) {
- delegate.info(status.getMessage());
- } else {
- delegate.info(status.getMessage(), status.getException());
- }
- }
+ trace(clazz, null, status.getMessage());
}
}
@@ -97,15 +117,15 @@
org.slf4j.Logger delegate = LoggerFactory.getLogger(clazz);
if (status.isError() && delegate.isErrorEnabled()) {
- String msg = getMessage(status, arguments);
+ String msg = getMessage(clazz, status, arguments);
if (status.getException() == null) {
delegate.error(msg);
} else {
- delegate.error(msg);
+ delegate.error(msg, status.getException());
}
} else if (status.isWarning() && delegate.isWarnEnabled()) {
- String msg = getMessage(status, arguments);
+ String msg = getMessage(clazz, status, arguments);
if (status.getException() == null) {
delegate.warn(msg);
@@ -113,7 +133,7 @@
delegate.warn(msg, status.getException());
}
} else if (status.isInfo() && delegate.isInfoEnabled()) {
- String msg = getMessage(status, arguments);
+ String msg = getMessage(clazz, status, arguments);
if (status.getException() == null) {
delegate.info(msg);
@@ -121,18 +141,52 @@
delegate.info(msg, status.getException());
}
} else {
- if (delegate.isTraceEnabled()) {
- String msg = getMessage(status, arguments);
+ trace(clazz, status.getException(), status.getMessage(), arguments);
+ }
+ }
- if (status.getException() == null) {
- delegate.info(msg);
- } else {
- delegate.info(msg, status.getException());
- }
+ /**
+ * @param clazz the class whose logger will be used
+ * @param e the error being logged or <code>null</code>
+ * @param msg the message being logged
+ * @since 0.6
+ */
+ public static void trace( Class<?> clazz,
+ Throwable e,
+ String msg ) {
+ org.slf4j.Logger delegate = LoggerFactory.getLogger(clazz);
+
+ if (delegate.isTraceEnabled()) {
+ if (e == null) {
+ delegate.trace(getMessage(clazz, msg));
+ } else {
+ delegate.trace(getMessage(clazz, msg), e);
}
}
}
+ /**
+ * @param clazz the class whose logger will be used
+ * @param e the error being logged or <code>null</code>
+ * @param pattern the {@link MessageFormat} pattern
+ * @param arguments the arguments to be inserted into the pattern
+ * @since 0.6
+ */
+ public static void trace( Class<?> clazz,
+ Throwable e,
+ String pattern,
+ Object... arguments ) {
+ org.slf4j.Logger delegate = LoggerFactory.getLogger(clazz);
+
+ if (delegate.isTraceEnabled()) {
+ if (e == null) {
+ delegate.trace(getMessage(clazz, pattern, arguments));
+ } else {
+ delegate.trace(getMessage(clazz, pattern, arguments), e);
+ }
+ }
+ }
+
// ===========================================================================================================================
// Constructors
// ===========================================================================================================================
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -23,6 +23,7 @@
*/
package org.jboss.dna.web.jcr.rest.client;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
import java.io.File;
import java.io.FileOutputStream;
import java.text.MessageFormat;
@@ -60,7 +61,7 @@
* @since 0.6
*/
@ThreadSafe
-public final class ServerManager implements IMessages {
+public final class ServerManager {
// ===========================================================================================================================
// Constants
@@ -124,7 +125,7 @@
*
* @since 0.6
*/
- private final IRestExecutor restExecutor;
+ private final IRestClient restExecutor;
/**
* The path where the server registry is persisted or <code>null</code> if not persisted.
@@ -159,7 +160,7 @@
* @since 0.6
*/
public ServerManager( String stateLocationPath,
- IRestExecutor restExecutor ) {
+ IRestClient restExecutor ) {
this.servers = new ArrayList<Server>();
this.stateLocationPath = stateLocationPath;
this.restExecutor = restExecutor;
@@ -235,9 +236,9 @@
Collection<Repository> repositories = this.restExecutor.getRepositories(server);
return Collections.unmodifiableCollection(new ArrayList<Repository>(repositories));
}
-
+
// server must be registered in order to obtain it's repositories
- String pattern = IMessages.ServerManagerUnregisteredServer;
+ String pattern = MESSAGES.getString(IMessages.ServerManagerUnregisteredServer);
throw new RuntimeException(MessageFormat.format(pattern, server.getShortDescription()));
} finally {
this.serverLock.readLock().unlock();
@@ -255,14 +256,14 @@
public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
try {
this.serverLock.readLock().lock();
-
+
if (isRegistered(repository.getServer())) {
Collection<Workspace> workspaces = this.restExecutor.getWorkspaces(repository);
return Collections.unmodifiableCollection(new ArrayList<Workspace>(workspaces));
}
-
+
// a repository's server must be registered in order to obtain it's workspaces
- String pattern = IMessages.ServerManagerUnregisteredServer;
+ String pattern = MESSAGES.getString(IMessages.ServerManagerUnregisteredServer);
throw new RuntimeException(MessageFormat.format(pattern, repository.getServer().getShortDescription()));
} finally {
this.serverLock.readLock().unlock();
@@ -301,7 +302,7 @@
}
// server already exists
- String pattern = MESSAGES.getString(ServerExistsMsg);
+ String pattern = MESSAGES.getString(IMessages.ServerExistsMsg);
String msg = MessageFormat.format(pattern, server.getShortDescription());
Status status = new Status(Severity.ERROR, msg, null);
return status;
@@ -341,7 +342,7 @@
}
// server could not be removed
- String pattern = MESSAGES.getString(ServerManagerRegistryRemoveUnexpectedError);
+ String pattern = MESSAGES.getString(IMessages.ServerManagerRegistryRemoveUnexpectedError);
String msg = MessageFormat.format(pattern, server.getShortDescription());
Status status = new Status(Severity.ERROR, msg, null);
return status;
@@ -416,10 +417,11 @@
}
for (Exception error : errors) {
- Logger.log(getClass(), new Status(Severity.ERROR, ServerManagerRegistryListenerError, error));
+ Logger.log(getClass(), new Status(Severity.ERROR, MESSAGES.getString(IMessages.ServerManagerRegistryListenerError),
+ error));
}
- return new Status(Severity.WARNING, ServerManagerRegistryListenerErrorsOccurred, null);
+ return new Status(Severity.WARNING, MESSAGES.getString(IMessages.ServerManagerRegistryListenerErrorsOccurred), null);
}
/**
@@ -472,7 +474,7 @@
}
}
} catch (Exception e) {
- String pattern = MESSAGES.getString(ErrorRestoringServerRegistry);
+ String pattern = MESSAGES.getString(IMessages.ErrorRestoringServerRegistry);
return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
}
}
@@ -519,7 +521,7 @@
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); //$NON-NLS-1$ //$NON-NLS-2$
transformer.transform(source, resultXML);
} catch (Exception e) {
- String pattern = MESSAGES.getString(ErrorSavingServerRegistry);
+ String pattern = MESSAGES.getString(IMessages.ErrorSavingServerRegistry);
return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
}
} else if ((this.stateLocationPath != null) && stateFileExists()) {
@@ -527,7 +529,7 @@
try {
new File(getStateFileName()).delete();
} catch (Exception e) {
- String pattern = MESSAGES.getString(ErrorDeletingServerRegistryFile);
+ String pattern = MESSAGES.getString(IMessages.ErrorDeletingServerRegistryFile);
return new Status(Severity.ERROR, MessageFormat.format(pattern, getStateFileName()), e);
}
}
@@ -570,7 +572,7 @@
}
// unexpected problem adding new version of server to registry
- String pattern = MESSAGES.getString(ServerManagerRegistryUpdateAddError);
+ String pattern = MESSAGES.getString(IMessages.ServerManagerRegistryUpdateAddError);
String msg = MessageFormat.format(pattern, status.getMessage());
status = new Status(Severity.ERROR, msg, status.getException());
return status;
@@ -580,7 +582,7 @@
}
// unexpected problem removing server from registry
- String pattern = MESSAGES.getString(ServerManagerRegistryUpdateRemoveError);
+ String pattern = MESSAGES.getString(IMessages.ServerManagerRegistryUpdateRemoveError);
String msg = MessageFormat.format(pattern, status.getMessage());
status = new Status(Severity.ERROR, msg, status.getException());
return status;
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Repository.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -23,11 +23,13 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.RepositoryShortDescription;
import java.text.MessageFormat;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.web.jcr.rest.client.IMessages;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.domain.validation.RepositoryValidator;
+import org.jboss.dna.web.jcr.rest.client.json.JsonUtils;
/**
* The Repository class is the business object for a DNA repository.
@@ -36,7 +38,7 @@
* @since 0.6
*/
@Immutable
-public final class Repository implements IMessages, IDnaObject {
+public final class Repository implements IDnaObject {
// ===========================================================================================================================
// Fields
@@ -131,7 +133,7 @@
*/
public String getShortDescription() {
String pattern = MESSAGES.getString(RepositoryShortDescription);
- return MessageFormat.format(pattern, this.name, this.server.getShortDescription());
+ return MessageFormat.format(pattern, JsonUtils.decodeEscaping(this.name), this.server.getShortDescription());
}
/**
@@ -148,4 +150,15 @@
return hash;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ * @since 0.6
+ */
+ @Override
+ public String toString() {
+ return getShortDescription();
+ }
+
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -23,9 +23,10 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerShortDescription;
import java.text.MessageFormat;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.web.jcr.rest.client.IMessages;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.Utils;
import org.jboss.dna.web.jcr.rest.client.domain.validation.RepositoryValidator;
@@ -38,7 +39,7 @@
* @since 0.6
*/
@Immutable
-public final class Server implements IMessages, IDnaObject {
+public final class Server implements IDnaObject {
// ===========================================================================================================================
// Fields
@@ -212,4 +213,15 @@
return this.persistPassword;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ * @since 0.6
+ */
+ @Override
+ public String toString() {
+ return getShortDescription();
+ }
+
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Workspace.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -23,11 +23,13 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.WorkspaceShortDescription;
import java.text.MessageFormat;
import net.jcip.annotations.Immutable;
-import org.jboss.dna.web.jcr.rest.client.IMessages;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.domain.validation.WorkspaceValidator;
+import org.jboss.dna.web.jcr.rest.client.json.JsonUtils;
/**
* The Workspace class is the business object for a DNA repository workspace.
@@ -36,7 +38,7 @@
* @since 0.6
*/
@Immutable
-public final class Workspace implements IMessages, IDnaObject {
+public final class Workspace implements IDnaObject {
// ===========================================================================================================================
// Fields
@@ -137,7 +139,7 @@
*/
public String getShortDescription() {
String pattern = MESSAGES.getString(WorkspaceShortDescription);
- return MessageFormat.format(pattern, this.name, this.repository.getShortDescription());
+ return MessageFormat.format(pattern, JsonUtils.decodeEscaping(this.name), this.repository.getShortDescription());
}
/**
@@ -154,4 +156,15 @@
return hash;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ * @since 0.6
+ */
+ @Override
+ public String toString() {
+ return getShortDescription();
+ }
+
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/RepositoryValidator.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/RepositoryValidator.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/RepositoryValidator.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -23,7 +23,9 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain.validation;
-import org.jboss.dna.web.jcr.rest.client.IMessages;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.RepositoryEmptyNameMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.RepositoryNullServerMsg;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.Status.Severity;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
@@ -32,7 +34,7 @@
* @author Dan Florian
* @since 0.6
*/
-public final class RepositoryValidator implements IMessages {
+public final class RepositoryValidator {
// ===========================================================================================================================
// Class Methods
@@ -93,5 +95,5 @@
private RepositoryValidator() {
// nothing to do
}
-
+
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/ServerValidator.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -23,9 +23,13 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain.validation;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerEmptyUrlMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerEmptyUserMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerExistsMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.ServerInvalidUrlMsg;
import java.net.URL;
import java.text.MessageFormat;
-import org.jboss.dna.web.jcr.rest.client.IMessages;
import org.jboss.dna.web.jcr.rest.client.ServerManager;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.Status.Severity;
@@ -35,7 +39,7 @@
* @author Dan Florian
* @since 0.6
*/
-public final class ServerValidator implements IMessages {
+public final class ServerValidator {
// ===========================================================================================================================
// Class Methods
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/WorkspaceValidator.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/WorkspaceValidator.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/validation/WorkspaceValidator.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -23,7 +23,9 @@
*/
package org.jboss.dna.web.jcr.rest.client.domain.validation;
-import org.jboss.dna.web.jcr.rest.client.IMessages;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.WorkspaceEmptyNameMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.WorkspaceNullRepositoryMsg;
import org.jboss.dna.web.jcr.rest.client.Status;
import org.jboss.dna.web.jcr.rest.client.Status.Severity;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
@@ -32,7 +34,7 @@
* @author Dan Florian
* @since 0.6
*/
-public final class WorkspaceValidator implements IMessages {
+public final class WorkspaceValidator {
// ===========================================================================================================================
// Class Methods
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FileNode.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -34,7 +34,7 @@
import net.jcip.annotations.Immutable;
import org.codehaus.jettison.json.JSONObject;
import org.jboss.dna.web.jcr.rest.client.IJcrConstants;
-import org.jboss.dna.web.jcr.rest.client.domain.Repository;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
/**
* @author Dan Florian
@@ -55,36 +55,37 @@
private final File file;
/**
- * The parent folder in the repository where the file is or will be published or unpublished.
+ * The folder in the workspace where the file is or will be published or unpublished.
*
* @since 0.6
*/
- private final String parentPath;
+ private final String path;
/**
- * The repository where the file is or will be being published or unpublished.
+ * The workspace where the file is or will be published or unpublished.
*
* @since 0.6
*/
- private final Repository repository;
+ private final Workspace workspace;
// ===========================================================================================================================
// Constructors
// ===========================================================================================================================
/**
- * @param repository the repository being used
- * @param parentPath the parent path in the repository
+ * @param workspace the workspace being used (never <code>null</code>)
+ * @param path the path in the workspace (never <code>null</code>)
* @param file the file on the local file system
* @throws Exception if there is a problem constructing the file node
+ * @since 0.6
*/
- public FileNode( Repository repository,
- String parentPath,
+ public FileNode( Workspace workspace,
+ String path,
File file ) throws Exception {
super(file.getName());
this.file = file;
- this.parentPath = parentPath;
- this.repository = repository;
+ this.path = path;
+ this.workspace = workspace;
// add properties
JSONObject properties = new JSONObject();
@@ -124,11 +125,11 @@
}
/**
- * @return the parent path where the file is or will be published or unpublished
+ * @return the path where the file is or will be published or unpublished
* @since 0.6
*/
- public String getParentPath() {
- return this.parentPath;
+ public String getPath() {
+ return this.path;
}
/**
@@ -139,13 +140,11 @@
*/
@Override
public URL getUrl() throws Exception {
- StringBuilder url = new StringBuilder(createUrl(this.repository, this.parentPath).toString());
+ FolderNode folderNode = new FolderNode(this.workspace, getPath());
+ StringBuilder url = new StringBuilder(folderNode.getUrl().toString());
- if (!this.parentPath.endsWith("/")) { //$NON-NLS-1$
- url.append('/');
- }
-
- url.append(this.file.getName());
+ // add file to path
+ url.append('/').append(this.file.getName());
return new URL(url.toString());
}
@@ -169,7 +168,7 @@
}
}
}
-
+
return bytes.toArray(new Byte[(bytes.size())]);
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/FolderNode.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -27,7 +27,7 @@
import net.jcip.annotations.Immutable;
import org.codehaus.jettison.json.JSONObject;
import org.jboss.dna.web.jcr.rest.client.IJcrConstants;
-import org.jboss.dna.web.jcr.rest.client.domain.Repository;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
/**
* @author Dan Florian
@@ -41,26 +41,26 @@
// ===========================================================================================================================
/**
- * The repository where the file is being published.
+ * The workspace where the file is being published.
*
* @since 0.6
*/
- private final Repository repository;
+ private final Workspace workspace;
// ===========================================================================================================================
// Constructors
// ===========================================================================================================================
/**
- * @param repository the repository being used
- * @param fullPath the full path of the folder within the repository
+ * @param workspace the workspace being used (never <code>null</code>)
+ * @param fullPath the full path of the folder within the workspace (never <code>null</code>)
* @throws Exception if there is a problem creating the folder node
* @since 0.6
*/
- public FolderNode( Repository repository,
+ public FolderNode( Workspace workspace,
String fullPath ) throws Exception {
super(fullPath);
- this.repository = repository;
+ this.workspace = workspace;
// add properties
JSONObject properties = new JSONObject();
@@ -73,22 +73,41 @@
// ===========================================================================================================================
/**
- * @return the full path of folder within the repository
+ * @return the full path of folder within the workspace
* @since 0.6
*/
public String getPath() {
return getId();
}
-
+
/**
* {@inheritDoc}
- *
+ * <p>
+ * The URL will NOT end in '/'.
+ *
* @see org.jboss.dna.web.jcr.rest.client.json.JsonNode#getUrl()
* @since 0.6
*/
@Override
public URL getUrl() throws Exception {
- return createUrl(this.repository, getId());
+ WorkspaceNode workspaceNode = new WorkspaceNode(this.workspace);
+ StringBuilder url = new StringBuilder(workspaceNode.getUrl().toString());
+
+ // add folder path
+ String path = getPath();
+
+ if (path.startsWith("/")) { //$NON-NLS-1$
+ url.append(path);
+ } else {
+ url.append('/').append(path);
+ }
+
+ // strip off ending '/'
+ if (path.endsWith("/")) { //$NON-NLS-1$
+ url.setLength(url.length() - 1);
+ }
+
+ return new URL(url.toString());
}
-
+
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/IJsonConstants.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/IJsonConstants.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/IJsonConstants.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -72,11 +72,6 @@
String CHILDREN_KEY = "children"; //$NON-NLS-1$
/**
- * @since 0.6
- */
- String REPOSITORY_URL_CONTEXT = "/"; //$NON-NLS-1$
-
- /**
* The key in the <code>JSONObject</code> whose value is the collection of node properties.
*
* @since 0.6
@@ -88,4 +83,9 @@
*/
String SERVER_CONTEXT = "/resources"; //$NON-NLS-1$
+ /**
+ * @since 0.6
+ */
+ String WORKSPACE_CONTEXT = "/items"; //$NON-NLS-1$
+
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonNode.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -25,8 +25,6 @@
import java.net.URL;
import org.codehaus.jettison.json.JSONObject;
-import org.jboss.dna.web.jcr.rest.client.domain.Repository;
-import org.jboss.dna.web.jcr.rest.client.domain.Server;
/**
* @author Dan Florian
@@ -35,51 +33,6 @@
public abstract class JsonNode extends JSONObject {
// ===========================================================================================================================
- // Class Methods
- // ===========================================================================================================================
-
- /**
- * The URL will always end in '/'.
- *
- * @param server the server to use when constructing the URL (never <code>null</code>)
- * @return the URL (never <code>null</code>)
- * @throws Exception if there is a problem constructing the URL
- * @since 0.6
- */
- public static URL createUrl( Server server ) throws Exception {
- StringBuilder url = new StringBuilder(server.getUrl());
-
- // strip off last '/' if necessary
- if (url.lastIndexOf("/") == (url.length() - 1)) { //$NON-NLS-1$
- url.delete((url.length() - 1), (url.length() - 1));
- }
-
- url.append(IJsonConstants.SERVER_CONTEXT);
- return new URL(url.toString());
- }
-
- /**
- * @param repository the repository to use when constructing the URL
- * @param path the path in the repository to use when constructing the URL
- * @return the URL (never <code>null</code>)
- * @throws Exception if there is a problem constructing the URL
- * @since 0.6
- */
- public static URL createUrl( Repository repository,
- String path ) throws Exception {
- StringBuilder url = new StringBuilder(createUrl(repository.getServer()).toString());
-
- // add a '/' after server URL if necessary
- if (path.startsWith("/")) { //$NON-NLS-1$
- url.append(path);
- } else {
- url.append('/').append(path);
- }
-
- return new URL(url.toString());
- }
-
- // ===========================================================================================================================
// Fields
// ===========================================================================================================================
Copied: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java (from rev 1113, branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessor.java)
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -0,0 +1,366 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client.json;
+
+import static org.jboss.dna.web.jcr.rest.client.IMessages.CreateFileFailedMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.CreateFolderFailedMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.GetRepositoriesFailedMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.GetWorkspacesFailedMsg;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.MESSAGES;
+import static org.jboss.dna.web.jcr.rest.client.IMessages.UnpublishFailedMsg;
+import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.Collection;
+import javax.ws.rs.core.MediaType;
+import org.jboss.dna.web.jcr.rest.client.IRestClient;
+import org.jboss.dna.web.jcr.rest.client.Logger;
+import org.jboss.dna.web.jcr.rest.client.domain.Repository;
+import org.jboss.dna.web.jcr.rest.client.domain.Server;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
+import org.jboss.dna.web.jcr.rest.client.json.IJsonConstants.RequestMethod;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class JsonRestClient implements IRestClient {
+
+ // ===========================================================================================================================
+ // Methods
+ // ===========================================================================================================================
+
+ /**
+ * Creates a file node in the specified repository. Note: All parent folders are assumed to already exist.
+ *
+ * @param workspace the workspace where the file node is being created
+ * @param path the path in the workspace to the folder where the file node is being created
+ * @param file the file whose contents will be contained in the file node being created
+ * @throws Exception if there is a problem creating the file
+ * @since 0.6
+ */
+ private void createFileNode( Workspace workspace,
+ String path,
+ File file ) throws Exception {
+ Logger.trace(JsonRestClient.class,
+ null,
+ "createFileNode: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ FileNode fileNode = new FileNode(workspace, path, file);
+ HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.POST);
+
+ try {
+ Logger.trace(JsonRestClient.class, null, "createFileNode: file node=" + fileNode); //$NON-NLS-1$
+ connection.getOutputStream().write(fileNode.getContent());
+
+ // make sure node was created
+ if (connection.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
+ String pattern = MESSAGES.getString(CreateFileFailedMsg);
+ String msg = MessageFormat.format(pattern,
+ file.getName(),
+ path,
+ workspace.getName(),
+ connection.getResponseCode());
+ throw new RuntimeException(msg);
+ }
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ /**
+ * Creates a folder node in the specified workspace. Note: All parent folders are assumed to already exist.
+ *
+ * @param workspace the workspace where the folder node is being created
+ * @param path the folder path in the workspace
+ * @throws Exception if there is a problem creating the folder
+ * @since 0.6
+ */
+ private void createFolderNode( Workspace workspace,
+ String path ) throws Exception {
+ Logger.trace(JsonRestClient.class, null, "createFolderNode: workspace=" + workspace + ", path=" + path); //$NON-NLS-1$//$NON-NLS-2$
+ FolderNode folderNode = new FolderNode(workspace, path);
+ HttpURLConnection connection = openConnection(folderNode.getUrl(), RequestMethod.POST);
+
+ try {
+ Logger.trace(JsonRestClient.class, null, "createFolderNode: folder node=" + folderNode); //$NON-NLS-1$
+ connection.getOutputStream().write(folderNode.getContent());
+
+ // make sure node was created
+ if (connection.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
+ String pattern = MESSAGES.getString(CreateFolderFailedMsg);
+ String msg = MessageFormat.format(pattern, path, workspace.getName(), connection.getResponseCode());
+ throw new RuntimeException(msg);
+ }
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ /**
+ * Ensures the specified path exists in the specified workspace. The path must only contain folder names.
+ *
+ * @param workspace the workspace being checked
+ * @param folderPath the path being checked
+ * @throws Exception if there is a problem ensuring the folder exists
+ * @since 0.6
+ */
+ private void ensureFolderExists( Workspace workspace,
+ String folderPath ) throws Exception {
+ Logger.trace(JsonRestClient.class, null, "ensureFolderExists: workspace=" + workspace + ", path=" + folderPath); //$NON-NLS-1$//$NON-NLS-2$
+ FolderNode folderNode = new FolderNode(workspace, folderPath);
+
+ if (!pathExists(folderNode.getUrl())) {
+ StringBuilder path = new StringBuilder();
+
+ for (char c : folderPath.toCharArray()) {
+ if (c == '/') {
+ if (path.length() > 1) {
+ folderNode = new FolderNode(workspace, path.toString());
+
+ if (!pathExists(folderNode.getUrl())) {
+ createFolderNode(workspace, folderNode.getPath());
+ }
+ }
+
+ path.append(c);
+ } else {
+ path.append(c);
+
+ if (path.length() == folderPath.length()) {
+ folderNode = new FolderNode(workspace, path.toString());
+
+ if (!pathExists(folderNode.getUrl())) {
+ createFolderNode(workspace, folderNode.getPath());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#getRepositories(org.jboss.dna.web.jcr.rest.client.domain.Server)
+ * @since 0.6
+ */
+ public Collection<Repository> getRepositories( Server server ) throws Exception {
+ Logger.trace(JsonRestClient.class, null, "getRepositories: server=" + server); //$NON-NLS-1$
+ ServerNode serverNode = new ServerNode(server);
+ HttpURLConnection connection = openConnection(serverNode.getFindRepositoriesUrl(), RequestMethod.GET);
+
+ try {
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ return serverNode.getRepositories(JsonUtils.readInputStream(connection));
+ }
+
+ // not a good response code
+ String pattern = MESSAGES.getString(GetRepositoriesFailedMsg);
+ String msg = MessageFormat.format(pattern, server.getName(), connection.getResponseCode());
+ throw new RuntimeException(msg);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#getWorkspaces(org.jboss.dna.web.jcr.rest.client.domain.Repository)
+ * @since 0.6
+ */
+ public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
+ Logger.trace(JsonRestClient.class, null, "getWorkspaces: repository=" + repository); //$NON-NLS-1$
+ RepositoryNode repositoryNode = new RepositoryNode(repository);
+ HttpURLConnection connection = openConnection(repositoryNode.getUrl(), RequestMethod.GET);
+
+ try {
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ return repositoryNode.getWorkspaces(JsonUtils.readInputStream(connection));
+ }
+
+ // not a good response code
+ String pattern = MESSAGES.getString(GetWorkspacesFailedMsg);
+ String msg = MessageFormat.format(pattern,
+ repository.getName(),
+ repository.getServer().getName(),
+ connection.getResponseCode());
+ throw new RuntimeException(msg);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ /**
+ * @param url the URL where the connection will be established
+ * @param method the request method
+ * @return the open connection which <strong>MUST</strong> be disconnected
+ * @throws Exception if there is a problem establishing the connection
+ * @since 0.6
+ */
+ private HttpURLConnection openConnection( URL url,
+ RequestMethod method ) throws Exception {
+ Logger.trace(JsonRestClient.class, null, "openConnection: url=" + url + ", method=" + method); //$NON-NLS-1$ //$NON-NLS-2$
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+ connection.setDoOutput(true);
+ connection.setRequestMethod(method.toString());
+ connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON); //$NON-NLS-1$
+ return connection;
+ }
+
+ /**
+ * @param url the path being checked (never <code>null</code>)
+ * @return <code>true</code> if the path exists
+ * @throws Exception if there is a problem checking the existence of the path
+ * @since 0.6
+ */
+ protected boolean pathExists( URL url ) throws Exception {
+ Logger.trace(JsonRestClient.class, null, "pathExists: url=" + url); //$NON-NLS-1$
+ HttpURLConnection connection = openConnection(url, RequestMethod.GET);
+
+ try {
+ Logger.trace(JsonRestClient.class, null, "pathExists: response code=" + connection.getResponseCode()); //$NON-NLS-1$
+ return (connection.getResponseCode() == HttpURLConnection.HTTP_OK);
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ /**
+ * @param workspace the workspace being checked (never <code>null</code>)
+ * @param path the path in workspace (never <code>null</code>)
+ * @param file the file being checked (never <code>null</code>)
+ * @return <code>true</code> if the file exists in the workspace at the specified path
+ * @throws Exception if there is a problem checking the existence of the file
+ * @since 0.6
+ */
+ protected boolean pathExists( Workspace workspace,
+ String path,
+ File file ) throws Exception {
+ Logger.trace(JsonRestClient.class,
+ null,
+ "pathExists: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ FileNode fileNode = new FileNode(workspace, path, file);
+ return pathExists(fileNode.getUrl());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#publish(org.jboss.dna.web.jcr.rest.client.domain.Workspace,
+ * java.lang.String, java.io.File)
+ * @since 0.6
+ */
+ public void publish( Workspace workspace,
+ String path,
+ File file ) throws Exception {
+ Logger.trace(JsonRestClient.class,
+ null,
+ "publish: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ // see if file exists at that path
+ if (pathExists(workspace, path, file)) {
+ // must be an update
+ updateFileNode(workspace, path, file);
+ } else {
+ // doesn't exist so make sure the parent path exists
+ ensureFolderExists(workspace, path);
+
+ // publish new file
+ createFileNode(workspace, path, file);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#unpublish(org.jboss.dna.web.jcr.rest.client.domain.Workspace,
+ * java.lang.String, java.io.File)
+ * @since 0.6
+ */
+ public void unpublish( Workspace workspace,
+ String path,
+ File file ) throws Exception {
+ Logger.trace(JsonRestClient.class,
+ null,
+ "publish: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ FileNode fileNode = new FileNode(workspace, path, file);
+ HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.DELETE);
+
+ try {
+ if (connection.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT) {
+ String pattern = MESSAGES.getString(UnpublishFailedMsg);
+ String msg = MessageFormat.format(pattern,
+ file.getName(),
+ workspace.getName(),
+ path,
+ connection.getResponseCode());
+ throw new RuntimeException(msg);
+ }
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ /**
+ * Updates a file node in the specified workspace. Note: All parent folders are assumed to already exist.
+ *
+ * @param workspace the workspace where the file node is being updated
+ * @param path the path to the folder where the file node is being updated
+ * @param file the file whose contents will be contained in the file node being created
+ * @throws Exception if there is a problem creating the file
+ * @since 0.6
+ */
+ private void updateFileNode( Workspace workspace,
+ String path,
+ File file ) throws Exception {
+ Logger.trace(JsonRestClient.class,
+ null,
+ "updateFileNode: workspace=" + workspace + ", path=" + path + ", file=" + file.getAbsolutePath()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ FileNode fileNode = new FileNode(workspace, path, file);
+ HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.PUT);
+
+ try {
+ connection.getOutputStream().write(fileNode.getContent());
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+}
Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClient.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessor.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessor.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessor.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -1,340 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.client.json;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.Collection;
-import javax.ws.rs.core.MediaType;
-import org.jboss.dna.web.jcr.rest.client.IMessages;
-import org.jboss.dna.web.jcr.rest.client.IRestExecutor;
-import org.jboss.dna.web.jcr.rest.client.domain.Repository;
-import org.jboss.dna.web.jcr.rest.client.domain.Server;
-import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
-import org.jboss.dna.web.jcr.rest.client.json.IJsonConstants.RequestMethod;
-
-/**
- * @author Dan Florian
- * @since 0.6
- */
-public final class JsonRestProcessor implements IRestExecutor {
-
- // ===========================================================================================================================
- // Methods
- // ===========================================================================================================================
-
- /**
- * Creates a file node in the specified repository. Note: All parent folders are assumed to already exist.
- *
- * @param repository the repository where the file node is being created
- * @param parentPath the path to the folder where the file node is being created
- * @param file the file whose contents will be contained in the file node being created
- * @throws Exception if there is a problem creating the file
- * @since 0.6
- */
- private void createFileNode( Repository repository,
- String parentPath,
- File file ) throws Exception {
- FileNode fileNode = new FileNode(repository, parentPath, file);
- HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.POST);
-
- try {
- connection.getOutputStream().write(fileNode.getContent());
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * Updates a file node in the specified repository. Note: All parent folders are assumed to already exist.
- *
- * @param repository the repository where the file node is being updated
- * @param parentPath the path to the folder where the file node is being updated
- * @param file the file whose contents will be contained in the file node being created
- * @throws Exception if there is a problem creating the file
- * @since 0.6
- */
- private void updateFileNode( Repository repository,
- String parentPath,
- File file ) throws Exception {
- FileNode fileNode = new FileNode(repository, parentPath, file);
- HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.PUT);
-
- try {
- connection.getOutputStream().write(fileNode.getContent());
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * Creates a folder node in the specified repository. Note: All parent folders are assumed to already exist.
- *
- * @param repository the repository where the folder node is being created
- * @param path the folder path in the repository
- * @throws Exception if there is a problem creating the folder
- * @since 0.6
- */
- private void createFolderNode( Repository repository,
- String path ) throws Exception {
- FolderNode folderNode = new FolderNode(repository, path);
- HttpURLConnection connection = openConnection(folderNode.getUrl(), RequestMethod.POST);
-
- try {
- connection.getOutputStream().write(folderNode.getContent());
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * Ensures the specified path exists in the specified repository. The path must only contain folder names.
- *
- * @param repository the repository being checked
- * @param folderPath the path being checked
- * @throws Exception if there is a problem ensuring the folder exists
- * @since 0.6
- */
- private void ensureFolderExists( Repository repository,
- String folderPath ) throws Exception {
- FolderNode folderNode = new FolderNode(repository, folderPath);
-
- if (!pathExists(folderNode.getUrl())) {
- StringBuilder path = new StringBuilder();
-
- for (char c : folderPath.toCharArray()) {
- if (c == '/') {
- if (path.length() > 1) {
- folderNode = new FolderNode(repository, path.toString());
-
- if (!pathExists(folderNode.getUrl())) {
- createFolderNode(repository, folderNode.getPath());
- }
- }
-
- path.append(c);
- } else {
- path.append(c);
-
- if (path.length() == folderPath.length()) {
- folderNode = new FolderNode(repository, path.toString());
-
- if (!pathExists(folderNode.getUrl())) {
- createFolderNode(repository, folderNode.getPath());
- }
- }
- }
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#getRepositories(org.jboss.dna.web.jcr.rest.client.domain.Server)
- * @since 0.6
- */
- public Collection<Repository> getRepositories( Server server ) throws Exception {
- ServerNode serverNode = new ServerNode(server);
- HttpURLConnection connection = openConnection(serverNode.getUrl(), RequestMethod.GET);
-
- try {
- if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
- return serverNode.getRepositories(readInputStream(connection));
- }
-
- // not a good response code
- String pattern = IMessages.GetRepositoriesFailedMsg;
- String msg = MessageFormat.format(pattern, server.getName(), connection.getResponseCode());
- throw new RuntimeException(msg);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#getWorkspaces(org.jboss.dna.web.jcr.rest.client.domain.Repository)
- * @since 0.6
- */
- public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
- RepositoryNode repositoryNode = new RepositoryNode(repository);
- HttpURLConnection connection = openConnection(repositoryNode.getUrl(), RequestMethod.GET);
-
- try {
- if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
- return repositoryNode.getWorkspaces(readInputStream(connection));
- }
-
- // not a good response code
- String pattern = IMessages.GetWorkspacesFailedMsg;
- String msg = MessageFormat.format(pattern,
- repository.getName(),
- repository.getServer().getName(),
- connection.getResponseCode());
- throw new RuntimeException(msg);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * @param url the URL where the connection will be established
- * @param method the request method
- * @return the open connection which <strong>MUST</strong> be disconnected
- * @throws Exception if there is a problem establishing the connection
- * @since 0.6
- */
- private HttpURLConnection openConnection( URL url,
- RequestMethod method ) throws Exception {
- HttpURLConnection connection = (HttpURLConnection)url.openConnection();
- connection.setDoOutput(true);
- connection.setRequestMethod(method.toString());
- connection.setRequestProperty("Content-Type", MediaType.APPLICATION_JSON); //$NON-NLS-1$
- return connection;
- }
-
- /**
- * @param url the path being checked (never <code>null</code>)
- * @return <code>true</code> if the path exists
- * @throws Exception if there is a problem checking the existence of the path
- * @since 0.6
- */
- private boolean pathExists( URL url ) throws Exception {
- HttpURLConnection connection = openConnection(url, RequestMethod.GET);
-
- try {
- return (connection.getResponseCode() == HttpURLConnection.HTTP_OK);
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
- /**
- * @param repository the repository being checked (never <code>null</code>)
- * @param path the parentPath in repository (never <code>null</code>)
- * @param file the file being checked (never <code>null</code>)
- * @return <code>true</code> if the file exists in the repository at the specified path
- * @throws Exception if there is a problem checking the existence of the file
- * @since 0.6
- */
- private boolean pathExists( Repository repository,
- String path,
- File file ) throws Exception {
- FileNode fileNode = new FileNode(repository, path, file);
- return pathExists(fileNode.getUrl());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#publish(org.jboss.dna.web.jcr.rest.client.domain.Repository,
- * java.lang.String, java.io.File)
- * @since 0.6
- */
- public void publish( Repository repository,
- String parentPath,
- File file ) throws Exception {
- // see if file exists at that path
- if (pathExists(repository, parentPath, file)) {
- // must be an update
- updateFileNode(repository, parentPath, file);
- } else {
- // doesn't exist so make sure the parent path exists
- ensureFolderExists(repository, parentPath);
-
- // publish new file
- createFileNode(repository, parentPath, file);
- }
- }
-
- /**
- * Note: The connection is not disconnected during this method.
- *
- * @param connection the connection whose input stream is going to be read from
- * @return the data read from the connection input stream
- * @throws IOException if there is a problem reading from the connection
- * @since 0.6
- */
- private String readInputStream( HttpURLConnection connection ) throws IOException {
- InputStream stream = connection.getInputStream();
- int bytesRead;
- byte[] bytes = new byte[1024];
- StringBuffer buff = new StringBuffer();
-
- while (-1 != (bytesRead = stream.read(bytes, 0, 1024))) {
- buff.append(new String(bytes, 0, bytesRead));
- }
-
- return buff.toString();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#unpublish(org.jboss.dna.web.jcr.rest.client.domain.Repository,
- * java.lang.String, java.io.File)
- * @since 0.6
- */
- public void unpublish( Repository repository,
- String parentPath,
- File file ) throws Exception {
- FileNode fileNode = new FileNode(repository, parentPath, file);
- HttpURLConnection connection = openConnection(fileNode.getUrl(), RequestMethod.DELETE);
-
- try {
- if (connection.getResponseCode() != HttpURLConnection.HTTP_NO_CONTENT) {
- String pattern = IMessages.UnpublishFailedMsg;
- String msg = MessageFormat.format(pattern,
- file.getName(),
- repository.getName(),
- parentPath,
- connection.getResponseCode());
- throw new RuntimeException(msg);
- }
- } finally {
- if (connection != null) {
- connection.disconnect();
- }
- }
- }
-
-}
Added: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -0,0 +1,82 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client.json;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class JsonUtils {
+
+ // ===========================================================================================================================
+ // Class Methods
+ // ===========================================================================================================================
+
+ /**
+ * @param text the text whose escape sequences will be replaced with the actual characters
+ * @return the decoded text
+ * @since 0.6
+ */
+ public static String decodeEscaping( String text ) {
+ return text.replace("%3a", ":"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Note: The connection is not disconnected during this method.
+ *
+ * @param connection the connection whose input stream is going to be read from
+ * @return the data read from the connection input stream
+ * @throws IOException if there is a problem reading from the connection
+ * @since 0.6
+ */
+ public static String readInputStream( HttpURLConnection connection ) throws IOException {
+ InputStream stream = connection.getInputStream();
+ int bytesRead;
+ byte[] bytes = new byte[1024];
+ StringBuffer buff = new StringBuffer();
+
+ while (-1 != (bytesRead = stream.read(bytes, 0, 1024))) {
+ buff.append(new String(bytes, 0, bytesRead));
+ }
+
+ return buff.toString();
+ }
+
+ // ===========================================================================================================================
+ // Constructors
+ // ===========================================================================================================================
+
+ /**
+ * Don't allow construction.
+ *
+ * @since 0.6
+ */
+ private JsonUtils() {
+ // nothing to do
+ }
+}
Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/JsonUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/RepositoryNode.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -53,7 +53,7 @@
// ===========================================================================================================================
/**
- * @param repository the DNA repository
+ * @param repository the DNA repository (never <code>null</code>)
* @since 0.6
*/
public RepositoryNode( Repository repository ) {
@@ -67,13 +67,20 @@
/**
* {@inheritDoc}
+ * <p>
+ * This URL can be used to obtain the workspaces contained in this repository. The URL will NOT end in '/'.
*
* @see org.jboss.dna.web.jcr.rest.client.json.JsonNode#getUrl()
* @since 0.6
*/
@Override
public URL getUrl() throws Exception {
- return createUrl(this.repository, this.repository.getName());
+ ServerNode serverNode = new ServerNode(this.repository.getServer());
+ StringBuilder url = new StringBuilder(serverNode.getUrl().toString());
+
+ // add repository path
+ url.append('/').append(repository.getName());
+ return new URL(url.toString());
}
/**
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/ServerNode.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -28,6 +28,7 @@
import java.util.Collection;
import java.util.Iterator;
import org.codehaus.jettison.json.JSONObject;
+import org.jboss.dna.web.jcr.rest.client.Logger;
import org.jboss.dna.web.jcr.rest.client.domain.Repository;
import org.jboss.dna.web.jcr.rest.client.domain.Server;
@@ -53,7 +54,7 @@
// ===========================================================================================================================
/**
- * @param server the server containing the repositories
+ * @param server the server containing the repositories (never <code>null</code>)
* @since 0.6
*/
public ServerNode( Server server ) {
@@ -67,43 +68,35 @@
/**
* {@inheritDoc}
+ * <p>
+ * The URL will NOT end in '/'.
*
* @see org.jboss.dna.web.jcr.rest.client.json.JsonNode#getUrl()
* @since 0.6
*/
@Override
public URL getUrl() throws Exception {
- return createUrl(this.server);
+ StringBuilder url = new StringBuilder(this.server.getUrl());
+
+ // strip off last '/' if necessary
+ if (url.lastIndexOf("/") == (url.length() - 1)) { //$NON-NLS-1$
+ url.delete((url.length() - 1), (url.length() - 1));
+ }
+
+ url.append(IJsonConstants.SERVER_CONTEXT);
+ return new URL(url.toString());
}
/**
- * @return the URL for this server to use when requesting the repositories (never <code>null</code>)
+ * @return the URL to use when requesting the repositories (never <code>null</code>)
* @throws Exception if there is a problem obtaining the repositories
* @since 0.6
*/
public URL getFindRepositoriesUrl() throws Exception {
- URL url = createUrl(this.server);
- return new URL(url.toString() + IJsonConstants.REPOSITORY_URL_CONTEXT);
+ return new URL(getUrl().toString() + '/');
}
/**
- * @param repository the repository whose workspaces are being requested (never <code>null</code>)
- * @return the URL for this server to use when requesting a collection of workspaces (never <code>null</code>)
- * @throws Exception if there is a problem obtaining the workspaces
- * @since 0.6
- */
- public URL getFindWorkspacesUrl( Repository repository ) throws Exception {
- StringBuilder url = new StringBuilder(createUrl(this.server).toString());
-
- if (!url.toString().endsWith("/")) { //$NON-NLS-1$
- url.append('/');
- }
-
- url.append(repository.getName());
- return new URL(url.toString());
- }
-
- /**
* @param jsonResponse the HTTP connection JSON response (never <code>null</code>) containing the repositories
* @return the repositories found in the JSON response (never <code>null</code>)
* @throws Exception if there is a problem obtaining the repositories
@@ -112,12 +105,14 @@
@SuppressWarnings( "unchecked" )
public Collection<Repository> getRepositories( String jsonResponse ) throws Exception {
Collection<Repository> repositories = new ArrayList<Repository>();
+ Logger.trace(ServerNode.class, null, "getRepositories:jsonResponse=" + jsonResponse); //$NON-NLS-1$
JSONObject jsonObj = new JSONObject(jsonResponse);
// keys are the repository names
for (Iterator<String> itr = jsonObj.keys(); itr.hasNext();) {
Repository repository = new Repository(itr.next(), this.server);
repositories.add(repository);
+ Logger.trace(ServerNode.class, null, "getRepositories:repository=" + repository); //$NON-NLS-1$
}
return repositories;
Added: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/WorkspaceNode.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/WorkspaceNode.java (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/WorkspaceNode.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -0,0 +1,73 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client.json;
+
+import java.net.URL;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
+
+/**
+ * @author dan
+ */
+public class WorkspaceNode extends JsonNode {
+
+ // ===========================================================================================================================
+ // Fields
+ // ===========================================================================================================================
+
+ private final Workspace workspace;
+
+ // ===========================================================================================================================
+ // Constructors
+ // ===========================================================================================================================
+
+ /**
+ * @param workspace the repository workspace (never <code>null</code>)
+ * @since 0.6
+ */
+ public WorkspaceNode( Workspace workspace ) {
+ super(workspace.getName());
+ this.workspace = workspace;
+ }
+
+ // ===========================================================================================================================
+ // Methods
+ // ===========================================================================================================================
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.json.JsonNode#getUrl()
+ * @since 0.6
+ */
+ @Override
+ public URL getUrl() throws Exception {
+ RepositoryNode repositoryNode = new RepositoryNode(this.workspace.getRepository());
+ StringBuilder url = new StringBuilder(repositoryNode.getUrl().toString());
+
+ // add workspace path
+ url.append('/').append(workspace.getName()).append(IJsonConstants.WORKSPACE_CONTEXT);
+ return new URL(url.toString());
+ }
+
+}
Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/json/WorkspaceNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties 2009-07-22 22:41:00 UTC (rev 1125)
@@ -47,8 +47,10 @@
WorkspaceNullRepositoryMsg = A workspace repository cannot be null
WorkspaceShortDescription = DNA Repository Workspace: Name: {0}, {1}
-# JsonRestProcessor messages
+# JsonRestClient messages
+CreateFileFailedMsg = Creating the "{0}" file node in folder "{1}" in workspace "{2}" failed with HTTP response code of "{3}"
+CreateFolderFailedMsg = Creating the "{0}" folder node in workspace "{1}" failed with HTTP response code of "{2}"
GetRepositoriesFailedMsg = Obtaining the repositories from server "{0}" failed with HTTP response code of "{1}"
GetWorkspacesFailedMsg = Obtaining the workspaces from repository "{0}" at server "{1}" failed with HTTP response code of "{2}"
UnpublishFailedMsg = The file "{0}" could not be unpublished in repository "{1}" at path "{2}". The HTTP response code was "{3}".
Modified: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -33,22 +33,16 @@
* @author Dan Florian
* @since 0.6
*/
-public final class MockRestExecutor implements IRestExecutor {
+public final class MockRestExecutor implements IRestClient {
// ===========================================================================================================================
- // Constants
- // ===========================================================================================================================
-
-
-
- // ===========================================================================================================================
// Methods
// ===========================================================================================================================
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#getRepositories(org.jboss.dna.web.jcr.rest.client.domain.Server)
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#getRepositories(org.jboss.dna.web.jcr.rest.client.domain.Server)
* @since 0.6
*/
public Collection<Repository> getRepositories( Server server ) throws Exception {
@@ -57,8 +51,8 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#getWorkspaces(org.jboss.dna.web.jcr.rest.client.domain.Repository)
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#getWorkspaces(org.jboss.dna.web.jcr.rest.client.domain.Repository)
* @since 0.6
*/
public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
@@ -67,23 +61,25 @@
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#publish(org.jboss.dna.web.jcr.rest.client.domain.Repository, java.lang.String, java.io.File)
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#publish(org.jboss.dna.web.jcr.rest.client.domain.Workspace,
+ * java.lang.String, java.io.File)
* @since 0.6
*/
- public void publish( Repository repository,
- String parentPath,
+ public void publish( Workspace workspace,
+ String path,
File file ) throws Exception {
}
/**
* {@inheritDoc}
- *
- * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#unpublish(org.jboss.dna.web.jcr.rest.client.domain.Repository, java.lang.String, java.io.File)
+ *
+ * @see org.jboss.dna.web.jcr.rest.client.IRestClient#unpublish(org.jboss.dna.web.jcr.rest.client.domain.Workspace,
+ * java.lang.String, java.io.File)
* @since 0.6
*/
- public void unpublish( Repository repository,
- String parentPath,
+ public void unpublish( Workspace workspace,
+ String path,
File file ) throws Exception {
}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -34,7 +34,7 @@
* @author Dan Florian
* @since 0.6
*/
-public class ServerManagerTest {
+public final class ServerManagerTest {
// ===========================================================================================================================
// Constants
Copied: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java (from rev 1113, branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessorTest.java)
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -0,0 +1,124 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.web.jcr.rest.client.json;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import java.io.File;
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
+import java.net.URL;
+import java.util.Collection;
+import org.jboss.dna.web.jcr.rest.client.IRestClient;
+import org.jboss.dna.web.jcr.rest.client.domain.Repository;
+import org.jboss.dna.web.jcr.rest.client.domain.Server;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class JsonRestClientTest {
+
+ // ===========================================================================================================================
+ // Constants
+ // ===========================================================================================================================
+
+ // user and password configured in pom
+ private static final String PSWD = "password"; //$NON-NLS-1$
+ private static final String USER = "dnauser"; //$NON-NLS-1$
+
+ private static final Server SERVER = new Server("http://localhost:8080", USER, PSWD, false); //$NON-NLS-1$
+ private static final String REPOSITORY_NAME = "dna%3arepository"; //$NON-NLS-1$
+ private static final Repository REPOSITORY1 = new Repository(REPOSITORY_NAME, SERVER);
+ private static final String WORKSPACE_NAME = "default"; //$NON-NLS-1$
+ private static final Workspace WORKSPACE1 = new Workspace(WORKSPACE_NAME, REPOSITORY1);
+
+ private static final String WORKSPACE_PATH = "/myproject/myfolder/"; //$NON-NLS-1$
+ private static final String FILE_PATH = WORKSPACE_PATH + "document.txt"; //$NON-NLS-1$
+// private static final String BINARY_FILE_PATH = WORKSPACE_PATH + "picture.txt"; //$NON-NLS-1$
+
+ // ===========================================================================================================================
+ // Fields
+ // ===========================================================================================================================
+
+ private IRestClient restClient;
+
+ // ===========================================================================================================================
+ // Methods
+ // ===========================================================================================================================
+
+ @Before
+ public void beforeEach() {
+ this.restClient = new JsonRestClient();
+
+ Authenticator.setDefault(new Authenticator() {
+ @Override
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(USER, PSWD.toCharArray());
+ }
+ });
+ }
+
+ // ===========================================================================================================================
+ // Tests
+ // ===========================================================================================================================
+
+ @Test
+ public void shouldGetRepositories() throws Exception {
+ Collection<Repository> repositories = this.restClient.getRepositories(SERVER);
+ assertThat(repositories.size(), equalTo(1));
+ assertThat(repositories.iterator().next(), is(REPOSITORY1));
+ }
+
+ @Test
+ public void shouldGetWorkspaces() throws Exception {
+ Collection<Workspace> workspaces = this.restClient.getWorkspaces(REPOSITORY1);
+ assertThat(workspaces.size(), is(1));
+ assertThat(workspaces.iterator().next(), is(WORKSPACE1));
+ }
+
+ // @Test
+ public void shouldPublishResource() throws Exception {
+ URL textFile = getClass().getResource(FILE_PATH);
+ assertThat(textFile, is(notNullValue()));
+
+ // publish
+ File file = new File(textFile.toURI());
+ this.restClient.publish(WORKSPACE1, WORKSPACE_PATH, file);
+
+ // confirm it exists in repository
+ assertThat(((JsonRestClient)this.restClient).pathExists(WORKSPACE1, WORKSPACE_PATH, file), is(true));
+ }
+
+ // @Test
+ public void shouldUnpublish() throws Exception {
+ this.restClient.unpublish(WORKSPACE1, WORKSPACE_PATH, new File(FILE_PATH));
+ }
+
+}
Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestClientTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessorTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessorTest.java 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/json/JsonRestProcessorTest.java 2009-07-22 22:41:00 UTC (rev 1125)
@@ -1,53 +0,0 @@
-/*
- * JBoss DNA (http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.dna.web.jcr.rest.client.json;
-
-import org.junit.Before;
-
-/**
- * @author Dan Florian
- * @since 0.6
- */
-public final class JsonRestProcessorTest {
-
- // ===========================================================================================================================
- // Fields
- // ===========================================================================================================================
-
-// private IRestExecutor processor;
-
- // ===========================================================================================================================
- // Methods
- // ===========================================================================================================================
-
- @Before
- public void beforeEach() {
- // this.processor = new JsonRestProcessor();
- }
-
- // ===========================================================================================================================
- // Tests
- // ===========================================================================================================================
-
-}
Modified: branches/eclipse/dna-web-jcr-rest-client/src/test/resources/log4j.properties
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/resources/log4j.properties 2009-07-22 17:32:10 UTC (rev 1124)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/resources/log4j.properties 2009-07-22 22:41:00 UTC (rev 1125)
@@ -17,12 +17,4 @@
log4j.appender.testlog-mdc.layout.ConversionPattern=%d{ABSOLUTE} %5p [%X{username}] %m%n
# Root logger option
-log4j.rootLogger=INFO, stdout, testlog, testlog-mdc
-
-# Set up the default logging to be INFO level, then override specific units
-log4j.logger.org.jboss.dna=INFO
-
-# Set up the logging for the LoggerTest test cases (which need this to be explicitly set rather than inherited)
-log4j.logger.org.jboss.dna.common.util.LoggerTest=INFO
-
-
+log4j.rootLogger=TRACE, stdout, testlog, testlog-mdc
Added: branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/document.txt
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/document.txt (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/document.txt 2009-07-22 22:41:00 UTC (rev 1125)
@@ -0,0 +1,304 @@
+Wikipedia is sustained by people like you. Please donate today.
+Candidates are currently being accepted for the Wikimedia Board of Trustees Election. Become a candidate.
+ [Hide]
+[Help us with translations!]
+Sledge Hammer!
+From Wikipedia, the free encyclopedia
+Jump to: navigation, search
+ This article does not cite any references or sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (September 2007)
+ This article may contain original research or unverified claims. Please improve the article by adding references. See the talk page for details. (September 2007)
+Sledge Hammer!
+
+Sledge Hammer! title screen from 1986 to 1988
+Format Comedy (sitcom)
+Created by Alan Spencer
+Starring David Rasche
+Anne-Marie Martin
+Harrison Page
+Theme music composer Danny Elfman
+Country of origin United States
+No. of seasons 2
+No. of episodes 41
+Production
+Running time 23 minutes (approximate)
+Broadcast
+Original channel ABC
+Original run 23 September 1986 –
+12 February 1988
+External links
+Official website
+
+Sledge Hammer! is a satirical police sitcom produced by New World Television that ran for two seasons on ABC from 1986 to 1988. The series was created by Alan Spencer and starred David Rasche as Inspector Sledge Hammer, a preposterous caricature of the standard "cop on the edge" character, with a name parodied from Mike Hammer.
+Contents
+[hide]
+
+ * 1 Origins
+ * 2 Premise and characters
+ * 3 Sledge humor
+ * 4 Intro and theme music
+ * 5 Ratings and second season
+ * 6 DVD releases
+ * 7 Guest appearances
+ * 8 Episode list
+ o 8.1 Season 1 (1986–1987)
+ o 8.2 Season 2 (1987–1988)
+ * 9 Trivia
+ * 10 External links
+
+[edit] Origins
+
+Inspired by Clint Eastwood's no-nonsense approach to law enforcement in the Dirty Harry films, teenager Alan Spencer dreamed up the idea of a police officer whose approach was even more over-the-top, to the point of comical absurdity. At the age of sixteen, Spencer wrote a screenplay based on this idea. The script and the main character were both named "Sledge Hammer".
+
+Spencer, who at his young age had already written for various standup comedians such as Rodney Dangerfield and television shows such as The Facts of Life and One Day at a Time, was unable to sell the script until the mid-1980s, when the release of the fourth Dirty Harry movie Sudden Impact and the popularity of NBC's Dirty Harry-inspired action series Hunter created demand for a satirical police television show. When HBO approached Leonard B. Stern, former producer of Get Smart, about developing such a show, Stern recommended Spencer's "Sledge Hammer!" idea.
+
+Spencer quickly reworked his script for a half-hour television format. HBO executives did not like it, however, and suggested changes that Spencer found unacceptable, such as casting Dangerfield or Joe Piscopo in the lead role. Surprisingly, last-place ABC was willing to take a chance on the unorthodox script. ABC insisted that the violence be toned down for network television and that a laugh track be included (although it should be noted that some versions, such as that shown by ITV regions in the United Kingdom, do not have this track), but agreed to cast Spencer's first choice for the lead character, the classically trained actor David Rasche. Sledge Hammer! entered ABC's fall lineup in 1986.
+
+Fortuitously, the pilot of Sledge Hammer! was completed just as Peter Gabriel's song "Sledgehammer" became a huge hit. ABC took advantage of this pleasant coincidence by using Gabriel's popular tune in television, radio and film advertisements for the show.
+
+[edit] Premise and characters
+
+Inspector Sledge Hammer of the San Francisco Police Department is a violent, sadistic, insensitive, yet oddly likable detective. His best friend is a .44 Magnum with a customized grip featuring a drawing of a sledgehammer. Hammer sleeps and showers with his gun, and even talks to it. Hammer believes in shooting first and asking questions never. In the pilot episode, he deals with a sniper on a roof by blowing up the entire building with a rocket launcher, then turns to the uniformed cops on scene and says "I think I got 'em"; he also mentions that his favorite charity is "Toy Guns for Tots". Hammer's father was Jack Hammer, a legendary carnival trick shooter whose repertoire of shooting tricks included catching a bullet in his teeth, which saved his son's life in one episode. His mothers name was Armin Hammer.
+
+While purportedly a stickler for law and order, Hammer is rather lax when it comes to following police regulations. He enjoys roughing up suspected criminals, whom he frequently refers to as "brain-dead mutants", "yogurt-sucking creeps", and the like. He is often suspended from duty, and his police file literally requires a wheelbarrow to transport.
+
+
+Hammer drives a beat-up, bullet-riddled, lime green Dodge St. Regis with an "I ♥ VIOLENCE" bumper sticker. He prefers to wear cheap sports jackets, loud neckties, and dark sunglasses. He is divorced, and frequently makes jokes at the expense of his ex-wife (who makes an appearance in the final episode, played by Rasche's real-life wife, Heather Lupton).
+
+Despite his irresponsibility and utter incompetence, Hammer always ends up getting his man (or woman), often through sheer luck or brute force. Hammer's unintentionally ironic motto is "Trust me. I know what I'm doing." (Disaster usually follows.) Another expression he often utters is "Don't confuse me", typically in response to any remark that challenges his ridiculously one-dimensional worldview.
+
+Hammer's partner is the beautiful Detective Dori Doreau (played by Anne-Marie Martin), who is competent, kind, sensitive, intelligent, and sophisticated—everything Sledge is not. Doreau is often shocked and offended by Hammer's crass behavior and obnoxious attitude, but she appears to see some redeeming qualities beneath his gruff exterior. (Indeed, it becomes apparent with time that she has some romantic feelings for Sledge.) Hammer's blatant male chauvinism is a running gag in his dialogues with Doreau:
+
+ Doreau: What, you think all women should be barefoot and pregnant?
+ Hammer: No, I encourage women to wear shoes.
+
+Doreau's cautious and compassionate approach to law enforcement is a crucial counterpoint to Hammer's reckless and nihilistic quest for justice. Yet Doreau is a tough, agile cop who can handle a gun and deliver a well-timed karate kick when necessary. She frequently saves Hammer from the extraordinary predicaments he invariably gets himself into.
+
+Hammer and Doreau are supervised by the chronically uptight, Pepto-Bismol-guzzling Captain Trunk, played by Harrison Page. Trunk spends most of his time yelling at Hammer for his incompetence or complaining about his migraine headaches brought on by Hammer's antics. If Trunk has any respect or fondness for Hammer, he hides it extremely well. In one episode ("Miss of the Spider Woman") Hammer is about to die from snake venom poisoning but is saved at the last minute when Trunk shows up with the antidote:
+
+ Hammer: How can I ever thank you?
+ Trunk: Don't drink it.
+
+[edit] Sledge humor
+
+Most of the humor in Sledge Hammer! is based on Sledge's callous, simplistic, narrow-minded worldview and its unfortunate consequences for those around him. Hammer is like a human tornado, devastating everyone and everything in his path. A camera view of his apartment shows that one of his favorite wall hangings is a "enemy soldier" target on his closet door. He blames gun control, feminism, and rock music for many of the world's ills. One example of such humor:
+
+ Sledge Hammer: Well, Miss, I was in this store when two thugs entered and threatened the owner with shotguns. At that time I drew my magnum and killed them both. Then I bought some eggs, milk, and some of those little cocktail weenies.
+ News reporter: Inspector Hammer, was what you did in the store absolutely necessary?
+ Sledge Hammer: Oh yes, I had almost no groceries at all.
+
+Hammer's over-the-top but deadpan antics have ranged from pulling a rocket launcher from his trunk and firing it at the building where a sniper is stationed, to forcing a purse-snatcher to beat himself up in order to avoid brutality charges.
+
+Physical comedy is another important element of the show. Through his Jack Tripper-like clumsiness, Sledge is constantly injuring Captain Trunk with, for example, a stray billiard ball to the head, a coffin lid dropped on the fingers, or a misguided attempt at fixing Trunk's sore neck with a little amateur chiropractic adjustment:
+
+ Trunk: (yelling in pain) You sadistic, depraved, bloodthirsty, barbaric...
+ Hammer: Is that why you called me in here? To shower me with compliments?
+
+Another running gag is Sledge's reckless driving; he is continually rear-ending and backing into things with his beat-up green jalopy.
+
+Sledge Hammer! also features a good deal of self-referential and topical, pop culture-based humor. For example, in the final episode of the first season, Captain Trunk tells a busted criminal "Your show's been canceled!"; Sledge replies, "You talking to me?", an obvious reference to the show's shaky prospects for a second season. In another episode, Hammer tells a suspect "Every breath you take, every move you make, I'll be watching you. That's police talk!", alluding to the 1983 hit song by The Police.
+
+There are numerous references - nearly all of them disparaging - to other popular television shows of the time, such as ALF, The Cosby Show, Miami Vice, Matlock, Webster, Moonlighting, Designing Women, Dallas, and Murder, She Wrote. (Particular scorn is reserved for Mr. Belvedere.)
+
+The show lampoons popular films of the '80s such as RoboCop, Witness, Flashdance, and Crocodile Dundee, but also alludes to classics such as Casablanca, Cool Hand Luke, Dog Day Afternoon, and A Clockwork Orange.
+
+[edit] Intro and theme music
+
+The introduction to the show features long, near-sensual closeup shots of Sledge's .44 Magnum as it rests on a luxurious satin pillow. The show's ominous theme music, composed by Danny Elfman, plays in the background. Sledge then picks up his gun, spins it expertly like an Old West gunslinger, and utters his catch phrase ("Trust me, I know what I'm doing") just before firing into the screen, making a hole in it. The original version had Sledge firing directly at the viewer, but ABC executives feared this could be too shocking, possibly even causing heart attacks (and leaving the network liable)[citation needed]. Thus, Sledge fires into the screen at a slight angle.
+
+[edit] Ratings and second season
+
+Despite critical acclaim, Sledge Hammer! struggled in the ratings. This was due in large part to its being scheduled in the Friday 9 p.m. timeslot (popularly known as the Friday night death slot), against CBS's Dallas and NBC's Miami Vice, two of the most popular shows on television at the time; in one episode, Hammer remarks that it must be bad to be between a man from Dallas and a man from Miami, an obvious reference to both shows. In his commentary on the first season DVDs, Alan Spencer remarks that the only series getting lower ratings than Sledge Hammer! was FOX's The Tracey Ullman Show. That actually applied to the second season.
+
+In truth, Sledge Hammer! attracted weekly viewership of nineteen million viewers who followed the show religiously through its many time slot shifts. The fact that the series appealed to key target demographics also kept it on the schedule. Hammer! would invariably improve on any time slot the network placed it into.
+
+Because ABC intended to cancel the series, the last episode of the first season ends with Hammer accidentally destroying the city when he attempts to disarm a stolen nuclear warhead; just before the explosion Hammer remarks on his infamous phrase "Trust Me....." . The last scene shows the "Beneath the Planet of the Apes"-style ruins of the city with Trunk's voice screaming "HAMMMMMMMER!", and a graphic flashed:
+
+"To Be Continued... Next Season?"
+
+However, this episode got much better than expected ratings, in large part because the network had moved the show to a better time slot. ABC changed its mind and renewed the show for a second season.
+
+The first episode of the second season perfunctorily explained that it and following episodes were set "five years before" the explosion. Bill Bixby (of Incredible Hulk fame) was brought in to direct numerous episodes. Doreau is Sledge's partner in the second season, a glaring (and unexplained) inconsistency, as the two are portrayed as meeting for the first time in the pilot episode, which supposedly takes place years later (though, it is possible that the explosion takes place five years after the first season and the second season picks up where the show left off). This is more than likely a spoof of cop-out endings to season-ending cliffhangers (a notorious example is Dallas's season opener, where the previous season was revealed to be a dream). In the final moments of the final episode, Sledge asks Dori to marry him, but then claims he was only kidding. The viewer is left to imagine what happens next.
+
+The second season suffered from another extremely undesirable time slot (this time against The Cosby Show), a reduced budget, and lowered filming standard (down to 16 mm film from the previous season's 35 mm). It was not renewed for a third season.
+
+[edit] DVD releases
+
+Anchor Bay Entertainment has released the entire series on DVD in Region 1. The first season of Sledge Hammer! was released on DVD on July 27, 2004. The laugh track, which the network had insisted on including on the pilot and first 12 episodes, is removed on the DVD version, for which Spencer hired an experienced sound designer. The DVD also includes an unaired version of the pilot that runs several minutes longer and has a different ending and different theme music. An earthquake hit while Alan Spencer was recording commentary for one of the DVDs; the tape kept rolling during the event and was included on the DVD, leaving viewers wondering whether the earthquake was real. The second season was released on DVD on April 12, 2005; the commentary on the final episode ended with Spencer, again, being caught in another earthquake, this time with sound effects and a convenient cliffhanger.
+DVD Name Ep # Release Date
+Season 1 22 July 27, 2004
+Season 2 19 April 12, 2005
+
+[edit] Guest appearances
+
+Some notable figures who made guest appearances on Sledge Hammer!:
+
+ * Adam Ant ("Icebreaker")
+ * Lewis Arquette ("Witless")
+ * Bill Bixby ("Hammer Hits the Rock") - Bixby also directed a number of episodes
+ * Bud Cort ("Last of the Red Hot Vampires")
+ * Bill Dana ("Haven't Gun, Will Travel")
+ * John Densmore ("State of Sledge")
+ * Norman Fell ("They Call Me Mr. Trunk")
+ * Conchata Ferrell ("Jagged Sledge")
+ * Dennis Fimple ("They Shoot Hammers, Don't They?")
+ * Sid Haig ("Hammeroid")
+ * Evan Handratthy ("Brother Can You Spare a Crime")
+ * Mark Holton ("The Secret of My Excess")
+ * Clint Howard ("State of Sledge")
+ * Brion James ("If I Had a Little Hammer" and "Model Dearest")
+ * Davy Jones ("Sledge, Rattle & Roll")
+
+
+
+ * Bernie Kopell ("Last of the Red Hot Vampires")
+ * Dan Lauria ("A Clockwork Hammer")
+ * Robin Leach ("The Spa Who Loved Me")
+ * David Leisure ("Hammer Hits the Rock" & "Magnum Farce")
+ * Peter Marshall ("To Live and Die on TV")
+ * Richard Moll ("Hammeroid")
+ * Ronnie Schell ("Hammer Gets Nailed")
+ * Armin Shimerman ("Hammeroid")
+ * Show creator Alan Spencer's hands steal the newspapers in "Under the Gun"
+ * Don Stark ("Under the Gun" and "Sledgepoo")
+ * Brenda Strong ("Miss of the Spider Woman")
+ * John Vernon ("Under the Gun" - parodying his role in the first Dirty Harry film)
+ * Ray Walston ("Big Nazi on Campus")
+ * Patrick Wayne ("Brother Can You Spare a Crime")
+ * Duane Whitaker ("Hammer Gets Nailed")
+ * Mary Woronov ("The Spa Who Loved Me")
+
+[edit] Episode list
+
+One episode ("Wild About Hammer") ended with an epilogue that was intentionally miscolored as a parody of the then-popular colorization trend; ABC received so many complaints from viewers thinking it was a transmission error that for a time callers to ABC's switchboard heard a recorded message explaining that it was all a joke.
+
+[edit] Season 1 (1986–1987)
+Sledge Hammer! DVD cover.
+Number Title Original airdate
+1 Under the Gun (Pilot) September 23, 1986
+2 Hammer Gets Nailed September 26, 1986
+3 Witless October 3, 1986
+4 They Shoot Hammers, Don't They? October 17, 1986
+5 Dori Day Afternoon October 24, 1986
+6 To Sledge, with Love October 31, 1986
+7 All Shook Up November 6, 1986
+8 Over My Dead Bodyguard November 13, 1986
+9 Magnum Farce November 22, 1986
+10 If I Had a Little Hammer November 29, 1986
+11 To Live and Die on TV December 13, 1986
+12 Miss of the Spider Woman December 20, 1986
+13 The Old Man and the Sledge January 3, 1987
+14 State of Sledge January 10, 1987
+15 Haven't Gun, Will Travel January 17, 1987
+16 The Color of Hammer January 24, 1987
+17 Brother, Can You Spare a Crime? January 31, 1987
+18 Desperately Seeking Dori February 7, 1987
+19 Sledgepoo February 14, 1987
+20 Comrade Hammer February 21, 1987
+21 Jagged Sledge April 21, 1987
+22 The Spa Who Loved Me April 28, 1987
+
+[edit] Season 2 (1987–1988)
+Number Title Original airdate
+1 A Clockwork Hammer September 17, 1987
+2 Big Nazi on Campus September 24, 1987
+3 Play It Again, Sledge October 1, 1987
+4 Wild About Hammer October 8, 1987
+5 The Death of a Few Salesmen October 15, 1987
+6 Vertical October 29, 1987
+7 Dressed to Call November 5, 1987
+8 Hammer Hits the Rock (a.k.a. Sledge on the Rock) November 12, 1987
+9 Hammeroid November 26, 1987
+10 Last of the Red Hot Vampires November 19, 1987
+11 Sledge in Toyland December 3, 1987
+12 Icebreaker December 10, 1987
+13 They Call Me Mr. Trunk December 17, 1987
+14 Model Dearest January 7, 1988
+15 Sledge, Rattle & Roll January 15, 1988
+16 Suppose They Gave a War & Sledge Came? January 22, 1988
+17 The Secret of My Excess January 29, 1988
+18 It Happened What Night? February 5, 1988
+19 Here's to You, Mrs. Hammer February 12, 1988
+
+[edit] Trivia
+ Lists of miscellaneous information should be avoided. Please relocate any relevant information into appropriate sections or articles. (June 2007)
+
+ * New World's then-subsidiary Marvel Comics released a short-lived comic book based upon the series, only publishing two issues.
+ * Al Jean and Mike Reiss, best known for their work on The Simpsons, wrote for the show and worked as story editors.
+ * The British rock band Jesus Jones sampled Sledge's famous catch phrase in their song "Trust Me" on their 1991 album Doubt.
+ * The phrase "Hammer time!" was used by Sledge in the episode "State of Sledge", a full three years before MC Hammer's "U Can't Touch This" was released in January 1990.
+ * In a later episode, after Sledge's badge is taken, he notes that the next time he shoots someone he could get arrested. Frank Drebin says the exact same thing in The Naked Gun, released years later.
+ * David Rasche appeared as the President of the United States in the short-lived 2001 television series DAG. His secret service code-name on the series was Sledge Hammer.
+
+[edit] External links
+Search Wikiquote Wikiquote has a collection of quotations related to: Sledge Hammer!
+
+ * Sledge Hammer! Online - Alan Spencer's official site
+ * Sledge Hammer! at the Internet Movie Database
+ * Sledge Hammer! at TV.com
+
+Retrieved from "http://en.wikipedia.org/wiki/Sledge_Hammer!"
+Categories: 1980s American television series | 1986 television series debuts | 1988 television series endings | American Broadcasting Company network shows | Crime television series | American television sitcoms | Television shows set in San Francisco
+Hidden categories: Articles lacking sources from September 2007 | All articles lacking sources | Articles that may contain original research from September 2007 | All articles that may contain original research | All articles with unsourced statements | Articles with unsourced statements from July 2009 | Articles with trivia sections from June 2007
+Views
+
+ * Article
+ * Discussion
+ * Edit this page
+ * History
+
+Personal tools
+
+ * Log in / create account
+
+Navigation
+
+ * Main page
+ * Contents
+ * Featured content
+ * Current events
+ * Random article
+
+Search
+
+Interaction
+
+ * About Wikipedia
+ * Community portal
+ * Recent changes
+ * Contact Wikipedia
+ * Donate to Wikipedia
+ * Help
+
+Toolbox
+
+ * What links here
+ * Related changes
+ * Upload file
+ * Special pages
+ * Printable version
+ * Permanent link
+ * Cite this page
+
+Languages
+
+ * Deutsch
+ * Español
+ * Français
+ * Bahasa Indonesia
+ * Italiano
+ * Nederlands
+ * Português
+ * Русский
+ * Suomi
+ * 中文
+
+Powered by MediaWiki
+Wikimedia Foundation
+
+ * This page was last modified on 7 July 2009 at 14:58.
+ * Text is available under the Creative Commons Attribution/Share-Alike License; additional terms may apply. See Terms of Use for details.
+ Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.
+ * Privacy policy
+ * About Wikipedia
+ * Disclaimers
+
Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/document.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/picture.jpg
===================================================================
(Binary files differ)
Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/resources/myproject/myfolder/picture.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
16 years, 5 months
DNA SVN: r1124 - in trunk: dna-jcr/src/main/java/org/jboss/dna/jcr and 2 other directories.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-07-22 13:32:10 -0400 (Wed, 22 Jul 2009)
New Revision: 1124
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
Log:
DNA-392 All sessions in a repository should share the same /jcr:system content
Changed the JcrRepository implementation to have a new option that defines the source name (and optionally workspace name) where the /jcr:system branch is to be found. If this option is not used, or if the supplied names do not correspond to a valid workspace in an existing source, a transient in-memory source will be used. The existing JcrConfiguration and JcrEngine are already able to process any options, so they do not need to be changed to allow a configuration to define the /jcr:system branch location.
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java 2009-07-21 20:53:05 UTC (rev 1123)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java 2009-07-22 17:32:10 UTC (rev 1124)
@@ -475,8 +475,10 @@
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append(this.workspaceName);
- sb.append('@');
+ if (this.workspaceName != null) {
+ sb.append(this.workspaceName);
+ sb.append('@');
+ }
sb.append(this.sourceName);
sb.append(" { ");
boolean first = true;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-07-21 20:53:05 UTC (rev 1123)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrI18n.java 2009-07-22 17:32:10 UTC (rev 1124)
@@ -99,6 +99,10 @@
public static I18n typeNotFound;
public static I18n supertypeNotFound;
+ public static I18n systemSourceNameOptionValueDoesNotReferenceExistingSource;
+ public static I18n systemSourceNameOptionValueDoesNotReferenceValidWorkspace;
+ public static I18n systemSourceNameOptionValueIsNotFormattedCorrectly;
+
// Used in AbstractJcrNode#getAncestor
public static I18n noNegativeDepth;
public static I18n tooDeep;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-07-21 20:53:05 UTC (rev 1123)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-07-22 17:32:10 UTC (rev 1124)
@@ -45,9 +45,12 @@
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
+import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.i18n.I18n;
import org.jboss.dna.common.text.Inflector;
import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.Graph;
import org.jboss.dna.graph.JaasSecurityContext;
@@ -115,9 +118,23 @@
* The {@link Configuration#getAppConfigurationEntry(String) JAAS application configuration name} that specifies which
* login modules should be used to validate credentials.
*/
- JAAS_LOGIN_CONFIG_NAME;
+ JAAS_LOGIN_CONFIG_NAME,
/**
+ * The name of the source (and optionally the workspace in the source) where the "/jcr:system" branch should be stored.
+ * The format is "<code>name of workspace@name of source</code>", or simply "<code>name of source</code>" if the default
+ * workspace is to be used. If this option is not used, a transient in-memory source will be used.
+ * <p>
+ * Note that all leading and trailing whitespace is removed for both the source name and workspace name. Thus, a value of
+ * "<code>@</code>" implies a zero-length workspace name and zero-length source name.
+ * </p>
+ * <p>
+ * Also, any use of the '@' character in source and workspace names must be escaped with a preceding backslash.
+ * </p>
+ */
+ SYSTEM_SOURCE_NAME;
+
+ /**
* Determine the option given the option name. This does more than {@link Option#valueOf(String)}, since this method first
* tries to match the supplied string to the option's {@link Option#name() name}, then the uppercase version of the
* supplied string to the option's name, and finally if the supplied string is a camel-case version of the name (e.g.,
@@ -180,7 +197,8 @@
private final RepositoryConnectionFactory connectionFactory;
private final RepositoryNodeTypeManager repositoryTypeManager;
private final Map<Option, String> options;
- private final RepositorySource systemSource;
+ private final String systemSourceName;
+ private final String systemWorkspaceName;
private final Projection systemSourceProjection;
private final FederatedRepositorySource federatedSource;
private final Observer observer;
@@ -268,20 +286,63 @@
// Initialize the observer, which receives events from all repository sources ...
this.observer = new RepositoryObserver();
- // Create the in-memory repository source that we'll use for the "/jcr:system" branch in this repository.
- // All workspaces will be set up with a federation connector that projects this system repository into
- // "/jcr:system", and all other content is projected to the repositories actual source (and workspace).
- // (The federation connector refers to this configuration as an "offset mirror".)
- InMemoryRepositorySource systemSource = new InMemoryRepositorySource();
- String systemWorkspaceName = "jcr:system";
- String systemSourceName = "jcr:system source";
- systemSource.setName(systemSourceName);
- systemSource.setDefaultWorkspaceName(systemWorkspaceName);
- this.systemSource = systemSource;
- this.connectionFactory = new ConnectionFactoryWithSystem(connectionFactory, this.systemSource);
+ // Set up the system source ...
+ String systemSourceNameValue = this.options.get(Option.SYSTEM_SOURCE_NAME);
+ String systemSourceName = null;
+ String systemWorkspaceName = null;
+ RepositoryConnectionFactory connectionFactoryWithSystem = connectionFactory;
+ if (systemSourceNameValue != null) {
+ // Find an existing source with the given name containing the named workspace ...
+ try {
+ SourceWorkspacePair pair = new SourceWorkspacePair(systemSourceNameValue);
+ // Look for a source with the given name ...
+ RepositoryConnection conn = connectionFactory.createConnection(pair.getSourceName());
+ if (conn != null) {
+ // We found a source that we can use for the system ...
+ systemSourceName = pair.getSourceName();
+ if (pair.getWorkspaceName() != null) {
+ // There should be the named workspace ...
+ Graph temp = Graph.create(conn, executionContext);
+ temp.useWorkspace(pair.getWorkspaceName());
+ // found it ...
+ systemWorkspaceName = pair.getWorkspaceName();
+ }
+ } else {
+ I18n msg = JcrI18n.systemSourceNameOptionValueDoesNotReferenceExistingSource;
+ Logger.getLogger(getClass()).warn(msg, systemSourceNameValue, systemSourceName);
+ }
+ } catch (InvalidWorkspaceException e) {
+ // Bad workspace name ...
+ systemSourceName = null;
+ I18n msg = JcrI18n.systemSourceNameOptionValueDoesNotReferenceValidWorkspace;
+ Logger.getLogger(getClass()).warn(msg, systemSourceNameValue, systemSourceName);
+ } catch (IllegalArgumentException e) {
+ // Invalid format ...
+ systemSourceName = null;
+ I18n msg = JcrI18n.systemSourceNameOptionValueIsNotFormattedCorrectly;
+ Logger.getLogger(getClass()).warn(msg, systemSourceNameValue);
+ }
+ }
+ if (systemSourceName == null) {
+ // Create the in-memory repository source that we'll use for the "/jcr:system" branch in this repository.
+ // All workspaces will be set up with a federation connector that projects this system repository into
+ // "/jcr:system", and all other content is projected to the repositories actual source (and workspace).
+ // (The federation connector refers to this configuration as an "offset mirror".)
+ systemWorkspaceName = "jcr:system";
+ systemSourceName = "jcr:system source";
+ InMemoryRepositorySource transientSystemSource = new InMemoryRepositorySource();
+ transientSystemSource.setName(systemSourceName);
+ transientSystemSource.setDefaultWorkspaceName(systemWorkspaceName);
+ connectionFactoryWithSystem = new ConnectionFactoryWithSystem(connectionFactory, transientSystemSource);
+ }
+ this.systemWorkspaceName = systemWorkspaceName;
+ this.systemSourceName = systemSourceName;
+ this.connectionFactory = connectionFactoryWithSystem;
+ assert this.systemSourceName != null;
+ assert this.connectionFactory != null;
// Set up the "/jcr:system" branch ...
- Graph systemGraph = Graph.create(this.systemSource, executionContext);
+ Graph systemGraph = Graph.create(this.systemSourceName, this.connectionFactory, executionContext);
systemGraph.useWorkspace(systemWorkspaceName);
initializeSystemContent(systemGraph);
this.sourceName = repositorySourceName;
@@ -353,8 +414,15 @@
}
Graph createSystemGraph() {
+ assert this.systemSourceName != null;
+ assert this.connectionFactory != null;
+ assert this.executionContext != null;
// The default workspace should be the system workspace ...
- return Graph.create(this.systemSource, this.executionContext);
+ Graph result = Graph.create(this.systemSourceName, this.connectionFactory, this.executionContext);
+ if (this.systemWorkspaceName != null) {
+ result.useWorkspace(systemWorkspaceName);
+ }
+ return result;
}
/**
@@ -462,7 +530,8 @@
* <li>provides neither a <code>getLoginContext()</code> nor a <code>getAccessControlContext()</code> method and is
* not an instance of {@code SimpleCredentials}.</li>
* <li>provides a <code>getLoginContext()</code> method that doesn't return a {@link LoginContext}.
- * <li>provides a <code>getLoginContext()</code> method that returns a <code>null</code> {@link LoginContext}.
+ * <li>provides a <code>getLoginContext()</code> method that returns a <code>
+ * null</code> {@link LoginContext}.
* <li>does not provide a <code>getLoginContext()</code> method, but provides a <code>getAccessControlContext()</code>
* method that doesn't return an {@link AccessControlContext}.
* <li>does not provide a <code>getLoginContext()</code> method, but provides a <code>getAccessControlContext()</code>
@@ -662,6 +731,72 @@
}
}
+ @Immutable
+ protected static class SourceWorkspacePair {
+ private final String sourceName;
+ private final String workspaceName;
+
+ protected SourceWorkspacePair( String sourceAndWorkspaceName ) {
+ assert sourceAndWorkspaceName != null;
+ sourceAndWorkspaceName = sourceAndWorkspaceName.trim();
+ assert sourceAndWorkspaceName.length() != 0;
+ sourceAndWorkspaceName = sourceAndWorkspaceName.trim();
+ // Look for the first '@' not preceded by a '\' ...
+ int maxIndex = sourceAndWorkspaceName.length() - 1;
+ int index = sourceAndWorkspaceName.indexOf('@');
+ while (index > 0 && index < maxIndex && sourceAndWorkspaceName.charAt(index - 1) == '\\') {
+ index = sourceAndWorkspaceName.indexOf('@', index + 1);
+ }
+ if (index > 0) {
+ // There is a workspace and source name ...
+ workspaceName = sourceAndWorkspaceName.substring(0, index).trim().replaceAll("\\\\@", "@");
+ if (index < maxIndex) sourceName = sourceAndWorkspaceName.substring(index + 1).trim().replaceAll("\\\\@", "@");
+ else throw new IllegalArgumentException("The source name is invalid");
+ } else if (index == 0) {
+ // The '@' was used, but the workspace is empty
+ if (sourceAndWorkspaceName.length() == 1) {
+ sourceName = "";
+ } else {
+ sourceName = sourceAndWorkspaceName.substring(1).trim().replaceAll("\\\\@", "@");
+ }
+ workspaceName = "";
+ } else {
+ // There is just a source name...
+ workspaceName = null;
+ sourceName = sourceAndWorkspaceName.replaceAll("\\\\@", "@");
+ }
+ assert this.sourceName != null;
+ }
+
+ /**
+ * @return sourceName
+ */
+ public String getSourceName() {
+ return sourceName;
+ }
+
+ /**
+ * @return workspaceName
+ */
+ public String getWorkspaceName() {
+ return workspaceName;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ if (sourceName == null) return "";
+ if (workspaceName != null) {
+ return workspaceName + '@' + sourceName;
+ }
+ return sourceName;
+ }
+ }
+
protected class RepositoryObserver implements Observer {
/**
* {@inheritDoc}
Modified: trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties
===================================================================
--- trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-07-21 20:53:05 UTC (rev 1123)
+++ trunk/dna-jcr/src/main/resources/org/jboss/dna/jcr/JcrI18n.properties 2009-07-22 17:32:10 UTC (rev 1124)
@@ -97,6 +97,10 @@
typeNotFound=No type exists with name "{0}"
supertypeNotFound=Could not find type "{0}" which is a required supertype of type "{1}"
+systemSourceNameOptionValueDoesNotReferenceExistingSource = The JCR Repository 'SYSTEM_SOURCE_NAME' option value "{0}" references an invalid or non-existant source "{1}"
+systemSourceNameOptionValueDoesNotReferenceValidWorkspace = The JCR Repository 'SYSTEM_SOURCE_NAME' option value "{0}" references an invalid or non-existant workspace in the "{1}" source
+systemSourceNameOptionValueIsNotFormattedCorrectly = The JCR Repository 'SYSTEM_SOURCE_NAME' option value "{0}" is invalid or improperly formatted
+
noNegativeDepth=Depth parameter ({0}) cannot be negative
tooDeep=Depth parameter ({0}) cannot be greater than the result of getDepth() for this node
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-07-21 20:53:05 UTC (rev 1123)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-07-22 17:32:10 UTC (rev 1124)
@@ -350,6 +350,47 @@
assertThat(session.getNamespaceURI("xmlns"), is("http://www.w3.org/2000/xmlns/"));
}
+ @Test
+ public void shouldParseSourceNameOptionWithOnlySourceName() {
+ assertSourceWorkspacePair("source name", "source name", null);
+ assertSourceWorkspacePair(" \t source name \n ", "source name", null);
+ assertSourceWorkspacePair(" \t source \\@ name \n ", "source @ name", null);
+ }
+
+ @Test
+ public void shouldParseSourceNameOptionWithWorkspaceNameAndSourceName() {
+ assertSourceWorkspacePair("workspace@source", "source", "workspace");
+ assertSourceWorkspacePair(" \t workspace\t@ \t source \t \n", "source", "workspace");
+ assertSourceWorkspacePair(" \t workspace\\@ name \t@ \t source\\@name \t \n", "source@name", "workspace@ name");
+ assertSourceWorkspacePair("@ \t source \\@ name \n ", "source @ name", "");
+ assertSourceWorkspacePair(" @ \t source \\@ name \n ", "source @ name", "");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldFailToParseSourceNameOptionThatHasZeroLengthSource() {
+ new JcrRepository.SourceWorkspacePair("workspace@");
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void shouldFailToParseSourceNameOptionThatHasBlankSource() {
+ new JcrRepository.SourceWorkspacePair("workspace@ ");
+ }
+
+ @Test
+ public void shouldParseSourceNameOptionThatHasBlankSourceAndWorkspace() {
+ assertSourceWorkspacePair("@", "", "");
+ assertSourceWorkspacePair(" @ ", "", "");
+ }
+
+ protected void assertSourceWorkspacePair( String value,
+ String expectedSourceName,
+ String expectedWorkspaceName ) {
+ JcrRepository.SourceWorkspacePair pair = new JcrRepository.SourceWorkspacePair(value);
+ assertThat(pair, is(notNullValue()));
+ assertThat(pair.getSourceName(), is(expectedSourceName));
+ assertThat(pair.getWorkspaceName(), is(expectedWorkspaceName));
+ }
+
protected JcrSession createSession() throws Exception {
LoginContext login = new LoginContext("dna-jcr", new UserPasswordCallbackHandler("superuser", "superuser".toCharArray()));
login.login();
16 years, 5 months
DNA SVN: r1123 - in trunk/dna-jcr/src: test/java/org/jboss/dna/jcr and 1 other directory.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-07-21 16:53:05 -0400 (Tue, 21 Jul 2009)
New Revision: 1123
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
Log:
DNA-392 All sessions in a repository should share the same /jcr:system content
Changed how the JcrSession and JcrWorkspace objects are instantiated to move all content initialization code into the JcrRepository class. Creating JcrSession and JcrWorkspace objects is not much faster, though there still is a single verify workspace request issued against the source (even though this is still done within the JcrRepository instance, the JcrWorkspace creates its own graph, which requires issuing this request). Changed a number of test cases to reflect the new behavior.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-07-21 19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrNamespaceRegistry.java 2009-07-21 20:53:05 UTC (rev 1123)
@@ -126,10 +126,6 @@
this.workspaceRegistry = workspaceRegistry;
this.session = session;
- // Add the built-ins, ensuring we overwrite any badly-initialized values ...
- for (Map.Entry<String, String> builtIn : STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
- this.registry.register(builtIn.getKey(), builtIn.getValue());
- }
assert this.behavior != null;
assert this.registry != null;
assert this.workspaceRegistry != null;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-07-21 19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2009-07-21 20:53:05 UTC (rev 1123)
@@ -299,6 +299,11 @@
this.persistentRegistry = new GraphNamespaceRegistry(systemGraph, namespacesPath, uriProperty, namespaceType);
this.executionContext = executionContext.with(persistentRegistry);
+ // Add the built-ins, ensuring we overwrite any badly-initialized values ...
+ for (Map.Entry<String, String> builtIn : JcrNamespaceRegistry.STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
+ this.persistentRegistry.register(builtIn.getKey(), builtIn.getValue());
+ }
+
// Set up the repository type manager ...
try {
this.repositoryTypeManager = new RepositoryNodeTypeManager(this.executionContext);
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-07-21 19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2009-07-21 20:53:05 UTC (rev 1123)
@@ -156,7 +156,7 @@
this.rootPath = this.executionContext.getValueFactories().getPathFactory().createRootPath();
// Set up the graph to use for this session (which uses the session's namespace registry and context) ...
- this.graph = repository.createWorkspaceGraph(workspace.getName());
+ this.graph = workspace.graph();
this.cache = new SessionCache(this);
this.isLive = true;
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-07-21 19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java 2009-07-21 20:53:05 UTC (rev 1123)
@@ -188,6 +188,10 @@
}
+ final Graph graph() {
+ return this.graph;
+ }
+
final String getSourceName() {
return this.repository.getRepositorySourceName();
}
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java 2009-07-21 19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java 2009-07-21 20:53:05 UTC (rev 1123)
@@ -96,6 +96,11 @@
graph.create("/jcr:system/dna:namespaces").and();
graph.set("jcr:primaryType").on("/jcr:system/dna:namespaces").to(DnaLexicon.NAMESPACES);
+ // Add the built-ins, ensuring we overwrite any badly-initialized values ...
+ for (Map.Entry<String, String> builtIn : JcrNamespaceRegistry.STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
+ context.getNamespaceRegistry().register(builtIn.getKey(), builtIn.getValue());
+ }
+
initializeContent();
// Stub out the connection factory ...
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java 2009-07-21 19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrNamespaceRegistryTest.java 2009-07-21 20:53:05 UTC (rev 1123)
@@ -94,29 +94,6 @@
}
}
- @Test
- public void shouldBeInitializedWithNamespacesDefinedByTheJcrSpecification() throws Exception {
- // Don't use the constants, since this needs to check that the actual values are correct
- assertThatNamespaceIsRegistered("jcr", "http://www.jcp.org/jcr/1.0");
- assertThatNamespaceIsRegistered("nt", "http://www.jcp.org/jcr/nt/1.0");
- assertThatNamespaceIsRegistered("mix", "http://www.jcp.org/jcr/mix/1.0");
- assertThatNamespaceIsRegistered("xml", "http://www.w3.org/XML/1998/namespace");
- assertThatNamespaceIsRegistered("", "");
- }
-
- @Test
- public void shouldBeInitializedWithNamespacesDefinedByTheJcrApiJavaDoc() throws Exception {
- // Don't use the constants, since this needs to check that the actual values are correct
- assertThatNamespaceIsRegistered("sv", "http://www.jcp.org/jcr/sv/1.0");
- assertThatNamespaceIsRegistered("xmlns", "http://www.w3.org/2000/xmlns/");
- }
-
- @Test
- public void shouldBeInitializedWithNamespacesSpecificToDna() throws Exception {
- // Don't use the constants, since this needs to check that the actual values are correct
- assertThatNamespaceIsRegistered("dna", "http://www.jboss.org/dna/1.0");
- }
-
@Test( expected = IllegalArgumentException.class )
public void shouldNotAllowRegisteringNullPrefix() throws Exception {
registry.registerNamespace("foo", null);
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-07-21 19:14:15 UTC (rev 1122)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2009-07-21 20:53:05 UTC (rev 1123)
@@ -323,6 +323,33 @@
}
}
+ @Test
+ public void shouldHaveRegisteredThoseNamespacesNeedeByDna() throws Exception {
+ session = createSession();
+ // Don't use the constants, since this needs to check that the actual values are correct
+ assertThat(session.getNamespaceURI("dna"), is("http://www.jboss.org/dna/1.0"));
+ assertThat(session.getNamespaceURI("dnaint"), is("http://www.jboss.org/dna/internal/1.0"));
+ }
+
+ @Test
+ public void shouldHaveRegisteredThoseNamespacesDefinedByTheJcrSpecification() throws Exception {
+ session = createSession();
+ // Don't use the constants, since this needs to check that the actual values are correct
+ assertThat(session.getNamespaceURI("dna"), is("http://www.jboss.org/dna/1.0"));
+ assertThat(session.getNamespaceURI("jcr"), is("http://www.jcp.org/jcr/1.0"));
+ assertThat(session.getNamespaceURI("mix"), is("http://www.jcp.org/jcr/mix/1.0"));
+ assertThat(session.getNamespaceURI("nt"), is("http://www.jcp.org/jcr/nt/1.0"));
+ assertThat(session.getNamespaceURI(""), is(""));
+ }
+
+ @Test
+ public void shouldHaveRegisteredThoseNamespacesDefinedByTheJcrApiJavaDoc() throws Exception {
+ session = createSession();
+ // Don't use the constants, since this needs to check that the actual values are correct
+ assertThat(session.getNamespaceURI("sv"), is("http://www.jcp.org/jcr/sv/1.0"));
+ assertThat(session.getNamespaceURI("xmlns"), is("http://www.w3.org/2000/xmlns/"));
+ }
+
protected JcrSession createSession() throws Exception {
LoginContext login = new LoginContext("dna-jcr", new UserPasswordCallbackHandler("superuser", "superuser".toCharArray()));
login.login();
16 years, 5 months
DNA SVN: r1122 - trunk/extensions/dna-sequencer-jbpm-jpdl.
by dna-commits@lists.jboss.org
Author: rhauch
Date: 2009-07-21 15:14:15 -0400 (Tue, 21 Jul 2009)
New Revision: 1122
Modified:
trunk/extensions/dna-sequencer-jbpm-jpdl/pom.xml
Log:
DNA-493 Integration tests should not be run via Maven by default
Corrected the JBPM project to no longer depend on 'dna-integration-tests' projection. This was an artificial dependency that broke the Hudson build.
Modified: trunk/extensions/dna-sequencer-jbpm-jpdl/pom.xml
===================================================================
--- trunk/extensions/dna-sequencer-jbpm-jpdl/pom.xml 2009-07-21 17:58:05 UTC (rev 1121)
+++ trunk/extensions/dna-sequencer-jbpm-jpdl/pom.xml 2009-07-21 19:14:15 UTC (rev 1122)
@@ -44,12 +44,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jboss.dna</groupId>
- <artifactId>dna-integration-tests</artifactId>
- <version>${pom.version}</version>
- <scope>test</scope>
- </dependency>
<!--
jBPM jPDL
-->
16 years, 5 months