/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/
/** * Gets classpath that contains the given resource bundle. * In addition to the bundle file, a source must be given that * will access the resource at run-time.
*/ publicstatic ClassPath getExecClassPath(FileObject srcFile, FileObject resFile) { // try EXECUTE class-path first
ClassPath ecp = ClassPath.getClassPath( srcFile, ClassPath.EXECUTE ); if ((ecp != null) && (ecp.getResourceName( resFile, '.',false) != null)) return ecp;
// if not directly on EXECUTE, might be on SOURCE
ClassPath scp = ClassPath.getClassPath( srcFile, ClassPath.SOURCE); // try to find the resource on source class path if ((scp != null) && (scp.getResourceName( resFile, '.',false) != null)) return scp;
// now try resource owner
ClassPath rcp = ClassPath.getClassPath( resFile, ClassPath.SOURCE); // try to find the resource on source class path if ((rcp!=null) && (rcp.getResourceName( resFile, '.',false) != null)) return rcp;
returnnull;
}
/** * Tries to find the bundle either in sources or in execution * classpath.
*/ publicstatic FileObject getResource(FileObject srcFile, String bundleName) { // try to find it in sources of the same project
ClassPath scp = ClassPath.getClassPath( srcFile, ClassPath.SOURCE); if (scp != null) {
FileObject ret = scp.findResource(bundleName); if (ret != null) return ret;
}
// try to find in sources of execution classpath
ClassPath ecp = ClassPath.getClassPath( srcFile, ClassPath.EXECUTE); if (ecp != null) { for (ClassPath.Entry e : ecp.entries()) {
SourceForBinaryQuery.Result r = SourceForBinaryQuery.findSourceRoots(e.getURL()); for (FileObject srcRoot : r.getRoots()) { // try to find the bundle under this source root
ClassPath cp = ClassPath.getClassPath(srcRoot, ClassPath.SOURCE); if (cp != null) {
FileObject ret = cp.findResource(bundleName); if (ret != null) return ret;
}
}
}
}
returnnull;
}
/** * Inverse to the previous method - finds name for the give * resource bundle. It is equivalent but more effective to use * this method instead of getExecClassPath(...).getResourceName(...) .
*/ publicstatic String getResourceName(FileObject srcFile, FileObject resFile, char separator, boolean bpar) { // try SOURCE class-path first
ClassPath scp = ClassPath.getClassPath( srcFile, ClassPath.SOURCE ); if (scp!= null) {
String ret = scp.getResourceName( resFile, separator, bpar); if (ret!=null) return ret;
}
ClassPath ecp = ClassPath.getClassPath( srcFile, ClassPath.EXECUTE ); if (ecp!=null) {
String ret = ecp.getResourceName( resFile, separator, bpar); if (ret != null) return ret;
}
ClassPath rcp = ClassPath.getClassPath( resFile, ClassPath.SOURCE ); if (rcp != null) {
String ret = rcp.getResourceName( resFile, separator, bpar); if (ret!=null) return ret;
}
returnnull;
}
}
¤ Dauer der Verarbeitung: 0.26 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.