KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > rendering > plugins > GoogleLinkPlugin


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.model.WeblogEntryPlugin;
24
25 import java.text.MessageFormat JavaDoc;
26 import java.util.regex.Pattern JavaDoc;
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 (&quot;I'm feeling
35  * lucky&quot;) 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 WeblogEntryPlugin {
41     private static final String JavaDoc version = "2.1";
42     private static final Pattern JavaDoc pattern = Pattern.compile("google([:!])\"(.*?)\"(?:\\{(.*?)\\})?");
43     private static final MessageFormat JavaDoc linkFormat = new MessageFormat JavaDoc("<a HREF=\"http://www.google.com/search?ie=UTF-8&q={3}\">{2}</a>");
44     private static final MessageFormat JavaDoc luckyLinkFormat = new MessageFormat JavaDoc("<a HREF=\"http://www.google.com/search?ie=UTF-8&q={3}&btnI=on\">{2}</a>");
45
46     private static final Log mLogger = LogFactory.getFactory().getInstance(GoogleLinkPlugin.class);
47
48     public GoogleLinkPlugin() {
49     }
50
51     public String JavaDoc getName() {
52         return "Google Links";
53     }
54
55     public String JavaDoc getDescription() {
56         return "Replace google:&quot;link text&quot;{search text} with a link that performs a google search. With ! instead of :," + "creates a &quot;I\\'m feeling lucky&quot; search. With {search text} omitted, uses link text as the value of the search text.";
57     }
58
59     public String JavaDoc getVersion() {
60         return version;
61     }
62
63     public Pattern JavaDoc getPattern() {
64         return pattern;
65     }
66
67     public MessageFormat JavaDoc getLinkFormat() {
68         return linkFormat;
69     }
70
71     public MessageFormat JavaDoc getLuckyLinkFormat() {
72         return luckyLinkFormat;
73     }
74
75     public Log getLogger() {
76         return mLogger;
77     }
78 }
79
Popular Tags