giacomo 00/10/30 10:40:50
Modified: src/org/apache/cocoon/selection Tag: xml-cocoon2
BrowserSelectorFactory.java
Log:
Reimplemented the usage of it's configuration. Because of some bugs in the
Xercex/Xalan/XSP engines it could not be tested at the moment
Revision Changes Path
No revision
No revision
1.1.2.9 +31 -5
xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java
Index: BrowserSelectorFactory.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/selection/Attic/BrowserSelectorFactory.java,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -r1.1.2.8 -r1.1.2.9
--- BrowserSelectorFactory.java 2000/10/25 16:02:18 1.1.2.8
+++ BrowserSelectorFactory.java 2000/10/30 18:40:48 1.1.2.9
@@ -26,7 +26,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.1.2.8 $ $Date: 2000/10/25 16:02:18 $
+ * @version CVS $Revision: 1.1.2.9 $ $Date: 2000/10/30 18:40:48 $
*/
@@ -34,12 +34,38 @@
public String generateParameterSource (DocumentFragment conf)
throws ConfigurationException {
- return "String";
+ return "String []";
}
public String generateClassSource (String test, String prefix,
DocumentFragment conf)
throws ConfigurationException {
- return "\nstatic String " + prefix + "_expr = \"" + test + "\";\n";
+ TreeWalker tw = new TreeWalkerImpl (conf, NodeFilter.SHOW_ALL, null,
false);
+ Node node = null;
+ Node nodeattrname = null;
+ Node nodeattruseragent = null;
+ NamedNodeMap nm = null;
+ int cnt = 0;
+ StringBuffer sb = new StringBuffer();
+ sb.append("static String [] ")
+ .append(prefix)
+ .append("_expr = {");
+ while ((node = tw.nextNode()) != null) {
+ if (node.getNodeName().equals("browser") &&
+ node.getNodeType() == Node.ELEMENT_NODE) {
+ nm = node.getAttributes();
+ if (nm != null) {
+ nodeattrname = nm.getNamedItem("name");
+ nodeattruseragent = nm.getNamedItem("useragent");
+ if (nodeattrname != null && nodeattruseragent != null
+ && nodeattrname.getNodeValue().equals(test)) {
+ sb.append(cnt==0 ? "\"" : ",\"")
+ .append(nodeattruseragent.getNodeValue())
+ .append("\"");
+ }
+ }
+ }
+ }
+ return sb.append("};").toString();
}
public String generateMethodSource (DocumentFragment conf)
@@ -51,8 +77,8 @@
NamedNodeMap nm = null;
StringBuffer sb = new StringBuffer();
- sb.append("if (pattern != null && objectModel.get(\"request\") !=
null) {")
- .append("javax.servlet.http.HttpServletRequest request =
(javax.servlet.http.HttpServletRequest) objectModel.get(\"request\");")
+ sb.append("if (pattern != null &&
objectModel.get(Cocoon.REQUEST_OBJECT) != null) {")
+ .append("javax.servlet.http.HttpServletRequest request =
(javax.servlet.http.HttpServletRequest)
objectModel.get(Cocoon.REQUEST_OBJECT);")
.append("String userAgent = request.getHeader(\"User-Agent\");")
.append("if (userAgent.indexOf(pattern) != -1) return true;");
return sb.append("} return false;").toString();