uima-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r1084699 - in /uima/uimaj/trunk: uimaj-core/src/main/java/org/apache/uima/impl/ uimaj-core/src/main/java/org/apache/uima/resource/impl/ uimaj-core/src/main/java/org/apache/uima/util/ uimaj-cpe/src/main/java/org/apache/uima/collection/impl/c...
Date Wed, 23 Mar 2011 19:52:12 GMT
Author: schor
Date: Wed Mar 23 19:52:12 2011
New Revision: 1084699

URL: http://svn.apache.org/viewvc?rev=1084699&view=rev
Log:
[UIMA-2097] fix URI handling with quoted otherwise illegal chars

Added:
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/UriUtils.java
Modified:
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurableDataResource_impl.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/DataResource_impl.java
    uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/JavaApplication.java
    uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/NonJavaApplication.java
    uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XCasWriterCasConsumer.java
    uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XmiWriterCasConsumer.java
    uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cpm/CpmPanel.java

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java
(original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/impl/UimaContext_ImplBase.java
Wed Mar 23 19:52:12 2011
@@ -55,6 +55,7 @@ import org.apache.uima.resource.Resource
 import org.apache.uima.resource.metadata.ConfigurationGroup;
 import org.apache.uima.resource.metadata.ConfigurationParameter;
 import org.apache.uima.util.Level;
+import org.apache.uima.util.UriUtils;
 
 /**
  * 
@@ -222,17 +223,20 @@ public abstract class UimaContext_ImplBa
    * @see org.apache.uima.UimaContext#getResourceURI(java.lang.String)
    */
   public URI getResourceURI(String aKey) throws ResourceAccessException {
-    URL resourceUrl = getResourceURL(aKey);
+    return getResourceURIfromURL( getResourceURL(aKey));
+  }
+  
+  private URI getResourceURIfromURL(URL resourceUrl) throws ResourceAccessException {
     if (resourceUrl != null) {
       try {
-        return new URI(resourceUrl.toString().replaceAll(" ", "%20"));
+        return UriUtils.quote(resourceUrl);
       } catch (URISyntaxException e) {
         throw new ResourceAccessException(e);
       }
     }
     else {
       return null;
-    }
+    } 
   }
  
 
