📄 componentconfig.java
字号:
this.classpathInfos.add(classpathInfo);
}
// entity-resource - entityResourceInfos
elementIter = UtilXml.childElementList(ofbizComponentElement, "entity-resource").iterator();
while (elementIter.hasNext()) {
Element curElement = (Element) elementIter.next();
EntityResourceInfo entityResourceInfo = new EntityResourceInfo(this, curElement);
this.entityResourceInfos.add(entityResourceInfo);
}
// service-resource - serviceResourceInfos
elementIter = UtilXml.childElementList(ofbizComponentElement, "service-resource").iterator();
while (elementIter.hasNext()) {
Element curElement = (Element) elementIter.next();
ServiceResourceInfo serviceResourceInfo = new ServiceResourceInfo(this, curElement);
this.serviceResourceInfos.add(serviceResourceInfo);
}
// webapp - webappInfos
elementIter = UtilXml.childElementList(ofbizComponentElement, "webapp").iterator();
while (elementIter.hasNext()) {
Element curElement = (Element) elementIter.next();
WebappInfo webappInfo = new WebappInfo(this, curElement);
this.webappInfos.add(webappInfo);
}
if (Debug.verboseOn()) Debug.logVerbose("Read component config : [" + rootLocation + "]", module);
}
public boolean isFileResource(ResourceInfo resourceInfo) throws ComponentException {
return isFileResourceLoader(resourceInfo.loader);
}
public boolean isFileResourceLoader(String resourceLoaderName) throws ComponentException {
ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos.get(resourceLoaderName);
if (resourceLoaderInfo == null) {
throw new ComponentException("Could not find resource-loader named: " + resourceLoaderName);
}
return "file".equals(resourceLoaderInfo.type) || "component".equals(resourceLoaderInfo.type);
}
public InputStream getStream(String resourceLoaderName, String location) throws ComponentException {
URL url = getURL(resourceLoaderName, location);
try {
return url.openStream();
} catch (java.io.IOException e) {
throw new ComponentException("Error opening resource at location [" + url.toExternalForm() + "]", e);
}
}
public URL getURL(String resourceLoaderName, String location) throws ComponentException {
ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos.get(resourceLoaderName);
if (resourceLoaderInfo == null) {
throw new ComponentException("Could not find resource-loader named: " + resourceLoaderName);
}
if ("component".equals(resourceLoaderInfo.type) || "file".equals(resourceLoaderInfo.type)) {
String fullLocation = getFullLocation(resourceLoaderName, location);
URL fileUrl = UtilURL.fromFilename(fullLocation);
if (fileUrl == null) {
throw new ComponentException("File Resource not found: " + fullLocation);
}
return fileUrl;
} else if ("classpath".equals(resourceLoaderInfo.type)) {
String fullLocation = getFullLocation(resourceLoaderName, location);
URL url = UtilURL.fromResource(fullLocation);
if (url == null) {
throw new ComponentException("Classpath Resource not found: " + fullLocation);
}
return url;
} else if ("url".equals(resourceLoaderInfo.type)) {
String fullLocation = getFullLocation(resourceLoaderName, location);
URL url = null;
try {
url = new URL(fullLocation);
} catch (java.net.MalformedURLException e) {
throw new ComponentException("Error with malformed URL while trying to load URL resource at location [" + fullLocation + "]", e);
}
if (url == null) {
throw new ComponentException("URL Resource not found: " + fullLocation);
}
return url;
} else {
throw new ComponentException("The resource-loader type is not recognized: " + resourceLoaderInfo.type);
}
}
public String getFullLocation(String resourceLoaderName, String location) throws ComponentException {
ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos.get(resourceLoaderName);
if (resourceLoaderInfo == null) {
throw new ComponentException("Could not find resource-loader named: " + resourceLoaderName);
}
StringBuffer buf = new StringBuffer();
// pre-pend component root location if this is a type component resource-loader
if ("component".equals(resourceLoaderInfo.type)) {
buf.append(rootLocation);
}
if (resourceLoaderInfo.prependEnv != null && resourceLoaderInfo.prependEnv.length() > 0) {
String propValue = System.getProperty(resourceLoaderInfo.prependEnv);
if (propValue == null) {
String errMsg = "The Java environment (-Dxxx=yyy) variable with name " + resourceLoaderInfo.prependEnv + " is not set, cannot load resource.";
Debug.logError(errMsg, module);
throw new IllegalArgumentException(errMsg);
}
buf.append(propValue);
}
if (resourceLoaderInfo.prefix != null && resourceLoaderInfo.prefix.length() > 0) {
buf.append(resourceLoaderInfo.prefix);
}
buf.append(location);
return buf.toString();
}
public List getClasspathInfos() {
return classpathInfos;
}
public String getComponentName() {
return componentName;
}
public List getEntityResourceInfos() {
return entityResourceInfos;
}
public String getGlobalName() {
return globalName;
}
public Map getResourceLoaderInfos() {
return resourceLoaderInfos;
}
public String getRootLocation() {
return rootLocation;
}
public List getServiceResourceInfos() {
return serviceResourceInfos;
}
public List getWebappInfos() {
return webappInfos;
}
public static class ResourceLoaderInfo {
public String name;
public String type;
public String prependEnv;
public String prefix;
public ResourceLoaderInfo(Element element) {
this.name = element.getAttribute("name");
this.type = element.getAttribute("type");
this.prependEnv = element.getAttribute("prepend-env");
this.prefix = element.getAttribute("prefix");
}
}
public static class ResourceInfo {
public ComponentConfig componentConfig;
public String loader;
public String location;
public ResourceInfo(ComponentConfig componentConfig, Element element) {
this.componentConfig = componentConfig;
this.loader = element.getAttribute("loader");
this.location = element.getAttribute("location");
}
public ComponentResourceHandler createResourceHandler() {
return new ComponentResourceHandler(componentConfig.getGlobalName(), loader, location);
}
}
public static class ClasspathInfo {
public ComponentConfig componentConfig;
public String type;
public String location;
public ClasspathInfo(ComponentConfig componentConfig, Element element) {
this.componentConfig = componentConfig;
this.type = element.getAttribute("type");
this.location = element.getAttribute("location");
}
}
public static class EntityResourceInfo extends ResourceInfo {
public String type;
public String readerName;
public EntityResourceInfo(ComponentConfig componentConfig, Element element) {
super(componentConfig, element);
this.type = element.getAttribute("type");
this.readerName = element.getAttribute("reader-name");
}
}
public static class ServiceResourceInfo extends ResourceInfo {
public String type;
public ServiceResourceInfo(ComponentConfig componentConfig, Element element) {
super(componentConfig, element);
this.type = element.getAttribute("type");
}
}
public static class WebappInfo {
public ComponentConfig componentConfig;
public List virtualHosts;
public Map initParameters;
public String name;
public String title;
public String server;
public String mountPoint;
public String location;
public String basePermission;
public boolean appBarDisplay;
public WebappInfo(ComponentConfig componentConfig, Element element) {
this.virtualHosts = new LinkedList();
this.initParameters = new HashMap();
this.componentConfig = componentConfig;
this.name = element.getAttribute("name");
this.title = element.getAttribute("title");
this.server = element.getAttribute("server");
this.mountPoint = element.getAttribute("mount-point");
this.location = element.getAttribute("location");
this.basePermission = element.getAttribute("base-permission");
this.appBarDisplay = !"false".equals(element.getAttribute("app-bar-display"));
// default title is name w/ upper-cased first letter
if (UtilValidate.isEmpty(this.title)) {
this.title = Character.toUpperCase(name.charAt(0)) + name.substring(1).toLowerCase();
}
// default mount point is name if none specified
if (UtilValidate.isEmpty(this.mountPoint)) {
this.mountPoint = this.name;
}
// default base permission 'NONE'
if (UtilValidate.isEmpty(this.basePermission)) {
this.basePermission = "NONE";
}
// check the mount point and make sure it is properly formatted
if (!"/".equals(this.mountPoint)) {
if (!this.mountPoint.startsWith("/")) {
this.mountPoint = "/" + this.mountPoint;
}
if (!this.mountPoint.endsWith("/*")) {
if (!this.mountPoint.endsWith("/")) {
this.mountPoint = this.mountPoint + "/";
}
this.mountPoint = this.mountPoint + "*";
}
}
// load the virtual hosts
List virtHostList = UtilXml.childElementList(element, "virtual-host");
if (virtHostList != null && virtHostList.size() > 0) {
Iterator elementIter = virtHostList.iterator();
while (elementIter.hasNext()) {
Element e = (Element) elementIter.next();
virtualHosts.add(e.getAttribute("host-name"));
}
}
// load the init parameters
List initParamList = UtilXml.childElementList(element, "init-param");
if (initParamList != null && initParamList.size() > 0) {
Iterator elementIter = initParamList.iterator();
while (elementIter.hasNext()) {
Element e = (Element) elementIter.next();
this.initParameters.put(e.getAttribute("name"), e.getAttribute("value"));
}
}
}
public String getContextRoot() {
if (mountPoint.endsWith("/*")) {
return mountPoint.substring(0, mountPoint.length() - 2);
}
return mountPoint;
}
public String getBasePermission() {
if (this.basePermission.indexOf('_') != -1) {
return this.basePermission.substring(0, this.basePermission.indexOf('_'));
}
return this.basePermission;
}
public String getTitle() {
return title;
}
public List getVirtualHosts() {
return virtualHosts;
}
public Map getInitParameters() {
return initParameters;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -