diff --git a/org.talend.commons.runtime/META-INF/MANIFEST.MF b/org.talend.commons.runtime/META-INF/MANIFEST.MF index d719d65ad2..d0e6ef092e 100644 --- a/org.talend.commons.runtime/META-INF/MANIFEST.MF +++ b/org.talend.commons.runtime/META-INF/MANIFEST.MF @@ -27,6 +27,7 @@ Export-Package: org.talend.commons, org.talend.commons.utils.network, org.talend.commons.utils.performance, org.talend.commons.utils.platform, + org.talend.commons.utils.resource, org.talend.commons.utils.scalability, org.talend.commons.utils.system, org.talend.commons.utils.threading, diff --git a/org.talend.commons.runtime/src/org/talend/commons/utils/resource/ResourceUtil.java b/org.talend.commons.runtime/src/org/talend/commons/utils/resource/ResourceUtil.java new file mode 100644 index 0000000000..8b29d137ed --- /dev/null +++ b/org.talend.commons.runtime/src/org/talend/commons/utils/resource/ResourceUtil.java @@ -0,0 +1,43 @@ +// ============================================================================ +// +// Copyright (C) 2006-2011 Talend Inc. - www.talend.com +// +// This source code is available under agreement available at +// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt +// +// You should have received a copy of the agreement +// along with this program; if not, write to Talend SA +// 9 rue Pages 92150 Suresnes, France +// +// ============================================================================ +package org.talend.commons.utils.resource; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.URIUtil; + +/** + * class ResourceUtil. Helper to handle resource URL from java or Eclipse. + */ +public class ResourceUtil { + + private static final String BUNDLERESOURCE = "bundleresource"; + + public static File convertResourceToFile(URL resource) throws IOException, URISyntaxException { + File fileDir = null; + if (BUNDLERESOURCE.equals(resource.getProtocol())) { + URL unescapedURL = FileLocator.toFileURL(resource); + URI escapedURI = new URI(unescapedURL.getProtocol(), unescapedURL.getPath(), unescapedURL.getQuery()); + fileDir = URIUtil.toFile(escapedURI); + } else { + fileDir = new File(resource.getFile()); + } + return fileDir; + } + +}