Author: ssmiweve Date: 2008-03-12 00:12:45 +0100 (Wed, 12 Mar 2008) New Revision: 6246
Added: trunk/result-spi/src/main/java/no/sesat/search/result/HitCount.java trunk/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java Modified: trunk/ trunk/generic.sesam/velocity-directives/pom.xml trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java trunk/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java trunk/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java trunk/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java trunk/war/src/main/webapp/WEB-INF/SearchPortal.tld Log: Merged revisions 6243-6245 via svnmerge from http://sesat.no/svn/sesat-kernel/branches/2.16 ........ r6244 | ssmiweve | 2008-03-12 00:10:44 +0100 (Wed, 12 Mar 2008) | 3 lines 1) make arg dynamic-attributes in TextMessageTag (arg0=".." arg1=".." arg2=".." etc etc) 2) abstract out the hitcount presentation logic into HitCount, and add a HitCountTag. ........ 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-6242 /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-6245 /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 Modified: trunk/generic.sesam/velocity-directives/pom.xml =================================================================== --- trunk/generic.sesam/velocity-directives/pom.xml 2008-03-11 23:12:09 UTC (rev 6245) +++ trunk/generic.sesam/velocity-directives/pom.xml 2008-03-11 23:12:45 UTC (rev 6246) @@ -55,7 +55,6 @@ <scope>provided</scope> </dependency> <dependency> - <!-- XXX temporary --> <groupId>sesat</groupId> <artifactId>sesat-result-spi</artifactId> <version>${version}</version> Modified: trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java =================================================================== --- trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java 2008-03-11 23:12:09 UTC (rev 6245) +++ trunk/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java 2008-03-11 23:12:45 UTC (rev 6246) @@ -26,10 +26,9 @@ import java.io.Writer; import java.io.IOException; -import java.text.Format; -import java.text.NumberFormat; import java.text.MessageFormat; +import no.sesat.search.result.HitCount; import no.sesat.search.result.ResultList; /** @@ -86,19 +85,7 @@ final ResultList results = (ResultList) getObjectArgument(cxt, node, 0); - switch(results.getHitCount()){ - - case -1: - writer.append('?'); - break; - - default: - final Format formatter - = NumberFormat.getIntegerInstance(getDataModel(cxt).getSite().getSite().getLocale()); - - writer.append(formatter.format(results.getHitCount())); - break; - } + writer.append(HitCount.present(results.getHitCount(), getDataModel(cxt).getSite().getSite().getLocale())); return true; } Copied: trunk/result-spi/src/main/java/no/sesat/search/result/HitCount.java (from rev 6244, branches/2.16/result-spi/src/main/java/no/sesat/search/result/HitCount.java) =================================================================== --- trunk/result-spi/src/main/java/no/sesat/search/result/HitCount.java (rev 0) +++ trunk/result-spi/src/main/java/no/sesat/search/result/HitCount.java 2008-03-11 23:12:45 UTC (rev 6246) @@ -0,0 +1,82 @@ +/* Copyright (2005-2007) Schibsted Søk AS + * This file is part of SESAT. + * You can use, redistribute, and/or modify it, under the terms of the SESAT License. + * You should have received a copy of the SESAT License along with this program. + * If not, see https://dev.sesat.no/confluence/display/SESAT/SESAT+License + * + * 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/>. + * + * HitCount.java + * + * + */ + +package no.sesat.search.result; +import java.text.NumberFormat; +import java.util.Locale; + +/** Utility to present a hit count. + * Transforms negative hit counts into appropriate strings, eg -1 becomes "?". + * + * @version $Id$ + * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a> + */ +public final class HitCount { + + // Constants ----------------------------------------------------- + + // Attributes ---------------------------------------------------- + + // Static -------------------------------------------------------- + + /** + * @param hitcount + * @param locale + * @return presentable version of the hitcount + */ + public static String present(final int hitcount, final Locale locale) { + + + switch(hitcount){ + + case -1: + return "?"; + + default: + return NumberFormat.getIntegerInstance(locale).format(hitcount); + } + } + + // Constructors -------------------------------------------------- + + /** Creates a new instance of HitCount */ + private HitCount(){} + + // Public -------------------------------------------------------- + + // Z implementation ---------------------------------------------- + + // Y overrides --------------------------------------------------- + + // Package protected --------------------------------------------- + + // Protected ----------------------------------------------------- + + // Private ------------------------------------------------------- + + // Inner classes ------------------------------------------------- + + + +} Modified: trunk/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java =================================================================== --- trunk/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java 2008-03-11 23:12:09 UTC (rev 6245) +++ trunk/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java 2008-03-11 23:12:45 UTC (rev 6246) @@ -17,7 +17,6 @@ */ package no.sesat.search.site.config; -import no.sesat.search.site.*; import java.text.MessageFormat; import java.util.HashMap; import java.util.Locale; @@ -57,7 +56,10 @@ private static final String INFO_USING_DEFAULT_LOCALE = " is falling back to the default locale "; /** Find the correct instance handling this Site. - **/ + * + * @param cxt + * @return + */ public static TextMessages valueOf(final Context cxt) { final Site site = cxt.getSite(); @@ -77,6 +79,8 @@ /** * Utility wrapper to the instanceOf(Context). + * @param site + * @return */ public static TextMessages valueOf(final Site site) { Modified: trunk/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java =================================================================== --- trunk/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java 2008-03-11 23:12:09 UTC (rev 6245) +++ trunk/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java 2008-03-11 23:12:45 UTC (rev 6246) @@ -15,7 +15,7 @@ * along with SESAT. If not, see <http://www.gnu.org/licenses/>. * * - * LinkPulseTag.java + * BoomerangTag.java * * Created on May 27, 2006, 5:55 PM */ Copied: trunk/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java (from rev 6244, branches/2.16/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java) =================================================================== --- trunk/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java (rev 0) +++ trunk/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java 2008-03-11 23:12:45 UTC (rev 6246) @@ -0,0 +1,75 @@ +/* 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/>. + * + * + * HitCountTag.java + */ + +package no.sesat.search.view.taglib; + +import java.io.IOException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.JspFragment; +import javax.servlet.jsp.tagext.SimpleTagSupport; +import no.sesat.search.datamodel.DataModel; +import no.sesat.search.result.HitCount; +import no.sesat.search.site.Site; + +/** SimpleTagSupport around the HitCount utility class. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a> + * @version $Id$ + */ +public final class HitCountTag extends SimpleTagSupport { + + private int hitcount; + + /** + * Called by the container to invoke this tag. + * The implementation of this method is provided by the tag library developer, + * and handles all tag processing, body iteration, etc. + * @throws javax.servlet.jsp.JspException + */ + @Override + public void doTag() throws JspException { + + final PageContext cxt = (PageContext) getJspContext(); + final JspWriter out = cxt.getOut(); + + try { + + final JspFragment f = getJspBody(); + if (f != null){ + f.invoke(out); + } + + final DataModel datamodel = (DataModel) cxt.findAttribute(DataModel.KEY); + final Site site = datamodel.getSite().getSite(); + + out.print(HitCount.present(hitcount, site.getLocale())); + + }catch(IOException e){ + throw new JspException(e); + } + + } + + public void setHitcount(int hitcount) { + this.hitcount = hitcount; + } +} \ No newline at end of file Modified: trunk/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java =================================================================== --- trunk/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java 2008-03-11 23:12:09 UTC (rev 6245) +++ trunk/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java 2008-03-11 23:12:45 UTC (rev 6246) @@ -22,22 +22,27 @@ package no.sesat.search.view.taglib; import java.io.IOException; -import javax.servlet.jsp.tagext.*; +import java.util.ArrayList; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.DynamicAttributes; import javax.servlet.jsp.tagext.JspFragment; import javax.servlet.jsp.tagext.SimpleTagSupport; -import no.sesat.search.site.Site; import no.sesat.search.site.config.TextMessages; -/** +/** Wraps functionality found in TextMessages into a custom tag. + * * * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a> * @version $Id$ */ -public final class TextMessageTag extends SimpleTagSupport { +public final class TextMessageTag extends SimpleTagSupport implements DynamicAttributes{ /** * Initialization of key property. @@ -47,12 +52,14 @@ /** * Initialization of args property. */ - private Object args; + private final List<Object> args = new ArrayList<Object>(); /**Called by the container to invoke this tag. * The implementation of this method is provided by the tag library developer, * and handles all tag processing, body iteration, etc. + * @throws javax.servlet.jsp.JspException */ + @Override public void doTag() throws JspException { final PageContext cxt = (PageContext) getJspContext(); @@ -66,7 +73,7 @@ } final TextMessages text = (TextMessages)cxt.findAttribute("text"); - out.print(text.getMessage(key, args)); + out.print(text.getMessage(key, args.toArray())); } catch (IOException ex) { throw new JspException(ex.getMessage()); @@ -76,15 +83,25 @@ /** * Setter for the key attribute. + * @param value */ - public void setKey(String value) { + public void setKey(final String value) { this.key = value; } - /** - * Setter for the args attribute. - */ - public void setArgs(Object value) { - this.args = value; + public void setDynamicAttribute( + final String uri, + final String localName, + final Object value) throws JspException { + + assert localName.startsWith("args") : "Only dynamic attributes of format argX are supported"; + + final int i = Integer.valueOf(localName.replaceAll("arg", "")); + while(args.size() <= i){ + args.add(""); + } + args.set(i, value); } + + } Property changes on: trunk/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/war/src/main/webapp/WEB-INF/SearchPortal.tld =================================================================== --- trunk/war/src/main/webapp/WEB-INF/SearchPortal.tld 2008-03-11 23:12:09 UTC (rev 6245) +++ trunk/war/src/main/webapp/WEB-INF/SearchPortal.tld 2008-03-11 23:12:45 UTC (rev 6246) @@ -79,10 +79,17 @@ <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> </attribute> + <dynamic-attributes>true</dynamic-attributes> + </tag> + <tag> + <name>hitcount</name> + <tag-class>no.sesat.search.view.taglib.HitCountTag</tag-class> + <body-content>empty</body-content> <attribute> - <name>args</name> + <name>hitcount</name> + <required>true</required> <rtexprvalue>true</rtexprvalue> - <type>java.lang.Object</type> + <type>int</type> </attribute> </tag> </taglib> _______________________________________________ Kernel-commits mailing list [email protected] http://sesat.no/mailman/listinfo/kernel-commits
