[bundlerepository] write resources with relative uri when possible

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@926535 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
index dace479..4411dff 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
@@ -19,6 +19,7 @@
 package org.apache.felix.bundlerepository.impl;
 
 import java.io.*;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
@@ -72,9 +73,18 @@
         return req;
     }
 
-    public Filter filter(String filter) throws InvalidSyntaxException
+    public Filter filter(String filter)
     {
-        return FilterImpl.newInstance(filter);
+        try
+        {
+            return FilterImpl.newInstance(filter);
+        }
+        catch (InvalidSyntaxException e)
+        {
+            IllegalArgumentException ex = new IllegalArgumentException();
+            ex.initCause(e);
+            throw ex;
+        }
     }
 
     public Repository repository(final URL url) throws Exception
@@ -313,15 +323,15 @@
             .attribute(Resource.ID, resource.getId())
             .attribute(Resource.SYMBOLIC_NAME, resource.getSymbolicName())
             .attribute(Resource.PRESENTATION_NAME, resource.getPresentationName())
-            .attribute(Resource.URI, resource.getURI())
+            .attribute(Resource.URI, getRelativeUri(resource, Resource.URI))
             .attribute(Resource.VERSION, resource.getVersion().toString());
 
         w.textElement(Resource.DESCRIPTION, resource.getProperties().get(Resource.DESCRIPTION))
             .textElement(Resource.SIZE, resource.getProperties().get(Resource.SIZE))
-            .textElement(Resource.DOCUMENTATION_URI, resource.getProperties().get(Resource.DOCUMENTATION_URI))
-            .textElement(Resource.SOURCE_URI, resource.getProperties().get(Resource.SOURCE_URI))
-            .textElement(Resource.JAVADOC_URI, resource.getProperties().get(Resource.JAVADOC_URI))
-            .textElement(Resource.LICENSE_URI, resource.getProperties().get(Resource.LICENSE_URI));
+            .textElement(Resource.DOCUMENTATION_URI, getRelativeUri(resource, Resource.DOCUMENTATION_URI))
+            .textElement(Resource.SOURCE_URI, getRelativeUri(resource, Resource.SOURCE_URI))
+            .textElement(Resource.JAVADOC_URI, getRelativeUri(resource, Resource.JAVADOC_URI))
+            .textElement(Resource.LICENSE_URI, getRelativeUri(resource, Resource.LICENSE_URI));
 
         String[] categories = resource.getCategories();
         for (int i = 0; categories != null && i < categories.length; i++)
@@ -343,6 +353,22 @@
         w.end();
     }
 
+    private static String getRelativeUri(Resource resource, String name) 
+    {
+        String uri = (String) resource.getProperties().get(name);
+        if (resource instanceof ResourceImpl)
+        {
+            try
+            {
+                uri = URI.create(((ResourceImpl) resource).getRepository().getURI()).relativize(URI.create(uri)).toASCIIString();
+            }
+            catch (Throwable t)
+            {
+            }
+        }
+        return uri;
+    }
+
     private static void toXml(XmlWriter w, Capability capability) throws IOException
     {
         w.element(RepositoryParser.CAPABILITY)
@@ -536,7 +562,6 @@
             resource.put(Resource.SOURCE_URI, headers.getHeader(BUNDLE_SOURCE));
         }
 
-        doSize(resource, headers);
         doCategories(resource, headers);
         doBundle(resource, headers);
         doImportExportServices(resource, headers);
@@ -547,11 +572,6 @@
         doExecutionEnvironment(resource, headers);
     }
 
-    private static void doSize(ResourceImpl resource, Headers headers)
-    {
-        //To change body of created methods use File | Settings | File Templates.
-    }
-
     private static void doCategories(ResourceImpl resource, Headers headers)
     {
         Clause[] clauses = Parser.parseHeader(headers.getHeader(Constants.BUNDLE_CATEGORY));