File Source: GoogleLinkPlugin.java
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.weblogger.business.plugins.entry;
20
21 import org.apache.roller.weblogger.business.plugins.entry.SearchPluginBase;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.roller.weblogger.business.plugins.entry.WeblogEntryPlugin;
25
26 import java.text.MessageFormat;
27 import java.util.regex.Pattern;
28
29 /**
30 * Google Link Plugin. This plugin provides a convenient way to write google search links.
31 * <p/>
32 * The plugin will replace strings of the form <code>google:"link text"{search text}</code> with a link that performs a
33 * Google search. The link will have the visible text "link text" and an href for the Google search. You may omit the
34 * <code>{search text}</code> portion, and the link text will be used as the search text. You can also use an
35 * exclamation point (<code>!</code>) instead of the colon (<code>:</code>), to get a lucky ("I'm feeling
36 * lucky") search, which takes the user directly to the highest ranked Google match.
37 *
38 * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
39 * @version 2.1
40 */
41 public class GoogleLinkPlugin extends SearchPluginBase implements WeblogEntryPlugin {
42 private static final String version = "2.1";
/*
P/P * Method: org.apache.roller.weblogger.business.plugins.entry.GoogleLinkPlugin__static_init
*
* Presumptions:
* org.apache.commons.logging.LogFactory:getFactory(...)@47 != null
*
* Postconditions:
* linkFormat == &new MessageFormat(GoogleLinkPlugin__static_init#1)
* luckyLinkFormat == &new MessageFormat(GoogleLinkPlugin__static_init#2)
* init'ed(mLogger)
* init'ed(pattern)
* new MessageFormat(GoogleLinkPlugin__static_init#1) num objects == 1
* new MessageFormat(GoogleLinkPlugin__static_init#2) num objects == 1
*/
43 private static final Pattern pattern = Pattern.compile("google([:!])\"(.*?)\"(?:\\{(.*?)\\})?");
44 private static final MessageFormat linkFormat = new MessageFormat("<a href=\"http://www.google.com/search?ie=UTF-8&q={3}\">{2}</a>");
45 private static final MessageFormat luckyLinkFormat = new MessageFormat("<a href=\"http://www.google.com/search?ie=UTF-8&q={3}&btnI=on\">{2}</a>");
46
47 private static final Log mLogger = LogFactory.getFactory().getInstance(GoogleLinkPlugin.class);
48
/*
P/P * Method: void org.apache.roller.weblogger.business.plugins.entry.GoogleLinkPlugin()
*
* Postconditions:
* this.baseVersion == &"2.1"
* init'ed(this.mLogger)
*/
49 public GoogleLinkPlugin() {
50 }
51
52 public String getName() {
/*
P/P * Method: String getName()
*
* Postconditions:
* return_value == &"Google Links"
*/
53 return "Google Links";
54 }
55
56 public String getDescription() {
/*
P/P * Method: String getDescription()
*
* Postconditions:
* return_value == &"Replace google:&quot;link text&quot;{search text} with a link that per ... {search text} omitted, uses link text as the value of the search text."
*/
57 return "Replace google:"link text"{search text} with a link that performs a google search. With ! instead of :," + "creates a "I\\'m feeling lucky" search. With {search text} omitted, uses link text as the value of the search text.";
58 }
59
60 public String getVersion() {
/*
P/P * Method: String getVersion()
*
* Postconditions:
* return_value == &"2.1"
*/
61 return version;
62 }
63
64 public Pattern getPattern() {
/*
P/P * Method: Pattern getPattern()
*
* Postconditions:
* init'ed(return_value)
*/
65 return pattern;
66 }
67
68 public MessageFormat getLinkFormat() {
/*
P/P * Method: MessageFormat getLinkFormat()
*
* Postconditions:
* return_value == &new MessageFormat(GoogleLinkPlugin__static_init#1)
*/
69 return linkFormat;
70 }
71
72 public MessageFormat getLuckyLinkFormat() {
/*
P/P * Method: MessageFormat getLuckyLinkFormat()
*
* Postconditions:
* return_value == &new MessageFormat(GoogleLinkPlugin__static_init#2)
*/
73 return luckyLinkFormat;
74 }
75
76 public Log getLogger() {
/*
P/P * Method: Log getLogger()
*
* Postconditions:
* init'ed(return_value)
*/
77 return mLogger;
78 }
79 }
SofCheck Inspector Build Version : 2.18479
| GoogleLinkPlugin.java |
2009-Jan-02 14:24:58 |
| GoogleLinkPlugin.class |
2009-Sep-04 03:12:32 |