Author: deepal
Date: Mon Dec 17 04:28:12 2007
New Revision: 11240
Log:
adding configuration file called "registry.xml"
- provide a way to configure data sources in registry.xml
-Removed unwanted classes
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/DataBaseConfiguration.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfiguration.java
trunk/registry/modules/core/src/main/resources/registry.xml
Removed:
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/EditProcessor.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ResourceMap.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ratings/RatingsManager.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/tags/TagManager.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/ConsoleURLMapper.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/FileUploadUtil.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryRealmFactory.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
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
Mon Dec 17 04:28:12 2007
@@ -29,6 +29,7 @@
public static final String JDBC_REGISTRY_TYPE = "JDBCRegistry";
public static final String REMOTE_REGISTRY_TYPE = "RemoteRegistry";
public static final String INMEM_REGISTRY_TYPE = "InMemoryRegistry";
+ public static final String STATUS_MESSAGE_NAME = "edit_status";
/**
* Built in user names
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/DataBaseConfiguration.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/DataBaseConfiguration.java
Mon Dec 17 04:28:12 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.wso2.registry.config;
+
+/**
+ * This class is to hold , database configurations such as URL , userName ,
password and ect
+ * User can define them in resgirty.xml or at the runtime he can add DB
configuration
+ */
+public class DataBaseConfiguration {
+
+ private String dbUrl;
+ private String userName;
+ private String passWord;
+ private String driverName;
+ private String configName;
+
+
+ public String getDbUrl() {
+ return dbUrl;
+ }
+
+ public void setDbUrl(String dbUrl) {
+ this.dbUrl = dbUrl;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassWord() {
+ return passWord;
+ }
+
+ public void setPassWord(String passWord) {
+ this.passWord = passWord;
+ }
+
+ public String getDriverName() {
+ return driverName;
+ }
+
+ public void setDriverName(String driverName) {
+ this.driverName = driverName;
+ }
+
+
+ public String getConfigName() {
+ return configName;
+ }
+
+ public void setConfigName(String configName) {
+ this.configName = configName;
+ }
+}
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfiguration.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfiguration.java
Mon Dec 17 04:28:12 2007
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.wso2.registry.config;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.i18n.Messages;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
+
+public class RegistryConfiguration {
+
+ private Map dbconfgigMap = new HashMap();
+
+ /**
+ * This method will read the regisrty.xml and using the data given in the
file
+ * resgistry configuratoon will be populated. And if the xmlLocation is
null then it
+ * will use the one in the class path.
+ *
+ * @param xmlLocation : Location of the
+ * @throws org.wso2.registry.RegistryException : if something went wrong
+ */
+ public void populateRegistryConfig(String xmlLocation) throws
RegistryException {
+ InputStream in;
+ if (xmlLocation != null) {
+ try {
+ in = new FileInputStream(xmlLocation);
+ } catch (FileNotFoundException e) {
+ throw new RegistryException(e.getMessage());
+ }
+ } else {
+ in =
Thread.currentThread().getContextClassLoader().getResourceAsStream("registry.xml");
+ if (in == null) {
+ throw new
RegistryException(Messages.getMessage("inputstream.null", "registry.xml"));
+ }
+ }
+ try {
+ StAXOMBuilder buillder = new StAXOMBuilder(in);
+ OMElement configElement = buillder.getDocumentElement();
+ if (configElement != null) {
+ Iterator dbconfgs = configElement.getChildrenWithName(new
QName("dbconfig"));
+ while (dbconfgs.hasNext()) {
+ OMElement dbconfig = (OMElement) dbconfgs.next();
+ DataBaseConfiguration dataBaseConfiguration = new
DataBaseConfiguration();
+ String dbName = dbconfig.getAttributeValue(new
QName("name"));
+ if(dbName == null){
+ throw new
RegistryException(Messages.getMessage("dbname.null"));
+ }
+ dataBaseConfiguration.setConfigName(dbName);
+ OMElement userName = dbconfig.getFirstChildWithName(new
QName("userName"));
+ if (userName != null) {
+ dataBaseConfiguration.setUserName(userName.getText());
+ }
+ OMElement password = dbconfig.getFirstChildWithName(new
QName("password"));
+ if (password != null) {
+ dataBaseConfiguration.setPassWord(password.getText());
+ }
+ OMElement url = dbconfig.getFirstChildWithName(new
QName("url"));
+ if (url != null) {
+ dataBaseConfiguration.setDbUrl(url.getText());
+ }
+ OMElement driverName = dbconfig.getFirstChildWithName(new
QName("driverName"));
+ if (driverName != null) {
+
dataBaseConfiguration.setDriverName(driverName.getText());
+ }
+ dbconfgigMap.put(dbName,dataBaseConfiguration);
+ }
+ }
+
+ } catch (XMLStreamException e) {
+ throw new RegistryException(e.getMessage());
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ RegistryConfiguration configuration = new RegistryConfiguration();
+ configuration.populateRegistryConfig(null);
+ }
+ public DataBaseConfiguration getDataBaseConfiguration(String configName){
+ return (DataBaseConfiguration) dbconfgigMap.get(configName);
+ }
+}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
Mon Dec 17 04:28:12 2007
@@ -56,12 +56,10 @@
}
public Resource get(String path) throws RegistryException {
-
Resource resource = (Resource) resourceMap.get(path);
if (resource == null) {
- throw new RegistryException("Requested resource " + path + " does
not exist");
+ throw new
RegistryException(Messages.getMessage("resource.get.error", path));
}
-
return resource;
}
@@ -93,13 +91,13 @@
// exists create directories for them. If there is a non-directory
resource
// corresponding to any of those parts, we can't add the resource.
String currentPath = RegistryConstants.ROOT_PATH;
- Resource currentDirectory =(Resource)
resourceMap.get(RegistryConstants.ROOT_PATH);
+ Resource currentDirectory = (Resource)
resourceMap.get(RegistryConstants.ROOT_PATH);
for (int i = 1; i < parts.length - 1; i++) {
// check if a Directory with current Path is already in the
resourceMap
currentPath =
(currentPath.equals(RegistryConstants.ROOT_PATH)) ?
RegistryConstants.ROOT_PATH +
- parts[i] : currentPath +
RegistryConstants.PATH_SEPARATOR + parts[i];
+ parts[i] : currentPath +
RegistryConstants.PATH_SEPARATOR + parts[i];
Resource r = (Resource) resourceMap.get(currentPath);
if (r == null) {
@@ -122,7 +120,7 @@
Messages.getMessage("resource.delete.error",
currentPath, path);
log.error(message);
throw new RegistryException(message);
- }
+ }
}
}
updateArtifact(currentDirectory, resource.getPath());
@@ -131,7 +129,7 @@
resourceMap.put(path, resource);
} else {
- Resource root =(Resource)
resourceMap.get(RegistryConstants.ROOT_PATH);
+ Resource root = (Resource)
resourceMap.get(RegistryConstants.ROOT_PATH);
updateArtifact(root, path);
// new resource is a top level resource. just add it to the
resourceMap
resourceMap.put(path, resource);
@@ -175,33 +173,28 @@
log.error(message);
throw new RegistryException(message);
}
-
// Object o = resource.getContent();
if (resource.isDirectory()) {
-
// remove all descendent resources
removeDescendents(resource);
-
// remove the directory
removeResource(resource.getPath());
-
} else {
removeResource(resource.getPath());
}
-
// remove all comments of the deleted resource
commentManager.removeComments(path);
}
public String[] getVersions(String path) throws RegistryException {
- throw new UnsupportedOperationException(
- "Versioning support is not implemented in the in memory
registry.");
+ throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
+ "Versioning"));
}
public void restoreVersion(String versionPath) throws RegistryException {
- throw new UnsupportedOperationException(
- "Versioning support is not implemented in the in memory
registry.");
+ throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
+ "Versioning"));
}
public synchronized void applyTag(String resourcePath, String tag) throws
RegistryException {
@@ -217,8 +210,8 @@
}
public void removeTag(String path, String tag) throws RegistryException {
- throw new UnsupportedOperationException(
- "Removing tags is not supported in the hashmap based
registry.");
+ throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
+ "Removing tags"));
}
public synchronized void addComment(String resourcePath, Comment comment)
@@ -240,13 +233,13 @@
}
public int getRating(String path, String userName) throws
RegistryException {
- throw new UnsupportedOperationException(
- "User level rating are not supported in HashMap based
in-memory registry.");
+ throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
+ "User level rating"));
}
public Resource executeQuery(String path, Object[] parameters) throws
RegistryException {
- throw new UnsupportedOperationException(
- "Custom queries are not supported in HashMap based in-memory
registry.");
+ throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
+ "Custom queries"));
}
public synchronized boolean isResourceAvailable(String path) {
@@ -269,7 +262,7 @@
String childPath = childPaths[i];
Resource childResource = (Resource) resourceMap.get(childPath);
-
+
if (childResource.isDirectory()) {
removeDescendents(childResource);
@@ -299,7 +292,7 @@
public LogEntry[] getLogs(String resourcePath, int action, String
userName, Date from, Date to, boolean recentFirst)
throws RegistryException {
- throw new UnsupportedOperationException(
- "Logs are not supported in HashMap based in-memory registry.");
+ throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
+ "Logs"));
}
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ResourceMap.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ResourceMap.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ResourceMap.java
Mon Dec 17 04:28:12 2007
@@ -47,15 +47,12 @@
}
private String preparePath(String path) {
-
String preparedPath = path;
-
// make sure that the path does not end with a "/"
if (!path.equals(RegistryConstants.ROOT_PATH) &&
path.endsWith(RegistryConstants.PATH_SEPARATOR)) {
preparedPath = path.substring(0, path.length() -
RegistryConstants.PATH_SEPARATOR.length());
}
-
return preparedPath;
}
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/comments/CommentManager.java
Mon Dec 17 04:28:12 2007
@@ -21,6 +21,7 @@
import org.wso2.registry.Comment;
import org.wso2.registry.RegistryException;
+import org.wso2.registry.i18n.Messages;
import org.wso2.registry.inmemory.InMemoryRegistry;
import java.util.*;
@@ -38,8 +39,7 @@
public void addComment(String resourcePath, Comment comment) throws
RegistryException {
if (!inMemoryRegistryProvider.isResourceAvailable(resourcePath)) {
- throw new RegistryException(
- "Cannot add a comment to a non-existing resource " +
resourcePath);
+ throw new
RegistryException(Messages.getMessage("cannotadd.comment",resourcePath));
}
comment.setCommentedTime(new Date());
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ratings/RatingsManager.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ratings/RatingsManager.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/ratings/RatingsManager.java
Mon Dec 17 04:28:12 2007
@@ -20,6 +20,7 @@
package org.wso2.registry.inmemory.ratings;
import org.wso2.registry.RegistryException;
+import org.wso2.registry.i18n.Messages;
import org.wso2.registry.inmemory.InMemoryRegistry;
import java.util.HashMap;
@@ -41,8 +42,7 @@
public void rateResource(String resourcePath, int rating) throws
RegistryException {
if (!inMemoryRegistryProvider.isResourceAvailable(resourcePath)) {
- throw new RegistryException(
- "Cannot rate on the non-existing resource " +
resourcePath);
+ throw new
RegistryException(Messages.getMessage("cannot.rate",resourcePath));
}
ResourceRating resourceRating = (ResourceRating)
ratings.get(resourcePath);
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/tags/TagManager.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/tags/TagManager.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/tags/TagManager.java
Mon Dec 17 04:28:12 2007
@@ -22,6 +22,7 @@
import org.wso2.registry.RegistryException;
import org.wso2.registry.Tag;
import org.wso2.registry.TaggedResourcePath;
+import org.wso2.registry.i18n.Messages;
import org.wso2.registry.inmemory.InMemoryRegistry;
import java.util.*;
@@ -51,8 +52,7 @@
public void applyTag(String resourcePath, String tag) throws
RegistryException {
if (!inMemoryRegistryProvider.isResourceAvailable(resourcePath)) {
- throw new RegistryException(
- "Cannot apply tag for a non-existing resource " +
resourcePath);
+ throw new
RegistryException(Messages.getMessage("cannot.add.tag",resourcePath));
}
// add tagging to the tags map
@@ -101,7 +101,7 @@
// "is not supported in the HashMap based in-memory registry.");
if (!inMemoryRegistryProvider.isResourceAvailable(resourcePath)) {
- throw new RegistryException("Resource " + resourcePath + " does
not exist.");
+ throw new
RegistryException(Messages.getMessage("resource.get.error",resourcePath));
}
List tagList = (List) resources.get(resourcePath);
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/ConsoleURLMapper.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/ConsoleURLMapper.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/ConsoleURLMapper.java
Mon Dec 17 04:28:12 2007
@@ -59,19 +59,6 @@
request.getSession().setAttribute(PATH_ATTR, path);
request.getRequestDispatcher(RESOURCES_JSP).forward(request, response);
-
- //if (query == null || query.length() == 0) {
- //
- // request.getSession().setAttribute(PATH_ATTR, path);
- // request.getRequestDispatcher(RESOURCES_JSP).forward(request,
response);
- //
- //} else if (query.equals("addCollection")) {
- //
- // request.getSession().setAttribute(PATH_ATTR, path);
- //
request.getRequestDispatcher(RESOURCE_DETAILS_JSP).forward(request, response);
- //
- //}
-
return true;
}
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/FileUploadUtil.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/FileUploadUtil.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/FileUploadUtil.java
Mon Dec 17 04:28:12 2007
@@ -34,15 +34,12 @@
import java.util.List;
public class FileUploadUtil {
- //TODO , we need to change the method signature
public static Resource processUpload(HttpServletRequest req)
throws IOException, ServletException {
RequestContext reqContext = new ServletRequestContext(req);
boolean isMultipart = ServletFileUpload.isMultipartContent(reqContext);
if (isMultipart) {
-
Resource resource = new Resource();
-
try {
//Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
@@ -60,16 +57,12 @@
if (item.isFormField()) {
if (item.getFieldName().equalsIgnoreCase("path")) {
- String currentPath =
(String)req.getSession().getAttribute("path");
parentPath = item.getString();
-
} else if
(item.getFieldName().equalsIgnoreCase("filename")) {
resourceName = item.getString();
-
}else if
(item.getFieldName().equalsIgnoreCase("description")) {
resource.setDescription(item.getString());
}
-
} else {
String fileName = item.getName();
String fileNameOnly;
@@ -108,44 +101,22 @@
} catch (Exception e) {
req.setAttribute("status", "failure");
req.setAttribute("cause", e.getMessage());
-
}
-
return resource;
}
return null;
}
private static String calcualtePath(String parentPath, String
resourceName) {
-
- String resourcePath = null;
-
+ String resourcePath ;
if (!parentPath.startsWith(RegistryConstants.PATH_SEPARATOR)) {
parentPath = RegistryConstants.PATH_SEPARATOR + parentPath;
}
-
if (parentPath.endsWith(RegistryConstants.PATH_SEPARATOR)) {
resourcePath = parentPath + resourceName;
} else {
resourcePath = parentPath + RegistryConstants.PATH_SEPARATOR +
resourceName;
}
-
return resourcePath;
}
-
- /**
- * Get an absolute path from a current path and a target path. If
- * the target path begins with a "/" it's absolute, so just use it.
- * Otherwise it's a relative path from currentPath.
- *
- * @param currentPath our current registry path
- * @param path the target path (may be relative or absolute)
- * @return an absolute path
- */
- private static String getAbsolutePath(String currentPath, String path) {
- if (path == null || path.length() == 0) return null;
- if (path.charAt(0) == '/') return path;
- if (currentPath == null || "/".equals(currentPath)) return "/" + path;
- return currentPath + "/" + path;
- }
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryRealmFactory.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryRealmFactory.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryRealmFactory.java
Mon Dec 17 04:28:12 2007
@@ -103,27 +103,21 @@
public static Realm createDataSourceAwareRegistryRealm(String
dataSourceName)
throws RegistryException {
-
DataSource dataSource = null;
try {
log.info("Trying to find the user manager data source " +
dataSourceName + "...");
-
Context context = new InitialContext();
dataSource = (DataSource) context.lookup(dataSourceName);
-
log.info("Found the user manager data source " + dataSourceName +
".");
-
} catch (NamingException e) {
log.info(Messages.
getMessage("datasource.not.found", dataSourceName));
}
-
try {
DefaultRealm realm = new DefaultRealm();
DefaultRealmConfig config =
(DefaultRealmConfig)realm.getRealmConfiguration();
config.setDataSource(dataSource);
realm.init(config);
-
// define built in roles
AuthorizationUtil.populateUserStore(realm);
return realm;
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 Dec 17 04:28:12 2007
@@ -45,56 +45,40 @@
private static final Log log = LogFactory.getLog(RegistryServlet.class);
protected transient ServletConfig servletConfig;
-
/**
* Core registry used in the back-end. Usually this is a JDBCRegistry and
there is only one
* instance of this registry for the whole application. This should be
initialized in this
* servlet and put in to the servlet context so that it can be accessed
from any where.
*/
-
- private EditProcessor editProcessor;
-
private ConsoleURLMapper consoleURLMapper;
//To store the conetxt path
private String contextRoot = null;
public void init(ServletConfig config) throws ServletException {
-
super.init(config);
RegistryRealm registryRealm;
Registry coreRegistry = null;
-
try {
-
registryRealm = new InMemoryRegistryRealm();
-
String coreRegistryTypeParam =
config.getInitParameter(RegistryConstants.REGISTRY_TYPE_PARAMTER);
-
if (coreRegistryTypeParam == null ||
coreRegistryTypeParam.equals(RegistryConstants.JDBC_REGISTRY_TYPE)) {
-
coreRegistry = new InMemoryJDBCRegistry(registryRealm);
-
} else if
(coreRegistryTypeParam.equals(RegistryConstants.REMOTE_REGISTRY_TYPE)) {
-
// todo: initialize core registry with a remote registry
instance.
}
-
// create a system registry and put it in the context
SecureRegistry systemRegistry =
new SecureRegistry(RegistryConstants.SYSTEM_USER,
RegistryConstants.SYSTEM_PASSWORD,
coreRegistry,
registryRealm);
-
config.getServletContext().setAttribute(RegistryConstants.REGISTRY,
coreRegistry);
config.getServletContext().setAttribute(RegistryConstants.REGISTRY_REALM,
registryRealm);
System.getProperties().put(RegistryConstants.REGISTRY,coreRegistry);
System.getProperties().put(RegistryConstants.SYSTEM_REGISTRY,
systemRegistry);
- this.editProcessor = new EditProcessor();
-
} catch (RegistryException e) {
e.printStackTrace();
throw new ServletException(e.getMessage());
@@ -113,16 +97,11 @@
HttpServletResponse httpServletResponse)
throws ServletException, IOException {
initContextRoot(httpServletRequest);
-
String uri = httpServletRequest.getRequestURI();
String p1 = uri.substring(contextRoot.length(), uri.length());
-
if (p1.equals("/web/addResource")) {
handleFileUpload(httpServletRequest, httpServletResponse);
- } else if (p1.startsWith("/edit")) {
- editProcessor.processEdit(httpServletRequest, httpServletResponse);
}
-
// throw error!
}
@@ -130,13 +109,11 @@
throws IOException, ServletException {
try {
Registry registry = Utils.getSecureRegistry(request);
-
Resource fileElement =
FileUploadUtil.processUpload(request);
String path = fileElement.getPath();
-
registry.put(path, fileElement);
-
request.getSession().setAttribute(EditProcessor.STATUS_MESSAGE_NAME,
+
request.getSession().setAttribute(RegistryConstants.STATUS_MESSAGE_NAME,
"Resource " + path + " is sucessfully added to the
registry.");
response.setContentType("text/html");
request.getRequestDispatcher(ConsoleURLMapper.RESOURCES_JSP)
@@ -145,7 +122,7 @@
} catch (RegistryException e) {
e.printStackTrace();
-
request.getSession().setAttribute(EditProcessor.STATUS_MESSAGE_NAME,
+
request.getSession().setAttribute(RegistryConstants.STATUS_MESSAGE_NAME,
e.getMessage());
response.setContentType("text/html");
request.getRequestDispatcher(ConsoleURLMapper.RESOURCES_JSP)
@@ -158,21 +135,14 @@
throws ServletException, IOException {
initContextRoot(request);
-
if (consoleURLMapper.mapAndForward(request, response)) {
return;
}
-
if (processMetadataView(request, response)) {
return;
}
-
if (processResourceView(request, response)) {
- return;
}
-
- // todo: editing UI is not a part of final registry UI. so remove this
before the final release.
- editProcessor.processEdit(request, response);
}
/**
@@ -216,7 +186,6 @@
} else {
query = "?" + query;
}
-
// we process only the URL in the form /wso2registry/view/...
String viewPart = uri.substring(contextRoot.length());
if (!viewPart.startsWith("/view")) {
@@ -263,13 +232,11 @@
request.getRequestDispatcher("/admin/error.jsp")
.forward(request, response);
}
-
return true;
}
private boolean processMetadataView(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
-
String query = request.getQueryString();
if (query != null) {
if (query.equalsIgnoreCase("tags")) {
@@ -294,7 +261,6 @@
return true;
}
}
-
return false;
}
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/Utils.java
Mon Dec 17 04:28:12 2007
@@ -44,16 +44,12 @@
* @return Map containg paramter name --> paramter value pairs
*/
public static Map getParameters(String queryString) {
-
Map paramMap = new HashMap();
-
String[] params = queryString.split(",");
-
for (int i = 0; i < params.length; i++) {
String[] param = params[i].split("=");
paramMap.put(param[0].trim(), param[1].trim());
}
-
return paramMap;
}
@@ -68,7 +64,6 @@
*/
public static synchronized SecureRegistry
getSecureRegistry(HttpServletRequest request)
throws RegistryException {
-
SecureRegistry registry;
Object o =
request.getSession().getAttribute(RegistryConstants.USER_REGISTRY);
if (o != null) {
@@ -76,22 +71,18 @@
} else {
Registry coreRegistry = (Registry) request.
getSession().getServletContext().getAttribute(RegistryConstants.REGISTRY);
-
RegistryRealm realm = (RegistryRealm)
request.getSession().getServletContext().
getAttribute(RegistryConstants.REGISTRY_REALM);
-
registry = new SecureRegistry(
RegistryConstants.ANONYMOUS_USER, "guest", coreRegistry,
realm);
request.getSession().setAttribute(RegistryConstants.USER_REGISTRY,
registry);
}
-
return registry;
}
public static synchronized void setSecureRegistry(
HttpServletRequest request, SecureRegistry secureRegistry) {
-
request.getSession().setAttribute(RegistryConstants.USER_REGISTRY,
secureRegistry);
}
}
Modified:
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
==============================================================================
---
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
(original)
+++
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
Mon Dec 17 04:28:12 2007
@@ -66,6 +66,12 @@
define.query.fail=Could not define the query {0} with SQL: {1}.
execute.query.fail=Failed to execute the predefined query {0}.
resource.already.tagged=Resource {0} is already tagged with tag {1} by the
user {2}.
+cannotadd.comment=Cannot add a comment to a non-existing resource {0}
+cannot.rate=Cannot rate on the non-existing resource {0}
+cannot.add.tag=Cannot apply tag for a non-existing resource {0}
+unsupported.exception={0} support is not implemented in the in memory registry.
+inputstream.null=could not create an inputstream for the file {0}
+dbname.null=dbconfig configuration in registry.xml must have the name attribute
################################ APP Messages
###########################################
resource.version=Resource Version for the resource {0}
resource.not.found=Resource Not found.
Added: trunk/registry/modules/core/src/main/resources/registry.xml
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/resources/registry.xml Mon Dec 17
04:28:12 2007
@@ -0,0 +1,8 @@
+<wso2regsitry>
+ <dbconfig name="DB1">
+ <url></url>
+ <userName></userName>
+ <password></password>
+ <driverName></driverName>
+ </dbconfig>
+</wso2regsitry>
\ No newline at end of file
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Mon Dec 17 04:28:12 2007
@@ -82,12 +82,9 @@
fail("Couldn't delete content resource /r1");
}
-
- Resource newR1 = null;
-
boolean failed = false;
try {
- newR1 = registry.get("/r1");
+ registry.get("/r1");
} catch (RegistryException e) {
failed = true;
}
@@ -155,10 +152,9 @@
}
assertTrue("Deleted collection /d1 is not marked as deleted.", f1);
- Resource newD1R1 = null;
boolean f2 = false;
try {
- newD1R1 = registry.get("/d1/r1");
+ registry.get("/d1/r1");
} catch (RegistryException e) {
f2 = true;
}
@@ -269,9 +265,7 @@
registry.put("/foo/bar", userProfile2);
Resource myUserProfile = registry.get("/foo/bar");
- Object userData = myUserProfile.getContent();
-
- int a = 1;
+ myUserProfile.getContent();
} catch (RegistryException e) {
e.printStackTrace();
}
@@ -884,13 +878,10 @@
registry.rateResource("/r200", 5);
- LogEntry[] logs = registry.getLogs("/r200", -1, null, null, null,
true);
- LogEntry l1 = logs[1];
// assertEquals("Log for adding /r200 is not added properly.",
LogEntry.UPDATE, l1.getAction());
// assertEquals("Log for adding /r200 is not added properly.", "/r200",
l1.getResourcePath());
- LogEntry l2 = logs[0];
// assertEquals("Log for rating /r200 is not added properly.",
LogEntry.RATING, l2.getAction());
// assertEquals("Log for rating /r200 is not added properly.", "5",
l2.getActionData());
}
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev