Author: ssmiweve
Date: 2008-03-12 00:10:44 +0100 (Wed, 12 Mar 2008)
New Revision: 6244
Added:
branches/2.16/result-spi/src/main/java/no/sesat/search/result/HitCount.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java
Modified:
branches/2.16/generic.sesam/velocity-directives/pom.xml
branches/2.16/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java
branches/2.16/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java
branches/2.16/war/src/main/webapp/WEB-INF/SearchPortal.tld
Log:
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.
Modified: branches/2.16/generic.sesam/velocity-directives/pom.xml
===================================================================
--- branches/2.16/generic.sesam/velocity-directives/pom.xml 2008-03-11
21:35:46 UTC (rev 6243)
+++ branches/2.16/generic.sesam/velocity-directives/pom.xml 2008-03-11
23:10:44 UTC (rev 6244)
@@ -55,7 +55,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <!-- XXX temporary -->
<groupId>sesat</groupId>
<artifactId>sesat-result-spi</artifactId>
<version>${version}</version>
Modified:
branches/2.16/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java
===================================================================
---
branches/2.16/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java
2008-03-11 21:35:46 UTC (rev 6243)
+++
branches/2.16/generic.sesam/velocity-directives/src/main/java/no/sesat/search/view/velocity/HitCountDirective.java
2008-03-11 23:10:44 UTC (rev 6244)
@@ -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;
}
Added:
branches/2.16/result-spi/src/main/java/no/sesat/search/result/HitCount.java
===================================================================
--- branches/2.16/result-spi/src/main/java/no/sesat/search/result/HitCount.java
(rev 0)
+++ branches/2.16/result-spi/src/main/java/no/sesat/search/result/HitCount.java
2008-03-11 23:10:44 UTC (rev 6244)
@@ -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 -------------------------------------------------
+
+
+
+}
Property changes on:
branches/2.16/result-spi/src/main/java/no/sesat/search/result/HitCount.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
branches/2.16/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java
===================================================================
---
branches/2.16/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java
2008-03-11 21:35:46 UTC (rev 6243)
+++
branches/2.16/site-spi/src/main/java/no/sesat/search/site/config/TextMessages.java
2008-03-11 23:10:44 UTC (rev 6244)
@@ -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:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java
2008-03-11 21:35:46 UTC (rev 6243)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/BoomerangTag.java
2008-03-11 23:10:44 UTC (rev 6244)
@@ -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
*/
Added:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java
(rev 0)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java
2008-03-11 23:10:44 UTC (rev 6244)
@@ -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
Property changes on:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/HitCountTag.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java
===================================================================
---
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java
2008-03-11 21:35:46 UTC (rev 6243)
+++
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java
2008-03-11 23:10:44 UTC (rev 6244)
@@ -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:
branches/2.16/war/src/main/java/no/sesat/search/view/taglib/TextMessageTag.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: branches/2.16/war/src/main/webapp/WEB-INF/SearchPortal.tld
===================================================================
--- branches/2.16/war/src/main/webapp/WEB-INF/SearchPortal.tld 2008-03-11
21:35:46 UTC (rev 6243)
+++ branches/2.16/war/src/main/webapp/WEB-INF/SearchPortal.tld 2008-03-11
23:10:44 UTC (rev 6244)
@@ -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