com.sun.msv.util.Util Maven / Gradle / Ivy
/*
* @(#)$Id: Util.java,v 1.7 2003/10/24 18:54:03 kohsuke Exp $
*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/
package com.sun.msv.util;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.xml.sax.InputSource;
/**
* Collection of utility methods.
*
* @author Kohsuke KAWAGUCHI
*/
public class Util
{
/**
* Gets an InputSource from a string, which contains either
* a file name or an URL.
*/
public static InputSource getInputSource( String fileOrURL ) {
try {
// try it as an URL
new URL(fileOrURL);
return new InputSource(fileOrURL);
} catch( MalformedURLException e ) {
// try it as a file
String path = new File(fileOrURL).getAbsolutePath();
if (File.separatorChar != '/')
path = path.replace(File.separatorChar, '/');
if (!path.startsWith("/"))
path = "/" + path;
// if (!path.endsWith("/") && isDirectory())
// path = path + "/";
return new InputSource("file://"+path);
}
}
/**
* Checks if a given string is an absolute URI if it is an URI.
*
*
* This method does not check whether it is an URI.
*
*
* This implementation is based on
*
* this post.
*/
public static boolean isAbsoluteURI( String uri ) {
int len = uri.length();
if(len==0) return true; // an empty string is OK.
if(len<2) return false;
char ch = uri.charAt(0);
if(('a'<=ch && ch<='z') || ('A'<=ch && ch<='Z')) {
for( int i=1; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy