Author: deepal
Date: Mon Dec 17 20:47:55 2007
New Revision: 11305
Log:
Now we can import file system to registry and export registry into a file
system
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfiguration.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/ConsoleURLMapper.java
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
trunk/registry/modules/core/src/main/resources/registry.xml
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 Dec 17 20:47:55 2007
@@ -31,7 +31,7 @@
import org.wso2.registry.i18n.Messages;
import javax.xml.namespace.QName;
-import java.io.ByteArrayInputStream;
+import java.io.*;
import java.net.URL;
import java.util.Date;
import java.util.Iterator;
@@ -49,6 +49,7 @@
* should be something like
* http://localhost:8080/wso2registry
* NOTE : Should not have "/" after the wso2registry part
+ *
* @param registryURL : URL to the registry
* @throws RegistryException
*/
@@ -63,7 +64,7 @@
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(collectionRoot +
path);
if (clientResponse.getType() == Response.ResponseType.SERVER_ERROR) {
- throw new
RegistryException(Messages.getMessage("resource.not.found.warn",path));
+ throw new
RegistryException(Messages.getMessage("resource.not.found.warn", path));
}
Document introspection =
clientResponse.getDocument();
@@ -158,16 +159,18 @@
if (content != null && content instanceof byte[]) {
ByteArrayInputStream in = new ByteArrayInputStream((byte[])
content);
entry.setContent(in);
+ } else if (content instanceof InputStream) {
+ entry.setContent((InputStream) content);
} else {
entry.setContent((String) content);
}
}
ClientResponse resp = abderaClient.post(collectionRoot + path, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("resource.add",path));
+ log.info(Messages.getMessage("resource.add", path));
} else {
- log.error(Messages.getMessage("add.resource.fail",path));
- throw new
RegistryException(Messages.getMessage("add.resource.fail",path));
+ log.error(Messages.getMessage("add.resource.fail", path));
+ throw new
RegistryException(Messages.getMessage("add.resource.fail", path));
}
}
@@ -176,10 +179,10 @@
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse resp = abderaClient.delete(entryRoot + path);
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("resource.deleted",path));
+ log.info(Messages.getMessage("resource.deleted", path));
} else {
- log.error(Messages.getMessage("resource.delete.fail",path));
- throw new
RegistryException(Messages.getMessage("resource.delete.fail",path));
+ log.error(Messages.getMessage("resource.delete.fail", path));
+ throw new
RegistryException(Messages.getMessage("resource.delete.fail", path));
}
}
@@ -208,10 +211,10 @@
entry.setAttributeValue("directory", "false");
ClientResponse resp = abderaClient.put(entryRoot, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("resource.restoreded",versionPath));
+ log.info(Messages.getMessage("resource.restoreded", versionPath));
} else {
-
log.error(Messages.getMessage("resource.restore.fail",versionPath));
- throw new
RegistryException(Messages.getMessage("resource.restore.fail",versionPath));
+ log.error(Messages.getMessage("resource.restore.fail",
versionPath));
+ throw new
RegistryException(Messages.getMessage("resource.restore.fail", versionPath));
}
}
@@ -225,10 +228,10 @@
entry.setAttributeValue("directory", "false");
ClientResponse resp = abderaClient.put(entryRoot, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("resource.tagged",resourcePath));
+ log.info(Messages.getMessage("resource.tagged", resourcePath));
} else {
- log.error(Messages.getMessage("resource.tag.fails",resourcePath));
- throw new
RegistryException(Messages.getMessage("resource.tag.fails",resourcePath));
+ log.error(Messages.getMessage("resource.tag.fails", resourcePath));
+ throw new
RegistryException(Messages.getMessage("resource.tag.fails", resourcePath));
}
}
@@ -287,10 +290,10 @@
entry.setSummary(RegistryConstants.PARAMETER_TAGS_REMOVED);
ClientResponse resp = abderaClient.put(entryRoot, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("tag.removed",path));
+ log.info(Messages.getMessage("tag.removed", path));
} else {
- log.error(Messages.getMessage("tag.removed.fails",path));
- throw new
RegistryException(Messages.getMessage("tag.removed.fails",path));
+ log.error(Messages.getMessage("tag.removed.fails", path));
+ throw new
RegistryException(Messages.getMessage("tag.removed.fails", path));
}
}
@@ -305,10 +308,10 @@
entry.setContent(comment.getCommentText());
ClientResponse resp = abderaClient.put(entryRoot, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("resource.commented",resourcePath));
+ log.info(Messages.getMessage("resource.commented", resourcePath));
} else {
-
log.error(Messages.getMessage("resouce.comment.fails",resourcePath));
- throw new
RegistryException(Messages.getMessage("resouce.comment.fails",resourcePath));
+ log.error(Messages.getMessage("resouce.comment.fails",
resourcePath));
+ throw new
RegistryException(Messages.getMessage("resouce.comment.fails", resourcePath));
}
}
@@ -346,10 +349,10 @@
entry.setSummary(RegistryConstants.PARAMETER_REATINGS);
ClientResponse resp = abderaClient.put(entryRoot, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
- log.info(Messages.getMessage("resource.rated",resourcePath));
+ log.info(Messages.getMessage("resource.rated", resourcePath));
} else {
- log.error(Messages.getMessage("resource.rate.fail",resourcePath));
- throw new
RegistryException(Messages.getMessage("resource.rate.fail",resourcePath));
+ log.error(Messages.getMessage("resource.rate.fail", resourcePath));
+ throw new
RegistryException(Messages.getMessage("resource.rate.fail", resourcePath));
}
}
@@ -446,4 +449,76 @@
}
return logs;
}
+
+ public void exportToRegistry(File file, String path) throws
RegistryException {
+ try {
+ processImport(file, path);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RegistryException(e.getMessage());
+ }
+ }
+
+ public void importFromRegistry(File toFile, String path) throws
RegistryException {
+ try {
+ processExport(path, toFile);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RegistryException(e.getMessage());
+ }
+ }
+
+ private void processImport(File file, String path) throws Exception {
+ String filePart = file.getName();
+ String resourcePath = path + "/" + filePart;
+ if (file.isDirectory()) {
+ File files[] = file.listFiles();
+ if (files.length > 0) {
+ for (int i = 0; i < files.length; i++) {
+ File childFile = files[i];
+ processImport(childFile, resourcePath);
+ }
+ } else {
+ Resource resource = new Resource();
+ resource.setPath(resourcePath);
+ resource.setDirectory(true);
+ put(resourcePath, resource);
+ }
+ } else {
+ Resource resource = new Resource();
+ resource.setContent(new FileInputStream(file));
+ resource.setPath(resourcePath);
+ resource.setDirectory(false);
+ put(resourcePath, resource);
+ }
+ }
+
+ private void processExport(String resourcePath,
+ File toFile) throws RegistryException {
+ Resource resource = get(resourcePath);
+ if (resource != null) {
+ if (resource.isDirectory()) {
+ File file = new File(toFile, resource.getPath());
+ file.mkdirs();
+ String childNodes[] = (String[]) resource.getContent();
+ for (int i = 0; i < childNodes.length; i++) {
+ String childNode = childNodes[i];
+ processExport(childNode, toFile);
+ }
+ } else {
+ File file = new File(toFile, resource.getPath());
+ try {
+ file.createNewFile();
+ FileOutputStream out = new FileOutputStream(file);
+ out.write((byte[])resource.getContent());
+ out.flush();
+ out.close();
+ } catch (IOException e) {
+ throw new RegistryException(Messages.getMessage(
+ "error.creating.file", resource.getPath()));
+ }
+
+ }
+ }
+ }
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfiguration.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfiguration.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfiguration.java
Mon Dec 17 20:47:55 2007
@@ -18,7 +18,9 @@
*/
package org.wso2.registry.config;
+import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.wso2.registry.RegistryException;
import org.wso2.registry.i18n.Messages;
@@ -28,9 +30,9 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.HashMap;
public class RegistryConfiguration {
@@ -42,7 +44,8 @@
* will use the one in the class path.
*
* @param xmlLocation : Location of the
- * @throws org.wso2.registry.RegistryException : if something went wrong
+ * @throws org.wso2.registry.RegistryException
+ * : if something went wrong
*/
public void populateRegistryConfig(String xmlLocation) throws
RegistryException {
InputStream in;
@@ -67,7 +70,7 @@
OMElement dbconfig = (OMElement) dbconfgs.next();
DataBaseConfiguration dataBaseConfiguration = new
DataBaseConfiguration();
String dbName = dbconfig.getAttributeValue(new
QName("name"));
- if(dbName == null){
+ if (dbName == null) {
throw new
RegistryException(Messages.getMessage("dbname.null"));
}
dataBaseConfiguration.setConfigName(dbName);
@@ -87,7 +90,7 @@
if (driverName != null) {
dataBaseConfiguration.setDriverName(driverName.getText());
}
- dbconfgigMap.put(dbName,dataBaseConfiguration);
+ dbconfgigMap.put(dbName, dataBaseConfiguration);
}
}
@@ -99,8 +102,36 @@
public static void main(String[] args) throws Exception {
RegistryConfiguration configuration = new RegistryConfiguration();
configuration.populateRegistryConfig(null);
+ OMElement ele = configuration.getRegistryConfigAsXML();
+ System.out.println(ele);
}
- public DataBaseConfiguration getDataBaseConfiguration(String configName){
+
+ public DataBaseConfiguration getDataBaseConfiguration(String configName) {
return (DataBaseConfiguration) dbconfgigMap.get(configName);
}
+
+ public OMElement getRegistryConfigAsXML() {
+ OMFactory factoty = OMAbstractFactory.getOMFactory();
+ OMElement root = factoty.createOMElement("wso2regsitry", null);
+ Iterator values = dbconfgigMap.values().iterator();
+ while (values.hasNext()) {
+ DataBaseConfiguration dataBaseConfiguration =
(DataBaseConfiguration) values.next();
+ OMElement config = factoty.createOMElement("dbconfig", null);
+ OMElement url = factoty.createOMElement("url", null);
+ url.setText(dataBaseConfiguration.getDbUrl());
+ config.addChild(url);
+ OMElement userName = factoty.createOMElement("userName", null);
+ userName.setText(dataBaseConfiguration.getUserName());
+ config.addChild(userName);
+ OMElement password = factoty.createOMElement("password", null);
+ password.setText(dataBaseConfiguration.getPassWord());
+ config.addChild(password);
+ OMElement driverName = factoty.createOMElement("driverName", null);
+ driverName.setText(dataBaseConfiguration.getDriverName());
+ config.addChild(driverName);
+ config.addAttribute("name", dataBaseConfiguration.getConfigName(),
null);
+ root.addChild(config);
+ }
+ return root;
+ }
}
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 20:47:55 2007
@@ -51,7 +51,6 @@
String path;
if (uri.equals("") || uri.endsWith(WEB_PATH +
RegistryConstants.PATH_SEPARATOR)) {
path = RegistryConstants.ROOT_PATH;
-
} else {
path = uri.substring((contextRoot +
RegistryConstants.PATH_SEPARATOR + WEB_PATH).
length(), uri.length());
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 20:47:55 2007
@@ -72,6 +72,7 @@
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
+error.creating.file=Unable to create file {0}.
################################ APP Messages
###########################################
resource.version=Resource Version for the resource {0}
resource.not.found=Resource Not found.
Modified: trunk/registry/modules/core/src/main/resources/registry.xml
==============================================================================
--- trunk/registry/modules/core/src/main/resources/registry.xml (original)
+++ trunk/registry/modules/core/src/main/resources/registry.xml Mon Dec 17
20:47:55 2007
@@ -1,8 +1,8 @@
<wso2regsitry>
<dbconfig name="DB1">
- <url></url>
- <userName></userName>
- <password></password>
- <driverName></driverName>
+ <url>url</url>
+ <userName>userName</userName>
+ <password>password</password>
+ <driverName>driverName</driverName>
</dbconfig>
</wso2regsitry>
\ No newline at end of file
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev