You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2009/03/10 17:16:32 UTC

svn commit: r752153 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/apps/FOURIResolver.java test/java/org/apache/fop/config/FOURIResolverTestCase.java test/java/org/apache/fop/config/FontBaseBadTestCase.java

Author: jeremias
Date: Tue Mar 10 16:16:31 2009
New Revision: 752153

URL: http://svn.apache.org/viewvc?rev=752153&view=rev
Log:
Restored ability to specify any URI base URI (URL), not just file URLs. For file URLs and file paths there's still a check whether the directory exists.
Enabled FontBaseBadTestCase.

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FOURIResolverTestCase.java   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOURIResolver.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FontBaseBadTestCase.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOURIResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOURIResolver.java?rev=752153&r1=752152&r2=752153&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOURIResolver.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOURIResolver.java Tue Mar 10 16:16:31 2009
@@ -24,6 +24,8 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
 
@@ -32,8 +34,10 @@
 import javax.xml.transform.URIResolver;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.xmlgraphics.util.io.Base64EncodeStream;
 import org.apache.xmlgraphics.util.uri.CommonURIResolver;
 
@@ -74,20 +78,31 @@
             base += "/";
         }
         File dir = new File(base);
-        try {
-            base = (dir.isDirectory() ? dir.toURI().toURL() : new URL(base)).toExternalForm();
-        } catch (MalformedURLException mfue) {
-            String message = mfue.getMessage();
-            if (!dir.isDirectory()) {
-                message = "base " + base + " is not a directory and not a valid URL: " + message;
-                mfue = new MalformedURLException(message);
+        if (dir.isDirectory()) {
+            return dir.toURI().toASCIIString();
+        } else {
+            URI baseURI;
+            try {
+                baseURI = new URI(base);
+                String scheme = baseURI.getScheme();
+                boolean directoryExists = true;
+                if ("file".equals(scheme)) {
+                    dir = FileUtils.toFile(baseURI.toURL());
+                    directoryExists = dir.isDirectory();
+                }
+                if (scheme == null || !directoryExists) {
+                    String message = "base " + base + " is not a valid directory";
+                    if (throwExceptions) {
+                        throw new MalformedURLException(message);
+                    }
+                    log.error(message);
+                }
+                return baseURI.toASCIIString();
+            } catch (URISyntaxException e) {
+                //TODO not ideal: our base URLs are actually base URIs.
+                throw new MalformedURLException(e.getMessage());
             }
-            if (throwExceptions) {
-                throw mfue;
-            }   
-            log.error(message);
         }
-        return base;
     }
 
     /**

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FOURIResolverTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FOURIResolverTestCase.java?rev=752153&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FOURIResolverTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FOURIResolverTestCase.java Tue Mar 10 16:16:31 2009
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.config;
+
+import java.net.MalformedURLException;
+
+import junit.framework.TestCase;
+
+import org.apache.fop.apps.FOURIResolver;
+
+/**
+ * This tests some aspects of the {@link FOURIResolver} class.
+ */
+public class FOURIResolverTestCase extends TestCase {
+
+    /**
+     * Checks the {@link FOURIResolver#checkBaseURL(String)} method.
+     * @throws Exception if an error occurs
+     */
+    public void testCheckBaseURI() throws Exception {
+        FOURIResolver resolver = new FOURIResolver(true);
+        System.out.println(resolver.checkBaseURL("./test/config"));
+        System.out.println(resolver.checkBaseURL("file:test/config"));
+        System.out.println(resolver.checkBaseURL("fantasy:myconfig"));
+        try {
+            resolver.checkBaseURL("./doesnotexist");
+            fail("Expected an exception for a inexistent base directory");
+        } catch (MalformedURLException mfue) {
+            //expected
+        }
+        try {
+            resolver.checkBaseURL("file:doesnotexist");
+            fail("Expected an exception for a inexistent base URI");
+        } catch (MalformedURLException mfue) {
+            //expected
+        }
+    }
+
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FOURIResolverTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FOURIResolverTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FontBaseBadTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FontBaseBadTestCase.java?rev=752153&r1=752152&r2=752153&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FontBaseBadTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/config/FontBaseBadTestCase.java Tue Mar 10 16:16:31 2009
@@ -20,7 +20,7 @@
 package org.apache.fop.config;
 
 /*
- * this font base does not exist and a relative font path is used
+ * This font base does not exist and a relative font path is used.
  */
 public class FontBaseBadTestCase extends BaseDestructiveUserConfigTestCase {
 
@@ -28,14 +28,7 @@
         super(name);
     }
 
-    public void testUserConfig() throws Exception {
-        // Override this method from the super-class and do nothing as this test doesn't pass ATM
-        // TODO re-enable later
-    }
-
-    /**
-     * @see org.apache.fop.config.BaseUserConfigTestCase#getUserConfigFilename()
-     */
+    /** {@inheritDoc} */
     public String getUserConfigFilename() {
         return "test_fontbase_bad.xconf";
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org