-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.utils.ui;\r
-\r
-import java.io.File;\r
-import java.net.URL;\r
-\r
-import org.eclipse.core.runtime.FileLocator;\r
-import org.eclipse.core.runtime.IPath;\r
-import org.eclipse.core.runtime.Path;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.osgi.framework.Bundle;\r
-\r
-/**\r
- * Utilities for locating OSGi bundle contents on local media.\r
- */\r
-public final class PathUtils {\r
- \r
- /**\r
- * Get the absolute path to the specified file in the specified bundle as an\r
- * IPath. An absolute path is only available for files that are extracted\r
- * onto any local or network mapped location. Files inside archived bundles\r
- * aren't considered to have an absolute path since they cannot be executed\r
- * as such.\r
- * \r
- * @param inBundle\r
- * @param fullpath\r
- * @return <code>null</code> if the specified file was not found under the\r
- * specified bundle or the bundle is archived.\r
- */\r
- public static IPath getAbsolutePath(Bundle inBundle, String fullpath) {\r
-// System.out.println("getAbsolutePath: " + inBundle + ", " + fullpath);\r
- IPath path = new Path(fullpath);\r
- URL u = FileLocator.find(inBundle, path, null);\r
- if (u != null) {\r
- try {\r
- u = FileLocator.resolve(u);\r
-// System.out.println(" PROTOCOL: " + u.getProtocol());\r
-// System.out.println(" FILE: " + u.getFile());\r
- // an absolute path is only available for the file protocol.\r
- if ("file".equals(u.getProtocol())) {\r
- IPath p = new Path(new File(u.getFile()).getAbsolutePath());\r
- return p;\r
- }\r
- } catch (Exception e) {\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * Get the absolute path to the specified file in the specified bundle as a\r
- * String.\r
- * \r
- * @param inBundle\r
- * @param fullpath\r
- * @return <code>null</code> if the specified file was not found under the\r
- * specified bundle\r
- */\r
- public static String getAbsolutePathString(Bundle inBundle, String fullpath) {\r
- IPath p = getAbsolutePath(inBundle, fullpath);\r
- return (p != null) ? p.toOSString() : null;\r
- }\r
-\r
- public static IPath getAbsolutePath(String inBundle, String fullpath) {\r
- Bundle b = Platform.getBundle(inBundle);\r
- if (b == null)\r
- return null;\r
- return getAbsolutePath(b, fullpath);\r
- }\r
-\r
- public static String getAbsolutePathString(String inBundle, String fullpath) {\r
- Bundle b = Platform.getBundle(inBundle);\r
- if (b == null)\r
- return null;\r
- return getAbsolutePathString(b, fullpath);\r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.utils.ui;
+
+import java.io.File;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+
+/**
+ * Utilities for locating OSGi bundle contents on local media.
+ */
+public final class PathUtils {
+
+ /**
+ * Get the absolute path to the specified file in the specified bundle as an
+ * IPath. An absolute path is only available for files that are extracted
+ * onto any local or network mapped location. Files inside archived bundles
+ * aren't considered to have an absolute path since they cannot be executed
+ * as such.
+ *
+ * @param inBundle
+ * @param fullpath
+ * @return <code>null</code> if the specified file was not found under the
+ * specified bundle or the bundle is archived.
+ */
+ public static IPath getAbsolutePath(Bundle inBundle, String fullpath) {
+// System.out.println("getAbsolutePath: " + inBundle + ", " + fullpath);
+ IPath path = new Path(fullpath);
+ URL u = FileLocator.find(inBundle, path, null);
+ if (u != null) {
+ try {
+ u = FileLocator.resolve(u);
+// System.out.println(" PROTOCOL: " + u.getProtocol());
+// System.out.println(" FILE: " + u.getFile());
+ // an absolute path is only available for the file protocol.
+ if ("file".equals(u.getProtocol())) {
+ IPath p = new Path(new File(u.getFile()).getAbsolutePath());
+ return p;
+ }
+ } catch (Exception e) {
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the absolute path to the specified file in the specified bundle as a
+ * String.
+ *
+ * @param inBundle
+ * @param fullpath
+ * @return <code>null</code> if the specified file was not found under the
+ * specified bundle
+ */
+ public static String getAbsolutePathString(Bundle inBundle, String fullpath) {
+ IPath p = getAbsolutePath(inBundle, fullpath);
+ return (p != null) ? p.toOSString() : null;
+ }
+
+ public static IPath getAbsolutePath(String inBundle, String fullpath) {
+ Bundle b = Platform.getBundle(inBundle);
+ if (b == null)
+ return null;
+ return getAbsolutePath(b, fullpath);
+ }
+
+ public static String getAbsolutePathString(String inBundle, String fullpath) {
+ Bundle b = Platform.getBundle(inBundle);
+ if (b == null)
+ return null;
+ return getAbsolutePathString(b, fullpath);
+ }
+
+}