1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.script.framework.provider;
25 
26 import java.util.StringTokenizer;
27 
28 import java.lang.reflect.Method;
29 
30 import com.sun.star.frame.XModel;
31 import com.sun.star.uno.IQueryInterface;
32 
33 public class PathUtils {
34 
35     public static String FILE_URL_PREFIX;
36     public static String BOOTSTRAP_NAME;
37     private static boolean m_windows = false;
38 
39     static {
40         // detect if windows platform
41         if (System.getProperty("os.name").startsWith("Windows"))
42             m_windows = true;
43 
44         FILE_URL_PREFIX = m_windows ? "file:///" : "file://";
45         BOOTSTRAP_NAME = m_windows ? "bootstrap.ini" : "bootstraprc";
46     }
getOidForModel( XModel xModel )47     public static String getOidForModel( XModel xModel )
48     {
49         String oid = new String("");
50         if ( xModel != null )
51         {
52             try
53             {
54                 Method getOid = IQueryInterface.class.getMethod("getOid", (java.lang.Class[])null);
55                 if ( getOid != null )
56                 {
57                     oid = (String)getOid.invoke( xModel, new Object[0] );
58                 }
59 
60             }
61             catch ( Exception ignore )
62             {
63             }
64         }
65         return oid;
66     }
make_url( String baseUrl, String url )67     static  public String make_url( String baseUrl, String url )
68     {
69         StringBuffer buff = new StringBuffer( baseUrl.length() + url.length() );        buff.append( baseUrl );
70         StringTokenizer t = new StringTokenizer( url, "/");
71         while ( t.hasMoreElements() )
72         {
73            if ( buff.charAt( buff.length() - 1 ) != '/' )
74            {
75                buff.append('/');
76            }
77            buff.append( java.net.URLEncoder.encode( (String)t.nextElement() ) );        }
78         return buff.toString();
79     }
80 
PathUtils()81     private PathUtils() {
82     }
83 }
84