You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by gv...@apache.org on 2005/12/08 06:37:50 UTC
svn commit: r354999 - in /struts/shale/trunk/clay-plugin/src:
java/org/apache/shale/clay/parser/ java/org/apache/shale/clay/utils/
test/org/apache/shale/clay/config/ test/org/apache/shale/clay/parser/
test/org/apache/shale/clay/utils/
Author: gvanmatre
Date: Wed Dec 7 21:37:05 2005
New Revision: 354999
URL: http://svn.apache.org/viewcvs?rev=354999&view=rev
Log:
Changed the clayImport function to handle a missing file. Added test case coverage for case insensitive symbol replacement. Applied fix for Bug# 37821 Reported by Alexandre Poitras.
Modified:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/ClayAmalgam.java
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/ClayAmalgamTestCase.java
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java?rev=354999&r1=354998&r2=354999&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/Parser.java Wed Dec 7 21:37:05 2005
@@ -593,22 +593,36 @@
} else {
// find the node name delimiter
- int e = token.getDocument().indexOf(" ", token.getBeginOffset() + 2);
- // end of token is the delimiter
- if (e == -1 || e >= token.getEndOffset())
- e = (node.isStart() && node.isEnd()) ? (token.getEndOffset() - 2)
- : (token.getEndOffset() - 1);
- // find the start of the node attribute body
- int s = (!node.isStart() && node.isEnd()) ? token.getBeginOffset() + 2
- : token.getBeginOffset() + 1;
-
- // return the full node name
- String nodeName = token.getDocument().substring(s, e);
- // separate the namespace
- e = nodeName.indexOf(':');
- if (e > -1)
- node.setQname(nodeName.substring(0, e));
- node.setName(nodeName.substring(e + 1));
+ //int e = token.getDocument().indexOf(" ", token.getBeginOffset() + 2);
+
+ //calc end of token body
+ int etb = (node.isStart() && node.isEnd()) ? (token.getEndOffset() - 2)
+ : (token.getEndOffset() - 1);
+
+ // find the start of the node attribute body
+ int s = (!node.isStart() && node.isEnd()) ? token.getBeginOffset() + 2
+ : token.getBeginOffset() + 1;
+
+ //look for the first whitespace
+ int e = -1;
+ indexOf: for (int i = s; i < etb; i++) {
+ if (Character.isWhitespace(token.getDocument().charAt(i))) {
+ e = i;
+ break indexOf;
+ }
+ }
+
+ // end of token is the end of body
+ if (e == -1)
+ e = etb;
+
+ // return the full node name
+ String nodeName = token.getDocument().substring(s, e);
+ // separate the namespace
+ e = nodeName.indexOf(':');
+ if (e > -1)
+ node.setQname(nodeName.substring(0, e));
+ node.setName(nodeName.substring(e + 1));
}
}
@@ -627,10 +641,17 @@
// look for attribute in a beginning tag only
if (node.isStart() && !node.isComment()) {
- int s = token.getDocument()
- .indexOf(" ", token.getBeginOffset() + 2);
int e = (node.isStart() && node.isEnd()) ? (token.getEndOffset() - 2)
: (token.getEndOffset() - 1);
+
+ int s = -1;
+ indexOf: for (int i = token.getBeginOffset() + 2; i < e; i++) {
+ if (Character.isWhitespace(token.getDocument().charAt(i))) {
+ s = i;
+ break indexOf;
+ }
+ }
+
if (s > -1 && s < e) {
// find the tokens and load them into the attributes map
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/ClayAmalgam.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/ClayAmalgam.java?rev=354999&r1=354998&r2=354999&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/ClayAmalgam.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/ClayAmalgam.java Wed Dec 7 21:37:05 2005
@@ -249,14 +249,16 @@
InputStream in = null;
try {
in = context.getExternalContext().getResourceAsStream(url);
- int c = 0;
- done: while (true) {
- c = in.read();
- if (c > -1)
- value.append((char) c);
- else
- break done;
-
+ if (in != null) {
+ int c = 0;
+ done: while (true) {
+ c = in.read();
+ if (c > -1)
+ value.append((char) c);
+ else
+ break done;
+
+ }
}
} catch (IOException e) {
throw new RuntimeException(messages.getMessage("invalid.attribute", new Object[] {"url", "clayImport"}));
Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java?rev=354999&r1=354998&r2=354999&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java Wed Dec 7 21:37:05 2005
@@ -714,8 +714,8 @@
assertEquals("command finished", isFinal, true);
assertEquals("value = \"\"", child.getValue(), "");
-
- attr.setValue("@test1, @test1 never @test2; @test1, @test1 till ya @test3"); //test multiple symbols
+ //Case insensitive and reoccurring replacement
+ attr.setValue("@TeSt1, @tEst1 never @test2; @test1, @teSt1 till ya @tesT3"); //test multiple symbols
child = (javax.faces.component.html.HtmlOutputText) facesContext.getApplication().createComponent("javax.faces.HtmlOutputText");
assertNotNull("javax.faces.HtmlOutputText", child);
Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java?rev=354999&r1=354998&r2=354999&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/parser/ParserTestCase.java Wed Dec 7 21:37:05 2005
@@ -539,7 +539,23 @@
assertTrue("Attribute selected exists", node.getAttributes().containsKey("value"));
value = (String) node.getAttributes().get("value");
assertNull("Attribute value", value);
-
+
+ //test tabbed attributes
+ doc.setLength(0);
+ doc.append("<a\thref=\"http://www.acme.com\">\nAcme Company</a>");
+
+ nodes = p.parse(doc);
+ assertTrue("1 root node", nodes.size() == 1);
+
+ node = (Node) nodes.get(0);
+ assertTrue("Node is well-formed", node.isWellFormed());
+
+
+ value = (String) node.getAttributes().get("href");
+ assertEquals("Attribute href", value, "http://www.acme.com");
+
+
+
}
public void testJSPTag() {
Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/ClayAmalgamTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/ClayAmalgamTestCase.java?rev=354999&r1=354998&r2=354999&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/ClayAmalgamTestCase.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/utils/ClayAmalgamTestCase.java Wed Dec 7 21:37:05 2005
@@ -111,6 +111,27 @@
assertEquals("value", attr.getValue(), "<html><head></head><body bgcolor=\"blue\">Hello World</body></html>");
+ //test no file found
+ requestParams = new TreeMap();
+ requestParams.put("url", "/org/apache/shale/clay/utils/notfound.html");
+ externalContext.setRequestParameterMap(requestParams);
+
+ displayElement = new ComponentBean();
+ displayElement.setId("clayImport");
+ displayElement.setComponentType("org.apache.shale.clay.component.Clay");
+ displayElement.setJsfid("clayImport");
+
+ component = application.createComponent("org.apache.shale.clay.component.Clay");
+ component.setId("clayImport");
+ component.getAttributes().put("url","#{param.url}");
+ component.getAttributes().put("escapeXml", Boolean.TRUE.toString());
+
+ clayAmalgam.clayImport(facesContext, component, displayElement);
+ attr = displayElement.getAttribute("value");
+ assertNotNull("value", attr);
+ assertEquals("value", attr.getValue(), "");
+
+
}
//convert an escaped value into a un-escaped outputText
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org