@@ -363,19 +367,8 @@ public abstract class UimaContext_ImplBa
    * @see org.apache.uima.UimaContext#getResourceURI(String, String[])
    */
   public URI getResourceURI(String aKey, String[] aParams) throws ResourceAccessException
{
-    URL resourceUrl = getResourceURL(aKey, aParams);
-    if (resourceUrl != null) {
-      try {
-        return new URI(resourceUrl.toString().replaceAll(" ", "%20"));
-      } catch (URISyntaxException e) {
-        throw new ResourceAccessException(e);
-      }
-    }
-    else {
-      return null;
-    }
-  }
- 
+    return getResourceURIfromURL(getResourceURL(aKey, aParams));
+  } 
 
   /* (non-Javadoc)
    * @see org.apache.uima.UimaContext#getResourceFilePath(String, String[])

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurableDataResource_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurableDataResource_impl.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurableDataResource_impl.java
(original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/ConfigurableDataResource_impl.java
Wed Mar 23 19:52:12 2011
@@ -34,6 +34,7 @@ import org.apache.uima.resource.Relative
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceSpecifier;
 import org.apache.uima.resource.Resource_ImplBase;
+import org.apache.uima.util.UriUtils;
 
 /**
  * A simple {@link DataResource} implementation that can read data from a file via a URL.
There is
@@ -74,7 +75,7 @@ public class ConfigurableDataResource_im
     ConfigurableDataResourceSpecifier spec = (ConfigurableDataResourceSpecifier) aSpecifier;
     try {
       // create URI object from URL specified in descriptor
-      mUri = new URI(spec.getUrl());
+      mUri = UriUtils.quote(spec.getUrl());
     } catch (URISyntaxException e) {
       throw new ResourceInitializationException(e);
     }

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/DataResource_impl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/DataResource_impl.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/DataResource_impl.java
(original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/resource/impl/DataResource_impl.java
Wed Mar 23 19:52:12 2011
@@ -35,6 +35,7 @@ import org.apache.uima.resource.Relative
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceSpecifier;
 import org.apache.uima.resource.Resource_ImplBase;
+import org.apache.uima.util.UriUtils;
 
 /**
  * A simple {@link DataResource} implementation that can read data from a file via a URL.
There is
@@ -158,10 +159,7 @@ public class DataResource_impl extends R
    */
   public URI getUri() {
     try {
-      // we need to escape any space characters in the URL. In Java,
-      // a URL object may contain a space but a URI may not.
-      String urlStr = mFileUrl.toString();
-      return new URI(urlStr.replaceAll(" ", "%20"));
+      return UriUtils.quote(mFileUrl);
     } catch (URISyntaxException e) {
       throw new UIMARuntimeException(e);
     }

Added: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/UriUtils.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/UriUtils.java?rev=1084699&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/UriUtils.java (added)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/UriUtils.java Wed Mar 23
19:52:12 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.util;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ * Static methods supporting proper handling of URIs
+ *
+ */
+public class UriUtils {
+
+  /**
+   * Create a URI from a string, with proper quoting.
+   * Already quoted things in the input string are not re-quoted.
+   * There are several cases:
+   *   String has no characters needing quoting
+   *   String has chars needing quoting, but no chars are currently quoted (e.g. %20)
+   *   String has quoted (e.g. %20) characters but no other chars needing quoting
+   *   String has quoted (e.g. %20) characters and chars needing quoting, not currently quoted
+   *     -- this case will throw an exception
+   * @param s
+   * @return URI with proper quoting
+   * @throws URISyntaxException 
+   */
+  public static URI quote (String s) throws URISyntaxException {
+    if (-1 == s.indexOf('%')) {
+      // 3 argument constructor does any needed quoting of otherwise illegal chars
+      // https://issues.apache.org/jira/browse/UIMA-2097
+      return new URI(null, s, null);  
+    }
+    
+    // assume s already has all otherwise illegal chars properly quoted
+    return new URI(s);
+  }
+
+  /**
+   * Create a URI from a URL, with proper quoting.
+   * Already quoted things in the input string are not re-quoted.
+   * @param u
+   * @return URI with proper quoting
+   * @throws URISyntaxException 
+   */
+
+  public static URI quote(URL u) throws URISyntaxException {
+    return quote(u.toString());
+  }
+}

Modified: uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/JavaApplication.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/JavaApplication.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/JavaApplication.java
(original)
+++ uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/JavaApplication.java
Wed Mar 23 19:52:12 2011
@@ -33,6 +33,7 @@ import org.apache.uima.collection.metada
 import org.apache.uima.collection.metadata.CpeCasProcessor;
 import org.apache.uima.resource.ResourceConfigurationException;
 import org.apache.uima.util.Level;
+import org.apache.uima.util.UriUtils;
 
 /**
  * Component responsible for configuring command line for java based CasProcessor. Each CasProcessor
@@ -157,7 +158,7 @@ public class JavaApplication extends Run
         URL descriptorUrl = aCasProcessorConfiguration.getDescriptorUrl();
         String descriptorPath;
         try {
-          descriptorPath = new URI(descriptorUrl.toString()).getPath();
+          descriptorPath = UriUtils.quote(descriptorUrl).getPath();
         } catch (URISyntaxException e) {
           throw new ResourceConfigurationException(e);
         }

Modified: uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/NonJavaApplication.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/NonJavaApplication.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/NonJavaApplication.java
(original)
+++ uima/uimaj/trunk/uimaj-cpe/src/main/java/org/apache/uima/collection/impl/cpm/container/deployer/NonJavaApplication.java
Wed Mar 23 19:52:12 2011
@@ -32,6 +32,7 @@ import org.apache.uima.collection.impl.c
 import org.apache.uima.collection.metadata.CpeCasProcessor;
 import org.apache.uima.resource.ResourceConfigurationException;
 import org.apache.uima.util.Level;
+import org.apache.uima.util.UriUtils;
 
 /**
  * Component responsible for configuring command line for non-java based CasProcessor. Each
@@ -98,7 +99,7 @@ public class NonJavaApplication extends 
         URL descriptorUrl = aCasProcessorConfiguration.getDescriptorUrl();
         String descriptorPath;
         try {
-          descriptorPath = new URI(descriptorUrl.toString()).getPath();
+          descriptorPath = UriUtils.quote(descriptorUrl).getPath();
         } catch (URISyntaxException e) {
           throw new ResourceConfigurationException(e);
         }

Modified: uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XCasWriterCasConsumer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XCasWriterCasConsumer.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XCasWriterCasConsumer.java
(original)
+++ uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XCasWriterCasConsumer.java
Wed Mar 23 19:52:12 2011
@@ -40,6 +40,7 @@ import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceProcessException;
 import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.UriUtils;
 import org.apache.uima.util.XMLInputSource;
 import org.apache.uima.util.XMLSerializer;
 import org.xml.sax.SAXException;
@@ -108,7 +109,9 @@ public class XCasWriterCasConsumer exten
       try {
         // handle blanks in path
         // https://issues.apache.org/jira/browse/UIMA-1748
-        URI uri = new URI(fileLoc.getUri());
+        // use 3 arg form of URI Constructor to properly quote any otherwise illegal chars
such as blank
+        // https://issues.apache.org/jira/browse/UIMA-2097
+        URI uri = UriUtils.quote(fileLoc.getUri());
         inFile = new File(uri);
 
         String outFileName = inFile.getName();

Modified: uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XmiWriterCasConsumer.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XmiWriterCasConsumer.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XmiWriterCasConsumer.java
(original)
+++ uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/components/XmiWriterCasConsumer.java
Wed Mar 23 19:52:12 2011
@@ -40,6 +40,7 @@ import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.resource.ResourceProcessException;
 import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.UriUtils;
 import org.apache.uima.util.XMLInputSource;
 import org.apache.uima.util.XMLSerializer;
 import org.xml.sax.SAXException;
@@ -102,7 +103,9 @@ public class XmiWriterCasConsumer extend
       try {
         // handle blanks in path
         // https://issues.apache.org/jira/browse/UIMA-1748
-        URI uri = new URI(fileLoc.getUri());
+        // use 3 arg form of URI Constructor to properly quote any otherwise illegal chars
such as blank
+        // https://issues.apache.org/jira/browse/UIMA-2097
+        URI uri = UriUtils.quote(fileLoc.getUri());
         inFile = new File(uri);
         String outFileName = inFile.getName();
         if (fileLoc.getOffsetInSource() > 0) {

Modified: uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cpm/CpmPanel.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cpm/CpmPanel.java?rev=1084699&r1=1084698&r2=1084699&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cpm/CpmPanel.java (original)
+++ uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cpm/CpmPanel.java Wed
Mar 23 19:52:12 2011
@@ -99,6 +99,7 @@ import org.apache.uima.tools.util.gui.XM
 import org.apache.uima.util.FileUtils;
 import org.apache.uima.util.InvalidXMLException;
 import org.apache.uima.util.Progress;
+import org.apache.uima.util.UriUtils;
 import org.apache.uima.util.XMLInputSource;
 
 public class CpmPanel extends JPanel implements ActionListener, FileSelectorListener,
@@ -1001,8 +1002,7 @@ public class CpmPanel extends JPanel imp
    * @return File corresponding to that URL
    */
   private File urlToFile(URL url) throws URISyntaxException {
-    String urlString = url.toString().replaceAll(" ", "%20");
-    return new File(new URI(urlString));
+    return new File(UriUtils.quote(url));
   }
 
   private void displayProgress() {



Mime
View raw message