Browse Source

URLProvider interface

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@817702 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
32f323668f
4 changed files with 53 additions and 5 deletions
  1. +5
    -0
      WHATSNEW
  2. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  3. +35
    -0
      src/main/org/apache/tools/ant/types/resources/URLProvider.java
  4. +9
    -1
      src/main/org/apache/tools/ant/types/resources/URLResource.java

+ 5
- 0
WHATSNEW View File

@@ -513,6 +513,11 @@ Other changes:
are instances or subclasses of FileResource.
Bugzilla Report 43348
* There is now a URLProvider interface for resources that act as a
source of URLs. This should be used by tasks that require resources
to provide URLs, rather than require that all resources are
instances or subclasses of URLResource.
* Fixcrlf now gives better error messages on bad directory attributes.
Bugzilla Report 43936


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java View File

@@ -54,7 +54,7 @@ import org.apache.tools.ant.types.XMLCatalog;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.resources.FileProvider;
import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.URLResource;
import org.apache.tools.ant.types.resources.URLProvider;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JAXPUtils;
import org.xml.sax.EntityResolver;
@@ -266,13 +266,13 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware
}

private String resourceToURI(Resource resource) {
// TODO turn URLResource into Provider
FileProvider fp = (FileProvider) resource.as(FileProvider.class);
if (fp != null) {
return FILE_UTILS.toURI(fp.getFile().getAbsolutePath());
}
if (resource instanceof URLResource) {
URL u = ((URLResource) resource).getURL();
URLProvider up = (URLProvider) resource.as(URLProvider.class);
if (up != null) {
URL u = up.getURL();
return String.valueOf(u);
} else {
return resource.getName();


+ 35
- 0
src/main/org/apache/tools/ant/types/resources/URLProvider.java View File

@@ -0,0 +1,35 @@
/*
* 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.tools.ant.types.resources;

import java.net.URL;

/**
* This is an interface that resources that can provide an URL should implement.
* This is a refactoring of {@link URLResource}, to allow other resources
* to act as sources of URLs.
* @since Ant 1.8
*/
public interface URLProvider {
/**
* Get the URL represented by this Resource.
* @return the file.
*/
URL getURL();
}

+ 9
- 1
src/main/org/apache/tools/ant/types/resources/URLResource.java View File

@@ -39,7 +39,7 @@ import org.apache.tools.ant.util.FileUtils;
* Exposes a URL as a Resource.
* @since Ant 1.7
*/
public class URLResource extends Resource {
public class URLResource extends Resource implements URLProvider {
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final int NULL_URL
= Resource.getMagicNumber("null URL".getBytes());
@@ -61,6 +61,14 @@ public class URLResource extends Resource {
setURL(u);
}

/**
* Convenience constructor.
* @param u holds the URL to expose.
*/
public URLResource(URLProvider u) {
setURL(u.getURL());
}

/**
* Convenience constructor.
* @param f the File to set as a URL.


Loading…
Cancel
Save