felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r919183 - in /felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl: ResourceImpl.java StaxParser.java
Date Thu, 04 Mar 2010 21:06:31 GMT
Author: gnodet
Date: Thu Mar  4 21:06:31 2010
New Revision: 919183

URL: http://svn.apache.org/viewvc?rev=919183&view=rev
Log:
[bundlerepository] fix uri handling which incorrectly change urls for uris which aren't really
specified.One problem i found was when parsing some license headers which aren't actually
considered URIs, such as the BND one which looks like:   ASL20;name="This material is licensed
under the Apache Software License, Version 2.0"; url="http://www.apache.org/licenses/LICENSE-2.0";distribution=repo
The solution is to let the user deal with URI unless the type is actually specified (and for
the main resource URI).

Modified:
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResourceImpl.java
    felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/StaxParser.java

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResourceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResourceImpl.java?rev=919183&r1=919182&r2=919183&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResourceImpl.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/ResourceImpl.java
Thu Mar  4 21:06:31 2010
@@ -36,12 +36,7 @@
     private List m_capList = new ArrayList();
     private List m_reqList = new ArrayList();
 
-    private String m_resourceURI = null;
-    private String m_docURI = null;
-    private String m_licenseURI = null;
-    private String m_sourceURI = null;
-    private String m_javadocURI = null;
-    private boolean m_converted = false;
+    private Map m_uris;
 
     private int m_hash;
 
@@ -100,10 +95,7 @@
 
     public Map getProperties()
     {
-        if (!m_converted)
-        {
-            convertURIs();
-        }
+        convertURIs();
         return m_map;
     }
 
@@ -131,10 +123,7 @@
 
     public String getURI()
     {
-        if (!m_converted)
-        {
-            convertURIs();
-        }
+        convertURIs();
         return (String) m_map.get(Resource.URI);
     }
 
@@ -189,95 +178,67 @@
     **/
     protected Object put(Object key, Object value)
     {
-        key = key.toString().toLowerCase();
-        m_converted = false;
+        put(key.toString(), value.toString(), null);
+        return null;
+    }
+
+    protected void put(String key, String value, String type)
+    {
+        key = key.toLowerCase();
         m_hash = 0;
-        // Capture the URIs since they might be relative, so we
-        // need to defer setting the actual URL value until they
-        // are used so that we will know our repository and its
-        // base URL.
-        if (key.equals(LICENSE_URI))
-        {
-            m_licenseURI = (String) value;
-        }
-        else if (key.equals(DOCUMENTATION_URI))
+        if ("uri".equals(type) || URI.equals(key))
         {
-            m_docURI = (String) value;
+            if (m_uris == null)
+            {
+                m_uris = new HashMap();
+            }
+            m_uris.put(key, value);
         }
-        else if (key.equals(SOURCE_URI))
+        else if ("version".equals(type) || VERSION.equals(key))
         {
-            m_sourceURI = (String) value;
+            m_map.put(key, Version.parseVersion(value));
         }
-        else if (key.equals(JAVADOC_URI))
+        else if ("long".equals(type) || SIZE.equals(key))
         {
-            m_javadocURI = (String) value;
+            m_map.put(key, Long.valueOf(value.toString()));
         }
-        else if (key.equals(URI))
+        else if (CATEGORY.equals(key))
         {
-            m_resourceURI = (String) value;
+            m_map.put(key, Arrays.asList(value.toString().split(",")));
         }
         else
         {
-            if (key.equals(VERSION))
-            {
-                value = Version.parseVersion(value.toString());
-            }
-            else if (key.equals(SIZE))
-            {
-                value = Long.valueOf(value.toString());
-            }
-            else if (key.equals(CATEGORY))
-            {
-                if (value instanceof Collection)
-                {
-                    value = new ArrayList((Collection) value);
-                }
-                else
-                {
-                    value = Arrays.asList(value.toString().split(","));
-                }
-            }
-    
-            return m_map.put(key, value);
+            m_map.put(key, value);
         }
-
-        return null;
     }
 
     private void convertURIs()
     {
-        if (m_repo != null)
+        if (m_uris != null)
         {
-            try
+            for (Iterator it = m_uris.keySet().iterator(); it.hasNext();)
             {
-                URI base = m_repo.getURI() != null ? new URI(m_repo.getURI()) : null;
-                if (m_resourceURI != null)
-                {
-                    m_map.put(URI, base != null ? base.resolve(m_resourceURI).toString()
: m_resourceURI);
-                }
-                if (m_docURI != null)
-                {
-                    m_map.put(DOCUMENTATION_URI, base != null ? base.resolve(m_docURI).toString()
: m_docURI);
-                }
-                if (m_licenseURI != null)
-                {
-                    m_map.put(LICENSE_URI, base != null ? base.resolve(m_licenseURI).toString()
: m_licenseURI);
-                }
-                if (m_sourceURI != null)
-                {
-                    m_map.put(SOURCE_URI, base != null ? base.resolve(m_sourceURI).toString()
: m_sourceURI);
-                }
-                if (m_javadocURI != null)
-                {
-                    m_map.put(JAVADOC_URI, base != null ? base.resolve(m_javadocURI).toString()
: m_javadocURI);
-                }
-                m_converted = true;
+                String key = (String) it.next();
+                String val = (String) m_uris.get(key);
+                m_map.put(key, resolveUri(val));
             }
-            catch (URISyntaxException ex)
+            m_uris = null;
+        }
+    }
+
+    private String resolveUri(String uri)
+    {
+        try
+        {
+            if (m_repo != null && m_repo.getURI() != null)
             {
-                ex.printStackTrace(System.err);
+                return new URI(m_repo.getURI()).resolve(uri).toString();
             }
         }
+        catch (Throwable t)
+        {
+        }
+        return uri;
     }
 
     public String toString()

Modified: felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/StaxParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/StaxParser.java?rev=919183&r1=919182&r2=919183&view=diff
==============================================================================
--- felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/StaxParser.java
(original)
+++ felix/trunk/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/StaxParser.java
Thu Mar  4 21:06:31 2010
@@ -188,6 +188,7 @@
                 else
                 {
                     StringBuffer sb = null;
+                    String type = reader.getAttributeValue(null, "type");
                     while ((event = reader.next()) != XMLStreamConstants.END_ELEMENT)
                     {
                         switch (event)
@@ -205,7 +206,7 @@
                     }
                     if (sb != null)
                     {
-                        resource.put(element, sb.toString().trim());
+                        resource.put(element, sb.toString().trim(), type);
                     }
                 }
             }



Mime
View raw message