[Registry-dev] svn commit r13251 - in trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes: builtin utils

svn at wso2.org svn at wso2.org
Mon Feb 4 23:59:56 PST 2008


Author: chathura
Date: Mon Feb  4 23:59:48 2008
New Revision: 13251

Log:


Refactored the XSD media type handler to return the saved name of the xsd.



Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/SchemaFileProcessor.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java	Mon Feb  4 23:59:48 2008
@@ -19,6 +19,7 @@
 import org.wso2.registry.RegistryConstants;
 import org.wso2.registry.RegistryException;
 import org.wso2.registry.Resource;
+import org.wso2.registry.utils.AuthorizationUtil;
 import org.wso2.registry.jdbc.mediatypes.MediaTypeHandler;
 import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
 import org.wso2.registry.jdbc.mediatypes.utils.SchemaFileProcessor;
@@ -54,9 +55,16 @@
     public String importResource(String path, String sourceURL, Resource metadata)
             throws RegistryException {
 
-        schemaFileProcessor
-                .saveSchemaFileToRegistry(sourceURL, getParentPath(path), true, metadata);
-        return path;
+        String savedName = schemaFileProcessor
+                    .saveSchemaFileToRegistry(sourceURL, getParentPath(path), true, metadata);
+
+        String parentPath = AuthorizationUtil.getParentPath(path);
+
+        if (parentPath.endsWith(RegistryConstants.PATH_SEPARATOR)) {
+            return parentPath + savedName;
+        } else {
+            return parentPath + RegistryConstants.PATH_SEPARATOR + savedName;
+        }
     }
 
     public boolean delete(String path) throws RegistryException {

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/SchemaFileProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/SchemaFileProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/SchemaFileProcessor.java	Mon Feb  4 23:59:48 2008
@@ -50,13 +50,13 @@
      * @throws FileNotFoundException
      */
 
-    public void saveSchemaFileToRegistry(String location,
+    public String saveSchemaFileToRegistry(String location,
                                          String registryBasePath,
                                          boolean processInclueds,
                                          Resource metadata)
             throws RegistryException {
 
-        saveSchemaFileToRegistry(location, new HashMap(), registryBasePath, processInclueds,
+        return saveSchemaFileToRegistry(location, new HashMap(), registryBasePath, processInclueds,
                                  metadata);
     }
 
@@ -64,7 +64,7 @@
      * @param location           - original schema location
      * @param processedSchemaMap - this map contains schema source URI vs new schema locaitons.
      */
-    public void saveSchemaFileToRegistry(String location,
+    public String saveSchemaFileToRegistry(String location,
                                          Map processedSchemaMap,
                                          String registryBasePath,
                                          boolean processInclueds,
@@ -76,11 +76,18 @@
         // here we assue schema is correct. schema validation is beyond registry scope.
         // hence passes null to validator.
         XmlSchema xmlSchema = xmlSchemaCollection.read(inputSource, null);
+
+        String baseUri = xmlSchema.getSourceURI();
+        String xsdFileName = baseUri.substring(baseUri.lastIndexOf("/") + 1);
+        String savedName = xsdFileName.substring(0, xsdFileName.indexOf(".")) + ".xsd";
+
         // this is not an inline wsdl schema. so pass null to change map.
         calculateNewSchemaNames(xmlSchema, processedSchemaMap, new HashSet(), false,
                                 processInclueds);
         saveSchemaFileToRegistry(xmlSchema, processedSchemaMap, null, new HashSet(), false,
                                  registryBasePath, processInclueds, metadata);
+
+        return savedName;
     }
 
     /**



More information about the Registry-dev mailing list