details: https://code.openbravo.com/erp/devel/pi/rev/9dc141df1f43
changeset: 16848:9dc141df1f43
user: Iván Perdomo <ivan.perdomo <at> openbravo.com>
date: Fri Jun 15 16:17:10 2012 +0200
summary: Fixes issue 20781: Adds the concept of _application_ to
ComponentResources
- Now a ComponentResource (dynamic, static, style) has a *valid for* list, in
this way we
can reuse the StaticResourcesComponent and StyleResourcesComponents in other
applications like Web POS
- This changeset doesn't introduce a change in behavior. If a request is made
with _appName,
the parameter is used, if not, we check for _mode, and the last case case (no
parameter)
is a classic mode call
- Adds an error handler to index.jsp to get an alert() when you have errors in
some static .js
diffstat:
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
| 1 +
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponent.java
| 27 ++
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponentProvider.java
| 119 ++++++++-
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
| 9 +
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
| 29 +-
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StyleSheetResourceComponent.java
| 13 +-
src/index.jsp
| 13 +-
7 files changed, 164 insertions(+), 47 deletions(-)
diffs (truncated from 429 to 300 lines):
diff -r 382b0838245b -r 9dc141df1f43
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
---
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
Wed Jun 13 10:46:36 2012 +0200
+++
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
Fri Jun 15 16:17:10 2012 +0200
@@ -80,6 +80,7 @@
@Override
public List<ComponentResource> getGlobalComponentResources() {
final List<ComponentResource> globalResources = new
ArrayList<ComponentResource>();
+
globalResources.add(createStaticResource(
"web/org.openbravo.client.application/js/utilities/ob-utilities.js",
true));
globalResources.add(createStaticResource(
diff -r 382b0838245b -r 9dc141df1f43
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponent.java
---
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponent.java
Wed Jun 13 10:46:36 2012 +0200
+++
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponent.java
Fri Jun 15 16:17:10 2012 +0200
@@ -32,6 +32,7 @@
import org.apache.log4j.Logger;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
+import org.openbravo.client.kernel.BaseComponentProvider.ComponentResource;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
@@ -285,4 +286,30 @@
public boolean isInDevelopment() {
return getModule().isInDevelopment();
}
+
+ protected String getApplicationName() {
+
+ final String appName = getParameter(KernelConstants.APP_NAME_PARAMETER);
+
+ if (!appName.equals("")) {
+ return appName;
+ }
+
+ final String appMode = getParameter(KernelConstants.MODE_PARAMETER);
+
+ if (appMode.equals("") ||
appMode.equals(KernelConstants.MODE_PARAMETER_CLASSIC)) {
+ return ComponentResource.APP_CLASSIC;
+ }
+
+ if (appMode.equals(KernelConstants.MODE_PARAMETER_300)) {
+ return ComponentResource.APP_OB3;
+ }
+
+ log4j.error("Couldn't detect the application name in StaticResource call");
+ return "";
+ }
+
+ protected boolean isClassicMode() {
+ return getApplicationName().equals(ComponentResource.APP_CLASSIC);
+ }
}
diff -r 382b0838245b -r 9dc141df1f43
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponentProvider.java
---
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponentProvider.java
Wed Jun 13 10:46:36 2012 +0200
+++
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponentProvider.java
Fri Jun 15 16:17:10 2012 +0200
@@ -19,6 +19,7 @@
package org.openbravo.client.kernel;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -97,31 +98,75 @@
return null;
}
+ protected ComponentResource createComponentResource(ComponentResourceType
type, String path) {
+ final ComponentResource resource = new ComponentResource();
+ resource.setType(type);
+ resource.setPath(path);
+ return resource;
+ }
+
+ protected ComponentResource createComponentResource(ComponentResourceType
type, String path,
+ String validForApp) {
+ final ComponentResource resource = new ComponentResource();
+ resource.setType(type);
+ resource.setPath(path);
+ resource.addValidForApp(validForApp);
+ return resource;
+ }
+
+ protected ComponentResource createComponentResource(ComponentResourceType
type, String path,
+ List<String> validForAppList) {
+ final ComponentResource resource = new ComponentResource();
+ resource.setType(type);
+ resource.setPath(path);
+ resource.setValidForAppList(validForAppList);
+ return resource;
+ }
+
protected ComponentResource createStaticResource(String path, boolean
includeAlsoInClassicMode,
boolean includeInNewUIMode) {
- final ComponentResource componentResource = new ComponentResource();
- componentResource.setType(ComponentResourceType.Static);
- componentResource.setPath(path);
- componentResource.setIncludeAlsoInClassicMode(includeAlsoInClassicMode);
- componentResource.setIncludeInNewUIMode(includeInNewUIMode);
+
+ final ComponentResource componentResource = createComponentResource(
+ ComponentResourceType.Static, path);
+
+ if (includeAlsoInClassicMode) {
+ componentResource.addValidForApp(ComponentResource.APP_CLASSIC);
+ }
+
+ if (includeInNewUIMode) {
+ componentResource.addValidForApp(ComponentResource.APP_OB3);
+ }
+
return componentResource;
}
protected ComponentResource createStaticResource(String path, boolean
includeAlsoInClassicMode) {
- final ComponentResource componentResource = new ComponentResource();
- componentResource.setType(ComponentResourceType.Static);
- componentResource.setPath(path);
- componentResource.setIncludeAlsoInClassicMode(includeAlsoInClassicMode);
+ final ComponentResource componentResource = createComponentResource(
+ ComponentResourceType.Static, path);
+
+ // mimic old behavior *always* include for OB3
+ componentResource.addValidForApp(ComponentResource.APP_OB3);
+
+ if (includeAlsoInClassicMode) {
+ componentResource.addValidForApp(ComponentResource.APP_CLASSIC);
+ }
+
return componentResource;
}
protected ComponentResource createStyleSheetResource(String path,
boolean includeAlsoInClassicMode, boolean includeInNewUIMode) {
- final ComponentResource componentResource = new ComponentResource();
- componentResource.setType(ComponentResourceType.Stylesheet);
- componentResource.setPath(path);
- componentResource.setIncludeAlsoInClassicMode(includeAlsoInClassicMode);
- componentResource.setIncludeInNewUIMode(includeInNewUIMode);
+ final ComponentResource componentResource = createComponentResource(
+ ComponentResourceType.Stylesheet, path);
+
+ if (includeAlsoInClassicMode) {
+ componentResource.addValidForApp(ComponentResource.APP_CLASSIC);
+ }
+
+ if (includeInNewUIMode) {
+ componentResource.addValidForApp(ComponentResource.APP_OB3);
+ }
+
return componentResource;
}
@@ -129,15 +174,20 @@
final ComponentResource componentResource = new ComponentResource();
componentResource.setType(ComponentResourceType.Stylesheet);
componentResource.setPath(path);
- componentResource.setIncludeAlsoInClassicMode(includeAlsoInClassicMode);
+
+ // mimic old behavior *always* include for OB3
+ componentResource.addValidForApp(ComponentResource.APP_OB3);
+
+ if (includeAlsoInClassicMode) {
+ componentResource.addValidForApp(ComponentResource.APP_CLASSIC);
+ }
+
return componentResource;
}
protected ComponentResource createDynamicResource(String path) {
- final ComponentResource componentResource = new ComponentResource();
- componentResource.setType(ComponentResourceType.Dynamic);
- componentResource.setPath(path);
- componentResource.setIncludeAlsoInClassicMode(false);
+ final ComponentResource componentResource = createComponentResource(
+ ComponentResourceType.Dynamic, path, ComponentResource.APP_OB3);
return componentResource;
}
@@ -165,11 +215,22 @@
Static, Dynamic, Stylesheet
}
+ public static final String APP_OB3 = "OB3";
+ public static final String APP_CLASSIC = "CLASSIC";
+ public static final List<String> ALL_CORE_APPS = Arrays.asList(new
String[] { APP_OB3,
+ APP_CLASSIC });
+
private ComponentResourceType type;
private String path;
+
+ @Deprecated
private boolean includeAlsoInClassicMode = false;
+
+ @Deprecated
private boolean includeInNewUIMode = true;
+ private List<String> validForAppList = new ArrayList<String>();
+
public ComponentResourceType getType() {
return type;
}
@@ -190,21 +251,41 @@
return type + " " + path;
}
+ @Deprecated
public boolean isIncludeAlsoInClassicMode() {
return includeAlsoInClassicMode;
}
+ @Deprecated
public void setIncludeAlsoInClassicMode(boolean includeAlsoInClassicMode) {
this.includeAlsoInClassicMode = includeAlsoInClassicMode;
}
+ @Deprecated
public boolean isIncludeInNewUIMode() {
return includeInNewUIMode;
}
+ @Deprecated
public void setIncludeInNewUIMode(boolean includeInNewUIMode) {
this.includeInNewUIMode = includeInNewUIMode;
}
+ public List<String> getValidForAppList() {
+ return validForAppList;
+ }
+
+ public void setValidForAppList(List<String> validForAppList) {
+ this.validForAppList = validForAppList;
+ }
+
+ public void addValidForApp(String app) {
+ this.validForAppList.add(app);
+ }
+
+ public boolean isValidForApp(String app) {
+ return this.validForAppList.contains(app);
+ }
+
}
}
diff -r 382b0838245b -r 9dc141df1f43
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
---
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
Wed Jun 13 10:46:36 2012 +0200
+++
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelConstants.java
Fri Jun 15 16:17:10 2012 +0200
@@ -68,6 +68,8 @@
public static final String MODE_PARAMETER_300 = "3.00";
public static final String MODE_PARAMETER_CLASSIC = "classic";
+ public static final String APP_NAME_PARAMETER = "_appName";
+
public static final String STYLE_SHEET_COMPONENT_ID = "StyleSheetResources";
public static final String RESOURCE_COMPONENT_ID = "StaticResources";
public static final String TEST_COMPONENT_ID = "TestResources";
@@ -130,4 +132,11 @@
* Name of dateFormat.sql property in Openbravo.properties.
*/
public static final String DATETIME_SQL_FORMAT_PROPERTY =
"dateTimeFormat.sql";
+
+ /**
+ * Function name used in index.jsp as window.onerror handler. This function
needs to be removed at
+ * the end of StaticResources process
+ */
+ public static final String BOOTSTRAP_ERROR_HANDLER_NAME =
"indexErrorHandler";
+
}
diff -r 382b0838245b -r 9dc141df1f43
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
---
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
Wed Jun 13 10:46:36 2012 +0200
+++
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
Fri Jun 15 16:17:10 2012 +0200
@@ -95,11 +95,7 @@
// directly and not the document.write, see here:
// http://www.codehouse.com/javascript/articles/external/
- final boolean classicMode =
!getParameters().containsKey(KernelConstants.MODE_PARAMETER)
- || !getParameters().get(KernelConstants.MODE_PARAMETER).equals(
- KernelConstants.MODE_PARAMETER_300);
-
- if (!classicMode) {
+ if (isClassicMode()) {
// set in the session that we are looking at the new ui
// note injecting the HttpSession through Weld does not work
// as it will instantiate one of the subclasses of HttpSession
@@ -113,7 +109,7 @@
final String scriptPath = getContextUrl() + GEN_TARGET_LOCATION + "/"
+ getStaticResourceFileName() + ".js";
- if (classicMode) {
+ if (isClassicMode()) {
result.append("document.write(\"<LINK rel='stylesheet' type='text/css'
href='"
+ getContextUrl()
+
"org.openbravo.client.kernel/OBCLKER_Kernel/StyleSheetResources?_skinVersion="
@@ -156,10 +152,6 @@
KernelConstants.SERVLET_CONTEXT);
final StringBuffer sb = new StringBuffer();
- final boolean classicMode =
!getParameters().containsKey(KernelConstants.MODE_PARAMETER)
- || !getParameters().get(KernelConstants.MODE_PARAMETER).equals(
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits