Author: magnuse
Date: 2006-04-04 18:00:03 +0200 (Tue, 04 Apr 2006)
New Revision: 2706
Added:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/package.html
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/CapitalizeWordsDirective.java
trunk/src/java/no/schibstedsok/front/searchportal/velocity/ChopStringDirective.java
trunk/src/java/no/schibstedsok/front/searchportal/velocity/HtmlEscapeDirective.java
trunk/src/java/no/schibstedsok/front/searchportal/velocity/PublishDirective.java
trunk/src/java/no/schibstedsok/front/searchportal/velocity/URLVelocityTemplateLoader.java
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlDecodeDirective.java
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlEncodeDirective.java
Log:
Therapy work. Checkstyling of sources.
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/CapitalizeWordsDirective.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/CapitalizeWordsDirective.java
2006-04-04 15:06:37 UTC (rev 2705)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/CapitalizeWordsDirective.java
2006-04-04 16:00:03 UTC (rev 2706)
@@ -32,59 +32,45 @@
*
* @author thomas
*/
-public class CapitalizeWordsDirective extends Directive {
-
+public final class CapitalizeWordsDirective extends Directive {
+
private static transient Log log =
LogFactory.getLog(CapitalizeWordsDirective.class);
-
private static final String NAME = "capitalizeWords";
-
- /**
- * returns the name of the directive.
- *
- * @return the name of the directive.
+
+ /**
+ * [EMAIL PROTECTED]
*/
public String getName() {
return NAME;
}
-
- /**
- * returns the type of the directive. The type is LINE.
- * @return The type == LINE
+
+ /**
+ * [EMAIL PROTECTED]
*/
public int getType() {
return LINE;
}
-
- /**
- * Renders the capitalized word(s).
- *
- * @param context
- * @param writer
- * @param node
- *
- * @throws java.io.IOException
- * @throws org.apache.velocity.exception.ResourceNotFoundException
- * @throws org.apache.velocity.exception.ParseErrorException
- * @throws org.apache.velocity.exception.MethodInvocationException
- * @return the encoded string.
+
+ /**
+ * [EMAIL PROTECTED]
*/
- public boolean render(InternalContextAdapter context, Writer writer, Node
node) throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException {
+ 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;
}
-
- String s = node.jjtGetChild(0).value(context).toString();
-
- writer.write(WordUtils.capitalize(s));
- Token lastToken = node.getLastToken();
-
+ final String input = node.jjtGetChild(0).value(context).toString();
+
+ writer.write(WordUtils.capitalize(input));
+
+ final Token lastToken = node.getLastToken();
+
if (lastToken.image.endsWith("\n")) {
writer.write("\n");
}
-
+
return true;
}
}
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/ChopStringDirective.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/ChopStringDirective.java
2006-04-04 15:06:37 UTC (rev 2705)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/ChopStringDirective.java
2006-04-04 16:00:03 UTC (rev 2706)
@@ -1,19 +1,19 @@
package no.schibstedsok.front.searchportal.velocity;
-import org.apache.velocity.runtime.directive.Directive;
-import org.apache.velocity.runtime.parser.node.Node;
-import org.apache.velocity.runtime.parser.Token;
-import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.WordUtils;
+import java.io.IOException;
import java.io.Writer;
-import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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;
+
/**
*
* A velocity directive to chop a string
@@ -26,64 +26,50 @@
*
* @author thomas
*/
-public class ChopStringDirective extends Directive {
+public final class ChopStringDirective extends Directive {
private static transient Log log =
LogFactory.getLog(ChopStringDirective.class);
-
private static final String NAME = "chopString";
/**
- * returns the name of the directive.
- *
- * @return the name of the directive.
+ * [EMAIL PROTECTED]
*/
public String getName() {
return NAME;
}
- /**
- * returns the type of the directive. The type is LINE.
- * @return The type == LINE
+ /**
+ * [EMAIL PROTECTED]
*/
public int getType() {
return LINE;
}
- /**
- * Renders the capitalized word(s).
- *
- * @param context
- * @param writer
- * @param node
- *
- * @throws java.io.IOException
- * @throws org.apache.velocity.exception.ResourceNotFoundException
- * @throws org.apache.velocity.exception.ParseErrorException
- * @throws org.apache.velocity.exception.MethodInvocationException
- * @return the encoded string.
+ /**
+ * [EMAIL PROTECTED]
*/
- public boolean render(InternalContextAdapter context, Writer writer, Node
node) throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException {
+ public boolean render(final InternalContextAdapter context, final Writer
writer, final Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException {
if (node.jjtGetNumChildren() != 2) {
rsvc.error("#" + getName() + " - wrong number of arguments");
return false;
}
- String s = node.jjtGetChild(0).value(context).toString();
- int length =
Integer.parseInt(node.jjtGetChild(1).value(context).toString());
+ final String s = node.jjtGetChild(0).value(context).toString();
+ final int length =
Integer.parseInt(node.jjtGetChild(1).value(context).toString());
String choppedString = "";
if (s.length() <= length)
choppedString = s;
else {
- String sub = s.substring(0, length);
- String lastChar = Character.toString(sub.charAt(sub.length() - 1));
+ final String sub = s.substring(0, length);
+ final String lastChar = Character.toString(sub.charAt(sub.length()
- 1));
if (lastChar.equals("."))
choppedString = sub.substring(0, length) + "..";
else if (lastChar.equals(" "))
choppedString = sub.substring(0, length) + " ...";
else {
- int lastSpace = sub.lastIndexOf(" ");
+ final int lastSpace = sub.lastIndexOf(" ");
if (lastSpace >= 0) {
choppedString = sub.substring(0, sub.lastIndexOf(" ")) + "
...";
@@ -95,7 +81,7 @@
writer.write(choppedString);
- Token lastToken = node.getLastToken();
+ final Token lastToken = node.getLastToken();
if (lastToken.image.endsWith("\n")) {
writer.write("\n");
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/HtmlEscapeDirective.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/HtmlEscapeDirective.java
2006-04-04 15:06:37 UTC (rev 2705)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/HtmlEscapeDirective.java
2006-04-04 16:00:03 UTC (rev 2706)
@@ -8,6 +8,7 @@
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;
@@ -27,55 +28,43 @@
*
* @author magnuse
*/
-public class HtmlEscapeDirective extends Directive {
-
- private static String NAME = "htmlescape";
-
+public final class HtmlEscapeDirective extends Directive {
+
+ private static final String NAME = "htmlescape";
+
/**
- *
- * @return returns the type of directive. Always returns <code>LINE</code>.
+ * [EMAIL PROTECTED]
*/
public int getType() {
return LINE;
}
-
+
/**
- *
- * @return returns the name of the directive. Always returns 'htmlescape'.
+ * [EMAIL PROTECTED]
*/
public String getName() {
return NAME;
}
-
+
/**
- *
- * Renders the html escaped string.
- *
- * @param context
- * @param writer
- * @param node
- * @throws java.io.IOException
- * @throws org.apache.velocity.exception.ResourceNotFoundException
- * @throws org.apache.velocity.exception.ParseErrorException
- * @throws org.apache.velocity.exception.MethodInvocationException
- * @return
+ * [EMAIL PROTECTED]
*/
- public boolean render(InternalContextAdapter context, Writer writer, Node
node) throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException {
+ 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 argumants");
return false;
}
-
- String s = node.jjtGetChild(0).value(context).toString();
-
- writer.write(StringEscapeUtils.escapeHtml(s));
-
- Token lastToken = node.getLastToken();
-
+
+ final String input = node.jjtGetChild(0).value(context).toString();
+
+ writer.write(StringEscapeUtils.escapeHtml(input));
+
+ final Token lastToken = node.getLastToken();
+
if (lastToken.image.endsWith("\n")) {
writer.write("\n");
}
-
+
return true;
}
}
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/PublishDirective.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/PublishDirective.java
2006-04-04 15:06:37 UTC (rev 2705)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/PublishDirective.java
2006-04-04 16:00:03 UTC (rev 2706)
@@ -43,37 +43,24 @@
private static final String NAME = "publish";
private static final String DEFAULT_CHARSET = "utf-8";
- /**
- * returns the name of the directive.
- *
- * @return the name of the directive.
+ /**
+ * [EMAIL PROTECTED]
*/
public String getName() {
return NAME;
}
- /**
- * returns the type of the directive. The type is LINE.
- * @return The type == LINE
+ /**
+ * [EMAIL PROTECTED]
*/
public int getType() {
return LINE;
}
- /**
- * Renders the publish url.
- *
- * @param context
- * @param writer
- * @param node
- *
- * @throws java.io.IOException
- * @throws org.apache.velocity.exception.ResourceNotFoundException
- * @throws org.apache.velocity.exception.ParseErrorException
- * @throws org.apache.velocity.exception.MethodInvocationException
- * @return the encoded string.
+ /**
+ * [EMAIL PROTECTED]
*/
- public boolean render(InternalContextAdapter context, Writer writer, Node
node) throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException {
+ public boolean render(final InternalContextAdapter context, final Writer
writer, final Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException {
if (node.jjtGetNumChildren() < 2) {
rsvc.error("#" + getName() + " - missing argument");
return false;
@@ -88,7 +75,7 @@
urlConn.addRequestProperty("host", header);
final BufferedReader reader = new BufferedReader(new
InputStreamReader(urlConn.getInputStream()));
- for(String line = reader.readLine();line!=null;line=reader.readLine()){
+ for (String line = reader.readLine(); line != null;
line=reader.readLine()) {
writer.write(line);
writer.write('\n');
}
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/URLVelocityTemplateLoader.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/URLVelocityTemplateLoader.java
2006-04-04 15:06:37 UTC (rev 2705)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/URLVelocityTemplateLoader.java
2006-04-04 16:00:03 UTC (rev 2706)
@@ -1,28 +1,10 @@
package no.schibstedsok.front.searchportal.velocity;
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License")
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
-import java.util.Vector;
import
no.schibstedsok.front.searchportal.configuration.loader.UrlResourceLoader;
import no.schibstedsok.front.searchportal.site.Site;
import org.apache.log4j.Logger;
@@ -44,9 +26,9 @@
*
*
* MODIFIED TO SUIT SCHIBSTEDSØK's NEEDS.
- * There was a choice here to implement all the URL handling stuff from
scratch or to plug into the existing
+ * There was a choice here to implement all the URL handling stuff from
scratch or to plug into the existing
* functionality found in
no.schibstedsøk.front.searchportal.configuration.loader
- * Since this class is hidden between the velocity API it made more sense to
go from scratch to best
+ * Since this class is hidden between the velocity API it made more sense to
go from scratch to best
* meet velocity's requirements...
*
* @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
@@ -55,14 +37,14 @@
public final class URLVelocityTemplateLoader extends ResourceLoader {
private static final Logger LOG =
Logger.getLogger(URLVelocityTemplateLoader.class);
-
+
private static final String ERR_RESOURCE_NOT_FOUND = "Cannot find resource
";
private static final String DEBUG_LOOKING_FOR = "Looking for ";
private static final String DEBUG_EXISTS = "Positive HEAD on ";
private static final String DEBUG_FULL_URL_IS = "Real URL is ";
private static final String DEBUG_HOST_HEADER_IS = "URL's host-header is ";
private static final String DEBUG_DOESNT_EXIST = "Using fallback URL";
-
+
private Site site;
private Site fallbackSite;
@@ -96,9 +78,9 @@
LOG.debug( ERR_RESOURCE_NOT_FOUND + url);
throw new ResourceNotFoundException( ERR_RESOURCE_NOT_FOUND + url
);
}
-
-
+
+
}
/** [EMAIL PROTECTED]
@@ -113,11 +95,11 @@
/** [EMAIL PROTECTED]
*/
public long getLastModified(Resource resource){
-
+
final String url = resource.getName();
LOG.trace("start getLastModified( "+url+" )");
try{
-
+
final URLConnection conn = getResourceURLConnection(url);
return conn.getLastModified();
@@ -125,9 +107,9 @@
LOG.error( ERR_RESOURCE_NOT_FOUND + url );
}
return 0;
-
+
}
-
+
private URLConnection getResourceURLConnection( final String url )
throws ResourceNotFoundException{
@@ -156,17 +138,17 @@
}
return conn;
}
-
+
private String getFallbackURL(final String url){
final String oldUrl = site.getName() + site.getConfigContext();
final String newUrl = fallbackSite.getName() +
fallbackSite.getConfigContext();
-
+
return url.replaceFirst(oldUrl, newUrl);
}
private URLConnection getURLConnection(final String url) throws
IOException{
-
+
LOG.trace(DEBUG_EXISTS + url);
final URL u = new URL( UrlResourceLoader.getURL(url) );
LOG.trace(DEBUG_FULL_URL_IS + u);
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlDecodeDirective.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlDecodeDirective.java
2006-04-04 15:06:37 UTC (rev 2705)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlDecodeDirective.java
2006-04-04 16:00:03 UTC (rev 2706)
@@ -27,44 +27,31 @@
*
* @author thomas
*/
-public class UrlDecodeDirective extends Directive {
+public final class UrlDecodeDirective extends Directive {
private static transient Log log =
LogFactory.getLog(UrlEncodeDirective.class);
-
private static final String NAME = "urldecode";
private static final String DEFAULT_CHARSET = "utf-8";
-
/**
- * @return the name of the directive.
+ * [EMAIL PROTECTED]
*/
public String getName() {
return NAME;
}
/**
- * returns the type of the directive. The type is LINE.
- * @return The type == LINE
+ * [EMAIL PROTECTED]
*/
public int getType() {
return LINE;
}
/**
- * Renders the urlencoded string.
- *
- * @param context
- * @param writer
- * @param node
- *
- * @throws java.io.IOException
- * @throws org.apache.velocity.exception.ResourceNotFoundException
- * @throws org.apache.velocity.exception.ParseErrorException
- * @throws org.apache.velocity.exception.MethodInvocationException
- * @return
+ * [EMAIL PROTECTED]
*/
- public boolean render(InternalContextAdapter context, Writer writer, Node
node) throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException {
+ public boolean render(final InternalContextAdapter context, final Writer
writer, final Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException {
if (node.jjtGetNumChildren() < 1) {
rsvc.error("#" + getName() + " - missing argument");
return false;
@@ -72,15 +59,15 @@
String charset = DEFAULT_CHARSET;
- String s = node.jjtGetChild(0).value(context).toString();
+ final String input = node.jjtGetChild(0).value(context).toString();
if (node.jjtGetNumChildren() == 2) {
charset = node.jjtGetChild(1).value(context).toString();
}
- writer.write(URLDecoder.decode(s, charset));
+ writer.write(URLDecoder.decode(input, charset));
- Token lastToken = node.getLastToken();
+ final Token lastToken = node.getLastToken();
if (lastToken.image.endsWith("\n")) {
writer.write("\n");
Modified:
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlEncodeDirective.java
===================================================================
---
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlEncodeDirective.java
2006-04-04 15:06:37 UTC (rev 2705)
+++
trunk/src/java/no/schibstedsok/front/searchportal/velocity/UrlEncodeDirective.java
2006-04-04 16:00:03 UTC (rev 2706)
@@ -10,6 +10,7 @@
import java.io.IOException;
import java.io.Writer;
import java.net.URLEncoder;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.context.InternalContextAdapter;
@@ -33,66 +34,52 @@
*
* @author magnuse
*/
-public class UrlEncodeDirective extends Directive {
-
+public final class UrlEncodeDirective extends Directive {
+
private static transient Log log =
LogFactory.getLog(UrlEncodeDirective.class);
-
-
+
private static final String NAME = "urlencode";
private static final String DEFAULT_CHARSET = "utf-8";
-
+
/**
- * returns the name of the directive.
- *
- * @return the name of the directive.
+ * [EMAIL PROTECTED]
*/
public String getName() {
return NAME;
}
-
+
/**
- * returns the type of the directive. The type is LINE.
- * @return The type == LINE
+ * [EMAIL PROTECTED]
*/
public int getType() {
return LINE;
}
-
+
/**
- * Renders the urlencoded string.
- *
- * @param context
- * @param writer
- * @param node
- *
- * @throws java.io.IOException
- * @throws org.apache.velocity.exception.ResourceNotFoundException
- * @throws org.apache.velocity.exception.ParseErrorException
- * @throws org.apache.velocity.exception.MethodInvocationException
- * @return the encoded string.
+ * [EMAIL PROTECTED]
*/
- public boolean render(InternalContextAdapter context, Writer writer, Node
node) throws IOException, ResourceNotFoundException, ParseErrorException,
MethodInvocationException {
+ public boolean render(final InternalContextAdapter context, final Writer
writer, final Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException {
if (node.jjtGetNumChildren() < 1) {
rsvc.error("#" + getName() + " - missing argument");
return false;
}
-
+
String charset = DEFAULT_CHARSET;
-
- String s = node.jjtGetChild(0).value(context).toString();
-
+
+ final String input = node.jjtGetChild(0).value(context).toString();
+
if (node.jjtGetNumChildren() == 2) {
charset = node.jjtGetChild(1).value(context).toString();
}
-
- writer.write(URLEncoder.encode(s, charset));
-
- Token lastToken = node.getLastToken();
-
+
+ writer.write(URLEncoder.encode(input, charset));
+
+ final Token lastToken = node.getLastToken();
+
if (lastToken.image.endsWith("\n")) {
writer.write("\n");
}
-
+
return true;
}
}
Added: trunk/src/java/no/schibstedsok/front/searchportal/velocity/package.html
===================================================================
--- trunk/src/java/no/schibstedsok/front/searchportal/velocity/package.html
(rev 0)
+++ trunk/src/java/no/schibstedsok/front/searchportal/velocity/package.html
2006-04-04 16:00:03 UTC (rev 2706)
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!--
+Copyright (2005-2006) Schibsted Søk AS
+-->
+<html>
+<head>
+</head>
+<body bgcolor="white">
+
+Provides for velocity specific stuff such as custom directives.
+
+<h2>Package Specification</h2>
+
+##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
+<!-- Put @see and @since tags down here. -->
+
+</body>
+</html>
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits