INTEGRATION: CWS scriptingf5 (1.3.8); FILE MERGED
2004/02/25 18:20:30 npower 1.3.8.1: #i25272# Added a container implementation ( new com/sun/star/script/framework/container defined ) to better seperate Browse functionality from io and script registry.
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
*
|
||||
* $RCSfile: PathUtils.java,v $
|
||||
*
|
||||
* $Revision: 1.3 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
* last change: $Author: rt $ $Date: 2004-01-05 12:54:33 $
|
||||
* last change: $Author: svesik $ $Date: 2004-04-19 23:08:55 $
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
@@ -77,6 +77,8 @@ import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import com.sun.star.script.framework.log.LogUtils;
|
||||
|
||||
import com.sun.star.script.framework.io.XStorageStreamHandler;
|
||||
|
||||
import com.sun.star.util.XMacroExpander;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
@@ -99,248 +101,4 @@ public class PathUtils {
|
||||
|
||||
private PathUtils() {
|
||||
}
|
||||
|
||||
public static String replaceWindowsPathSeparators( String path ) {
|
||||
if ( m_windows ) {
|
||||
path = path.replace( File.separatorChar, '/' );
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static InputStream getScriptFileStream( String pathURL ) throws MalformedURLException, IOException
|
||||
{
|
||||
URL url = createScriptURL( pathURL );
|
||||
return url.openStream();
|
||||
}
|
||||
|
||||
public static URL createScriptURL( String url ) throws MalformedURLException
|
||||
{
|
||||
XModel model=null;
|
||||
if ( url.indexOf( XStorageStreamHandler.XSTORAGESCHEME ) == 0 )
|
||||
{
|
||||
String modelUrl = url.substring(( XStorageStreamHandler.XSTORAGESCHEME + "://").length());
|
||||
int indexOfScriptsDir = modelUrl.lastIndexOf( "Scripts" );
|
||||
if ( indexOfScriptsDir > -1 )
|
||||
{
|
||||
modelUrl = modelUrl.substring( 0, indexOfScriptsDir - 1 );
|
||||
}
|
||||
model = com.sun.star.script.framework.provider.ScriptProvider.frameWorkRegistry.getModelForURL( modelUrl );
|
||||
}
|
||||
URL result = null;
|
||||
if ( model != null )
|
||||
{
|
||||
result = createScriptURL( url, model );
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new URL( url );
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private static URL createScriptURL(String pathURL, XModel xModel)
|
||||
throws MalformedURLException
|
||||
{
|
||||
URL url = null;
|
||||
|
||||
//if ( pathURL.startsWith( UCBStreamHandler.UCBSCHEME ) )
|
||||
if ( pathURL.startsWith( XStorageStreamHandler.XSTORAGESCHEME ) )
|
||||
{
|
||||
URLStreamHandler handler = new XStorageStreamHandler(xModel);
|
||||
pathURL += XStorageStreamHandler.separator;
|
||||
url = new URL(null, pathURL, handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
url = new URL( pathURL );
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private static String createPathURLRelativeToParcel( String parcelURI, String relativePart )
|
||||
{
|
||||
LogUtils.DEBUG("**** createPathURLRelativeToParcel() parcel = " + parcelURI + " path = " + relativePart );
|
||||
String path = null;
|
||||
String dummyPath = m_windows ? "z:" : "/dummy";
|
||||
|
||||
|
||||
File f = new File ( dummyPath, relativePart );
|
||||
try
|
||||
{
|
||||
path = f.getCanonicalPath();
|
||||
LogUtils.DEBUG("createPathURLRelativeToParcel() canonical path = " + path );
|
||||
// strip off dummy path prefix
|
||||
path = path.substring( dummyPath.length() );
|
||||
path = replaceWindowsPathSeparators( path );
|
||||
// strip off leading "/" if present, parcel always has
|
||||
// trailing "/" and "//" causes problems with ucb on some platforms
|
||||
if ( path.startsWith("/") )
|
||||
{
|
||||
path = path.substring( 1 );
|
||||
}
|
||||
LogUtils.DEBUG("createPathURLRelativeToParcel() relative portion of path = " + path );
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
LogUtils.DEBUG("Caught exception " + ioe );
|
||||
return null;
|
||||
}
|
||||
if ( path == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
path = parcelURI + path;
|
||||
|
||||
if ( !path.endsWith(".jar") && !path.endsWith("/"))
|
||||
{
|
||||
path += "/";
|
||||
}
|
||||
|
||||
LogUtils.DEBUG("createPathURLRelativeToParcel() path url = " + path );
|
||||
return path;
|
||||
}
|
||||
|
||||
public static Vector buildClasspath(String parcelURI, String classpath)
|
||||
throws MalformedURLException
|
||||
{
|
||||
// ParcelURI should always end with Seperator ( it's a directory )
|
||||
if ( !parcelURI.endsWith("/") )
|
||||
{
|
||||
parcelURI += "/";
|
||||
}
|
||||
|
||||
Vector result = new Vector();
|
||||
StringTokenizer stk = new StringTokenizer(classpath, ":");
|
||||
|
||||
while (stk.hasMoreElements()) {
|
||||
String path = "";
|
||||
String relativeClasspath = (String)stk.nextElement();
|
||||
path = createPathURLRelativeToParcel( parcelURI, relativeClasspath );
|
||||
if ( path != null )
|
||||
{
|
||||
result.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.size() == 0) {
|
||||
result.add(parcelURI);
|
||||
}
|
||||
|
||||
LogUtils.DEBUG("buildClassPath() returning vector of size "
|
||||
+ result.size() );
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Returns a path with ./ and ../ relative path directives evaluated.
|
||||
*
|
||||
* @return path with ./ and ../ relative path directives evaluated.
|
||||
* The path passed in must not start with "../", null is returned * in this case.
|
||||
*/
|
||||
static private String processRelativePath( String path )
|
||||
{
|
||||
Vector pathComponents = new Vector();
|
||||
boolean isJarPath = false;
|
||||
if ( path.endsWith( ".jar" ) )
|
||||
{
|
||||
isJarPath = true;
|
||||
}
|
||||
StringTokenizer stk = new StringTokenizer( path, "/" );
|
||||
while( stk.hasMoreElements() )
|
||||
{
|
||||
String pathPart = (String)stk.nextElement();
|
||||
|
||||
if ( pathPart.equals( ".." ) )
|
||||
{
|
||||
if ( pathComponents.isEmpty() )
|
||||
{
|
||||
//System.err.println( "Illegal path, path when evaluated will point beyond start of path ->" + path );
|
||||
return null;
|
||||
}
|
||||
pathComponents.removeElementAt( pathComponents.size() - 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !pathPart.equals(".") )
|
||||
{
|
||||
pathComponents.add( pathPart );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String returnPath = "";
|
||||
for ( int i = 0; i < pathComponents.size(); i++ )
|
||||
{
|
||||
if ( i == 0 )
|
||||
{
|
||||
returnPath = ( String )pathComponents.elementAt( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
returnPath = returnPath + "/" + ( String )pathComponents.elementAt( i );
|
||||
}
|
||||
}
|
||||
|
||||
if ( returnPath.length() > 0 && !isJarPath )
|
||||
{
|
||||
returnPath += "/";
|
||||
}
|
||||
return returnPath;
|
||||
}
|
||||
|
||||
private static String getOfficeURL(XComponentContext ctxt, String name) {
|
||||
|
||||
String result = null;
|
||||
|
||||
try {
|
||||
Object serviceObj = ctxt.getValueByName(
|
||||
"/singletons/com.sun.star.util.theMacroExpander");
|
||||
|
||||
LogUtils.DEBUG("got serviceObj");
|
||||
XMacroExpander me = (XMacroExpander) AnyConverter.toObject(
|
||||
new Type(XMacroExpander.class), serviceObj);
|
||||
|
||||
result = me.expandMacros(name);
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException iae) {
|
||||
LogUtils.DEBUG("Caught IllegalArgumentException trying to " +
|
||||
"expand dir: " + name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getShareURL(XComponentContext ctxt) {
|
||||
return getOfficeURL(ctxt,
|
||||
"${$SYSBINDIR/" + BOOTSTRAP_NAME +
|
||||
"::BaseInstallation}/share");
|
||||
}
|
||||
|
||||
public static String getSharePath(XComponentContext ctxt) {
|
||||
String s = getShareURL(ctxt);
|
||||
|
||||
if (s.startsWith(FILE_URL_PREFIX)) {
|
||||
s = s.substring(FILE_URL_PREFIX.length());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static String getUserURL(XComponentContext ctxt) {
|
||||
return getOfficeURL(ctxt,
|
||||
"${$SYSBINDIR/" + BOOTSTRAP_NAME +
|
||||
"::UserInstallation}/user");
|
||||
}
|
||||
|
||||
public static String getUserPath(XComponentContext ctxt) {
|
||||
String s = getUserURL(ctxt);
|
||||
|
||||
if (s.startsWith(FILE_URL_PREFIX)) {
|
||||
s = s.substring(FILE_URL_PREFIX.length());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user