01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License. For additional information regarding
15: * copyright in this work, please see the NOTICE file in the top level
16: * directory of this distribution.
17: */
18:
19: package org.apache.roller.ui.rendering.plugins;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.apache.roller.business.WeblogEntryPlugin;
24:
25: import java.text.MessageFormat;
26: import java.util.regex.Pattern;
27:
28: /**
29: * Google Link Plugin. This plugin provides a convenient way to write google search links.
30: * <p/>
31: * The plugin will replace strings of the form <code>google:"link text"{search text}</code> with a link that performs a
32: * Google search. The link will have the visible text "link text" and an href for the Google search. You may omit the
33: * <code>{search text}</code> portion, and the link text will be used as the search text. You can also use an
34: * exclamation point (<code>!</code>) instead of the colon (<code>:</code>), to get a lucky ("I'm feeling
35: * lucky") search, which takes the user directly to the highest ranked Google match.
36: *
37: * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
38: * @version 2.1
39: */
40: public class GoogleLinkPlugin extends SearchPluginBase implements
41: WeblogEntryPlugin {
42: private static final String version = "2.1";
43: private static final Pattern pattern = Pattern
44: .compile("google([:!])\"(.*?)\"(?:\\{(.*?)\\})?");
45: private static final MessageFormat linkFormat = new MessageFormat(
46: "<a href=\"http://www.google.com/search?ie=UTF-8&q={3}\">{2}</a>");
47: private static final MessageFormat luckyLinkFormat = new MessageFormat(
48: "<a href=\"http://www.google.com/search?ie=UTF-8&q={3}&btnI=on\">{2}</a>");
49:
50: private static final Log mLogger = LogFactory.getFactory()
51: .getInstance(GoogleLinkPlugin.class);
52:
53: public GoogleLinkPlugin() {
54: }
55:
56: public String getName() {
57: return "Google Links";
58: }
59:
60: public String getDescription() {
61: return "Replace google:"link text"{search text} with a link that performs a google search. With ! instead of :,"
62: + "creates a "I\\'m feeling lucky" search. With {search text} omitted, uses link text as the value of the search text.";
63: }
64:
65: public String getVersion() {
66: return version;
67: }
68:
69: public Pattern getPattern() {
70: return pattern;
71: }
72:
73: public MessageFormat getLinkFormat() {
74: return linkFormat;
75: }
76:
77: public MessageFormat getLuckyLinkFormat() {
78: return luckyLinkFormat;
79: }
80:
81: public Log getLogger() {
82: return mLogger;
83: }
84: }
|