Author: glen
Date: Sun Feb 3 22:31:08 2008
New Revision: 13237
Log:
* Move Atom-specific stuff into APPConstants to clean up RegistryConstants
* Code cleanup
* Improve JavaDocs a bit
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
Sun Feb 3 22:31:08 2008
@@ -26,14 +26,14 @@
public interface Registry extends CoreRegistry {
/**
- * Creates a resource in the suggested path (which may be altered) by
fetching the resource
- * content from the given URL.
+ * Creates a resource by fetching the resource content from the given URL.
*
- * @param suggestedPath Path to add the new resource. Although this path
is specified by the
- * caller of the method, resource may not be actually
added to this path.
- * @param sourceURL URL to fetch the resource content
- * @param metadata
- * @return Actual path to which the resource is added
+ * @param suggestedPath path where we'd like to add the new resource.
Although this path is
+ * specified by the caller of the method, resource
may not be actually
+ * added to this path.
+ * @param sourceURL where to fetch the resource content
+ * @param metadata a template Resource
+ * @return actual path to which the resource is added
* @throws RegistryException
*/
String importResource(String suggestedPath, String sourceURL, Resource
metadata)
@@ -50,12 +50,12 @@
void delete(String path) throws RegistryException;
/**
- * Move or rename a resources in the registry. Rename can be considered as
- First delete the
- * resource - Then add the resource to the new location
+ * Move or rename a resource in the registry. This is equivalent to 1)
delete the
+ * resource 2) add the resource to the new location.
*
- * @param currentPath : Current path of the resource
- * @param newPath where to move the reosurce
- * @return generated path for the resource
+ * @param currentPath current path of the resource
+ * @param newPath where we'd like to move the reosurce
+ * @return the actual path for the new resource
* @throws RegistryException : If something went wrong
*/
String rename(String currentPath, String newPath) throws RegistryException;
@@ -64,8 +64,8 @@
* Returns the paths of the versions of the resource located at the given
path. Version paths
* are returned in the form /projects/myresource?v=12
*
- * @param path Path of a current version of a resource
- * @return Paths of versions
+ * @param path path of a current version of a resource
+ * @return a String array containing the individual paths of versions
* @throws RegistryException if there is an error
*/
String[] getVersions(String path) throws RegistryException;
@@ -94,10 +94,10 @@
void applyTag(String resourcePath, String tag) throws RegistryException;
/**
- * Returns the paths of the resources, which are tagged using the given
tag.
+ * Returns the paths of all Resources that are tagged with the given tag.
*
- * @param tag Tag
- * @return Resource paths
+ * @param tag the tag to search for
+ * @return an array of TaggedResourcePaths
* @throws RegistryException if an error occurs
*/
TaggedResourcePath[] getResourcePathsWithTag(String tag) throws
RegistryException;
@@ -136,13 +136,20 @@
*/
String addComment(String resourcePath, Comment comment) throws
RegistryException;
+ /**
+ * Change the text of an existing comment.
+ *
+ * @param commentPath path to comment resource ("..foo/r1;comment:1")
+ * @param text new text
+ * @throws RegistryException
+ */
void editComment(String commentPath, String text) throws RegistryException;
/**
- * Retruns all comments for the given resource.
+ * Get all comments for the given resource.
*
- * @param resourcePath Path of the resource.
- * @return Array of Comment objects.
+ * @param resourcePath path of the resource.
+ * @return an array of Comment objects.
* @throws RegistryException if an error occurs
*/
Comment[] getComments(String resourcePath) throws RegistryException;
@@ -152,7 +159,7 @@
////////////////////////////////////////////////////////
/**
- * Rates the given resource.
+ * Rate the given resource.
*
* @param resourcePath Path of the resource.
* @param rating rating value between 1 and 5.
@@ -181,11 +188,10 @@
int getRating(String path, String userName) throws RegistryException;
/**
- * Executes a custom query defined by users. Returned RowSet contains
fields of tables specified
- * by the custom query.
+ * Executes a custom query which lives at the given path in the Registry.
*
* @param path Path of the query to execute.
- * @param parameters Query parameters.
+ * @param parameters a Map of query parameters (name -> value)
* @return RowSet containing the fields specified in the query.
* @throws RegistryException depends on the implementation.
*/
@@ -203,8 +209,8 @@
* returned. If null, there will not be a bound for
the starting date.
* @param to If given, logs for activities occured before the
given date will be
* returned. If null, there will not be a bound for
the ending date.
- * @param recentFirst If true, returned activities will be in the
descending order. If false,
- * returned activities will be in the ascending order.
+ * @param recentFirst If true, returned activities will be most-recent
first. If false,
+ * returned activities will be oldest first.
* @return Array of LogEntry objects representing the logs
* @throws RegistryException if there is a problem
*/
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
Sun Feb 3 22:31:08 2008
@@ -26,7 +26,7 @@
* These constants are used to specify the core registry to use in the
registry server. This is
* specified as a init parameter of the Registry servlet.
*/
- public static final String REGISTRY_TYPE_PARAMTER = "registryType";
+ public static final String REGISTRY_TYPE_PARAMETER = "registryType";
public static final String JDBC_REGISTRY_TYPE = "JDBCRegistry";
public static final String REMOTE_REGISTRY_TYPE = "RemoteRegistry";
public static final String INMEM_REGISTRY_TYPE = "InMemoryRegistry";
@@ -118,30 +118,12 @@
public static final String RATINGS_RESULT_TYPE = "Ratings";
public static final String TAGS_RESULT_TYPE = "Tags";
- //APP Constants
- public static final String PARAMETER_VERSION = "version";
- public static final String PARAMETER_RESTORE = "restore";
- public static final String PARAMETER_RENAME = "rename";
- public static final String PARAMETER_TAGS = "tags";
- public static final String PARAMETER_TAG_PATHS = "tagpaths";
- public static final String PARAMETER_TAGS_REMOVED = "removeTags";
- public static final String PARAMETER_RATINGS = "ratings";
- public static final String PARAMETER_AVERAGE_RATINGS = "avgRtings";
- public static final String PARAMETER_COMMENTS = "comments";
- public static final String PARAMETER_LOGS = "logs";
- public static final String PARAMETER_QUERY = "query";
- public static final String PARAMETER_RESOURCE_EXIST = "resourceExists";
-
public static final String RESOURCES_JSP = "/admin/registry-resources.jsp";
public static final String RESOURCE_DETAILS_JSP =
"/admin/resources_details.jsp";
public static final String ERROR_MESSAGE = "error.message";
public static final String ERROR_JSP = "/admin/error.jsp";
public static final String PATH_ATTR = "path";
- // Custom elements in Atom feeds and entries
- public static final String NAMESPACE = "http://wso2.org/registry";
- public static final QName QNAME_AVGRATING = new QName(NAMESPACE,
"AverageRating", "wso2");
-
// Separator used to access Registry metadata - i.e. "/resource$tags"
public static final String URL_SEPARATOR = ";";
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/APPConstants.java
Sun Feb 3 22:31:08 2008
@@ -15,12 +15,26 @@
*/
package org.wso2.registry.app;
-import org.wso2.registry.RegistryConstants;
-
import javax.xml.namespace.QName;
public interface APPConstants {
- static final QName COMMENTS_QNAME = new QName(RegistryConstants.NAMESPACE
, "isComments");
- static final QName COMMENTID_QNAME = new QName(RegistryConstants.NAMESPACE
,"commentID");
+ // Custom elements in Atom feeds and entries
+ static final String NAMESPACE = "http://wso2.org/registry";
+ static final QName QNAME_AVGRATING = new QName(NAMESPACE, "AverageRating",
"wso2");
+ static final QName COMMENTS_QNAME = new QName(NAMESPACE , "isComments");
+ static final QName COMMENTID_QNAME = new QName(NAMESPACE ,"commentID");
static final String IMPORT_MEDIATYPE = "application/resource-import";
+
+ static final String PARAMETER_VERSION = "version";
+ static final String PARAMETER_RESTORE = "restore";
+ static final String PARAMETER_RENAME = "rename";
+ static final String PARAMETER_TAGS = "tags";
+ static final String PARAMETER_TAG_PATHS = "tagpaths";
+ static final String PARAMETER_TAGS_REMOVED = "removeTags";
+ static final String PARAMETER_RATINGS = "ratings";
+ static final String PARAMETER_AVERAGE_RATINGS = "avgRtings";
+ static final String PARAMETER_COMMENTS = "comments";
+ static final String PARAMETER_LOGS = "logs";
+ static final String PARAMETER_QUERY = "query";
+ static final String PARAMETER_RESOURCE_EXIST = "resourceExists";
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
Sun Feb 3 22:31:08 2008
@@ -36,7 +36,6 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.Comment;
import org.wso2.registry.*;
-import org.wso2.registry.servlet.utils.Utils;
import org.wso2.registry.exceptions.ResourceNotFoundException;
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.jdbc.realm.RegistryRealm;
@@ -138,16 +137,16 @@
// } else {
Resource resource = new Resource();
// }
- String attValue = entry.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,
+ String attValue = entry.getSimpleExtension(new QName(NAMESPACE ,
"directory"));
Properties properties =
entry.getExtension(PropertyExtensionFactory.PROPERTIES);
RemoteRegistry.createPropertiesFromExtensionElement(properties,
resource);
- String mediaType = entry.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,
+ String mediaType = entry.getSimpleExtension(new QName(NAMESPACE ,
"mediaType"));
if (mediaType != null) {
resource.setMediaType(mediaType);
}
- String parentPath = entry.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,
+ String parentPath = entry.getSimpleExtension(new QName(NAMESPACE ,
"parentPath"));
if (parentPath != null && !"".equals(parentPath)) {
resource.setParentPath(parentPath);
@@ -159,7 +158,7 @@
resource.setDescription(entry.getSummary());
}
String contentModified = entry.getSimpleExtension(
- new QName(RegistryConstants.NAMESPACE ,
+ new QName(NAMESPACE ,
"contentModified"));
if (attValue != null && "true".equals(attValue)) {
// Directory
@@ -200,9 +199,9 @@
Document<Entry> entry_doc =
(Document<Entry>)request.getDocument(parser).clone();
Entry entry = entry_doc.getRoot();
String entryContent = entry.getContent();
- if (RegistryConstants.PARAMETER_TAGS.equals(modifier)) {
+ if (PARAMETER_TAGS.equals(modifier)) {
getSecureRegistry(request).applyTag(resourcePath,
entryContent);
- } else if (RegistryConstants.PARAMETER_COMMENTS.equals(modifier)) {
+ } else if (PARAMETER_COMMENTS.equals(modifier)) {
Comment comment = new Comment();
comment.setText(entryContent);
comment.setUser(entry.getAuthor().getName());
@@ -212,10 +211,10 @@
EmptyResponseContext responseContext = new
EmptyResponseContext(200);
responseContext.setLocation(commentPath);
return responseContext;
- } else if (RegistryConstants.PARAMETER_RATINGS.equals(modifier)) {
+ } else if (PARAMETER_RATINGS.equals(modifier)) {
getSecureRegistry(request).rateResource(resourcePath,
Integer.parseInt(entryContent));
- } else if (RegistryConstants.PARAMETER_RENAME.equals(modifier)) {
+ } else if (PARAMETER_RENAME.equals(modifier)) {
getSecureRegistry(request).rename(resourcePath, entryContent);
} else {
//TODO : We need to implement the other operation as well
@@ -237,7 +236,7 @@
// if (values.length > 1) {
// String operation = values[1];
//// String resourcePath = values[0];
-// if (RegistryConstants.PARAMETER_TAGS.equals(operation)) {
+// if (PARAMETER_TAGS.equals(operation)) {
// //TODO Need to implement this
// }
// //deleting something else, not a resource like Tag or
comment
@@ -281,22 +280,22 @@
operation =
operation.substring(0,operation.indexOf(":"));
}
}
- if (RegistryConstants.PARAMETER_RESTORE.equals(operation)) {
+ if (PARAMETER_RESTORE.equals(operation)) {
String version = values[0];
getSecureRegistry(request).restoreVersion(version);
- } else if (RegistryConstants.PARAMETER_TAGS.equals(operation))
{
+ } else if (PARAMETER_TAGS.equals(operation)) {
String path = values[0];
String tags = entry.getContent();
getSecureRegistry(request).applyTag(path, tags);
- } else if
(RegistryConstants.PARAMETER_TAGS_REMOVED.equals(operation)) {
+ } else if (PARAMETER_TAGS_REMOVED.equals(operation)) {
String path = values[0];
String tag = entry.getContent();
getSecureRegistry(request).removeTag(path, tag);
- } else if
(RegistryConstants.PARAMETER_RATINGS.equals(operation)) {
+ } else if (PARAMETER_RATINGS.equals(operation)) {
String path = values[0];
String rate = entry.getContent();
getSecureRegistry(request).rateResource(path,
Integer.parseInt(rate));
- } else if
(RegistryConstants.PARAMETER_COMMENTS.equals(operation)) {
+ } else if (PARAMETER_COMMENTS.equals(operation)) {
String commentString = entry.getContent();
getSecureRegistry(request).editComment(values[0] + ";" +
values[1], commentString);
}
@@ -349,7 +348,7 @@
parameter = parts[1];
operation = parts[0];
}
- if (RegistryConstants.PARAMETER_VERSION.equals(operation)) {
+ if (PARAMETER_VERSION.equals(operation)) {
// Need to return list of version for the given resource ,
[resourcePath]
try {
String[] versions =
getSecureRegistry(request).getVersions(resourcePath);
@@ -368,7 +367,7 @@
} catch (RegistryException e) {
return new StringResponseContext(request.getAbdera(), e,
500);
}
- } else if (RegistryConstants.PARAMETER_TAGS.equals(operation)) {
+ } else if (PARAMETER_TAGS.equals(operation)) {
// if the user [parameter] name is null then need to return
all the
// tags for the given path
if (parameter == null) {
@@ -382,20 +381,20 @@
feed = populateFeed(abdera, baseURI, entry_id, resource,
false);
}
- } else if
(RegistryConstants.PARAMETER_AVERAGE_RATINGS.equals(operation)) {
+ } else if (PARAMETER_AVERAGE_RATINGS.equals(operation)) {
feed = getRatingsFeed(abdera, resourcePath, baseURI);
- } else if (RegistryConstants.PARAMETER_RATINGS.equals(operation)) {
+ } else if (PARAMETER_RATINGS.equals(operation)) {
try {
resource = getSecureRegistry(request).get(entry_id);
feed = populateFeed(abdera, baseURI, entry_id, resource,
false);
if (parameter == null) {
-
feed.addSimpleExtension(RegistryConstants.QNAME_AVGRATING,
+ feed.addSimpleExtension(QNAME_AVGRATING,
"" +
jdbcregistry.getAverageRating(resourcePath));
}
} catch (RegistryException e) {
return new StringResponseContext(abdera, e, 500);
}
- } else if (RegistryConstants.PARAMETER_COMMENTS.equals(operation))
{
+ } else if (PARAMETER_COMMENTS.equals(operation)) {
if (parameter == null) {
feed = getFeedForComments(abdera, entry_id, request);
} else {
@@ -406,9 +405,9 @@
}
feed = populateFeed(abdera, baseURI, entry_id, resource,
false);
}
- } else if
(RegistryConstants.PARAMETER_TAG_PATHS.equals(operation)) {
+ } else if (PARAMETER_TAG_PATHS.equals(operation)) {
feed = getFeedForTagPaths(abdera, parameter, baseURI, request);
- } else if (RegistryConstants.PARAMETER_LOGS.equals(operation)) {
+ } else if (PARAMETER_LOGS.equals(operation)) {
Date to = request.getDateHeader("ToDate");
Date from = request.getDateHeader("FromDate");
String action = request.getHeader("Action");
@@ -418,7 +417,7 @@
} catch (RegistryException e) {
return new StringResponseContext(request.getAbdera(), e,
500);
}
- } else if (RegistryConstants.PARAMETER_QUERY.equals(operation)) {
+ } else if (PARAMETER_QUERY.equals(operation)) {
try {
// Trying to execute a query for a given path for a given
paramater
String parms = request.getHeader("parameters");
@@ -428,7 +427,7 @@
} catch (RegistryException e) {
return new StringResponseContext(request.getAbdera(), e,
500);
}
- } else if
(RegistryConstants.PARAMETER_RESOURCE_EXIST.equals(operation)) {
+ } else if (PARAMETER_RESOURCE_EXIST.equals(operation)) {
feed = getFeedResourceExist(abdera, resourcePath, request);
} else {
return createErrorResponse();
@@ -498,7 +497,7 @@
//if the resource is deleted then there will be comment saying that
the resource is
// deleted
if (resource.getState() == RegistryConstants.DELETED_STATE) {
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
"state"), "Deleted");
+ feed.addSimpleExtension(new QName(NAMESPACE , "state"), "Deleted");
}
feed.setId("http://wso2.org/jdbcregistry:atom" + resource.getId());
if (resource.getDescription() != null &&
!"".equals(resource.getDescription())) {
@@ -515,23 +514,23 @@
}
// resource.getCreatedTime()
if (resource.getCreatedTime() != null) {
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"createdTime"),
+ feed.addSimpleExtension(new QName(NAMESPACE ,"createdTime"),
"" + resource.getCreatedTime().getTime());
}
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"mediaType"),
+ feed.addSimpleExtension(new QName(NAMESPACE ,"mediaType"),
resource.getMediaType());
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"parentPath"),
+ feed.addSimpleExtension(new QName(NAMESPACE ,"parentPath"),
resource.getParentPath());
path = RemoteRegistry.encodeURL(path);
String href = baseURI + "atom" + path;
feed.addLink(href);
feed.addLink(href, "self");
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
+ feed.addSimpleExtension(new QName(NAMESPACE ,
"lastUpdatedUser"), resource.getLastUpdaterUserName());
//if the content type is comment then the resource will contains ,
// String array of comments
if (resource.isDirectory()) {
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"directory"), "true");
+ feed.addSimpleExtension(new QName(NAMESPACE ,"directory"), "true");
}
if (exceuteQuery) {
String values[] = (String[])resource.getContent();
@@ -557,7 +556,7 @@
} else {
//Now the resource is a actual resource , so need to send the
content
//adding attribute to indicate the resource is not a directory
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"directory"), "false");
+ feed.addSimpleExtension(new QName(NAMESPACE ,"directory"),
"false");
Object content = resource.getContent();
Entry entry = abdera.getFactory().newEntry();
String link = baseURI + "atom" + path;
@@ -698,7 +697,7 @@
try {
uri = URLDecoder.decode(uri,"utf-8");
} catch (UnsupportedEncodingException e) {
-
+ // TODO : do anything here?
}
return (uri.length() == 0) ? "/" : uri;
}
@@ -750,7 +749,7 @@
feed.setTitle("Tags for " + path);
String nodeLink = baseUri + "atom" + path +
RegistryConstants.URL_SEPARATOR +
- RegistryConstants.PARAMETER_TAGS;
+ PARAMETER_TAGS;
feed.addLink(nodeLink);
feed.setUpdated(new Date());
@@ -758,7 +757,7 @@
Entry entry = abdera.getFactory().newEntry();
entry.setTitle(tag.getTagName());
entry.setContent(tag.getTagName());
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"taggings"), "" + tag.getTagCount());
+ entry.addSimpleExtension(new QName(NAMESPACE ,"taggings"), ""
+ tag.getTagCount());
feed.addEntry(entry);
}
return feed;
@@ -785,9 +784,9 @@
feed.setTitle("Average Rating for the resource " + path);
String nodeLink = baseUri + "atom" + path +
RegistryConstants.URL_SEPARATOR +
- RegistryConstants.PARAMETER_AVERAGE_RATINGS;
+ PARAMETER_AVERAGE_RATINGS;
feed.addLink(nodeLink);
- feed.addSimpleExtension(RegistryConstants.QNAME_AVGRATING,
+ feed.addSimpleExtension(QNAME_AVGRATING,
"" + jdbcregistry.getAverageRating(path));
return feed;
} catch (RegistryException e) {
@@ -809,7 +808,7 @@
try {
Factory factory = abdera.getFactory();
Feed feed = factory.newFeed();
- feed.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"directory"), "true");
+ feed.addSimpleExtension(new QName(NAMESPACE ,"directory"), "true");
feed.addSimpleExtension(COMMENTS_QNAME, "true");
Comment comments[] = getSecureRegistry(request).getComments(path);
feed.setId("http://wso2.org/registry,Comments" + path);
@@ -861,7 +860,7 @@
Entry entry = abdera.getFactory().newEntry();
String path = tagPath.getResourcePath();
entry.setTitle(path);
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE
,"taggings"), "" + tagPath.getTagCount());
+ entry.addSimpleExtension(new QName(NAMESPACE ,"taggings"), ""
+ tagPath.getTagCount());
Map tagCounts = tagPath.getTagCounts();
Iterator iCounts = tagCounts.keySet().iterator();
java.util.Properties properties = new java.util.Properties();
@@ -941,9 +940,9 @@
entry.setEdited(logentry.getDate());
entry.setContent(logentry.getActionData());
entry.addAuthor(logentry.getUserName());
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
+ entry.addSimpleExtension(new QName(NAMESPACE ,
"action"), "" + logentry.getAction());
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
+ entry.addSimpleExtension(new QName(NAMESPACE ,
"path"), logentry.getResourcePath());
feed.addEntry(entry);
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
Sun Feb 3 22:31:08 2008
@@ -34,7 +34,10 @@
import org.wso2.registry.i18n.Messages;
import javax.xml.namespace.QName;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
@@ -86,14 +89,15 @@
public Resource get(String path) throws RegistryException {
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
- ClientResponse clientResponse = abderaClient.get(baseURI +
encodeURL(path), getAuthorization());
+ ClientResponse clientResponse =
+ abderaClient.get(baseURI + encodeURL(path),
getAuthorization());
if (clientResponse.getType() == Response.ResponseType.CLIENT_ERROR ||
clientResponse.getType() == Response.ResponseType.SERVER_ERROR) {
throw new ResourceNotFoundException(path);
}
Document introspection = clientResponse.getDocument();
Feed feed = (Feed)introspection.getRoot();
- String state = feed.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,"state"));
+ String state = feed.getSimpleExtension(new QName(NAMESPACE, "state"));
if (state != null && state.equals("Deleted")) {
throw new ResourceNotFoundException(path);
}
@@ -112,7 +116,7 @@
* : If user is unable to open the URL connection
*/
private Resource createResourceFromFeed(Feed feed, boolean isQuery) throws
RegistryException {
- String isDirectory = feed.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,"directory"));
+ String isDirectory = feed.getSimpleExtension(new QName(NAMESPACE,
"directory"));
Resource resource = new Resource();
Properties properties =
feed.getExtension(PropertyExtensionFactory.PROPERTIES);
RemoteRegistry.createPropertiesFromExtensionElement(properties,
resource);
@@ -120,27 +124,27 @@
resource.setAuthorUserName(feed.getAuthor().getName());
}
resource.setLastModified(feed.getUpdated());
- String createdDate = feed.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,"createdTime"));
+ String createdDate = feed.getSimpleExtension(new QName(NAMESPACE,
"createdTime"));
if (createdDate != null) {
resource.setCreatedTime(new Date(Long.parseLong(createdDate)));
}
- String lastUpdatedUser = feed.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,
- "lastUpdatedUser"));
+ String lastUpdatedUser = feed.getSimpleExtension(new QName(NAMESPACE,
+
"lastUpdatedUser"));
if (lastUpdatedUser != null) {
resource.setLastUpdaterUserName(lastUpdatedUser);
}
- String mediaType = feed.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,"mediaType"));
+ String mediaType = feed.getSimpleExtension(new QName(NAMESPACE,
"mediaType"));
if (mediaType != null) {
resource.setMediaType(mediaType);
}
- String parentPath = feed.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,"parentPath"));
+ String parentPath = feed.getSimpleExtension(new QName(NAMESPACE,
"parentPath"));
if (parentPath != null) {
resource.setParentPath(parentPath);
}
resource.setPath(feed.getTitle());
resource.setDescription(feed.getSubtitle());
- String state = feed.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,"state"));
+ String state = feed.getSimpleExtension(new QName(NAMESPACE, "state"));
if (state != null && "Deleted".equals(state)) {
resource.setState(DELETED_STATE);
}
@@ -189,8 +193,8 @@
resource.setContent(out.toByteArray());
return resource;
} catch (IOException e) {
- throw new
RegistryException(Messages.getMessage("unable.to.receive" ,
- link.getHref().toString()));
+ throw new
RegistryException(Messages.getMessage("unable.to.receive",
+
link.getHref().toString()));
}
}
String content1 = entry.getContent();
@@ -225,20 +229,15 @@
java.util.Properties properties = resource.getProperties();
addPropertyExtensionElement(properties, abdera, entry,
PropertyExtensionFactory.PROPERTIES,
PropertyExtensionFactory.PROPERTY);
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
- "mediaType"), resource.getMediaType());
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
- "parentPath"), resource.getParentPath());
+ entry.addSimpleExtension(new QName(NAMESPACE, "mediaType"),
resource.getMediaType());
+ entry.addSimpleExtension(new QName(NAMESPACE, "parentPath"),
resource.getParentPath());
if (resource.isContentModified()) {
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
- "contentModified"), "true");
+ entry.addSimpleExtension(new QName(NAMESPACE, "contentModified"),
"true");
}
if (resource.isDirectory()) {
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
- "directory"), "true");
+ entry.addSimpleExtension(new QName(NAMESPACE, "directory"),
"true");
} else {
- entry.addSimpleExtension(new QName(RegistryConstants.NAMESPACE ,
- "directory"), "false");
+ entry.addSimpleExtension(new QName(NAMESPACE, "directory"),
"false");
Object content = resource.getContent();
if (content != null && content instanceof byte[]) {
ByteArrayInputStream in = new
ByteArrayInputStream((byte[])content);
@@ -253,7 +252,8 @@
RequestOptions requestOptions = getAuthorization();
requestOptions.setSlug(relativePath);
- ClientResponse resp = abderaClient.post(baseURI +
encodeURL(parentPath), entry, requestOptions);
+ ClientResponse resp =
+ abderaClient.post(baseURI + encodeURL(parentPath), entry,
requestOptions);
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.add", suggestedPath));
} else {
@@ -347,8 +347,10 @@
Entry entry = abdera.getFactory().newEntry();
entry.setContent(newPath);
ClientResponse resp = abderaClient.post(baseURI +
encodeURL(currentPath +
- URL_SEPARATOR +
- PARAMETER_RENAME), entry,
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_RENAME),
+ entry,
+ getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.rename", currentPath));
} else {
@@ -362,8 +364,9 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
encodeURL(path +
- URL_SEPARATOR +
- PARAMETER_VERSION),
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_VERSION),
+ getAuthorization());
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed)introspection.getRoot();
@@ -384,8 +387,10 @@
AbderaClient abderaClient = new AbderaClient(abdera);
Entry entry = abdera.getFactory().newEntry();
ClientResponse resp = abderaClient.put(baseURI + encodeURL(versionPath
+
- URL_SEPARATOR +
- PARAMETER_RESTORE), entry,
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_RESTORE),
+ entry,
+ getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.restoreded", versionPath));
} else {
@@ -400,8 +405,10 @@
Entry entry = abdera.getFactory().newEntry();
entry.setContent(tag);
ClientResponse resp = abderaClient.put(baseURI +
encodeURL(resourcePath +
- URL_SEPARATOR +
- PARAMETER_TAGS), entry,
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_TAGS),
+ entry,
+ getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.tagged", resourcePath));
} else {
@@ -445,8 +452,8 @@
TaggedResourcePath tagpath = new TaggedResourcePath();
tagpath.setResourcePath(entry.getTitle());
tagpath.setTagCount(
- Long.parseLong(entry.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,
- "taggings"))));
+ Long.parseLong(entry.getSimpleExtension(new
QName(NAMESPACE,
+
"taggings"))));
taggedResourcePaths[i] = tagpath;
tagpath.setTagCounts(map);
}
@@ -459,8 +466,9 @@
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
encodeURL(resourcePath +
- URL_SEPARATOR +
- PARAMETER_TAGS),
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_TAGS),
+ getAuthorization());
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed)introspection.getRoot();
@@ -471,8 +479,8 @@
for (int i = 0; i < entries.size(); i++) {
Entry entry = (Entry)entries.get(i);
Tag tag = new Tag();
- tag.setTagCount(Long.parseLong(entry.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,
- "taggings"))));
+ tag.setTagCount(Long.parseLong(entry.getSimpleExtension(new
QName(NAMESPACE,
+
"taggings"))));
tag.setTagName(entry.getTitle());
tags[i] = tag;
}
@@ -486,8 +494,10 @@
Entry entry = abdera.getFactory().newEntry();
entry.setContent(tag);
ClientResponse resp = abderaClient.put(baseURI + encodeURL(path +
- URL_SEPARATOR +
- PARAMETER_TAGS_REMOVED), entry,
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_TAGS_REMOVED),
+ entry,
+ getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("tag.removed", path));
} else {
@@ -504,8 +514,10 @@
entry.addAuthor(comment.getUser());
entry.setContent(comment.getText());
ClientResponse resp = abderaClient.post(baseURI +
encodeURL(resourcePath +
- URL_SEPARATOR +
- PARAMETER_COMMENTS), entry,
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_COMMENTS),
+ entry,
+ getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.commented", resourcePath));
return resp.getLocation().toString();
@@ -522,8 +534,10 @@
Entry entry = abdera.getFactory().newEntry();
entry.setContent(text);
ClientResponse resp = abderaClient.put(baseURI + encodeURL(commentPath
+
- URL_SEPARATOR +
- PARAMETER_COMMENTS), entry,
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_COMMENTS),
+ entry,
+ getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.commented", commentPath));
} else {
@@ -536,8 +550,9 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
encodeURL(resourcePath +
- URL_SEPARATOR +
- PARAMETER_COMMENTS),
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_COMMENTS),
+ getAuthorization());
Document introspection = clientResponse.getDocument();
Element element = introspection.getRoot();
Feed feed = (Feed)element;
@@ -574,8 +589,10 @@
entry.setContent("" + rating);
entry.setSummary(PARAMETER_RATINGS);
ClientResponse resp = abderaClient.put(baseURI +
encodeURL(resourcePath +
- URL_SEPARATOR +
- PARAMETER_RATINGS), entry,
getAuthorization());
+
URL_SEPARATOR +
+
PARAMETER_RATINGS),
+ entry,
+ getAuthorization());
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.rated", resourcePath));
} else {
@@ -588,7 +605,8 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
encodeURL(resourcePath +
- URL_SEPARATOR +
PARAMETER_RATINGS),
+
URL_SEPARATOR +
+
PARAMETER_RATINGS),
getAuthorization());
Document introspection = clientResponse.getDocument();
Feed feed = (Feed)introspection.getRoot();
@@ -601,7 +619,8 @@
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse =
abderaClient.get(baseURI + encodeURL(path + URL_SEPARATOR +
- PARAMETER_RATINGS + ":" + userName),
getAuthorization());
+ PARAMETER_RATINGS + ":" +
userName),
+ getAuthorization());
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed)introspection.getRoot();
@@ -615,8 +634,9 @@
RequestOptions requestOptions = getAuthorization();
requestOptions.setHeader("parameters",
encodeParametersAsString(parameters));
ClientResponse resp = abderaClient.get(baseURI + encodeURL(path +
- URL_SEPARATOR +
- PARAMETER_QUERY),
requestOptions);
+
URL_SEPARATOR +
+
PARAMETER_QUERY),
+ requestOptions);
Document introspection =
resp.getDocument();
Feed feed = (Feed)introspection.getRoot();
@@ -674,7 +694,8 @@
requestOptions.addHeader("Action", "" + action);
requestOptions.addHeader("Author", userName);
ClientResponse resp = abderaClient.get(baseURI +
encodeURL(resourcePath +
- URL_SEPARATOR +
PARAMETER_LOGS), requestOptions);
+
URL_SEPARATOR + PARAMETER_LOGS),
+ requestOptions);
Document introspection =
resp.getDocument();
Feed feed = (Feed)introspection.getRoot();
@@ -688,10 +709,9 @@
logEntry.setDate(entry.getEdited());
logEntry.setActionData(entry.getContent());
logEntry.setUserName(entry.getAuthor().getName());
-
logEntry.setAction(Integer.parseInt(entry.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE,
- "action"))));
- logEntry.setResourcePath(entry.getSimpleExtension(new
QName(RegistryConstants.NAMESPACE ,
- "path")));
+ logEntry.setAction(Integer.parseInt(
+ entry.getSimpleExtension(new QName(NAMESPACE,
"action"))));
+ logEntry.setResourcePath(entry.getSimpleExtension(new
QName(NAMESPACE, "path")));
logs[i] = logEntry;
}
}
@@ -709,10 +729,10 @@
return requestOptions;
}
- public static String encodeURL(String path){
+ public static String encodeURL(String path) {
//I know I should use URLEncoder but when I used that it tries
// to encode "/" as well which is not need here
- return path.replaceAll(" " ,"+");
+ return path.replaceAll(" ", "+");
}
}
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/utils/AdvancedResourceQuery.java
Sun Feb 3 22:31:08 2008
@@ -57,7 +57,7 @@
// else, create new query and execute
String queryPath = computeQueryPath();
- if (!queryExist(queryPath)) {
+ if (!queryExists(queryPath)) {
defineQuery();
}
@@ -109,11 +109,10 @@
Map paramMap = new HashMap();
for (int i = 0; i < params.size(); i++) {
Object value = params.get(i);
- paramMap.put(new Integer(i + 1).toString(), value);
+ paramMap.put(Integer.toString(i + 1), value);
}
- Resource resultCollection = registry.executeQuery(queryPath, paramMap);
- return resultCollection;
+ return registry.executeQuery(queryPath, paramMap);
}
public String getResourceName() {
@@ -201,7 +200,7 @@
this.commentWords = commentWords;
}
- private boolean queryExist(String queryPath) throws RegistryException {
+ private boolean queryExists(String queryPath) throws RegistryException {
SecureRegistry systemRegistry =
(SecureRegistry)
System.getProperties().get(RegistryConstants.SYSTEM_REGISTRY);
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev