Mail Archive Home | barracuda-commits List | July 2008 Index
| Date Index --> | Thread Index --> |
Author: alci
Date: 2008-07-21 12:01:29 +0200 (Mon, 21 Jul 2008)
New Revision: 203
Modified:
Barracuda2/trunk/WEB-INF/A_Changes_History.txt
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/BScriptResource.java
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/renderer/html/HTMLScriptResourceRenderer.java
Log:
Fro - fro_071508_1 - Add dependOn method on BScriptResource to allow multiple
dependencies between resources.
The renderer will put each script resource only once and in the same order
they are declared.
Modified: Barracuda2/trunk/WEB-INF/A_Changes_History.txt
===================================================================
--- Barracuda2/trunk/WEB-INF/A_Changes_History.txt 2008-05-27 16:33:35
UTC (rev 202)
+++ Barracuda2/trunk/WEB-INF/A_Changes_History.txt 2008-07-21 10:01:29
UTC (rev 203)
@@ -11,6 +11,9 @@
contributed, make sure you give credit to them here.
----------------------------------------------------------------------------------------------------
+fro_071508_1 - Add dependOn method on BScriptResource to allow multiple
dependencies between resources.
+ The renderer will put each script resource only
once and in the same order they are declared.
+
saw_052708_1 - Add support for setting default behavior in BAction (e.g. via
ObjectRepository) for
disableBackButton and disableFormLocking.
Modified:
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/BScriptResource.java
===================================================================
---
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/BScriptResource.java
2008-05-27 16:33:35 UTC (rev 202)
+++
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/BScriptResource.java
2008-07-21 10:01:29 UTC (rev 203)
@@ -19,6 +19,10 @@
*/
package org.barracudamvc.core.comp;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.log4j.Logger;
import org.barracudamvc.core.comp.renderer.Renderer;
import org.barracudamvc.core.comp.renderer.RendererFactory;
@@ -50,7 +54,9 @@
public static final String JS_SCRIPTING_CHECK =
"/org/barracudamvc/core/scripts/ScriptingCheck.js";
//private vars
- protected String src = null;
+ // fro_071508_1
+ protected List<String> sources = new ArrayList<String>();
+ //protected String src = null;
//--------------- Constructors -------------------------------
/**
@@ -123,8 +129,9 @@
*
* @param isrc the src script that backs this component
*/
+ // fro_071508_1_begin
public BScriptResource setSrc(String isrc) {
- src = isrc;
+ sources.add(isrc);
invalidate();
return this;
}
@@ -134,11 +141,30 @@
*
* @return the src for this particular component
*/
- public String getSrc() {
- return src;
+ public List<String> getSources() {
+ return sources;
}
/**
+ * Add a single dependency for this resource
+ */
+ public void dependsOn(String src) {
+ sources.add(0, src);
+ }
+
+ /**
+ * Add a resource dependency for this resource
+ * Every src in this resource will be rendered before
+ * the component's own src.
+ */
+ public BScriptResource dependsOn(BScriptResource res) {
+ sources.addAll(0, res.getSources());
+ invalidate();
+ return this;
+ }
+ // fro_071508_1_end
+
+ /**
* Render a specific view for the component.
*
* @param view View to be rendered
@@ -165,7 +191,8 @@
* Get a String representation of the component
*/
public String toString() {
- return src;
+ //fro_071508_1
+ return sources.toString();
}
-}
+}
\ No newline at end of file
Modified:
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/renderer/html/HTMLScriptResourceRenderer.java
===================================================================
---
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/renderer/html/HTMLScriptResourceRenderer.java
2008-05-27 16:33:35 UTC (rev 202)
+++
Barracuda2/trunk/WEB-INF/src/org/barracudamvc/core/comp/renderer/html/HTMLScriptResourceRenderer.java
2008-07-21 10:01:29 UTC (rev 203)
@@ -19,6 +19,9 @@
*/
package org.barracudamvc.core.comp.renderer.html;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.log4j.Logger;
import org.barracudamvc.core.comp.BComponent;
import org.barracudamvc.core.comp.BScriptResource;
@@ -56,14 +59,15 @@
super.renderComponent(comp, view, vc);
BScriptResource bsr = (BScriptResource) comp;
- String src = bsr.getSrc();
+ // fro_071508_1_begin
+ List<String> sources = bsr.getSources();
//Shortcircuit rendering if no src to set
- if (src == null) {
+ if (sources.size() < 1) {
logger.warn("Null src, skipping rendering.");
return;
}
-
+ // fro_071508_1_end
Node node = view.getNode();
//find the root
@@ -89,26 +93,43 @@
//now see if we have script elements that match already in place
//(if so, we don't need to do anything)
+ //Also retain the last script element with a source attribute. Will
insert after it.
+ // fro_071508_1_begin
HTMLScriptElement elScript = null;
child = elHead.getFirstChild();
- while (child!=null) {
+ HTMLScriptElement lastSrc = null;
+ List<String> srcList=new ArrayList<String>(sources);
+
+ while (child!=null && !srcList.isEmpty()) {
if (child instanceof HTMLScriptElement) {
HTMLScriptElement scel = (HTMLScriptElement) child;
- if (src.equals(scel.getSrc())) {
- elScript = scel;
- break;
+ if (scel.getSrc() != null && !"".equals(scel.getSrc())) {
+ lastSrc = scel;
}
+ // see if the src already exists
+ for (String source : sources){
+ if (source.equals(scel.getSrc())) {
+ elScript = scel;
+ srcList.remove(source);
+ break;
+ }
+ }
}
child = child.getNextSibling();
}
- //if we don't, create one
- if (elScript==null) {
- elScript = (HTMLScriptElement) doc.createElement("SCRIPT");
- elHead.appendChild(elScript);
- elScript.setType("text/javascript");
- elScript.setSrc(src);
- }
+ //if we don't, create one for each src in sources
+// if (elScript==null) {
+ for (String src : srcList) {
+ elScript = (HTMLScriptElement)
doc.createElement("SCRIPT");
+ // fro_022308_1 make sure script resources are inserted
before scripts themselves
+ elHead.insertBefore(elScript, lastSrc.getNextSibling());
+ elScript.setType("text/javascript");
+ elScript.setSrc(src);
+ lastSrc = elScript;
+ }
+// }
+ // fro_071508_1_end
}
}
\ No newline at end of file
| Date Index --> | Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.