Author: ssmiweve
Date: 2008-06-02 16:04:22 +0200 (Mon, 02 Jun 2008)
New Revision: 6647
Added:
branches/2.17/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java
Modified:
branches/2.17/generic.sesam/war/src/main/conf/configuration.properties
branches/2.17/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java
Log:
Issue SKER4760: (Replace usages of ${request.requestURL} in velocity templates
with AllParametersDirective)
small part applied to 2.17 to fix reload bug when URL comes in ISO encoded.
Added:
branches/2.17/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java
===================================================================
---
branches/2.17/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java
(rev 0)
+++
branches/2.17/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java
2008-06-02 14:04:22 UTC (rev 6647)
@@ -0,0 +1,84 @@
+/* Copyright (2008) Schibsted Søk AS
+ * This file is part of SESAT.
+ *
+ * SESAT is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SESAT is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package no.sesat.search.view.velocity;
+
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.runtime.parser.node.Node;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.log4j.Logger;
+
+import java.io.Writer;
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import java.util.Map;
+import no.sesat.search.datamodel.generic.StringDataObject;
+import no.sesat.search.result.HitCount;
+import no.sesat.search.result.ResultList;
+
+/** Very simple directive to loop through all parameters as defined in the
datamodel and write them out in one line.
+ * Resulting output assured to be UTF8 url encoded.
+ *
+ *
+ * Finishes with a trailing & (ampersand)
+ *
+ * http://sesat.no/scarab/issues/id/SKER4760
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Mick</a>
+ * @version $Id$
+ */
+public final class AllParametersDirective extends AbstractDirective {
+
+ private static final Logger LOG =
Logger.getLogger(AllParametersDirective.class);
+
+ private static final String NAME = "allParameters";
+ private static final String ERR_MISSING_ARG = "#{0} - missing or invalid
argument at {1}:{2},{3}";
+
+ public String getName() {
+ return NAME;
+ }
+
+ public int getType() {
+ return LINE;
+ }
+
+ public boolean render(final InternalContextAdapter cxt, final Writer
writer, final Node node)
+ throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException {
+
+ if (node.jjtGetNumChildren() != 0) {
+
+ LOG.error(MessageFormat.format(
+ ERR_MISSING_ARG, getName(), cxt.getCurrentTemplateName(),
node.getLine(), node.getColumn()));
+ return false;
+ }
+
+ for(Map.Entry<String,StringDataObject> entry :
getDataModel(cxt).getParameters().getValues().entrySet()){
+
+ final String key = entry.getKey();
+ // only include url parameters. currently private detail to
DataModelFilter.updateDataModelForRequest(..)
+ if(getDataModel(cxt).getParameters().getValues().containsKey(key +
"-isUrl")){
+ final String value = entry.getValue().getUtf8UrlEncoded();
+ writer.append(key + '=' + value + '&');
+ }
+ }
+
+ return true;
+ }
+}
Property changes on:
branches/2.17/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: branches/2.17/generic.sesam/war/src/main/conf/configuration.properties
===================================================================
--- branches/2.17/generic.sesam/war/src/main/conf/configuration.properties
2008-05-30 09:22:05 UTC (rev 6646)
+++ branches/2.17/generic.sesam/war/src/main/conf/configuration.properties
2008-06-02 14:04:22 UTC (rev 6647)
@@ -8,7 +8,7 @@
sesam.datamodel.impl=no.sesat.search.datamodel.DataModelFactoryImpl
# Velocity Directives
-velocity.directives.0=no.sesat.search.view.velocity.UrlEncodeDirective,no.sesat.search.view.velocity.HtmlEscapeDirective,no.sesat.search.view.velocity.CapitalizeWordsDirective,no.sesat.search.view.velocity.ChopStringDirective,no.sesat.search.view.velocity.PublishDirective,no.sesat.search.view.velocity.XmlEscapeDirective,no.sesat.search.view.velocity.MailEncodeDirective,no.sesat.search.view.velocity.WikiDirective,no.sesat.search.view.velocity.UpperCaseDirective,no.sesat.search.view.velocity.WeekdayDirective,no.sesat.search.view.velocity.MD5ParameterDirective,no.sesat.search.view.velocity.TopDomainDirective,no.sesat.search.view.velocity.DateFormattingDirective,no.sesat.search.view.velocity.BoldWordDirective,no.sesat.search.view.velocity.RemovePrefixDirective,no.sesat.search.view.velocity.SlashTrimStringDirective,no.sesat.search.view.velocity.XPathDirective,no.sesat.search.view.velocity.XPathForeachDirective,no.sesat.search.view.velocity.HitCountDirective,no.sesat.search.view.velocity.CssDirective,no.sesat.search.view.velocity.JavaScriptDirective,no.sesat.search.view.velocity.ImageDirective
+velocity.directives.0=no.sesat.search.view.velocity.UrlEncodeDirective,no.sesat.search.view.velocity.HtmlEscapeDirective,no.sesat.search.view.velocity.CapitalizeWordsDirective,no.sesat.search.view.velocity.ChopStringDirective,no.sesat.search.view.velocity.PublishDirective,no.sesat.search.view.velocity.XmlEscapeDirective,no.sesat.search.view.velocity.MailEncodeDirective,no.sesat.search.view.velocity.WikiDirective,no.sesat.search.view.velocity.UpperCaseDirective,no.sesat.search.view.velocity.WeekdayDirective,no.sesat.search.view.velocity.MD5ParameterDirective,no.sesat.search.view.velocity.TopDomainDirective,no.sesat.search.view.velocity.DateFormattingDirective,no.sesat.search.view.velocity.BoldWordDirective,no.sesat.search.view.velocity.RemovePrefixDirective,no.sesat.search.view.velocity.SlashTrimStringDirective,no.sesat.search.view.velocity.XPathDirective,no.sesat.search.view.velocity.XPathForeachDirective,no.sesat.search.view.velocity.HitCountDirective,no.sesat.search.view.velocity.CssDirective,no.sesat.search.view.velocity.JavaScriptDirective,no.sesat.search.view.velocity.ImageDirective,no.sesat.search.view.velocity.AllParametersDirective
[EMAIL PROTECTED]@
Modified:
branches/2.17/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java
===================================================================
---
branches/2.17/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java
2008-05-30 09:22:05 UTC (rev 6646)
+++
branches/2.17/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java
2008-06-02 14:04:22 UTC (rev 6647)
@@ -1,4 +1,4 @@
-/* Copyright (2006-2007) Schibsted Søk AS
+/* Copyright (2006-2008) Schibsted Søk AS
* This file is part of SESAT.
* SESAT is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
by
@@ -237,7 +237,7 @@
}
private static SiteDataObject getSiteDO(
- final ServletRequest request,
+ final ServletRequest request,
final DataModelFactory factory,
final DataModel datamodel) {
@@ -251,7 +251,9 @@
new DataObject.Property("siteConfiguration", siteConf));
}
- /** Update the request elements in the datamodel. **/
+ /** Update the request elements in the datamodel.
+ * TODO public documentation on "-isUrl" and "-isCookie" parameter key
suffixes.
+ **/
private static ParametersDataObject updateDataModelForRequest(
final DataModelFactory factory,
final DataModel datamodel,
@@ -269,15 +271,29 @@
StringDataObject.class,
datamodel,
new DataObject.Property("string",
getParameterSafely(request, key))));
+
+ // meta-data noting this is a parameter from the url
+ values.put(key + "-isUrl", factory.instantiate(
+ StringDataObject.class,
+ datamodel,
+ new DataObject.Property("string", "true")));
}
// Adding all cookies into parameters.
if (null != request.getCookies()) {
for (Cookie cookie : request.getCookies()) {
+
+ // the cookie key-value
values.put(cookie.getName(), factory.instantiate(
StringDataObject.class,
datamodel,
new DataObject.Property("string",
cookie.getValue())));
+
+ // meta-data noting this is a parameter from cookie
+ values.put(cookie.getName() + "-isCookie",
factory.instantiate(
+ StringDataObject.class,
+ datamodel,
+ new DataObject.Property("string", "true")));
}
}
}catch(Exception e){
@@ -300,7 +316,7 @@
private static void cleanDataModel(final DataModelFactory factory, final
DataModel datamodel){
if(null != datamodel.getPage() && null !=
datamodel.getPage().getCurrentTab()){
-
+
final SearchTab.Scope scope =
datamodel.getPage().getCurrentTab().getScope();
// we need to reset control level so to be able to unset
properties in it.
factory.assignControlLevel(datamodel,
ControlLevel.DATA_MODEL_CONSTRUCTION);
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits