Author: ssmiweve Date: 2008-06-02 16:35:28 +0200 (Mon, 02 Jun 2008) New Revision: 6648
Added: trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java Modified: trunk/ trunk/generic.sesam/war/src/main/conf/configuration.properties trunk/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java Log: Merged revisions 6646-6647 via svnmerge from http://sesat.no/svn/sesat-kernel/branches/2.17 ........ r6647 | ssmiweve | 2008-06-02 16:04:22 +0200 (Mon, 02 Jun 2008) | 3 lines 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. ........ Property changes on: trunk ___________________________________________________________________ Name: svnmerge-integrated - /branches/2.10:1-4690,4692-4745 /branches/2.11:1-4933 /branches/2.12:1-5051,5053-5106 /branches/2.13:1-5378 /branches/2.14:1-5508 /branches/2.15:1-5995 /branches/2.16:1-6499 /branches/2.17:1-6645 /branches/2.6:1-3877 /branches/2.7:1-4160 /branches/2.8:1-4446 /branches/2.9:1-4626 /branches/MAP_SEARCHv2:1-4544 + /branches/2.10:1-4690,4692-4745 /branches/2.11:1-4933 /branches/2.12:1-5051,5053-5106 /branches/2.13:1-5378 /branches/2.14:1-5508 /branches/2.15:1-5995 /branches/2.16:1-6499 /branches/2.17:1-6647 /branches/2.6:1-3877 /branches/2.7:1-4160 /branches/2.8:1-4446 /branches/2.9:1-4626 /branches/MAP_SEARCHv2:1-4544 Copied: trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java (from rev 6647, branches/2.17/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java) =================================================================== --- trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java (rev 0) +++ trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/AllParametersDirective.java 2008-06-02 14:35:28 UTC (rev 6648) @@ -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; + } +} Modified: trunk/generic.sesam/war/src/main/conf/configuration.properties =================================================================== --- trunk/generic.sesam/war/src/main/conf/configuration.properties 2008-06-02 14:04:22 UTC (rev 6647) +++ trunk/generic.sesam/war/src/main/conf/configuration.properties 2008-06-02 14:35:28 UTC (rev 6648) @@ -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: trunk/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java =================================================================== --- trunk/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java 2008-06-02 14:04:22 UTC (rev 6647) +++ trunk/war/src/main/java/no/sesat/search/http/filters/DataModelFilter.java 2008-06-02 14:35:28 UTC (rev 6648) @@ -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 @@ -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){ _______________________________________________ Kernel-commits mailing list [email protected] http://sesat.no/mailman/listinfo/kernel-commits
