[Registry-dev] svn commit r16547 - in trunk/registry/modules:
core/src/main/java/org/wso2/registry
core/src/main/java/org/wso2/registry/app
core/src/main/java/org/wso2/registry/jdbc
core/src/main/java/org/wso2/registry/jdbc/dao
core/src/main/java/org/wso2/registry/jdbc/handlers/builtin
core/src/main/java/org/wso2/registry/jdbc/queries
core/src/main/java/org/wso2/registry/jdbc/urlhandlers
core/src/main/java/org/wso2/registry/servlet
core/src/main/java/org/wso2/registry/utils
core/src/test/java/org/wso2/registry/app webapps/conf
webapps/src/main/java/org/wso2/registry/web/actions
svn at wso2.org
svn at wso2.org
Mon May 5 21:28:10 PDT 2008
Author: glen
Date: Mon May 5 21:26:15 2008
New Revision: 16547
Log:
* Use consistent registry namespace for properties
* Use constants for URL_SEPARATOR
* Use UUID for Atom ID
* Introduce RemoteResourceImpl, which is a ResourceImpl that doesn't open a separate content connection until the content is asked for. This could later be tweaked with a config setting, but for now this makes us much more efficient when we just want metadata.
* Start prepping for non-singleton RegistryContext... still don't quite know the best way to get it from the RegistryServlet to the AbderaServlet though. Might have to go through HttpRequest attributes (bleh)....
* Little bits of code cleanup (redundant initializers, unused code, etc)
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteResourceImpl.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyExtensionFactory.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryProvider.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentCollectionURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingCollectionURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagCollectionURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java
trunk/registry/modules/webapps/conf/web.xml
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java Mon May 5 21:26:15 2008
@@ -401,7 +401,6 @@
public Object getContent() throws RegistryException {
if (content == null) {
-
contentStream = getContentStream();
if (contentStream != null) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(contentStream);
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyExtensionFactory.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyExtensionFactory.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyExtensionFactory.java Mon May 5 21:26:15 2008
@@ -19,21 +19,24 @@
package org.wso2.registry.app;
import org.apache.abdera.util.AbstractExtensionFactory;
+import org.wso2.registry.RegistryConstants;
import javax.xml.namespace.QName;
public class PropertyExtensionFactory extends AbstractExtensionFactory {
-
- public static final String NS = "tag:wso2.org,2008:foo";
- public static final QName PROPERTY_NAME = new QName(NS, "name", "ns");
- public static final QName PROPERTY_VALUE = new QName(NS, "value", "ns");
- public static final QName PROPERTIES = new QName(NS, "properties", "ns");
- public static final QName PROPERTY = new QName(NS, "property", "ns");
- public static final QName TAGS = new QName(NS, "tags", "ns");
- public static final QName TAG = new QName(NS, "tag", "ns");
+ public static final QName PROPERTY_NAME =
+ new QName(RegistryConstants.REGISTRY_NAMESPACE, "name", "ns");
+ public static final QName PROPERTY_VALUE =
+ new QName(RegistryConstants.REGISTRY_NAMESPACE, "value", "ns");
+ public static final QName PROPERTIES =
+ new QName(RegistryConstants.REGISTRY_NAMESPACE, "properties", "ns");
+ public static final QName PROPERTY =
+ new QName(RegistryConstants.REGISTRY_NAMESPACE, "property", "ns");
+ public static final QName TAGS = new QName(RegistryConstants.REGISTRY_NAMESPACE, "tags", "ns");
+ public static final QName TAG = new QName(RegistryConstants.REGISTRY_NAMESPACE, "tag", "ns");
public PropertyExtensionFactory() {
- super(NS);
+ super(RegistryConstants.REGISTRY_NAMESPACE);
addImpl(PROPERTY_NAME, PropertyName.class);
addImpl(PROPERTY_VALUE, PropertyValue.class);
addImpl(PROPERTIES, Properties.class);
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java Mon May 5 21:26:15 2008
@@ -156,7 +156,7 @@
EmptyResponseContext response = new EmptyResponseContext(200);
response.setLocation(getAtomURI(path, request));
- return response; // TODO - fix return value
+ return response;
}
String getAtomURI(String path, RequestContext context) {
@@ -476,7 +476,8 @@
try {
feed.addSimpleExtension(APPConstants.QNAME_AVGRATING,
"" + myRegistry.getAverageRating(path));
- Collection c = (Collection)myRegistry.get(path + ";ratings");
+ Collection c = (Collection)myRegistry.get(path + RegistryConstants.URL_SEPARATOR +
+ "ratings");
String [] ratings = (String[])c.getContent();
if (ratings != null && ratings.length > 0) {
for (String rating : ratings) {
@@ -1015,7 +1016,9 @@
if ("comments".equals(splitPath[1])) {
// Looking for comments, not the resource itself... so...
try {
- resource = getSecureRegistry(request).get(resource.getPath() + ";comments");
+ resource = getSecureRegistry(request).get(resource.getPath() +
+ RegistryConstants.URL_SEPARATOR +
+ "comments");
} catch (RegistryException e) {
throw new ResponseContextException(new StackTraceResponseContext(e));
}
@@ -1077,7 +1080,7 @@
}
public String getId(Resource entry) throws ResponseContextException {
- return entry.getPath(); // TODO - use Abdera Builder mechanism for URL
+ return "urn:uuid:" + entry.getId();
}
public String getName(Resource entry) throws ResponseContextException {
@@ -1181,7 +1184,7 @@
try {
String commentPath = registry.addComment(path, comment);
comment.setPath(commentPath);
- comment.setParentPath(path + ";comments");
+ comment.setParentPath(path + RegistryConstants.URL_SEPARATOR + "comments");
} catch (RegistryException e) {
throw new ResponseContextException(new StackTraceResponseContext(e));
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryProvider.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryProvider.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryProvider.java Mon May 5 21:26:15 2008
@@ -16,7 +16,6 @@
package org.wso2.registry.app;
import org.apache.abdera.protocol.server.*;
-import org.apache.abdera.protocol.server.context.RequestContextWrapper;
import org.apache.abdera.protocol.server.impl.AbstractWorkspaceProvider;
import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;
import org.apache.abdera.protocol.server.impl.TemplateTargetBuilder;
@@ -33,38 +32,12 @@
public class RegistryProvider extends AbstractWorkspaceProvider {
RegistryAdapter adapter;
- RegistryResolver resolver;
public static final String baseURI = "/wso2registry";
- public class SimpleFilter implements Filter {
- public ResponseContext filter(RequestContext request, FilterChain chain) {
- RequestContextWrapper rcw = new RequestContextWrapper(request);
- rcw.setAttribute("offset", 10);
- rcw.setAttribute("count", 10);
- return chain.next(rcw);
- }
- }
-
public CollectionAdapter getCollectionAdapter(RequestContext request) {
return adapter;
}
-// private void populate() throws RegistryException {
-// Resource r = registry.newResource();
-// r.setContent("here's some text!");
-// r.setMediaType("text/plain");
-// registry.put("/r1", r);
-//
-// Collection c = registry.newCollection();
-// registry.put("/dept", c);
-//
-// registry.put("/dept/finance", c);
-//
-// registry.put("/dept/finance/myserv", r);
-//
-// registry.applyTag("/dept/finance/myserv", "cool");
-// }
-
public RegistryProvider() throws Exception {
RegistryContext context = RegistryContext.getRegistryContext();
EmbeddedRegistry embeddedRegistry = null;
@@ -87,7 +60,7 @@
embeddedRegistry = new InMemoryEmbeddedRegistry(realm);
}
- resolver = new RegistryResolver(embeddedRegistry, baseURI);
+ RegistryResolver resolver = new RegistryResolver(embeddedRegistry, baseURI);
adapter = new RegistryAdapter(resolver, embeddedRegistry);
this.setTargetResolver(resolver);
@@ -100,6 +73,5 @@
workspace.setTitle("A Simple Workspace");
workspace.addCollection(adapter);
addWorkspace(workspace);
- addFilter(new SimpleFilter());
}
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java Mon May 5 21:26:15 2008
@@ -18,6 +18,7 @@
import org.apache.abdera.protocol.server.Target;
import org.apache.abdera.protocol.server.RequestContext;
import org.apache.abdera.protocol.server.TargetType;
+import org.apache.abdera.protocol.server.servlet.ServletRequestContext;
import org.apache.abdera.protocol.server.impl.SimpleTarget;
import org.apache.abdera.protocol.Resolver;
import org.apache.abdera.protocol.Request;
@@ -29,6 +30,7 @@
import org.wso2.registry.exceptions.ResourceNotFoundException;
import javax.activation.MimeType;
+import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.HashMap;
import java.net.URLDecoder;
@@ -82,6 +84,19 @@
public Target resolve(Request request) {
RequestContext context = (RequestContext)request;
+
+ if (embeddedRegistry == null) {
+ if (context instanceof ServletRequestContext) {
+ final ServletRequestContext requestContext = (ServletRequestContext)request;
+ embeddedRegistry = (EmbeddedRegistry)requestContext.getRequest()
+ .getAttribute(RegistryConstants.REGISTRY);
+ }
+ if (embeddedRegistry == null) {
+ // Houston, we have a problem...
+ // TODO - exception here
+ }
+ }
+
final String method = context.getMethod();
String uri = context.getUri().toString();
try {
@@ -113,7 +128,7 @@
// Make sure this is a restore...
if (parts[2].equals("restore")) {
type = RESTORE_TYPE;
- uri = parts[0] + ";" + parts[1];
+ uri = parts[0] + RegistryConstants.URL_SEPARATOR + parts[1];
} else {
// There's an extra semicolon here somewhere...
return null;
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 Mon May 5 21:26:15 2008
@@ -19,6 +19,7 @@
package org.wso2.registry.app;
import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.*;
import org.apache.abdera.protocol.Response;
@@ -39,13 +40,9 @@
import javax.xml.namespace.QName;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.MalformedURLException;
-import java.net.URLEncoder;
+import java.net.*;
import java.util.*;
public class RemoteRegistry implements Registry, APPConstants {
@@ -98,7 +95,7 @@
}
public Resource newResource() throws RegistryException {
- ResourceImpl resource = new ResourceImpl();
+ ResourceImpl resource = new RemoteResourceImpl();
resource.setAuthorUserName(username);
return resource;
}
@@ -213,10 +210,9 @@
}
private ResourceImpl createResourceFromEntry(Entry entry) throws RegistryException {
- ResourceImpl resource = new ResourceImpl();
+ RemoteResourceImpl resource = new RemoteResourceImpl();
- // TODO -
- resource.setPath(entry.getId().toString());
+ resource.setPath(entry.getTitle());
String mediaType = entry.getSimpleExtension(new QName(NAMESPACE, "mediaType"));
if (mediaType != null) {
resource.setMediaType(mediaType);
@@ -238,27 +234,27 @@
resource.setLastUpdaterUserName(lastUpdatedUser);
}
- // TODO - get content-type in an Atom-appropriate way
-// String mediaType = entry.getSimpleExtension(new QName(NAMESPACE, "mediaType"));
resource.setDescription(entry.getSummary());
- Link link = entry.getLink("edit-media");
- if (link != null) {
+ final Content content = entry.getContentElement();
+ resource.setMediaType(content.getContentType().toString());
+
+ IRI srcIri = content.getSrc();
+ if (srcIri != null) {
try {
- URL url = new URL(new URL(baseURI), link.getHref().toString());
- URLConnection uc = url.openConnection();
+ final URL url = srcIri.toURL();
+ resource.setContentURL(url);
if (authorizationString != null) {
- uc.setRequestProperty("Authorization", authorizationString);
+ resource.setAuthorizationString(authorizationString);
}
- InputStream in = url.openStream();
- resource.setContentStream(in);
return resource;
- } catch (IOException e) {
+ } catch (Exception e) {
throw new RegistryException(Messages.getMessage("unable.to.receive",
- link.getHref().toString()));
+ srcIri.toString()));
}
}
+
String content1 = entry.getContent();
resource.setContent(content1);
return resource;
@@ -794,7 +790,7 @@
if (entry.getLink("direct") != null) {
comment.setPath(entry.getLink("direct").getHref().toString());
}
- comment.setPath(entry.getId().toString());
+ comment.setPath(entry.getTitle());
comment.setText(entry.getContent());
comment.setUser(entry.getAuthor().getName());
comments[i] = comment;
Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteResourceImpl.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteResourceImpl.java Mon May 5 21:26:15 2008
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2007, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.registry.app;
+
+import org.wso2.registry.ResourceImpl;
+import org.wso2.registry.RegistryException;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class RemoteResourceImpl extends ResourceImpl {
+ URL contentURL;
+ String authorizationString;
+
+ public void setContentURL(URL contentURL) {
+ this.contentURL = contentURL;
+ }
+
+ public String getAuthorizationString() {
+ return authorizationString;
+ }
+
+ public void setAuthorizationString(String authorizationString) {
+ this.authorizationString = authorizationString;
+ }
+
+ public InputStream getContentStream() throws RegistryException {
+ InputStream is = super.getContentStream();
+ if (is != null) return is;
+
+ if (contentURL != null) {
+ try {
+ URLConnection uc = contentURL.openConnection();
+ if (authorizationString != null) {
+ uc.setRequestProperty("Authorization", authorizationString);
+ }
+ contentStream = uc.getInputStream();
+ } catch (IOException e) {
+ throw new RegistryException("Couldn't open stream to source URL " + contentURL);
+ }
+ }
+
+ return contentStream;
+ }
+}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java Mon May 5 21:26:15 2008
@@ -166,8 +166,9 @@
registerBuiltInHandlers();
- transactionalRegistry = new TransactionalJDBCRegistry(
- handlerManager, repository, versionRepository, queryProcessorManager, aspects);
+ transactionalRegistry =
+ new TransactionalJDBCRegistry(registryContext, handlerManager, repository,
+ versionRepository, queryProcessorManager, aspects);
nonTransactionalRegistry = new NonTransactionalJDBCRegistry(
transactionalRegistry, dataSource);
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/TransactionalJDBCRegistry.java Mon May 5 21:26:15 2008
@@ -16,32 +16,33 @@
package org.wso2.registry.jdbc;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.wso2.registry.*;
import org.wso2.registry.Collection;
-import org.wso2.registry.users.UserRealm;
-import org.wso2.registry.users.UserStoreException;
import org.wso2.registry.config.RegistryContext;
-import org.wso2.registry.i18n.Messages;
-import org.wso2.registry.utils.RegistryUtils;
-import org.wso2.registry.utils.VersionedPath;
-import org.wso2.registry.session.CurrentSession;
import org.wso2.registry.exceptions.ResourceNotFoundException;
+import org.wso2.registry.i18n.Messages;
+import org.wso2.registry.jdbc.dao.*;
+import org.wso2.registry.jdbc.handlers.Handler;
import org.wso2.registry.jdbc.handlers.HandlerManager;
import org.wso2.registry.jdbc.handlers.RequestContext;
-import org.wso2.registry.jdbc.handlers.Handler;
import org.wso2.registry.jdbc.handlers.filters.Filter;
import org.wso2.registry.jdbc.queries.QueryProcessorManager;
-import org.wso2.registry.jdbc.dao.*;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.wso2.registry.session.CurrentSession;
+import org.wso2.registry.users.UserRealm;
+import org.wso2.registry.users.UserStoreException;
+import org.wso2.registry.utils.RegistryUtils;
+import org.wso2.registry.utils.VersionedPath;
-import javax.sql.DataSource;
import java.util.*;
public class TransactionalJDBCRegistry implements Registry {
public static final Log log = LogFactory.getLog(TransactionalJDBCRegistry.class);
+ private RegistryContext registryContext;
+
private HandlerManager handlerManager;
private Repository repository;
private QueryProcessorManager queryProcessorManager;
@@ -55,13 +56,13 @@
private RatingsDAO ratingsDAO = new RatingsDAO();
private LogsDAO logsDAO = new LogsDAO();
- public TransactionalJDBCRegistry(
- HandlerManager handlerManager,
- Repository repository,
- VersionRepository versionRepository,
- QueryProcessorManager queryProcessorManager,
- Map<String, Aspect> aspects) {
-
+ public TransactionalJDBCRegistry(RegistryContext registryContext,
+ HandlerManager handlerManager,
+ Repository repository,
+ VersionRepository versionRepository,
+ QueryProcessorManager queryProcessorManager,
+ Map<String, Aspect> aspects) {
+ this.registryContext = registryContext;
this.handlerManager = handlerManager;
this.repository = repository;
this.versionRepository = versionRepository;
@@ -93,10 +94,11 @@
}
public RegistryContext getRegistryContext() {
- return null;
+ return registryContext;
}
public void setRegistryContext(RegistryContext registryContext) {
+ this.registryContext = registryContext;
}
public void addHandler(Filter filter, Handler handler) throws RegistryException {
@@ -161,12 +163,7 @@
VersionedPath versionedPath = RegistryUtils.getVersionedPath(path);
- if (versionedPath.getVersion() == -1) {
- return repository.resourceExists(path);
- } else {
- // todo: delegate to version repository
- return false;
- }
+ return versionedPath.getVersion() == -1 && repository.resourceExists(path);
}
/**
@@ -633,9 +630,7 @@
resourcePath = RegistryUtils.prepareGeneralPath(resourcePath);
resourcePath = getCurrentPath(resourcePath);
- Tag[] tags = tagsDAO.getTagsWithCount(resourcePath);
-
- return tags;
+ return tagsDAO.getTagsWithCount(resourcePath);
}
public void removeTag(String path, String tag) throws RegistryException {
@@ -701,7 +696,7 @@
}
String commentPath = commentsDAO.addComment(resourceID, userID, comment);
- commentPath = resourcePath + ";comments:" + commentPath;
+ commentPath = resourcePath + RegistryConstants.URL_SEPARATOR + "comments:" + commentPath;
logsDAO.addLog(
resourcePath, userID, LogEntry.COMMENT, comment.getText());
@@ -711,7 +706,7 @@
public void editComment(String commentPath, String text) throws RegistryException {
- String[] parts = commentPath.split(";");
+ String[] parts = commentPath.split(RegistryConstants.URL_SEPARATOR);
String commentPart = parts[1];
if (parts.length == 2 && commentPart.startsWith("comments:")) {
@@ -729,9 +724,8 @@
public Comment[] getComments(String resourcePath) throws RegistryException {
resourcePath = getCurrentPath(resourcePath);
- Comment[] comments = commentsDAO.getComments(resourcePath);
- return comments;
+ return commentsDAO.getComments(resourcePath);
}
////////////////////////////////////////////////////////
@@ -783,14 +777,12 @@
*/
public float getAverageRating(String resourcePath) throws RegistryException {
- float rating = ratingsDAO.getAverageRating(resourcePath);
- return rating;
+ return ratingsDAO.getAverageRating(resourcePath);
}
public int getRating(String path, String userName) throws RegistryException {
- int rating = ratingsDAO.getRating(path, userName);
- return rating;
+ return ratingsDAO.getRating(path, userName);
}
//////////////////////////////////////////////////////////////////////////////
@@ -801,9 +793,7 @@
Resource query = get(path);
- Collection resultCollection = queryProcessorManager.executeQuery(query, parameters);
-
- return resultCollection;
+ return queryProcessorManager.executeQuery(query, parameters);
}
@@ -811,7 +801,7 @@
String currentPath = resourcePath;
if (resourcePath.indexOf("?") > 0) {
currentPath = resourcePath.split("\\?")[0];
- } else if (resourcePath.indexOf(";") > 0) {
+ } else if (resourcePath.indexOf(RegistryConstants.URL_SEPARATOR) > 0) {
currentPath = resourcePath.split("\\;")[0];
}
@@ -852,9 +842,6 @@
private Aspect getAspect(String name) throws RegistryException {
Aspect aspect = aspects.get(name);
if (aspect == null) {
- RegistryContext registryContext = RegistryContext.getRegistryContext();
- //RegistryContext registryContext = (RegistryContext)System.
- // getProperties().get(RegistryConstants.REGISTRY_CONTEXT);
aspect = registryContext.getAspect(name);
}
if (aspect == null) {
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/CommentsDAO.java Mon May 5 21:26:15 2008
@@ -21,6 +21,7 @@
import org.wso2.registry.Comment;
import org.wso2.registry.RegistryException;
+import org.wso2.registry.RegistryConstants;
import org.wso2.registry.jdbc.DatabaseConstants;
import org.wso2.registry.jdbc.utils.Transaction;
import org.apache.commons.logging.Log;
@@ -151,10 +152,10 @@
comment.setUser(results.getString(DatabaseConstants.COMMENTED_USER_ID_FIELD));
comment.setTime(results.getTimestamp(DatabaseConstants.COMMENTED_TIME_FIELD));
comment.setResourcePath(path);
- String commentPath = path + ";comments:" +
+ String commentPath = path + RegistryConstants.URL_SEPARATOR + "comments:" +
results.getInt("COMMENT_ID");
comment.setPath(commentPath);
- comment.setParentPath(path + ";comments");
+ comment.setParentPath(path + RegistryConstants.URL_SEPARATOR + "comments");
commentList.add(comment);
}
s.close();
@@ -194,7 +195,7 @@
Comment comment = null;
if (result.next()) {
String resourcePath = result.getString(DatabaseConstants.PATH_FIELD);
- String commentPath = resourcePath + ";comments:" +
+ String commentPath = resourcePath + RegistryConstants.URL_SEPARATOR + "comments:" +
result.getInt("COMMENT_ID");
comment = new Comment();
@@ -203,7 +204,7 @@
comment.setTime(result.getTimestamp(DatabaseConstants.COMMENTED_TIME_FIELD));
comment.setResourcePath(resourcePath);
comment.setPath(commentPath);
- comment.setParentPath(resourcePath + ";comments");
+ comment.setParentPath(resourcePath + RegistryConstants.URL_SEPARATOR + "comments");
}
s.close();
return comment;
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/ResourceDAO.java Mon May 5 21:26:15 2008
@@ -16,18 +16,19 @@
package org.wso2.registry.jdbc.dao;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.wso2.registry.*;
import org.wso2.registry.Collection;
-import org.wso2.registry.users.accesscontrol.AccessControlConstants;
-import org.wso2.registry.utils.AuthorizationUtils;
-import org.wso2.registry.session.CurrentSession;
import org.wso2.registry.jdbc.utils.Transaction;
+import org.wso2.registry.session.CurrentSession;
+import org.wso2.registry.utils.AuthorizationUtils;
import org.wso2.registry.jdbc.dataobjects.ResourceDO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.sql.*;
import java.io.*;
+import java.sql.*;
import java.util.*;
import java.util.Date;
@@ -145,7 +146,7 @@
Connection conn = Transaction.getConnection();
- int resourceType = 0;
+ int resourceType;
try {
String sql = "SELECT COLLECTION FROM RESOURCE WHERE PATH=?";
@@ -182,7 +183,7 @@
Connection conn = Transaction.getConnection();
- boolean exists = false;
+ boolean exists;
try {
String sql = "SELECT PATH FROM RESOURCE WHERE PATH=?";
@@ -191,10 +192,7 @@
ResultSet result = ps.executeQuery();
- exists = false;
- if (result.next()) {
- exists = true;
- }
+ exists = result.next();
ps.close();
@@ -955,7 +953,6 @@
* identify that content. This content is independent and can be refered by any resource.
*
* @param resourceImpl Resource of which the content has to be written
- * @return UUID to identify the added content.
* @throws RegistryException if there is any exception while adding the content.
*/
private void addContent(ResourceImpl resourceImpl) throws RegistryException {
@@ -970,7 +967,7 @@
// we should first write the content stream to a temporary file because JDBC
// needs the length of the binary stream.
- File tempFile = null;
+ File tempFile;
try {
tempFile = File.createTempFile("reg", "tmp");
OutputStream fileStream = new BufferedOutputStream(new FileOutputStream(tempFile));
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentCollectionURLHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentCollectionURLHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentCollectionURLHandler.java Mon May 5 21:26:15 2008
@@ -18,10 +18,7 @@
import org.wso2.registry.jdbc.handlers.Handler;
import org.wso2.registry.jdbc.handlers.RequestContext;
-import org.wso2.registry.Resource;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.Comment;
-import org.wso2.registry.CollectionImpl;
+import org.wso2.registry.*;
public class CommentCollectionURLHandler extends Handler {
@@ -29,7 +26,7 @@
String url = requestContext.getResourcePath();
- String[] parts = url.split(";");
+ String[] parts = url.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return null;
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentURLHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentURLHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/CommentURLHandler.java Mon May 5 21:26:15 2008
@@ -48,7 +48,7 @@
public Resource get(RequestContext requestContext) throws RegistryException {
String url = requestContext.getResourcePath();
- String[] parts = url.split(";");
+ String[] parts = url.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return null;
@@ -103,7 +103,7 @@
requestContext.setProcessingComplete(false);
String path = requestContext.getResourcePath();
- String[] parts = path.split(";");
+ String[] parts = path.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return;
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingCollectionURLHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingCollectionURLHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingCollectionURLHandler.java Mon May 5 21:26:15 2008
@@ -22,6 +22,7 @@
import org.wso2.registry.Resource;
import org.wso2.registry.RegistryException;
import org.wso2.registry.CollectionImpl;
+import org.wso2.registry.RegistryConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -38,7 +39,7 @@
String url = requestContext.getResourcePath();
- String[] parts = url.split(";");
+ String[] parts = url.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return null;
@@ -66,7 +67,8 @@
String[] ratedUserNames = ratingsDAO.getRatedUserNames(resourcePath);
List ratingPaths = new ArrayList();
for (String ratedUserName : ratedUserNames) {
- String ratingPath = resourcePath + ";ratings:" + ratedUserName;
+ String ratingPath = resourcePath + RegistryConstants.URL_SEPARATOR + "ratings:" +
+ ratedUserName;
ratingPaths.add(ratingPath);
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingURLHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingURLHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/RatingURLHandler.java Mon May 5 21:26:15 2008
@@ -38,7 +38,7 @@
String url = requestContext.getResourcePath();
- String[] parts = url.split(";");
+ String[] parts = url.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return null;
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagCollectionURLHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagCollectionURLHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagCollectionURLHandler.java Mon May 5 21:26:15 2008
@@ -36,7 +36,7 @@
String url = requestContext.getResourcePath();
- String[] parts = url.split(";");
+ String[] parts = url.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return null;
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagURLHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagURLHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/builtin/TagURLHandler.java Mon May 5 21:26:15 2008
@@ -39,7 +39,7 @@
String url = requestContext.getResourcePath();
- String[] parts = url.split(";");
+ String[] parts = url.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return null;
@@ -64,6 +64,7 @@
ResourceImpl resource = new ResourceImpl();
resource.setMediaType(RegistryConstants.TAG_MEDIA_TYPE);
+ resource.setPath(url);
resource.setContent(taggingDO.getTagName());
resource.setAuthorUserName(taggingDO.getTaggedUserName());
final Date taggedTime = taggingDO.getTaggedTime();
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/queries/SQLQueryProcessor.java Mon May 5 21:26:15 2008
@@ -168,7 +168,7 @@
path = result.getString(DatabaseConstants.PATH_FIELD);
}
- String commentPath = path + ";comments:" + commentID;
+ String commentPath = path + RegistryConstants.URL_SEPARATOR + "comments:" + commentID;
commentPathList.add(commentPath);
}
@@ -197,7 +197,8 @@
RatingDO ratingDAO = ratingsDAO.getRating(ratingID);
String ratingPath =
- ratingDAO.getResourcePath() + ";ratings:" + ratingDAO.getRatedUserName();
+ ratingDAO.getResourcePath() + RegistryConstants.URL_SEPARATOR + "ratings:" +
+ ratingDAO.getRatedUserName();
ratingPathList.add(ratingPath);
}
@@ -244,8 +245,8 @@
// tag = result2.getString(DatabaseConstants.TAG_NAME_FIELD);
//}
- String tagPath = taggingDO.getResourcePath() + ";tags:" + taggingDO.getTagName() + ":" +
- taggingDO.getTaggedUserName();
+ String tagPath = taggingDO.getResourcePath() + RegistryConstants.URL_SEPARATOR +
+ "tags:" + taggingDO.getTagName() + ":" + taggingDO.getTaggedUserName();
tagPathList.add(tagPath);
}
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java Mon May 5 21:26:15 2008
@@ -28,7 +28,7 @@
public ResourceImpl get(String url) throws RegistryException {
- String[] parts = url.split(";");
+ String[] parts = url.split(RegistryConstants.URL_SEPARATOR);
if (parts.length != 2) {
return null;
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java Mon May 5 21:26:15 2008
@@ -30,7 +30,6 @@
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.jdbc.EmbeddedRegistry;
import org.wso2.registry.jdbc.InMemoryEmbeddedRegistry;
-import org.wso2.registry.jdbc.realm.RegistryRealm;
import org.wso2.registry.jdbc.utils.RegistryDataSource;
import org.wso2.registry.servlet.utils.Utils;
import org.wso2.registry.users.AccessControlAdmin;
@@ -62,7 +61,6 @@
public void init(final ServletConfig config) throws ServletException {
super.init(config);
- RegistryRealm registryRealm;
EmbeddedRegistry embeddedRegistry;
try {
Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java (original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java Mon May 5 21:26:15 2008
@@ -307,7 +307,7 @@
String preparedPath = resourcePath;
if (resourcePath.indexOf("?") > 0) {
preparedPath = resourcePath.split("\\?")[0];
- } else if (resourcePath.indexOf(";") > 0) {
+ } else if (resourcePath.indexOf(RegistryConstants.URL_SEPARATOR) > 0) {
preparedPath = resourcePath.split("\\;")[0];
}
Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java (original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/app/AbstractAPPTest.java Mon May 5 21:26:15 2008
@@ -26,9 +26,24 @@
RegistryServer server;
Registry registry;
- int clientPort = 8081; // Default client port. Change prior to setUp() to debug with tcpmon.
+ int clientPort = 8081;
String baseURL;
+ public AbstractAPPTest() {
+ String portProp = System.getProperty("clientPort");
+ if (portProp != null) {
+ clientPort = Integer.parseInt(portProp);
+ }
+ }
+
+ public AbstractAPPTest(String name) {
+ super(name);
+ String portProp = System.getProperty("clientPort");
+ if (portProp != null) {
+ clientPort = Integer.parseInt(portProp);
+ }
+ }
+
protected void setUp() throws Exception {
baseURL = "http://localhost:" + clientPort + "/wso2registry/";
if (server == null) {
Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java (original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java Mon May 5 21:26:15 2008
@@ -29,12 +29,19 @@
public class JettyBasedServerTest extends JDBCRegistryTest {
RegistryServer server = new RegistryServer();
+ String clientPort = "8081";
public void setUp() {
try {
+ String portProp = System.getProperty("clientPort");
+ if (portProp != null) {
+ clientPort = portProp;
+ }
+
if (registry == null) {
server.start();
- registry = new RemoteRegistry(new URL("http://localhost:8081/wso2registry"),
+ registry = new RemoteRegistry(new URL("http://localhost:" + clientPort +
+ "/wso2registry"),
"admin", "admin");
}
} catch (Exception e) {
Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java (original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java Mon May 5 21:26:15 2008
@@ -31,9 +31,9 @@
try {
String path="/f95/f2/r1";
- String commentPath = path + ";comments";
+ String commentPath = path + RegistryConstants.URL_SEPARATOR + "comments";
String new_path="/f96/f2/r1";
- String commentPathNew = new_path + ";comments";
+ String commentPathNew = new_path + RegistryConstants.URL_SEPARATOR + "comments";
Resource r1 = registry.newResource();
r1.setDescription("This is a file to be renamed");
byte[] r1content = "R2 content".getBytes();
@@ -119,9 +119,9 @@
try {
String path="/c9011/c1/c2";
- String commentPath = path + ";comments";
+ String commentPath = path + RegistryConstants.URL_SEPARATOR + "comments";
String new_path="/c9111/c1/c3";
- String commentPathNew = new_path + ";comments";
+ String commentPathNew = new_path + RegistryConstants.URL_SEPARATOR + "comments";
Resource r1 = registry.newCollection();
r1.setDescription("This is a file to be renamed");
Modified: trunk/registry/modules/webapps/conf/web.xml
==============================================================================
--- trunk/registry/modules/webapps/conf/web.xml (original)
+++ trunk/registry/modules/webapps/conf/web.xml Mon May 5 21:26:15 2008
@@ -76,4 +76,8 @@
<servlet-name>Abdera</servlet-name>
<url-pattern>/feed/*</url-pattern>
</servlet-mapping>
+ <servlet-mapping id="abdera-resource-mapping">
+ <servlet-name>Abdera</servlet-name>
+ <url-pattern>/resource/*</url-pattern>
+ </servlet-mapping>
</web-app>
Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java (original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceDetailsAction.java Mon May 5 21:26:15 2008
@@ -280,7 +280,7 @@
String authorizationPath = path;
if (path.indexOf("?") > 0) {
authorizationPath = path.split("\\?")[0];
- } else if (path.indexOf(";") > 0) {
+ } else if (path.indexOf(RegistryConstants.URL_SEPARATOR) > 0) {
authorizationPath = path.split("\\;")[0];
}
More information about the Registry-dev
mailing list