You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/05/02 00:29:25 UTC
svn commit: r398715 [1/2] - in
/incubator/roller/trunk/contrib/plugins/src/org/apache: ./ roller/
roller/presentation/ roller/presentation/velocity/
roller/presentation/velocity/plugins/
roller/presentation/velocity/plugins/acronyms/ roller/presentatio...
Author: snoopdave
Date: Mon May 1 15:29:19 2006
New Revision: 398715
URL: http://svn.apache.org/viewcvs?rev=398715&view=rev
Log:
Moving to org.apache.roller packaging
Added:
incubator/roller/trunk/contrib/plugins/src/org/apache/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/acronyms/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/acronyms/AcronymsPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/BookmarkPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/package.html
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/convertbreaks/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/convertbreaks/ConvertLineBreaksPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/ObfuscateEmailPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/package.html
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/RollerPageProvider.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/WikiPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/package.html
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/WikiPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/package.html
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/ReadMorePlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/package.html
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/GoogleLinkPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/SearchPluginBase.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/WikipediaLinkPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/SmileysPlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/smileys.properties
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/TextilePlugin.java
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/package.html
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/topictag/
incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/topictag/TopicTagPlugin.java
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/acronyms/AcronymsPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/acronyms/AcronymsPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/acronyms/AcronymsPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/acronyms/AcronymsPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,248 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Filename: AcronymsPlugin.java
+ *
+ * Created on 22-Jun-04
+ */
+package org.apache.roller.presentation.velocity.plugins.acronyms;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.UserManager;
+import org.apache.roller.pojos.WeblogTemplate;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.model.PagePlugin;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Adds full text to pre-defined acronyms.
+ *
+ * Example: HTML would become <acronym title="Hyper Text Markup Language">HTML</acronym>
+ *
+ * @author <a href="mailto:molen@mail.com">Jaap van der Molen</a>
+ * @version $Revision: 1.3 $
+ */
+public class AcronymsPlugin implements PagePlugin
+{
+ /**
+ * Logger
+ */
+ private static final Log mLogger = LogFactory.getLog(AcronymsPlugin.class);
+
+ /**
+ * Name of this Plugin.
+ */
+ protected String name = "Acronyms";
+ protected String description = "Expands acronyms defined in _acronym page. " +
+ "Example: definition 'HTML=Hyper Text Markup Language' " +
+ "becomes <acronym title='Hyper Text Markup Language'>HTML</acronym>. " +
+ "You must create an " +
+ "<a href='page.do?method=editPages&rmik=tabbedmenu.website.pages'>" +
+ "_acronym page</a> to use Acronyms.";
+
+ /**
+ * Constructor
+ */
+ public AcronymsPlugin()
+ {
+ super();
+ mLogger.debug("AcronymsPlugin instantiated.");
+ }
+
+ /**
+ * @see org.apache.roller.presentation.velocity.PagePlugin#init(org.apache.roller.presentation.RollerRequest, org.apache.velocity.context.Context)
+ */
+ public void init(
+ WebsiteData website,
+ Object config,
+ String baseURL,
+ Context ctx) throws RollerException
+ {
+ if (mLogger.isDebugEnabled()) {
+ mLogger.debug("init(ctx = "+ctx+" )");
+ }
+ }
+
+ /**
+ * Look for any _acronyms Page and parse it into Properties.
+ * @param website
+ * @return
+ * @throws RollerException
+ */
+ private Properties loadAcronyms(WebsiteData website)
+ {
+ Properties acronyms = new Properties();
+ try
+ {
+ UserManager userMgr = RollerFactory.getRoller().getUserManager();
+ WeblogTemplate acronymsPage = userMgr.getPageByName(
+ website, "_acronyms");
+ if (acronymsPage != null)
+ {
+ acronyms = parseAcronymPage(acronymsPage, acronyms);
+ }
+ }
+ catch (RollerException e)
+ {
+ // not much we can do about it
+ mLogger.warn(e);
+ }
+ return acronyms;
+ }
+
+ /**
+ * @see org.apache.roller.presentation.velocity.PagePlugin#render(org.apache.roller.pojos.WeblogEntryData, boolean)
+ */
+ public String render(WeblogEntryData entry, String str)
+ {
+ String text = str;
+
+ if (mLogger.isDebugEnabled()) {
+ mLogger.debug("render(entry = "+entry.getId()+")");
+ }
+
+ /*
+ * Get acronyms Properties.
+ */
+ Properties acronyms = loadAcronyms(entry.getWebsite());
+ mLogger.debug("acronyms.size()=" + acronyms.size());
+ if (acronyms.size() == 0)
+ {
+ return text;
+ }
+
+ /*
+ * Compile the user's acronyms into RegEx patterns.
+ */
+ Pattern[] acronymPatterns = new Pattern[acronyms.size()];
+ String[] acronymTags = new String[acronyms.size()];
+ int count = 0;
+ for (Iterator iter = acronyms.keySet().iterator(); iter.hasNext();)
+ {
+ String acronym = (String) iter.next();
+ acronymPatterns[count] = Pattern.compile("\\b" + acronym + "\\b");
+ mLogger.debug("match '" + acronym + "'");
+ acronymTags[count] =
+ "<acronym title=\""
+ + acronyms.getProperty(acronym)
+ + "\">"
+ + acronym
+ + "</acronym>";
+ count++;
+ }
+
+ // if there are none, no work to do
+ if (acronymPatterns == null || acronymPatterns.length == 0) {
+ return text;
+ }
+
+ return matchAcronyms(text, acronymPatterns, acronymTags);
+ }
+
+ /**
+ * Without Website cannot lookup _acronyms page.
+ * @see org.apache.roller.presentation.velocity.PagePlugin#render(java.lang.String)
+ */
+ public String render(String text)
+ {
+ return text;
+ }
+
+ /**
+ * @return this Page Plugin's name
+ */
+ public String toString()
+ {
+ return name;
+ }
+
+ /**
+ * Iterates through the acronym properties and replaces matching
+ * acronyms in the entry text with acronym html-tags.
+ *
+ * @param text entry text
+ * @param acronyms user provided set of acronyms
+ * @return entry text with acronym explanations
+ */
+ private String matchAcronyms(String text, Pattern[] acronymPatterns, String[] acronymTags)
+ {
+ if (mLogger.isDebugEnabled()) {
+ mLogger.debug("matchAcronyms("+text+")");
+ }
+
+ Matcher matcher = null;
+ for (int i=0; i<acronymPatterns.length; i++)
+ {
+ matcher = acronymPatterns[i].matcher(text);
+ text = matcher.replaceAll(acronymTags[i]);
+ }
+ return text;
+ }
+
+ /**
+ * Parse the Template of the provided WeblogTemplate and turns it
+ * into a <code>Properties</code> collection.
+ *
+ * @param acronymPage
+ * @return acronym properties (key = acronym, value= full text), empty if Template is empty
+ */
+ private Properties parseAcronymPage(WeblogTemplate acronymPage, Properties acronyms)
+ {
+ String rawAcronyms = acronymPage.getContents();
+
+ if (mLogger.isDebugEnabled())
+ {
+ mLogger.debug("parsing _acronyms template: \n'"+rawAcronyms+"'");
+ }
+
+ String regex = "\n"; // end of line
+ String[] lines = rawAcronyms.split(regex);
+
+ if (lines != null)
+ {
+ for (int i = 0; i < lines.length; i++)
+ {
+ int index = lines[i].indexOf('=');
+ if (index > 0)
+ {
+ String key = lines[i].substring(0, index).trim();
+ String value =
+ lines[i].substring(index + 1, lines[i].length()).trim();
+ acronyms.setProperty(key, value);
+ }
+ }
+ }
+
+ return acronyms;
+ }
+
+ public String getName() { return name; }
+ public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/BookmarkPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/BookmarkPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/BookmarkPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/BookmarkPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,198 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Nov 2, 2003
+ *
+ */
+package org.apache.roller.presentation.velocity.plugins.bookmarks;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.BookmarkManager;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.BookmarkData;
+import org.apache.roller.pojos.FolderData;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.model.PagePlugin;
+import java.util.regex.PatternSyntaxException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.Collection;
+import java.util.Iterator;
+import org.apache.roller.pojos.WebsiteData;
+
+/**
+ * @author lance
+ * @author Anil Gangolli (significant modifications)
+ */
+public class BookmarkPlugin implements PagePlugin
+{
+ protected String name = "Bookmark Linker";
+ protected String description = "Automatically uses your Bookmarks to " +
+ "create links. Simply use the Name of a Bookmark and it will be " +
+ "converted into a hyperlink using the Bookmark's URL.";
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(BookmarkPlugin.class);
+
+ public BookmarkPlugin()
+ {
+ mLogger.debug("BookmarkPlugin instantiated.");
+ }
+
+ public String toString() { return name; }
+
+ /* (non-Javadoc)
+ * @see org.apache.roller.presentation.velocity.PagePlugin#init(org.apache.roller.presentation.RollerRequest, org.apache.velocity.context.Context)
+ */
+ public void init(
+ WebsiteData website,
+ Object config,
+ String baseURL,
+ Context ctx) throws RollerException
+ {
+ }
+
+ /*
+ * Without Website cannot lookup Folders & Bookmarks
+ * (non-Javadoc)
+ * @see org.apache.roller.presentation.velocity.PagePlugin#render(java.lang.String)
+ */
+ public String render(String text)
+ {
+ return text;
+ }
+
+ public String render(WeblogEntryData entry, String str)
+ {
+ String text = str;
+ try
+ {
+ BookmarkManager bMgr = RollerFactory.getRoller().getBookmarkManager();
+ FolderData rootFolder = bMgr.getRootFolder(entry.getWebsite());
+ text = matchBookmarks(text, rootFolder);
+ text = lookInFolders(text, rootFolder.getFolders());
+ }
+ catch (RollerException e)
+ {
+ // nothing much I can do, go with default "Weblog" value
+ // could be RollerException or NullPointerException
+ mLogger.warn(e);
+ }
+ return text;
+ }
+
+ /**
+ * Recursively travel down Folder tree, attempting
+ * to match up Bookmarks in each Folder.
+ *
+ * @param text
+ * @param folders
+ * @return
+ */
+ private String lookInFolders(String text, Collection folders)
+ {
+ Iterator it = folders.iterator();
+ while (it.hasNext())
+ {
+ FolderData folder = (FolderData)it.next();
+ text = matchBookmarks(text, folder);
+
+ try
+ {
+ if (!folder.getFolders().isEmpty())
+ {
+ lookInFolders(text, folder.getFolders());
+ }
+ }
+ catch (RollerException e)
+ {
+ mLogger.error("Error getting child Folders");
+ }
+ }
+ return text;
+ }
+
+ private String matchBookmarks(String text, FolderData folder)
+ {
+ Iterator bookmarks = folder.getBookmarks().iterator();
+ String workingText = text;
+ while (bookmarks.hasNext())
+ {
+ BookmarkData bookmark = (BookmarkData)bookmarks.next();
+ String bkDescription = bookmark.getDescription();
+ if (bkDescription == null) bkDescription = "";
+ String bookmarkLink = "<a href=\"" +
+ bookmark.getUrl() + "\" title=\"" +
+ bkDescription + "\">" +
+ bookmark.getName() + "</a>";
+ try
+ {
+ // Replace all occurrences of bookmark name that don't occur within the bounds of an anchor tag
+ // Notes:
+ // - use reluctant quantifiers on the tags to avoid gobbling more than desired
+ // - use non-capturing groups for boundaries to avoid replacing the boundary as well as the bookmark name.
+ // - we depend on the numbering of the specific groups in this expression in the replacement code below.
+ // TODO: should escape the bookmark name
+ String regEx = "(<a(?:\\s.*?)??/>)|(<a(?:\\s.*?)??>)|(</a(?:\\s.*?)??>)|(?:\\b)(" + bookmark.getName() + ")(?:\\b)";
+ Matcher m = Pattern.compile(regEx).matcher(workingText);
+ StringBuffer textBuf = new StringBuffer(workingText.length());
+ int inLink = 0;
+ while (m.find())
+ {
+ if (m.group(1) != null)
+ {
+ // self-closed anchor tag <a ... /> -- ignore
+ }
+ else if (m.group(2) != null)
+ {
+ // matched opening anchor tag <a ...>
+ inLink++;
+ }
+ else if (m.group(3) != null)
+ {
+ // closing anchor tag </a>, but ignore nonmatching ones
+ if (inLink > 0) inLink--;
+ }
+ else if (m.group(4) != null)
+ {
+ // matched the bookmark -- replace, but only if not within a link tag.
+ if (inLink == 0) m.appendReplacement(textBuf, bookmarkLink);
+ }
+ // Any remaining case indicates a bug. One could add an else with assertion here. Conservatively don't substitute.
+ }
+ m.appendTail(textBuf);
+ workingText = textBuf.toString();
+ }
+ catch (PatternSyntaxException e)
+ {
+ // Can happen since we don't escape pattern the bookmark name to protect pattern characters.
+ mLogger.warn("Failed to substitute for bookmark [" + bookmark.getName() + "] due to regular expression characters.");
+ }
+ }
+ return workingText.toString();
+ }
+
+ public String getName() { return name; }
+ public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/package.html?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/package.html (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/bookmarks/package.html Mon May 1 15:29:19 2006
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. The ASF licenses this file to You
+ 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. For additional information regarding
+ copyright in this work, please see the NOTICE file in the top level
+ directory of this distribution.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+PagePlugin: Bookmark substitution in weblog entries.<br>
+</body>
+</html>
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/convertbreaks/ConvertLineBreaksPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/convertbreaks/ConvertLineBreaksPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/convertbreaks/ConvertLineBreaksPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/convertbreaks/ConvertLineBreaksPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,146 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/* Created on July 10, 2005, 3:17 PM */
+
+package org.apache.roller.presentation.velocity.plugins.convertbreaks;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.apache.roller.RollerException;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.model.PagePlugin;
+
+/**
+ * Simple page plugin that converts paragraphs of plain text into html paragraphs.
+ * We wrap each full paragraph in html <p> opening and closing tags, and
+ * also add <br> tags to the end of lines with breaks inside a paragraph.
+ *
+ * Example:
+ * This is one
+ * paragraph
+ *
+ * Becomes:
+ * <p>This is one<br/>
+ * paragraph</p>
+ *
+ * @author Allen Gilliland
+ */
+public class ConvertLineBreaksPlugin implements PagePlugin {
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(ConvertLineBreaksPlugin.class);
+
+ private static final String name = "Convert Line Breaks";
+ private static final String description = "Convert plain text paragraphs to html by adding p and br tags";
+ private static final String version = "0.1";
+
+
+ public ConvertLineBreaksPlugin() {
+ mLogger.debug("Instantiating ConvertLineBreaksPlugin v"+this.version);
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void init(
+ WebsiteData website,
+ Object config,
+ String baseURL,
+ Context ctx) throws RollerException {
+ // we don't need to do any init.
+ mLogger.debug("initing");
+ }
+
+
+ /**
+ * Transform the given plain text into html text by inserting p and br
+ * tags around paragraphs and after line breaks.
+ */
+ public String render(WeblogEntryData entry, String str) {
+
+ mLogger.debug("Rendering weblog entry: "+entry.getTitle());
+
+ return this.render(str);
+ }
+
+
+ /**
+ * Transform the given plain text into html text by inserting p and br
+ * tags around paragraphs and after line breaks.
+ */
+ public String render(String str) {
+
+ if(str == null || str.trim().equals(""))
+ return "";
+
+ mLogger.debug("Rendering string of length "+str.length());
+
+ /* setup a buffered reader and iterate through each line
+ * inserting html as needed
+ *
+ * NOTE: we consider a paragraph to be 2 endlines with no text between them
+ */
+ StringBuffer buf = new StringBuffer();
+ try {
+ BufferedReader br = new BufferedReader(new StringReader(str));
+
+ String line = null;
+ boolean insidePara = false;
+ while((line = br.readLine()) != null) {
+
+ if(!insidePara && line.trim().length() > 0) {
+ // start of a new paragraph
+ buf.append("\n<p>");
+ buf.append(line);
+ insidePara = true;
+ } else if(insidePara && line.trim().length() > 0) {
+ // another line in an existing paragraph
+ buf.append("<br/>\n");
+ buf.append(line);
+ } else if(insidePara && line.trim().length() < 1) {
+ // end of a paragraph
+ buf.append("</p>\n\n");
+ insidePara = false;
+ }
+ }
+
+ // if the text ends without an empty line then we need to
+ // terminate the last paragraph now
+ if(insidePara)
+ buf.append("</p>\n\n");
+
+ } catch(Exception e) {
+ mLogger.warn("trouble rendering text.", e);
+ return str;
+ }
+
+ return buf.toString();
+ }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/ObfuscateEmailPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/ObfuscateEmailPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/ObfuscateEmailPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/ObfuscateEmailPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,83 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Nov 2, 2003
+ *
+ */
+package org.apache.roller.presentation.velocity.plugins.email;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.model.PagePlugin;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.util.RegexUtil;
+
+/**
+ * @author lance
+ *
+ */
+public class ObfuscateEmailPlugin implements PagePlugin
+{
+ protected String name = "Email Scrambler";
+ protected String description = "Automatically converts email addresses " +
+ "to me-AT-mail-DOT-com format. Also "scrambles" mailto: links.";
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(ObfuscateEmailPlugin.class);
+
+ public ObfuscateEmailPlugin()
+ {
+ mLogger.debug("ObfuscateEmailPlugin instantiated.");
+ }
+
+ public String toString() { return name; }
+
+ /* (non-Javadoc)
+ * @see org.apache.roller.presentation.velocity.PagePlugin#init(org.apache.roller.presentation.RollerRequest, org.apache.velocity.context.Context)
+ */
+ public void init(
+ WebsiteData website,
+ Object config,
+ String baseURL,
+ Context ctx)
+ {
+ }
+
+ /*
+ * Find any likely email addresses and HEX escape them
+ * (non-Javadoc)
+ * @see org.apache.roller.presentation.velocity.PagePlugin#render(java.lang.String)
+ */
+ public String render(String str)
+ {
+ return RegexUtil.encodeEmail(str);
+ }
+
+ public String render(WeblogEntryData entry, String str)
+ {
+ return render(str);
+ }
+
+ public String getName() { return name; }
+ public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/package.html?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/package.html (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/email/package.html Mon May 1 15:29:19 2006
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. The ASF licenses this file to You
+ 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. For additional information regarding
+ copyright in this work, please see the NOTICE file in the top level
+ directory of this distribution.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+PagePlugin: Email address obfuscation.<br>
+</body>
+</html>
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/RollerPageProvider.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/RollerPageProvider.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/RollerPageProvider.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/RollerPageProvider.java Mon May 1 15:29:19 2006
@@ -0,0 +1,39 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on May 29, 2003
+ */
+package org.apache.roller.presentation.velocity.plugins.jspwiki;
+
+import com.ecyrd.jspwiki.providers.FileSystemProvider;
+
+/**
+ * Override page provider so that Wiki links always appear as hyperlinks
+ * to the external Wiki's Wiki.jsp?page=MyPageName page. Without this, they
+ * would appear as links tp Edit.jsp?page=MyPageName, which is not quite as
+ * nice. Eventually, it may be a good idea to use JSPWiki's XML-RPC interface
+ * to figure out if the page exists or not.
+ * @author David M Johnson
+ */
+public class RollerPageProvider extends FileSystemProvider
+{
+ public boolean pageExists(String arg0)
+ {
+ return true;
+ }
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/WikiPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/WikiPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/WikiPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/WikiPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1 @@
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. The ASF licenses this file to You
* 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. For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
package org.apache.roller.presentation.velocity.plugins.jspwiki;
import com.ecyrd.jspwiki.FileUtil;
import com.ecyrd.jspwiki.TranslatorReader;
import com.ecyrd.jspwik
i.WikiContext;
import com.ecyrd.jspwiki.WikiEngine;
import com.ecyrd.jspwiki.WikiPage;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.context.Context;
import org.apache.roller.pojos.WeblogEntryData;
import org.apache.roller.model.PagePlugin;
import java.io.StringReader;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import org.apache.roller.pojos.WebsiteData;
/**
* Wiki plugin using the JSPWiki WikiEngine. If you want Wiki links to point
* to your JSPWiki, then edit the jspwiki.properties fiel in Roller's WEB-INF
* directory and set the jspwiki.baseURL appropriately. For example, if your
* Wiki is on your localhost in the Servlet Context named 'wiki' then you'd
* set jspwiki.baseURL like so:<br />
* <br />
* jspwiki.baseURL=http://local:8080/wiki/<br />
*
* @author David M Johnson
*/
public clas
s WikiPlugin implements PagePlugin {
protected String name = "JSPWiki Syntax";
public String description = "Allows use of JSPWiki formatting to easily " +
"generate HTML. See the " +
"<a href='http://www.jspwiki.org/Wiki.jsp?page=TextFormattingRules' target='jspwiki'>JSPWiki</a> site.";
private static Log mLogger =
LogFactory.getFactory().getInstance(WikiPlugin.class);
static WikiEngine mWikiEngine = null;
static WikiContext mWikiContext = null;
static WikiPage mWikiPage = new WikiPage("dummyPage");
public WikiPlugin() {
mLogger.debug("JSPWiki WikiPlugin instantiated.");
}
public String toString() { return name; }
/**
* Initialize the JSPWiki Engine if not done so already.
* Put the Plugin into the VelocityContex (is this still necessary?-Lance).
*/
public void init(
WebsiteData website,
Object context,
String con
textURL,
Context ctx) {
try {
if (WikiPlugin.mWikiEngine == null) {
if (context != null) {
// get wiki engine when running inside webapp
ServletContext servletContext = (ServletContext)context;
WikiPlugin.mWikiEngine = WikiEngine.getInstance(servletContext, null);
} else {
// get wiki engine when running from command-line
Properties wikiprops = new Properties();
wikiprops.load(getClass().getResourceAsStream("/jspwiki.properties"));
WikiPlugin.mWikiEngine = new WikiEngine(wikiprops);
}
}
if (WikiPlugin.mWikiContext == null && WikiPlugin.mWikiEngine != null) {
WikiPlugin.mWikiContext = new WikiContext(
WikiPlugin.mWikiEngine, WikiPlugin.mWikiPage );
}
if (WikiPlugin.mWikiCo
ntext != null && WikiPlugin.mWikiEngine != null) {
ctx.put("wikiPlugin",this);
}
} catch (Exception e) {
mLogger.error("ERROR initializing WikiPlugin",e);
}
}
/**
* Convert an input string that contains text that uses JSPWiki
* syntax to an output string in HTML format.
* @param src Input string that uses JSPWiki syntax
* @return Output string in HTML format.
*/
public String render( String src ) {
String ret = null;
try {
StringReader reader = new StringReader(src);
TranslatorReader tr = new TranslatorReader( mWikiContext, reader );
ret = FileUtil.readContents( tr );
} catch (Exception e) {
mLogger.error("ERROR rendering Wiki text",e);
}
return ret;
}
public String render( WeblogEntryData entry, String str) {
return render(str);
}
/** Return URL to the Wiki page
for a weblog entry, CamelCase style */
public String makeCamelCaseWikiLink( WeblogEntryData wd, String prefix ) {
StringBuffer sb = new StringBuffer();
StringTokenizer toker = new StringTokenizer(wd.getAnchor(),"_");
while ( toker.hasMoreTokens() ) {
String token = toker.nextToken();
sb.append( token.substring(0,1).toUpperCase() );
sb.append( token.substring(1) );
}
return mWikiEngine.getBaseURL()+"Wiki.jsp?page="+prefix+sb.toString();
}
/** Return URL to the Wiki page for a weblog entry, spacey style */
public String makeSpacedWikiLink( WeblogEntryData wd, String prefix ) {
StringBuffer sb = new StringBuffer();
StringTokenizer toker = new StringTokenizer(wd.getAnchor(),"_");
while ( toker.hasMoreTokens() ) {
sb.append( toker.nextToken() );
if ( toker.hasMoreTokens() ) sb.append("%20");
}
return mWikiEngine.getBaseUR
L()+"Wiki.jsp?page="+prefix+sb.toString();
}
public String getName() { return name; }
public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
public boolean getSkipOnSingleEntry() {return false;}
}
\ No newline at end of file
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/package.html?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/package.html (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/jspwiki/package.html Mon May 1 15:29:19 2006
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. The ASF licenses this file to You
+ 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. For additional information regarding
+ copyright in this work, please see the NOTICE file in the top level
+ directory of this distribution.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+PagePlugin: JSPWiki rendering of weblog entries.<br>
+</body>
+</html>
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/WikiPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/WikiPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/WikiPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/WikiPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,84 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+
+package org.apache.roller.presentation.velocity.plugins.radeox;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.radeox.EngineManager;
+import org.radeox.engine.context.BaseRenderContext;
+import org.radeox.engine.context.RenderContext;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.model.PagePlugin;
+import org.apache.roller.pojos.WebsiteData;
+
+/**
+ * @author David M Johnson
+ */
+public class WikiPlugin implements PagePlugin
+{
+ protected String name = "Radeox Wiki";
+ protected String description = "Allows use of Radeox formatting to generate HTML. " +
+ "See the <a href='http://radeox.org/space/snipsnap-help' target='radeox'>Radeox</a> site.";
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(WikiPlugin.class);
+
+ public WikiPlugin()
+ {
+ mLogger.debug("Radeox WikiPlugin instantiated.");
+ }
+
+ public String toString() { return name; }
+
+ /**
+ * Put plugin into the page context so templates may access it.
+ */
+ public void init(
+ WebsiteData website,
+ Object config,
+ String baseURL,
+ Context ctx)
+ {
+ ctx.put("wikiRenderer",this);
+ }
+
+ /**
+ * Convert an input string that contains text that uses the Radeox Wiki
+ * syntax to an output string in HTML format.
+ * @param src Input string that uses Radeox Wiki syntax
+ * @return Output string in HTML format.
+ */
+ public String render( String src )
+ {
+ RenderContext context = new BaseRenderContext();
+ return EngineManager.getInstance().render(src, context);
+ }
+
+ public String render( WeblogEntryData entry, String str)
+ {
+ return render(str);
+ }
+
+ public String getName() { return name; }
+ public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/package.html?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/package.html (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/radeox/package.html Mon May 1 15:29:19 2006
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. The ASF licenses this file to You
+ 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. For additional information regarding
+ copyright in this work, please see the NOTICE file in the top level
+ directory of this distribution.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+PagePlugin: Radeox Wiki rendering of weblog entries.<br>
+</body>
+</html>
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/ReadMorePlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/ReadMorePlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/ReadMorePlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/ReadMorePlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,129 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Nov 2, 2003
+ *
+ */
+package org.apache.roller.presentation.velocity.plugins.readmore;
+
+import javax.servlet.ServletConfig;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.UserManager;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.model.PagePlugin;
+import org.apache.roller.util.Utilities;
+
+/**
+ * @author lance
+ */
+public class ReadMorePlugin implements PagePlugin
+{
+ protected String name = "Read More Summary";
+ protected String description = "Stops entry after 250 characters and creates " +
+ "a link to the full entry.";
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(ReadMorePlugin.class);
+
+ String baseURL = "";
+
+ public ReadMorePlugin()
+ {
+ mLogger.debug("ReadMorePlugin instantiated.");
+ }
+
+ public String toString() { return name; }
+
+ /* (non-Javadoc)
+ * @see org.apache.roller.presentation.velocity.PagePlugin#init(
+ * org.apache.roller.presentation.RollerRequest,
+ * org.apache.velocity.context.Context)
+ */
+ public void init(
+ WebsiteData website,
+ Object config,
+ String baseURL,
+ Context ctx) throws RollerException
+ {
+ this.baseURL = baseURL;
+ }
+
+ /**
+ * @param mgr
+ * @param website
+ * @return
+ */
+ private String getPageLink(UserManager mgr, WebsiteData website) throws RollerException
+ {
+ return website.getDefaultPage().getLink();
+ }
+
+ /*
+ * This method cannot do it's intended job (since it cannot
+ * read the current Entry) so it is to do no work!
+ *
+ * (non-Javadoc)
+ * @see org.apache.roller.presentation.velocity.PagePlugin#render(java.lang.String)
+ */
+ public String render(String str)
+ {
+ return str;
+ }
+
+ public String render(WeblogEntryData entry, String str)
+ {
+ // in case it didn't initialize
+ String pageLink = "Weblog";
+ try
+ {
+ pageLink = getPageLink(
+ RollerFactory.getRoller().getUserManager(), entry.getWebsite());
+ }
+ catch (RollerException e)
+ {
+ mLogger.warn("Unable to get pageLink", e);
+ }
+
+ String result = Utilities.removeHTML(str, true);
+ result = Utilities.truncateText(result, 240, 260, "...");
+ //String result = Utilities.truncateNicely(entry.getText(), 240, 260, "... ");
+
+ // if the result is shorter, we need to add "Read More" link
+ if (result.length() < str.length())
+ {
+ String link = "<div class=\"readMore\"><a href=\"" +
+ baseURL + entry.getPermaLink() + "\">Read More</a></div>";
+
+ result += link;
+ }
+ return result;
+ }
+
+
+ public String getName() { return name; }
+ public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
+
+
+ public boolean getSkipOnSingleEntry() {return true;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/package.html?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/package.html (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/readmore/package.html Mon May 1 15:29:19 2006
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. The ASF licenses this file to You
+ 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. For additional information regarding
+ copyright in this work, please see the NOTICE file in the top level
+ directory of this distribution.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+PagePlugin: Readmore rendering of weblog entries.<br>
+</body>
+</html>
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/GoogleLinkPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/GoogleLinkPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/GoogleLinkPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/GoogleLinkPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.presentation.velocity.plugins.search;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.model.PagePlugin;
+
+import java.text.MessageFormat;
+import java.util.regex.Pattern;
+
+/**
+ * Google Link Plugin. This plugin provides a convenient way to write google search links.
+ * <p/>
+ * The plugin will replace strings of the form <code>google:"link text"{search text}</code> with a link that performs a
+ * Google search. The link will have the visible text "link text" and an href for the Google search. You may omit the
+ * <code>{search text}</code> portion, and the link text will be used as the search text. You can also use an
+ * exclamation point (<code>!</code>) instead of the colon (<code>:</code>), to get a lucky ("I'm feeling
+ * lucky") search, which takes the user directly to the highest ranked Google match.
+ *
+ * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
+ * @version 2.1
+ */
+public class GoogleLinkPlugin extends SearchPluginBase implements PagePlugin {
+ private static final String version = "2.1";
+ private static final Pattern pattern = Pattern.compile("google([:!])\"(.*?)\"(?:\\{(.*?)\\})?");
+ private static final MessageFormat linkFormat = new MessageFormat("<a href=\"http://www.google.com/search?ie=UTF-8&q={3}\">{2}</a>");
+ private static final MessageFormat luckyLinkFormat = new MessageFormat("<a href=\"http://www.google.com/search?ie=UTF-8&q={3}&btnI=on\">{2}</a>");
+
+ private static final Log mLogger = LogFactory.getFactory().getInstance(GoogleLinkPlugin.class);
+
+ public GoogleLinkPlugin() {
+ }
+
+ public String getName() {
+ return "Google Links";
+ }
+
+ public String getDescription() {
+ 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.";
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public Pattern getPattern() {
+ return pattern;
+ }
+
+ public MessageFormat getLinkFormat() {
+ return linkFormat;
+ }
+
+ public MessageFormat getLuckyLinkFormat() {
+ return luckyLinkFormat;
+ }
+
+ public Log getLogger() {
+ return mLogger;
+ }
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/SearchPluginBase.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/SearchPluginBase.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/SearchPluginBase.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/SearchPluginBase.java Mon May 1 15:29:19 2006
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.presentation.velocity.plugins.search;
+
+import org.apache.commons.logging.Log;
+import org.apache.velocity.context.Context;
+import org.apache.roller.RollerException;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.FieldPosition;
+import java.text.MessageFormat;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Implements the common portion of search link plugins.
+ *
+ * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
+ * @version 2.1
+ */
+public abstract class SearchPluginBase {
+ private String baseVersion = "2.1";
+ private Log mLogger;
+
+ /**
+ * Instantiation is per request.
+ */
+ public SearchPluginBase() {
+ mLogger = getLogger();
+ }
+
+ /**
+ * Initialize. Called once for each request.
+ *
+ * @see org.apache.roller.model.PagePlugin#init(WebsiteData, Object, String baseUrl, org.apache.velocity.context.Context)
+ */
+ public void init(WebsiteData website, Object servletContext, String baseUrl, Context ctx) throws RollerException {
+ if (mLogger.isDebugEnabled()) {
+ mLogger.debug(getClass().getName() + "; version: " + getVersion() + "; base version " + baseVersion);
+ }
+ }
+
+ /**
+ * Apply plugin to content of specified WeblogEntry.
+ *
+ * @param entry WeblogEntry to which plugin should be applied.
+ * @param singleEntry Ignored.
+ * @return Results of applying plugin to entry.
+ * @see org.apache.roller.model.PagePlugin#render(org.apache.roller.pojos.WeblogEntryData, boolean)
+ */
+ public String render(WeblogEntryData entry, String str) {
+ return render(str);
+ }
+
+ /**
+ * Apply plugin to content of specified String.
+ *
+ * @param str String to which plugin should be applied.
+ * @return Results of applying plugin to string.
+ * @see org.apache.roller.model.PagePlugin#render(String)
+ */
+ public String render(String str) {
+ Pattern pattern = getPattern();
+ Matcher m = pattern.matcher(str);
+ StringBuffer result = new StringBuffer(str.length() + 128); // rough guess at a reasonable length
+ Object[] args = new Object[]{"", "", null, null};
+ while (m.find()) {
+ // parse out the parts of the match
+ String type = m.group(1);
+ boolean feelinLucky = type.equals("!"); // are ya feelin lucky? are ya punk?
+ String linkText = m.group(2);
+ String searchText = m.group(3);
+ if (searchText == null || searchText.length() == 0) {
+ searchText = linkText;
+ }
+
+ // URL-encode the search text
+ String encodedSearchText = encodeSearchText(searchText);
+
+ // form the replacement string
+ MessageFormat linkFormat = feelinLucky ? getLuckyLinkFormat() : getLinkFormat();
+ StringBuffer replacement = new StringBuffer(128);
+ args[2] = linkText;
+ args[3] = encodedSearchText;
+ linkFormat.format(args, replacement, new FieldPosition(0));
+
+ // append replacement
+ m.appendReplacement(result, replacement.toString());
+ }
+ m.appendTail(result);
+
+ return result.toString();
+ }
+
+ /**
+ * Returns the human-friendly name of this Plugin. This is what users will see.
+ *
+ * @return The human-friendly name of this Plugin.
+ * @see org.apache.roller.model.PagePlugin#getName()
+ */
+ public abstract String getName();
+
+ /**
+ * Briefly describes the function of the Plugin. May contain HTML.
+ *
+ * @return A brief description of the Plugin.
+ * @see org.apache.roller.model.PagePlugin#getDescription()
+ */
+ public abstract String getDescription();
+
+ /**
+ * Return the logger for this class.
+ *
+ * @return the logger for this class.
+ */
+ protected abstract Log getLogger();
+
+ /**
+ * Return the implementation version.
+ *
+ * @return the implementation version.
+ */
+ protected abstract String getVersion();
+
+ /**
+ * Get the regexp pattern for finding search links in the input text. Three matching groups are expected: (1) The
+ * lucky or not indicator (either <code>!</code> or <code>:</code>) (2) the link text (3) the search text (optional,
+ * defaults to the link text).
+ *
+ * @return the regexp pattern for finding search links in the input text
+ */
+ protected abstract Pattern getPattern();
+
+ /**
+ * The MessageFormat for the replacement string (actual HTML link) that will form the replacement in the regular
+ * (non-"lucky") case. This must have two positional parameters "{2} and {3}" which are the link text and
+ * (URL-encoded) search text from the regexp pattern. Note that the parameters "{0}" and "{1}" are not used. They
+ * will be empty strings.
+ *
+ * @return the message format for non-"lucky" search links.
+ */
+ protected abstract MessageFormat getLinkFormat();
+
+ /**
+ * The MessageFormat for the replacement string (actual HTML link) that will form the replacement in the "lucky"
+ * case. This must have two positional parameters "{2} and {3}" which are the link text and (URL-encoded) search
+ * text from the regexp pattern. Note that the parameters "{0}" and "{1}" are not used. They will be empty
+ * strings.
+ *
+ * @return the message format for "lucky" search links.
+ */
+ protected abstract MessageFormat getLuckyLinkFormat();
+
+
+ // Private helper to URL encode the search text.
+ private String encodeSearchText(String searchText) {
+ // URL encode the searchtext
+ try {
+ return URLEncoder.encode(searchText, "UTF-8");
+ } catch (UnsupportedEncodingException uex) {
+ // By Java spec, this should never actually occur for UTF-8. If it does, we barf bitterly.
+ throw new RuntimeException(uex);
+ }
+ }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/WikipediaLinkPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/WikipediaLinkPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/WikipediaLinkPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/search/WikipediaLinkPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.presentation.velocity.plugins.search;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.model.PagePlugin;
+
+import java.text.MessageFormat;
+import java.util.regex.Pattern;
+
+/**
+ * Wikipedia Link Plugin. This plugin provides a convenient way to write wikipedia search links.
+ * <p/>
+ * The plugin will replace strings of the form <code>wikipedia:"link text"{search text}</code> with a link that performs
+ * a Wikipedia search. The link will have the visible text "link text" and an href for the Google search. You may omit
+ * the <code>{search text}</code> portion, and the link text will be used as the search text. You can also use an
+ * exclamation point (<code>!</code>) instead of the colon (<code>:</code>), to get a lucky ("lucky") search,
+ * which takes the user directly to the best ranked match.
+ *
+ * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
+ * @version 2.1
+ */
+public class WikipediaLinkPlugin extends SearchPluginBase implements PagePlugin {
+ private static final String version = "2.1";
+ private static final Pattern pattern = Pattern.compile("wikipedia([:!])\"(.*?)\"(?:\\{(.*?)\\})?");
+ private static final MessageFormat linkFormat = new MessageFormat("<a href=\"http://www.wikipedia.org/wiki/Special:Search?search={3}\">{2}</a>");
+ private static final MessageFormat luckyLinkFormat = new MessageFormat("<a href=\"http://www.wikipedia.org/wiki/Special:Search?search={3}&go=Go\">{2}</a>");
+
+ private static final Log mLogger = LogFactory.getFactory().getInstance(WikipediaLinkPlugin.class);
+
+ public WikipediaLinkPlugin() {
+ }
+
+ public String getName() {
+ return "Wikipedia Search Links";
+ }
+
+ public String getDescription() {
+ return "Replace wikipedia:"link text"{search text} with a link that performs a wikipedia search. With ! instead of :," + "creates a "lucky" search, going directly to the first result. With {search text} omitted, uses link text as the value of the search text.";
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public Pattern getPattern() {
+ return pattern;
+ }
+
+ public MessageFormat getLinkFormat() {
+ return linkFormat;
+ }
+
+ public MessageFormat getLuckyLinkFormat() {
+ return luckyLinkFormat;
+ }
+
+ public Log getLogger() {
+ return mLogger;
+ }
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/SmileysPlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/SmileysPlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/SmileysPlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/SmileysPlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,203 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.roller.presentation.velocity.plugins.smileys;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.apache.roller.RollerException;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.model.PagePlugin;
+
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.roller.pojos.WebsiteData;
+
+/**
+ * Converts ascii emoticons into HTML image tags.
+ *
+ * @author lance.lavandowska
+ * Created on Jun 8, 2004
+ */
+public class SmileysPlugin implements PagePlugin
+{
+ private String name = "Emoticons";
+ private String description = "Change ASCII emoticons to graphics. " +
+ ":-) becomes <img src='./images/smileys/smile.gif'>";
+
+ public String toString() { return name; }
+
+ static Pattern[] smileyPatterns = new Pattern[0];
+ static String[] imageTags = new String[0];
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(SmileysPlugin.class);
+
+ /*
+ * Definition of the emoticons 'glyph' and graphic.
+ */
+ private static Properties smileyDefs = new Properties();
+ static
+ {
+ try
+ {
+ smileyDefs.load(SmileysPlugin.class.getResourceAsStream("smileys.properties"));
+ }
+ catch (Exception e)
+ {
+ mLogger.error("Unable to load smileys.properties", e);
+ }
+ }
+
+ public SmileysPlugin()
+ {
+ mLogger.debug("SmileysPlugin instantiated.");
+ }
+
+ /*
+ * Find occurences of ascii emoticons and turn them into
+ * HTML image pointers.
+ *
+ * @see org.apache.roller.presentation.velocity.PagePlugin#render(java.lang.String)
+ */
+ public String render(String text)
+ {
+ Matcher matcher = null;
+ for (int i=0; i<smileyPatterns.length; i++)
+ {
+ matcher = smileyPatterns[i].matcher(text);
+ text = matcher.replaceAll(imageTags[i]);
+ }
+ return text;
+ }
+
+ /*
+ * Convert the SmileyDefs into RegEx patterns and img tags for
+ * later use. Need an HttpServletRequest though so that we can
+ * get the ServletContext Path. But only do it once.
+ *
+ * @see org.apache.roller.presentation.velocity.PagePlugin#init(org.apache.roller.presentation.RollerRequest, org.apache.velocity.context.Context)
+ */
+ public synchronized void init(
+ WebsiteData website,
+ Object servletContext,
+ String baseURL,
+ Context ctx) throws RollerException
+ {
+ // don't do this work if Smileys already loaded
+ if (SmileysPlugin.smileyPatterns.length < 1)
+ {
+ Pattern[] tempP = new Pattern[SmileysPlugin.smileyDefs.size()];
+ String[] tempS = new String[SmileysPlugin.smileyDefs.size()];
+ //System.out.println("# smileys: " + smileyDefs.size());
+ int count = 0;
+ Enumeration enum1 = SmileysPlugin.smileyDefs.propertyNames();
+ while(enum1.hasMoreElements())
+ {
+ String smiley = (String)enum1.nextElement();
+ String smileyAlt = htmlEscape(smiley);
+ tempP[count] = Pattern.compile(regexEscape(smiley));
+ tempS[count] = "<img src=\"" +
+ baseURL + "/images/smileys/" +
+ smileyDefs.getProperty(smiley, "smile.gif") +
+ "\" class=\"smiley\"" +
+ " alt=\"" + smileyAlt + "\"" +
+ " title=\"" + smileyAlt +"\" />";
+ //System.out.println(smiley + "=" + tempS[count]);
+ count++;
+ }
+ SmileysPlugin.smileyPatterns = tempP;
+ SmileysPlugin.imageTags = tempS;
+ }
+ }
+
+ /*
+ * To display the smiley 'glyph' certain characters
+ * must be HTML escaped.
+ */
+ private String htmlEscape(String smiley)
+ {
+ char[] chars = smiley.toCharArray();
+ StringBuffer buf = new StringBuffer();
+ for (int i=0; i<chars.length; i++)
+ {
+ if (chars[i] == '"')
+ {
+ buf.append(""");
+ }
+ else if (chars[i] == '>')
+ {
+ buf.append(">");
+ }
+ else if (chars[i] == '<')
+ {
+ buf.append("<");
+ }
+ else
+ {
+ buf.append(chars[i]);
+ }
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Some characters have to escaped with a backslash before
+ * being compiled into a Regular Expression.
+ *
+ * @param smiley
+ * @return
+ */
+ private static char[] escape_regex = new char[]
+ {'-', '(', ')', '\\', '|', ':', '^', '$', '*', '+', '?',
+ '{', '}', '!', '=', '<', '>', '&', '[', ']' };
+ private String regexEscape(String smiley)
+ {
+ char[] chars = smiley.toCharArray();
+ StringBuffer buf = new StringBuffer();
+ for (int i=0; i<chars.length; i++)
+ {
+ for (int x=0; x<escape_regex.length; x++)
+ {
+ if (escape_regex[x] == chars[i])
+ {
+ buf.append("\\");
+ break;
+ }
+ }
+ buf.append(chars[i]);
+ }
+ return buf.toString();
+ }
+
+ /*
+ * @see org.apache.roller.presentation.velocity.PagePlugin#render(org.apache.roller.pojos.WeblogEntryData, boolean)
+ */
+ public String render(WeblogEntryData entry, String str)
+ {
+ return render(str);
+ }
+
+ public String getName() { return name; }
+ public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/smileys.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/smileys.properties?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/smileys.properties (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/smileys/smileys.properties Mon May 1 15:29:19 2006
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. The ASF licenses this file to You
+# 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. For additional information regarding
+# copyright in this work, please see the NOTICE file in the top level
+# directory of this distribution.
+
+\:-)=smile.gif
+\:)=smile.gif
+;-)=wink.gif
+;)=wink.gif
+\:-(=sad.gif
+\:(=sad.gif
+\:-0=surprised.gif
+8-)=sunglasses.gif
+\:-D=grin.gif
+\\-o=bored.gif
+\:-P=tongue.gif
+O\:-)=angelic.gif
+\:-||=angry.gif
+%-)=drunk.gif
+/\:)=20.gif
+\:-S=15.gif
+\:|=19.gif
+;;)=smirk.gif
+\:-B=bucktooth.gif
+\=;=hand.gif
+[-(=28.gif
+(\:|=depressed.gif
+\=P~=drool.gif
+\:-?=thinker.gif
+\=D>=whisper.gif
+\:">=blush.gif
+\:o)=clown.gif
+\:-/=confused.gif
+\:((=cry.gif
+>\:)=devil.gif
+\#-o=doh.gif
+\:-*=kiss.gif
+\:))=laugh.gif
+\:x=love.gif
+8-|=rolleyes.gif
+\:(\:-$=shush.gif
+\:-&=sick.gif
+8-}=silly.gif
+I-)=sleep.gif
+\:->=smug.gif
\ No newline at end of file
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/TextilePlugin.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/TextilePlugin.java?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/TextilePlugin.java (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/TextilePlugin.java Mon May 1 15:29:19 2006
@@ -0,0 +1,83 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* 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. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+
+package org.apache.roller.presentation.velocity.plugins.textile;
+
+import javax.servlet.ServletConfig;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.velocity.context.Context;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.model.PagePlugin;
+
+/**
+ * @author David M Johnson
+ */
+public class TextilePlugin implements PagePlugin
+{
+ public String name = "Textile Formatter";
+ public String description = "Allows use of Textile formatting to easily " +
+ "generate HTML. See the <a href='http://textism.com/tools/textile' target='textile'>Textile</a> site.";
+
+ public String toString() { return name; }
+
+ private net.sf.textile4j.Textile mTextile = new net.sf.textile4j.Textile();
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(TextilePlugin.class);
+
+ public TextilePlugin()
+ {
+ mLogger.debug("Textile Plugin instantiated.");
+ }
+
+ /**
+ * Put plugin into the page context so templates may access it.
+ */
+ public void init(
+ WebsiteData website,
+ Object config,
+ String baseURL,
+ Context ctx)
+ {
+ ctx.put("textileRenderer",this);
+ }
+
+ /**
+ * Convert an input string that contains text that uses the Textile
+ * syntax to an output string in HTML format.
+ * @param src Input string that uses Textile syntax
+ * @return Output string in HTML format.
+ */
+ public String render( String src )
+ {
+ return mTextile.process(src);
+ }
+
+ public String render( WeblogEntryData entry, String str )
+ {
+ return render( str );
+ }
+
+ public String getName() { return name; }
+ public String getDescription() { return StringEscapeUtils.escapeJavaScript(description); }
+
+ public boolean getSkipOnSingleEntry() {return false;}
+}
Added: incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/package.html
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/package.html?rev=398715&view=auto
==============================================================================
--- incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/package.html (added)
+++ incubator/roller/trunk/contrib/plugins/src/org/apache/roller/presentation/velocity/plugins/textile/package.html Mon May 1 15:29:19 2006
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. The ASF licenses this file to You
+ 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. For additional information regarding
+ copyright in this work, please see the NOTICE file in the top level
+ directory of this distribution.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <title></title>
+</head>
+<body>
+PagePlugin: Textile rendering of weblog entries.<br>
+</body>
+</html>