Author: magnuse
Date: 2006-04-28 16:20:24 +0200 (Fri, 28 Apr 2006)
New Revision: 2825
Added:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/XmlEscapeDirective.java
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
Log:
New directive for escaping xml.
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
2006-04-28 12:25:33 UTC (rev 2824)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
2006-04-28 14:20:24 UTC (rev 2825)
@@ -90,7 +90,7 @@
engine.setProperty(SearchConstants.PUBLISH_SYSTEM_HOST,
props.getProperty(SearchConstants.PUBLISH_SYSTEM_HOST));
engine.setProperty("input.encoding", "UTF-8");
engine.setProperty("output.encoding", "UTF-8");
- engine.setProperty("userdirective",
"no.schibstedsok.front.searchportal.velocity.UrlEncodeDirective,no.schibstedsok.front.searchportal.velocity.HtmlEscapeDirective,no.schibstedsok.front.searchportal.velocity.CapitalizeWordsDirective,no.schibstedsok.front.searchportal.velocity.ChopStringDirective,no.schibstedsok.front.searchportal.velocity.PublishDirective,no.schibstedsok.front.searchportal.velocity.AccountingDirective,no.schibstedsok.front.searchportal.velocity.RolesDirective");
+ engine.setProperty("userdirective",
"no.schibstedsok.front.searchportal.velocity.UrlEncodeDirective,no.schibstedsok.front.searchportal.velocity.HtmlEscapeDirective,no.schibstedsok.front.searchportal.velocity.CapitalizeWordsDirective,no.schibstedsok.front.searchportal.velocity.ChopStringDirective,no.schibstedsok.front.searchportal.velocity.PublishDirective,no.schibstedsok.front.searchportal.velocity.AccountingDirective,no.schibstedsok.front.searchportal.velocity.RolesDirective,no.schibstedsok.front.searchportal.velocity.XmlEscapeDirective");
engine.init();
} catch (Exception e) {
Added:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/XmlEscapeDirective.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/XmlEscapeDirective.java
(rev 0)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/XmlEscapeDirective.java
2006-04-28 14:20:24 UTC (rev 2825)
@@ -0,0 +1,72 @@
+/*
+ * XmlEscapeDirective.java
+ *
+ * Created on April 28, 2006, 2:49 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+package no.schibstedsok.front.searchportal.velocity;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.directive.Directive;
+import org.apache.velocity.runtime.parser.Token;
+import org.apache.velocity.runtime.parser.node.Node;
+
+/**
+ *
+ * @author maek
+ */
+public class XmlEscapeDirective extends Directive {
+
+ private static final String NAME = "xmlescape";
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public int getType() {
+ return LINE;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public String getName() {
+ return NAME;
+ }
+
+ /**
+ * [EMAIL PROTECTED]
+ */
+ public boolean render(final InternalContextAdapter context, final Writer
writer, final Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException {
+ if (node.jjtGetNumChildren() != 1) {
+ rsvc.error("#" + getName() + " - wrong number of arguments");
+ return false;
+ }
+
+ if (node.jjtGetChild(0).value(context) != null) {
+
+ final String input = node.jjtGetChild(0).value(context).toString();
+
+ if (input != null) {
+ writer.write(StringEscapeUtils.escapeXml(input));
+ }
+
+ final Token lastToken = node.getLastToken();
+
+ if (lastToken.image.endsWith("\n")) {
+ writer.write("\n");
+ }
+
+ }
+ return true;
+ }
+}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits