Author: chathura
Date: Tue Feb  5 00:00:01 2008
New Revision: 13252

Log:


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



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

Modified: 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java
==============================================================================
--- 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java
 (original)
+++ 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/XSDMediaTypeHandler.java
 Tue Feb  5 00:00:01 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: 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/SchemaFileProcessor.java
==============================================================================
--- 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/SchemaFileProcessor.java
   (original)
+++ 
branches/registry/1_0/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/utils/SchemaFileProcessor.java
   Tue Feb  5 00:00:01 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;
     }
 
     /**

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to