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 2010/03/20 19:37:54 UTC
svn commit: r925653 [4/5] - in /roller/trunk:
planet-business/src/test/resources/ planet-web/ planet-web/src/
planet-web/src/main/ planet-web/src/main/java/
planet-web/src/main/java/org/ planet-web/src/main/java/org/apache/
planet-web/src/main/java/org...
Added: roller/trunk/planet-web/src/main/java/org/apache/roller/util/OldUtilities.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/util/OldUtilities.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/util/OldUtilities.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/util/OldUtilities.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,729 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.util.RegexUtil;
+import org.apache.roller.planet.util.Utilities;
+
+
+/**
+ * Utility methods needed by old Roller 2.X macros/templates.
+ * Deprecated because they are either redundant or unnecesary.
+ */
+public class OldUtilities {
+
+ /** The <code>Log</code> instance for this class. */
+ private static Log mLogger = LogFactory.getLog(OldUtilities.class);
+
+ private static Pattern mLinkPattern =
+ Pattern.compile("<a href=.*?>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_B_TAG_PATTERN =
+ Pattern.compile("<b>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_B_TAG_PATTERN =
+ Pattern.compile("</b>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_I_TAG_PATTERN =
+ Pattern.compile("<i>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_I_TAG_PATTERN =
+ Pattern.compile("</i>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_BLOCKQUOTE_TAG_PATTERN =
+ Pattern.compile("<blockquote>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_BLOCKQUOTE_TAG_PATTERN =
+ Pattern.compile("</blockquote>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern BR_TAG_PATTERN =
+ Pattern.compile("<br */*>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_P_TAG_PATTERN =
+ Pattern.compile("<p>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_P_TAG_PATTERN =
+ Pattern.compile("</p>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_PRE_TAG_PATTERN =
+ Pattern.compile("<pre>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_PRE_TAG_PATTERN =
+ Pattern.compile("</pre>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_UL_TAG_PATTERN =
+ Pattern.compile("<ul>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_UL_TAG_PATTERN =
+ Pattern.compile("</ul>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_OL_TAG_PATTERN =
+ Pattern.compile("<ol>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_OL_TAG_PATTERN =
+ Pattern.compile("</ol>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_LI_TAG_PATTERN =
+ Pattern.compile("<li>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_LI_TAG_PATTERN =
+ Pattern.compile("</li>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_A_TAG_PATTERN =
+ Pattern.compile("</a>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_A_TAG_PATTERN =
+ Pattern.compile("<a href=.*?>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern QUOTE_PATTERN =
+ Pattern.compile(""", Pattern.CASE_INSENSITIVE);
+
+ public static boolean isEmpty(String str) {
+ if (str == null) return true;
+ return "".equals(str.trim());
+ }
+
+ public static boolean isNotEmpty(String str) {
+ return !isEmpty(str);
+ }
+
+ public static String[] split(String str1, String str2) {
+ return StringUtils.split(str1, str2);
+ }
+
+ public static String replace(String src, String target, String rWith) {
+ return StringUtils.replace(src, target, rWith);
+ }
+
+ public static String replace(String src, String target, String rWith, int maxCount) {
+ return StringUtils.replace(src, target, rWith, maxCount);
+ }
+
+ public static boolean equals(String str1, String str2) {
+ return StringUtils.equals(str1, str2);
+ }
+
+ public static boolean isAlphanumeric(String str) {
+ return StringUtils.isAlphanumeric(str);
+ }
+
+ public static String[] stripAll(String[] strs) {
+ return StringUtils.stripAll(strs);
+ }
+
+ public static String left(String str, int length) {
+ return StringUtils.left(str, length);
+ }
+
+ public static String escapeHTML(String str) {
+ return StringEscapeUtils.escapeHtml(str);
+ }
+
+ public static String unescapeHTML(String str) {
+ return StringEscapeUtils.unescapeHtml(str);
+ }
+
+ /**
+ * Remove occurences of html, defined as any text
+ * between the characters "<" and ">". Replace
+ * any HTML tags with a space.
+ */
+ public static String removeHTML(String str) {
+ return removeHTML(str, true);
+ }
+
+ /**
+ * Remove occurences of html, defined as any text
+ * between the characters "<" and ">".
+ * Optionally replace HTML tags with a space.
+ */
+ public static String removeHTML(String str, boolean addSpace) {
+ return Utilities.removeHTML(str, addSpace);
+ }
+
+ /**
+ * Autoformat.
+ */
+ public static String autoformat(String s) {
+ String ret = StringUtils.replace(s, "\n", "<br />");
+ return ret;
+ }
+
+ /**
+ * Return date for current time.
+ */
+ public static Date getNow() {
+ return new Date();
+ }
+
+ /**
+ * Format date using SimpleDateFormat format string.
+ */
+ public static String formatDate(Date d, String fmt) {
+ SimpleDateFormat format = new SimpleDateFormat(fmt);
+ return format.format(d);
+ }
+
+ /**
+ * Format date in ISO-8601 format.
+ */
+ public static String formatIso8601Date(Date d) {
+ return DateUtil.formatIso8601(d);
+ }
+
+ /**
+ * Format date in ISO-8601 format.
+ */
+ public static String formatIso8601Day(Date d) {
+ return DateUtil.formatIso8601Day(d);
+ }
+
+ /**
+ * Return a date in RFC-822 format.
+ */
+ public static String formatRfc822Date(Date date) {
+ return DateUtil.formatRfc822(date);
+ }
+
+ /**
+ * Return a date in RFC-822 format.
+ */
+ public static String format8charsDate(Date date) {
+ return DateUtil.format8chars(date);
+ }
+
+ /**
+ * Strips HTML and truncates.
+ */
+ public static String truncate(
+ String str, int lower, int upper, String appendToEnd) {
+ // strip markup from the string
+ String str2 = removeHTML(str, false);
+
+ // quickly adjust the upper if it is set lower than 'lower'
+ if (upper < lower) {
+ upper = lower;
+ }
+
+ // now determine if the string fits within the upper limit
+ // if it does, go straight to return, do not pass 'go' and collect $200
+ if(str2.length() > upper) {
+ // the magic location int
+ int loc;
+
+ // first we determine where the next space appears after lower
+ loc = str2.lastIndexOf(' ', upper);
+
+ // now we'll see if the location is greater than the lower limit
+ if(loc >= lower) {
+ // yes it was, so we'll cut it off here
+ str2 = str2.substring(0, loc);
+ } else {
+ // no it wasnt, so we'll cut it off at the upper limit
+ str2 = str2.substring(0, upper);
+ loc = upper;
+ }
+
+ // the string was truncated, so we append the appendToEnd String
+ str2 = str2 + appendToEnd;
+ }
+
+ return str2;
+ }
+
+ public static String truncateNicely(String str, int lower, int upper, String appendToEnd) {
+ return Utilities.truncateNicely(str, lower, upper, appendToEnd);
+ }
+
+ public static String truncateText(String str, int lower, int upper, String appendToEnd) {
+ // strip markup from the string
+ String str2 = removeHTML(str, false);
+ boolean diff = (str2.length() < str.length());
+
+ // quickly adjust the upper if it is set lower than 'lower'
+ if(upper < lower) {
+ upper = lower;
+ }
+
+ // now determine if the string fits within the upper limit
+ // if it does, go straight to return, do not pass 'go' and collect $200
+ if(str2.length() > upper) {
+ // the magic location int
+ int loc;
+
+ // first we determine where the next space appears after lower
+ loc = str2.lastIndexOf(' ', upper);
+
+ // now we'll see if the location is greater than the lower limit
+ if(loc >= lower) {
+ // yes it was, so we'll cut it off here
+ str2 = str2.substring(0, loc);
+ } else {
+ // no it wasnt, so we'll cut it off at the upper limit
+ str2 = str2.substring(0, upper);
+ loc = upper;
+ }
+ // the string was truncated, so we append the appendToEnd String
+ str = str2 + appendToEnd;
+ }
+ return str;
+ }
+
+ public static String hexEncode(String str) {
+ if (StringUtils.isEmpty(str)) return str;
+
+ return RegexUtil.encode(str);
+ }
+
+ public static String encodeEmail(String str) {
+ return str!=null ? RegexUtil.encodeEmail(str) : null;
+ }
+
+ /**
+ * URL encoding.
+ * @param s a string to be URL-encoded
+ * @return URL encoding of s using character encoding UTF-8; null if s is null.
+ */
+ public static final String encode(String s) {
+ try {
+ if (s != null)
+ return URLEncoder.encode(s, "UTF-8");
+ else
+ return s;
+ } catch (UnsupportedEncodingException e) {
+ // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+ return s;
+ }
+ }
+
+ /**
+ * URL decoding.
+ * @param s a URL-encoded string to be URL-decoded
+ * @return URL decoded value of s using character encoding UTF-8; null if s is null.
+ */
+ public static final String decode(String s) {
+ try {
+ if (s != null)
+ return URLDecoder.decode(s, "UTF-8");
+ else
+ return s;
+ } catch (UnsupportedEncodingException e) {
+ // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+ return s;
+ }
+ }
+
+ /**
+ * Code (stolen from Pebble) to add rel="nofollow" string to all links in HTML.
+ */
+ public static String addNofollow(String html) {
+ if (html == null || html.length() == 0) {
+ return html;
+ }
+ Matcher m = mLinkPattern.matcher(html);
+ StringBuffer buf = new StringBuffer();
+ while (m.find()) {
+ int start = m.start();
+ int end = m.end();
+ String link = html.substring(start, end);
+ buf.append(html.substring(0, start));
+ if (link.indexOf("rel=\"nofollow\"") == -1) {
+ buf.append(
+ link.substring(0, link.length() - 1) + " rel=\"nofollow\">");
+ } else {
+ buf.append(link);
+ }
+ html = html.substring(end, html.length());
+ m = mLinkPattern.matcher(html);
+ }
+ buf.append(html);
+ return buf.toString();
+ }
+
+ /**
+ * Transforms the given String into a subset of HTML displayable on a web
+ * page. The subset includes <b>, <i>, <p>, <br>,
+ * <pre> and <a href> (and their corresponding end tags).
+ *
+ * @param s the String to transform
+ * @return the transformed String
+ */
+ public static String transformToHTMLSubset(String s) {
+
+ if (s == null) {
+ return null;
+ }
+
+ s = replace(s, OPENING_B_TAG_PATTERN, "<b>");
+ s = replace(s, CLOSING_B_TAG_PATTERN, "</b>");
+ s = replace(s, OPENING_I_TAG_PATTERN, "<i>");
+ s = replace(s, CLOSING_I_TAG_PATTERN, "</i>");
+ s = replace(s, OPENING_BLOCKQUOTE_TAG_PATTERN, "<blockquote>");
+ s = replace(s, CLOSING_BLOCKQUOTE_TAG_PATTERN, "</blockquote>");
+ s = replace(s, BR_TAG_PATTERN, "<br />");
+ s = replace(s, OPENING_P_TAG_PATTERN, "<p>");
+ s = replace(s, CLOSING_P_TAG_PATTERN, "</p>");
+ s = replace(s, OPENING_PRE_TAG_PATTERN, "<pre>");
+ s = replace(s, CLOSING_PRE_TAG_PATTERN, "</pre>");
+ s = replace(s, OPENING_UL_TAG_PATTERN, "<ul>");
+ s = replace(s, CLOSING_UL_TAG_PATTERN, "</ul>");
+ s = replace(s, OPENING_OL_TAG_PATTERN, "<ol>");
+ s = replace(s, CLOSING_OL_TAG_PATTERN, "</ol>");
+ s = replace(s, OPENING_LI_TAG_PATTERN, "<li>");
+ s = replace(s, CLOSING_LI_TAG_PATTERN, "</li>");
+ s = replace(s, QUOTE_PATTERN, "\"");
+
+ // HTTP links
+ s = replace(s, CLOSING_A_TAG_PATTERN, "</a>");
+ Matcher m = OPENING_A_TAG_PATTERN.matcher(s);
+ while (m.find()) {
+ int start = m.start();
+ int end = m.end();
+ String link = s.substring(start, end);
+ link = "<" + link.substring(4, link.length() - 4) + ">";
+ s = s.substring(0, start) + link + s.substring(end, s.length());
+ m = OPENING_A_TAG_PATTERN.matcher(s);
+ }
+
+ // escaped angle brackets
+ s = s.replaceAll("&lt;", "<");
+ s = s.replaceAll("&gt;", ">");
+ s = s.replaceAll("&#", "&#");
+
+ return s;
+ }
+
+ private static String replace(String string, Pattern pattern, String replacement) {
+ Matcher m = pattern.matcher(string);
+ return m.replaceAll(replacement);
+ }
+
+ /**
+ * Convert a byte array into a Base64 string (as used in mime formats)
+ */
+ public static String toBase64(byte[] aValue) {
+
+ final String m_strBase64Chars =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ int byte1;
+ int byte2;
+ int byte3;
+ int iByteLen = aValue.length;
+ StringBuffer tt = new StringBuffer();
+
+ for (int i = 0; i < iByteLen; i += 3) {
+ boolean bByte2 = (i + 1) < iByteLen;
+ boolean bByte3 = (i + 2) < iByteLen;
+ byte1 = aValue[i] & 0xFF;
+ byte2 = (bByte2) ? (aValue[i + 1] & 0xFF) : 0;
+ byte3 = (bByte3) ? (aValue[i + 2] & 0xFF) : 0;
+
+ tt.append(m_strBase64Chars.charAt(byte1 / 4));
+ tt.append(m_strBase64Chars.charAt((byte2 / 16) + ((byte1 & 0x3) * 16)));
+ tt.append(((bByte2) ? m_strBase64Chars.charAt((byte3 / 64) + ((byte2 & 0xF) * 4)) : '='));
+ tt.append(((bByte3) ? m_strBase64Chars.charAt(byte3 & 0x3F) : '='));
+ }
+
+ return tt.toString();
+ }
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Escape, but do not replace HTML.
+ * @param escapeAmpersand Optionally escape
+ * ampersands (&).
+ */
+ public static String escapeHTML(String s, boolean escapeAmpersand) {
+ return Utilities.escapeHTML(s, escapeAmpersand);
+ }
+
+ //------------------------------------------------------------------------
+ /**
+ * Replace occurrences of str1 in string str with str2
+ */
+ public static String stringReplace(String str, String str1, String str2) {
+ String ret = StringUtils.replace(str,str1,str2);
+ return ret;
+ }
+
+ //------------------------------------------------------------------------
+ /**
+ * Replace occurrences of str1 in string str with str2
+ * @param str String to operate on
+ * @param str1 String to be replaced
+ * @param str2 String to be used as replacement
+ * @param maxCount Number of times to replace, 0 for all
+ */
+ public static String stringReplace(
+ String str,
+ String str1,
+ String str2,
+ int maxCount) {
+ String ret = StringUtils.replace(str,str1,str2,maxCount);
+ return ret;
+ }
+
+
+
+ /**
+ * Encode a string using Base64 encoding. Used when storing passwords
+ * as cookies.
+ *
+ * This is weak encoding in that anyone can use the decodeString
+ * routine to reverse the encoding.
+ *
+ * @param str
+ * @return String
+ * @throws IOException
+ */
+ public static String encodeString(String str) throws IOException {
+ String encodedStr = new String(Base64.encodeBase64(str.getBytes()));
+ return (encodedStr.trim());
+ }
+
+ /**
+ * Decode a string using Base64 encoding.
+ *
+ * @param str
+ * @return String
+ * @throws IOException
+ */
+ public static String decodeString(String str) throws IOException {
+ String value = new String(Base64.decodeBase64(str.getBytes()));
+ return (value);
+ }
+
+ /**
+ * @param str
+ * @return
+ */
+ private static String stripLineBreaks(String str) {
+ // TODO: use a string buffer, ignore case !
+ str = str.replaceAll("<br>", "");
+ str = str.replaceAll("<br/>", "");
+ str = str.replaceAll("<br />", "");
+ str = str.replaceAll("<p></p>", "");
+ str = str.replaceAll("<p/>","");
+ str = str.replaceAll("<p />","");
+ return str;
+ }
+
+ /**
+ * Need need to get rid of any user-visible HTML tags once all text has been
+ * removed such as <BR>. This sounds like a better approach than removing
+ * all HTML tags and taking the chance to leave some tags un-closed.
+ *
+ * WARNING: this method has serious performance problems a
+ *
+ * @author Alexis Moussine-Pouchkine (alexis.moussine-pouchkine@france.sun.com)
+ * @author Lance Lavandowska
+ * @param str the String object to modify
+ * @return the new String object without the HTML "visible" tags
+ */
+ private static String removeVisibleHTMLTags(String str) {
+ str = stripLineBreaks(str);
+ StringBuffer result = new StringBuffer(str);
+ StringBuffer lcresult = new StringBuffer(str.toLowerCase());
+
+ // <img should take care of smileys
+ String[] visibleTags = {"<img"}; // are there others to add?
+ int stringIndex;
+ for ( int j = 0 ; j < visibleTags.length ; j++ ) {
+ while ( (stringIndex = lcresult.indexOf(visibleTags[j])) != -1 ) {
+ if ( visibleTags[j].endsWith(">") ) {
+ result.delete(stringIndex, stringIndex+visibleTags[j].length() );
+ lcresult.delete(stringIndex, stringIndex+visibleTags[j].length() );
+ } else {
+ // need to delete everything up until next closing '>', for <img for instance
+ int endIndex = result.indexOf(">", stringIndex);
+ if (endIndex > -1) {
+ // only delete it if we find the end! If we don't the HTML may be messed up, but we
+ // can't safely delete anything.
+ result.delete(stringIndex, endIndex + 1 );
+ lcresult.delete(stringIndex, endIndex + 1 );
+ }
+ }
+ }
+ }
+
+ // TODO: This code is buggy by nature. It doesn't deal with nesting of tags properly.
+ // remove certain elements with open & close tags
+ String[] openCloseTags = {"li", "a", "div", "h1", "h2", "h3", "h4"}; // more ?
+ for (int j = 0; j < openCloseTags.length; j++) {
+ // could this be better done with a regular expression?
+ String closeTag = "</"+openCloseTags[j]+">";
+ int lastStringIndex = 0;
+ while ( (stringIndex = lcresult.indexOf( "<"+openCloseTags[j], lastStringIndex)) > -1) {
+ lastStringIndex = stringIndex;
+ // Try to find the matching closing tag (ignores possible nesting!)
+ int endIndex = lcresult.indexOf(closeTag, stringIndex);
+ if (endIndex > -1) {
+ // If we found it delete it.
+ result.delete(stringIndex, endIndex+closeTag.length());
+ lcresult.delete(stringIndex, endIndex+closeTag.length());
+ } else {
+ // Try to see if it is a self-closed empty content tag, i.e. closed with />.
+ endIndex = lcresult.indexOf(">", stringIndex);
+ int nextStart = lcresult.indexOf("<", stringIndex+1);
+ if (endIndex > stringIndex && lcresult.charAt(endIndex-1) == '/' && (endIndex < nextStart || nextStart == -1)) {
+ // Looks like it, so remove it.
+ result.delete(stringIndex, endIndex + 1);
+ lcresult.delete(stringIndex, endIndex + 1);
+
+ }
+ }
+ }
+ }
+
+ return result.toString();
+ }
+
+
+ /**
+ * Converts a character to HTML or XML entity.
+ *
+ * @param ch The character to convert.
+ * @param xml Convert the character to XML if set to true.
+ * @author Erik C. Thauvin
+ *
+ * @return The converted string.
+ */
+ public static final String charToHTML(char ch, boolean xml) {
+ int c;
+
+ // Convert left bracket
+ if (ch == '<') {
+ return ("<");
+ }
+
+ // Convert left bracket
+ else if (ch == '>') {
+ return (">");
+ }
+
+ // Convert ampersand
+ else if (ch == '&') {
+ return ("&");
+ }
+
+ // Commented out to eliminate redundant numeric character codes (ROL-507)
+ // High-ASCII character
+ //else if (ch >= 128)
+ //{
+ //c = ch;
+ //return ("&#" + c + ';');
+ //}
+
+ // Convert double quote
+ else if (xml && (ch == '"')) {
+ return (""");
+ }
+
+ // Convert single quote
+ else if (xml && (ch == '\'')) {
+ return ("'");
+ }
+
+ // No conversion
+ else {
+ // Return character as string
+ return (String.valueOf(ch));
+ }
+ }
+
+ /**
+ * Converts a text string to HTML or XML entities.
+ *
+ * @author Erik C. Thauvin
+ * @param text The string to convert.
+ * @param xml Convert the string to XML if set to true.
+ *
+ * @return The converted string.
+ */
+ public static final String textToHTML(String text, boolean xml) {
+ if (text == null) return "null";
+ final StringBuffer html = new StringBuffer();
+
+ // Loop thru each characters of the text
+ for (int i = 0; i < text.length(); i++) {
+ // Convert character to HTML/XML
+ html.append(charToHTML(text.charAt(i), xml));
+ }
+
+ // Return HTML/XML string
+ return html.toString();
+ }
+
+ /**
+ * Converts a text string to HTML or XML entities.
+ *
+ * @param text The string to convert.
+ * @author Erik C. Thauvin
+ * @return The converted string.
+ */
+ public static final String textToHTML(String text) {
+ return textToHTML(text, false);
+ }
+
+ /**
+ * Converts a text string to XML entities.
+ *
+ * @param text The string to convert.
+ * @author Erik C. Thauvin
+ * @return The converted string.
+ */
+ public static final String textToXML(String text) {
+ return textToHTML(text, true);
+ }
+
+ /**
+ * Converts a text string to HTML or XML entities.
+ * @param text The string to convert.
+ * @return The converted string.
+ */
+ public static final String textToCDATA(String text) {
+ if (text == null) return "null";
+ final StringBuffer html = new StringBuffer();
+
+ // Loop thru each characters of the text
+ for (int i = 0; i < text.length(); i++) {
+ // Convert character to HTML/XML
+ html.append(charToCDATA(text.charAt(i)));
+ }
+
+ // Return HTML/XML string
+ return html.toString();
+ }
+
+ /**
+ * Converts a character to CDATA character.
+ * @param ch The character to convert.
+ * @return The converted string.
+ */
+ public static final String charToCDATA(char ch) {
+ int c;
+
+ if (ch >= 128) {
+ c = ch;
+
+ return ("&#" + c + ';');
+ }
+
+ // No conversion
+ else {
+ // Return character as string
+ return (String.valueOf(ch));
+ }
+ }
+
+}
Added: roller/trunk/planet-web/src/main/java/org/apache/roller/util/StandaloneWebappClassLoader.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/util/StandaloneWebappClassLoader.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/util/StandaloneWebappClassLoader.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/util/StandaloneWebappClassLoader.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ *
+ * StandaloneWebappClassLoader.java
+ * Created on October 20, 2006, 11:11 PM
+ */
+
+package org.apache.roller.util;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ClassLoader to enable running webapp classes outside of webapp.
+ * You provide webappDir and jarsDir paths and the classloader will include
+ * webappDir/WEB-INF/classes, webappDir/WEB-INF/lib/*jar and jarsDir/*.jar.
+ */
+public class StandaloneWebappClassLoader extends URLClassLoader {
+ public static String FS = File.separator;
+
+ /** Use calling class's parent classloader */
+ public StandaloneWebappClassLoader(String webappDir, String jarsDir) throws Exception {
+ super(buildURLsArray(webappDir, jarsDir));
+ }
+
+ /** Use a specific parent classloader, or null for no parent */
+ public StandaloneWebappClassLoader(String webappDir, String jarsDir, ClassLoader cl) throws Exception {
+ super(buildURLsArray(webappDir, jarsDir), cl);
+ }
+
+ private static URL[] buildURLsArray(String webappDir, String jarsDir) throws Exception {
+ // Create collection of URLs needed for classloader
+ List urlList = new ArrayList();
+
+ // Add WEB-INF/lib jars
+ String libPath = webappDir + FS + "WEB-INF" + FS + "lib";
+ addURLs(libPath, urlList);
+
+ // Added WEB-INF/classes
+ String classesPath = webappDir + FS + "WEB-INF" + FS + "classes" + FS;
+ urlList.add(new URL("file://" + classesPath));
+
+ // Add additional jars
+ addURLs(jarsDir, urlList);
+
+ return (URL[])urlList.toArray(new URL[urlList.size()]);
+ }
+
+ private static void addURLs(String dirPath, List urlList) throws Exception {
+ File libDir = new File(dirPath);
+ String[] libJarNames = libDir.list(new FilenameFilter() {
+ public boolean accept(File dir, String pathname) {
+ if (pathname.endsWith(".jar")) {
+ return true;
+ }
+ return false;
+ }
+ });
+ for (int i=0; i<libJarNames.length; i++) {
+ String url = "file://" + dirPath + FS + libJarNames[i];
+ urlList.add(new URL(url));
+ }
+ }
+}
Added: roller/trunk/planet-web/src/main/java/org/apache/roller/util/TaskRunner.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/util/TaskRunner.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/util/TaskRunner.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/util/TaskRunner.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,82 @@
+/*
+* 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.util;
+
+import java.io.File;
+import org.apache.roller.planet.tasks.PlanetTask;
+
+/**
+ * Sets up classpath for Roller and runs a task.
+ * Expects these JVM parameters:
+ * webapp.dir must specify Roller webapp directory
+ * jars.dir must specify additional jars directory (e.g. Tomcat commons/lib)
+ */
+public class TaskRunner {
+
+ public TaskRunner() {}
+
+ public static void main(String[] args) throws Exception {
+ if (args.length < 3) {
+ System.err.println("USAGE: java -cp roller-planet.jar TaskRunner WEBAPPDIR JARSDIR CLASSNAME");
+ System.err.println("WEBAPPDIR: The directory path to the web application ");
+ System.err.println(" (e.g. $CATALINA_HOME/webapps/roller)");
+ System.err.println("JARSDIR: The directory path to the additional jars ");
+ System.err.println(" directory (e.g. $CATALINA_HOME/common/lib)");
+ System.err.println("CLASSNAME: The name of the class to be executed by TaskRunner ");
+ System.exit(-1);
+ }
+ String webappDir = args[0];
+ String jarsDir = args[1];
+ String taskClassName = args[2];
+ System.out.println("WEBAPPDIR = " + webappDir);
+ System.out.println("JARSDIR = " + jarsDir);
+ System.out.println("CLASSNAME = " + taskClassName);
+
+ File webappDirFile = new File(webappDir);
+ File jarsDirFile = new File(jarsDir);
+ if (!webappDirFile.isDirectory() || !jarsDirFile.isDirectory()) {
+ System.err.println("ERROR: webapp.dir and jars.dir must specify existing directories");
+ System.exit(-1);
+ }
+
+ ClassLoader cl = new StandaloneWebappClassLoader(webappDir, jarsDir, null);
+
+ // We're using the new classloader from here on out
+ Thread.currentThread().setContextClassLoader(cl);
+
+ // Go!
+ Class taskClass = cl.loadClass(taskClassName);
+ PlanetTask task = (PlanetTask) taskClass.newInstance();
+ task.initialize();
+ task.run();
+ }
+}
+
+
+/* for example:
+
+java \
+ -Dplanet.custom.config=planet-custom.properties \
+ -Dcatalina.base=. \
+ -cp ./build/webapp/WEB-INF/lib/roller-business.jar \
+ org.apache.roller.util.TaskRunner \
+ ~/roller_trunk/sandbox/planetroller/build/webapp \
+ /Applications/Java/jakarta-tomcat-5.5.9/common/lib \
+ org.apache.roller.planet.tasks.GeneratePlanetTask
+
+ */
Added: roller/trunk/planet-web/src/main/java/org/apache/roller/util/UtilitiesModel.java
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/java/org/apache/roller/util/UtilitiesModel.java?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/java/org/apache/roller/util/UtilitiesModel.java (added)
+++ roller/trunk/planet-web/src/main/java/org/apache/roller/util/UtilitiesModel.java Sat Mar 20 18:37:51 2010
@@ -0,0 +1,525 @@
+/*
+ * 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.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.planet.PlanetException;
+//import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
+//import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
+//import org.apache.roller.ui.core.RollerSession;
+//import org.apache.roller.ui.rendering.util.WeblogRequest;
+import org.apache.roller.util.DateUtil;
+import org.apache.roller.util.RegexUtil;
+import org.apache.roller.planet.util.Utilities;
+
+/**
+ * Model which provides access to a set of general utilities.
+ */
+public class UtilitiesModel { // implements Model {
+
+ private static Log log = LogFactory.getLog(UtilitiesModel.class);
+
+ private static Pattern mLinkPattern =
+ Pattern.compile("<a href=.*?>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_B_TAG_PATTERN =
+ Pattern.compile("<b>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_B_TAG_PATTERN =
+ Pattern.compile("</b>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_I_TAG_PATTERN =
+ Pattern.compile("<i>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_I_TAG_PATTERN =
+ Pattern.compile("</i>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_BLOCKQUOTE_TAG_PATTERN =
+ Pattern.compile("<blockquote>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_BLOCKQUOTE_TAG_PATTERN =
+ Pattern.compile("</blockquote>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern BR_TAG_PATTERN =
+ Pattern.compile("<br */*>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_P_TAG_PATTERN =
+ Pattern.compile("<p>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_P_TAG_PATTERN =
+ Pattern.compile("</p>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_PRE_TAG_PATTERN =
+ Pattern.compile("<pre>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_PRE_TAG_PATTERN =
+ Pattern.compile("</pre>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_UL_TAG_PATTERN =
+ Pattern.compile("<ul>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_UL_TAG_PATTERN =
+ Pattern.compile("</ul>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_OL_TAG_PATTERN =
+ Pattern.compile("<ol>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_OL_TAG_PATTERN =
+ Pattern.compile("</ol>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_LI_TAG_PATTERN =
+ Pattern.compile("<li>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_LI_TAG_PATTERN =
+ Pattern.compile("</li>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CLOSING_A_TAG_PATTERN =
+ Pattern.compile("</a>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern OPENING_A_TAG_PATTERN =
+ Pattern.compile("<a href=.*?>", Pattern.CASE_INSENSITIVE);
+ private static final Pattern QUOTE_PATTERN =
+ Pattern.compile(""", Pattern.CASE_INSENSITIVE);
+
+ private TimeZone tz = null;
+
+
+ /** Template context name to be used for model */
+ public String getModelName() {
+ return "utils";
+ }
+
+
+// /** Init page model based on request */
+// public void init(Map initData) throws PlanetException {
+//
+// // extract request object
+// this.request = (HttpServletRequest) initData.get("request");
+//
+// // extract timezone if available
+// WeblogRequest weblogRequest = (WeblogRequest)initData.get("weblogRequest");
+// if (weblogRequest != null && weblogRequest.getWeblog() != null) {
+// tz = weblogRequest.getWeblog().getTimeZoneInstance();
+// }
+// }
+//
+//
+// //---------------------------------------------------- Authentication utils
+//
+// public boolean isUserAuthorizedToAuthor(WebsiteDataWrapper weblog) {
+// try {
+// RollerSession rses = RollerSession.getRollerSession(request);
+// if (rses != null && rses.getAuthenticatedUser() != null) {
+// return rses.isUserAuthorizedToAuthor(weblog.getPojo());
+// }
+// } catch (Exception e) {
+// log.warn("ERROR: checking user authorization", e);
+// }
+// return false;
+// }
+//
+// public boolean isUserAuthorizedToAdmin(WebsiteDataWrapper weblog) {
+// try {
+// RollerSession rses = RollerSession.getRollerSession(request);
+// if (rses != null && rses.getAuthenticatedUser() != null) {
+// return rses.isUserAuthorizedToAdmin(weblog.getPojo());
+// }
+// } catch (Exception e) {
+// log.warn("ERROR: checking user authorization", e);
+// }
+// return false;
+// }
+//
+// public boolean isUserAuthenticated() {
+// return (request.getUserPrincipal() != null);
+// }
+
+ //-------------------------------------------------------------- Date utils
+ /**
+ * Return date for current time.
+ */
+ public static Date getNow() {
+ return new Date();
+ }
+
+ /**
+ * Format date using SimpleDateFormat format string.
+ */
+ public String formatDate(Date d, String fmt) {
+ if(d == null || fmt == null)
+ return fmt;
+
+ SimpleDateFormat format = new SimpleDateFormat(fmt);
+ if (tz != null) {
+ format.setTimeZone(tz);
+ }
+ return format.format(d);
+ }
+
+ /**
+ * Format date using SimpleDateFormat format string.
+ */
+ public static String formatDate(Date d, String fmt, TimeZone tzOverride) {
+ if(d == null || fmt == null)
+ return fmt;
+
+ SimpleDateFormat format = new SimpleDateFormat(fmt);
+ format.setTimeZone(tzOverride);
+ return format.format(d);
+ }
+
+ /**
+ * Format date in ISO-8601 format.
+ */
+ public static String formatIso8601Date(Date d) {
+ return DateUtil.formatIso8601(d);
+ }
+
+ /**
+ * Format date in ISO-8601 format.
+ */
+ public static String formatIso8601Day(Date d) {
+ return DateUtil.formatIso8601Day(d);
+ }
+
+ /**
+ * Return a date in RFC-822 format.
+ */
+ public static String formatRfc822Date(Date date) {
+ return DateUtil.formatRfc822(date);
+ }
+
+ /**
+ * Return a date in RFC-822 format.
+ */
+ public static String format8charsDate(Date date) {
+ return DateUtil.format8chars(date);
+ }
+
+ //------------------------------------------------------------ String utils
+
+ public static boolean isEmpty(String str) {
+ if (str == null) return true;
+ return "".equals(str.trim());
+ }
+
+ public static boolean isNotEmpty(String str) {
+ return !isEmpty(str);
+ }
+
+ public static String[] split(String str1, String str2) {
+ return StringUtils.split(str1, str2);
+ }
+
+
+ public static boolean equals(String str1, String str2) {
+ return StringUtils.equals(str1, str2);
+ }
+
+ public static boolean isAlphanumeric(String str) {
+ return StringUtils.isAlphanumeric(str);
+ }
+
+ public static String[] stripAll(String[] strs) {
+ return StringUtils.stripAll(strs);
+ }
+
+ public static String left(String str, int length) {
+ return StringUtils.left(str, length);
+ }
+
+ public static String escapeHTML(String str) {
+ return StringEscapeUtils.escapeHtml(str);
+ }
+
+ public static String unescapeHTML(String str) {
+ return StringEscapeUtils.unescapeHtml(str);
+ }
+
+ public static String escapeXML(String str) {
+ return StringEscapeUtils.escapeXml(str);
+ }
+
+ public static String unescapeXML(String str) {
+ return StringEscapeUtils.unescapeXml(str);
+ }
+
+ public static String replace(String src, String target, String rWith) {
+ return StringUtils.replace(src, target, rWith);
+ }
+
+ public static String replace(String src, String target, String rWith, int maxCount) {
+ return StringUtils.replace(src, target, rWith, maxCount);
+ }
+
+ private static String replace(String string, Pattern pattern, String replacement) {
+ Matcher m = pattern.matcher(string);
+ return m.replaceAll(replacement);
+ }
+
+ /**
+ * Remove occurences of html, defined as any text
+ * between the characters "<" and ">". Replace
+ * any HTML tags with a space.
+ */
+ public static String removeHTML(String str) {
+ return removeHTML(str, true);
+ }
+
+ /**
+ * Remove occurences of html, defined as any text
+ * between the characters "<" and ">".
+ * Optionally replace HTML tags with a space.
+ */
+ public static String removeHTML(String str, boolean addSpace) {
+ return Utilities.removeHTML(str, addSpace);
+ }
+
+ /**
+ * Autoformat.
+ */
+ public static String autoformat(String s) {
+ String ret = StringUtils.replace(s, "\n", "<br />");
+ return ret;
+ }
+ /**
+ * Strips HTML and truncates.
+ */
+ public static String truncate(
+ String str, int lower, int upper, String appendToEnd) {
+ // strip markup from the string
+ String str2 = removeHTML(str, false);
+
+ // quickly adjust the upper if it is set lower than 'lower'
+ if (upper < lower) {
+ upper = lower;
+ }
+
+ // now determine if the string fits within the upper limit
+ // if it does, go straight to return, do not pass 'go' and collect $200
+ if(str2.length() > upper) {
+ // the magic location int
+ int loc;
+
+ // first we determine where the next space appears after lower
+ loc = str2.lastIndexOf(' ', upper);
+
+ // now we'll see if the location is greater than the lower limit
+ if(loc >= lower) {
+ // yes it was, so we'll cut it off here
+ str2 = str2.substring(0, loc);
+ } else {
+ // no it wasnt, so we'll cut it off at the upper limit
+ str2 = str2.substring(0, upper);
+ loc = upper;
+ }
+
+ // the string was truncated, so we append the appendToEnd String
+ str2 = str2 + appendToEnd;
+ }
+
+ return str2;
+ }
+
+ public static String truncateNicely(String str, int lower, int upper, String appendToEnd) {
+ return Utilities.truncateNicely(str, lower, upper, appendToEnd);
+ }
+
+ public static String truncateText(String str, int lower, int upper, String appendToEnd) {
+ // strip markup from the string
+ String str2 = removeHTML(str, false);
+ boolean diff = (str2.length() < str.length());
+
+ // quickly adjust the upper if it is set lower than 'lower'
+ if(upper < lower) {
+ upper = lower;
+ }
+
+ // now determine if the string fits within the upper limit
+ // if it does, go straight to return, do not pass 'go' and collect $200
+ if(str2.length() > upper) {
+ // the magic location int
+ int loc;
+
+ // first we determine where the next space appears after lower
+ loc = str2.lastIndexOf(' ', upper);
+
+ // now we'll see if the location is greater than the lower limit
+ if(loc >= lower) {
+ // yes it was, so we'll cut it off here
+ str2 = str2.substring(0, loc);
+ } else {
+ // no it wasnt, so we'll cut it off at the upper limit
+ str2 = str2.substring(0, upper);
+ loc = upper;
+ }
+ // the string was truncated, so we append the appendToEnd String
+ str = str2 + appendToEnd;
+ }
+ return str;
+ }
+
+ public static String hexEncode(String str) {
+ if (StringUtils.isEmpty(str)) return str;
+
+ return RegexUtil.encode(str);
+ }
+
+ public static String encodeEmail(String str) {
+ return str!=null ? RegexUtil.encodeEmail(str) : null;
+ }
+
+ /**
+ * URL encoding.
+ * @param s a string to be URL-encoded
+ * @return URL encoding of s using character encoding UTF-8; null if s is null.
+ */
+ public static final String encode(String s) {
+ try {
+ if (s != null)
+ return URLEncoder.encode(s, "UTF-8");
+ else
+ return s;
+ } catch (UnsupportedEncodingException e) {
+ // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+ return s;
+ }
+ }
+
+ /**
+ * URL decoding.
+ * @param s a URL-encoded string to be URL-decoded
+ * @return URL decoded value of s using character encoding UTF-8; null if s is null.
+ */
+ public static final String decode(String s) {
+ try {
+ if (s != null)
+ return URLDecoder.decode(s, "UTF-8");
+ else
+ return s;
+ } catch (UnsupportedEncodingException e) {
+ // Java Spec requires UTF-8 be in all Java environments, so this should not happen
+ return s;
+ }
+ }
+
+ /**
+ * Code (stolen from Pebble) to add rel="nofollow" string to all links in HTML.
+ */
+ public static String addNofollow(String html) {
+ if (html == null || html.length() == 0) {
+ return html;
+ }
+ Matcher m = mLinkPattern.matcher(html);
+ StringBuffer buf = new StringBuffer();
+ while (m.find()) {
+ int start = m.start();
+ int end = m.end();
+ String link = html.substring(start, end);
+ buf.append(html.substring(0, start));
+ if (link.indexOf("rel=\"nofollow\"") == -1) {
+ buf.append(
+ link.substring(0, link.length() - 1) + " rel=\"nofollow\">");
+ } else {
+ buf.append(link);
+ }
+ html = html.substring(end, html.length());
+ m = mLinkPattern.matcher(html);
+ }
+ buf.append(html);
+ return buf.toString();
+ }
+
+ /**
+ * Transforms the given String into a subset of HTML displayable on a web
+ * page. The subset includes <b>, <i>, <p>, <br>,
+ * <pre> and <a href> (and their corresponding end tags).
+ *
+ * @param s the String to transform
+ * @return the transformed String
+ */
+ public static String transformToHTMLSubset(String s) {
+
+ if (s == null) {
+ return null;
+ }
+
+ s = replace(s, OPENING_B_TAG_PATTERN, "<b>");
+ s = replace(s, CLOSING_B_TAG_PATTERN, "</b>");
+ s = replace(s, OPENING_I_TAG_PATTERN, "<i>");
+ s = replace(s, CLOSING_I_TAG_PATTERN, "</i>");
+ s = replace(s, OPENING_BLOCKQUOTE_TAG_PATTERN, "<blockquote>");
+ s = replace(s, CLOSING_BLOCKQUOTE_TAG_PATTERN, "</blockquote>");
+ s = replace(s, BR_TAG_PATTERN, "<br />");
+ s = replace(s, OPENING_P_TAG_PATTERN, "<p>");
+ s = replace(s, CLOSING_P_TAG_PATTERN, "</p>");
+ s = replace(s, OPENING_PRE_TAG_PATTERN, "<pre>");
+ s = replace(s, CLOSING_PRE_TAG_PATTERN, "</pre>");
+ s = replace(s, OPENING_UL_TAG_PATTERN, "<ul>");
+ s = replace(s, CLOSING_UL_TAG_PATTERN, "</ul>");
+ s = replace(s, OPENING_OL_TAG_PATTERN, "<ol>");
+ s = replace(s, CLOSING_OL_TAG_PATTERN, "</ol>");
+ s = replace(s, OPENING_LI_TAG_PATTERN, "<li>");
+ s = replace(s, CLOSING_LI_TAG_PATTERN, "</li>");
+ s = replace(s, QUOTE_PATTERN, "\"");
+
+ // HTTP links
+ s = replace(s, CLOSING_A_TAG_PATTERN, "</a>");
+ Matcher m = OPENING_A_TAG_PATTERN.matcher(s);
+ while (m.find()) {
+ int start = m.start();
+ int end = m.end();
+ String link = s.substring(start, end);
+ link = "<" + link.substring(4, link.length() - 4) + ">";
+ s = s.substring(0, start) + link + s.substring(end, s.length());
+ m = OPENING_A_TAG_PATTERN.matcher(s);
+ }
+
+ // escaped angle brackets
+ s = s.replaceAll("&lt;", "<");
+ s = s.replaceAll("&gt;", ">");
+ s = s.replaceAll("&#", "&#");
+
+ return s;
+ }
+
+ /**
+ * Convert a byte array into a Base64 string (as used in mime formats)
+ */
+ public static String toBase64(byte[] aValue) {
+
+ final String m_strBase64Chars =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ int byte1;
+ int byte2;
+ int byte3;
+ int iByteLen = aValue.length;
+ StringBuffer tt = new StringBuffer();
+
+ for (int i = 0; i < iByteLen; i += 3) {
+ boolean bByte2 = (i + 1) < iByteLen;
+ boolean bByte3 = (i + 2) < iByteLen;
+ byte1 = aValue[i] & 0xFF;
+ byte2 = (bByte2) ? (aValue[i + 1] & 0xFF) : 0;
+ byte3 = (bByte3) ? (aValue[i + 2] & 0xFF) : 0;
+
+ tt.append(m_strBase64Chars.charAt(byte1 / 4));
+ tt.append(m_strBase64Chars.charAt((byte2 / 16) + ((byte1 & 0x3) * 16)));
+ tt.append(((bByte2) ? m_strBase64Chars.charAt((byte3 / 64) + ((byte2 & 0xF) * 4)) : '='));
+ tt.append(((bByte3) ? m_strBase64Chars.charAt(byte3 & 0x3F) : '='));
+ }
+
+ return tt.toString();
+ }
+
+}
Added: roller/trunk/planet-web/src/main/resources/JPAEMF.properties
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/resources/JPAEMF.properties?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/resources/JPAEMF.properties (added)
+++ roller/trunk/planet-web/src/main/resources/JPAEMF.properties Sat Mar 20 18:37:51 2010
@@ -0,0 +1,27 @@
+# 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.
+
+# JPA properties file
+#
+# You can set JPA/Toplink, JPA/OpenJPA and JPA/Hibernate properties in your
+# roller-custom.properties override file. For other JPA implementations set
+# properties here and Roller will pick them up.
+
+# Required properties for using OpenJPA with Roller
+openjpa.IgnoreChanges=true
+openjpa.FlushBeforeQueries=true
+#openjpa.Log=DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE
+
Added: roller/trunk/planet-web/src/main/resources/commons-logging.properties
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/resources/commons-logging.properties?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/resources/commons-logging.properties (added)
+++ roller/trunk/planet-web/src/main/resources/commons-logging.properties Sat Mar 20 18:37:51 2010
@@ -0,0 +1,18 @@
+# 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.
+
+org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
+org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
\ No newline at end of file
Added: roller/trunk/planet-web/src/main/resources/ehcache.xml
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/resources/ehcache.xml?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/resources/ehcache.xml (added)
+++ roller/trunk/planet-web/src/main/resources/ehcache.xml Sat Mar 20 18:37:51 2010
@@ -0,0 +1,13 @@
+<ehcache>
+
+ <diskStore path="java.io.tmpdir"/>
+
+ <!-- default cache expires items after 30 mins -->
+ <defaultCache
+ maxElementsInMemory="1000"
+ eternal="false"
+ timeToIdleSeconds="1200"
+ timeToLiveSeconds="1200"
+ overflowToDisk="false" />
+
+</ehcache>
Added: roller/trunk/planet-web/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/resources/log4j.properties?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/resources/log4j.properties (added)
+++ roller/trunk/planet-web/src/main/resources/log4j.properties Sat Mar 20 18:37:51 2010
@@ -0,0 +1,60 @@
+# 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.
+
+# Properties for configuring Log4j for this application
+# This is the configuring for logging displayed in the Application Server
+log4j.rootCategory=INFO, planet
+
+log4j.appender.planet=org.apache.log4j.DailyRollingFileAppender
+log4j.appender.planet.File=${catalina.base}/logs/planet.log
+log4j.appender.planet.layout=org.apache.log4j.PatternLayout
+log4j.appender.planet.layout.ConversionPattern=%-5p %d{yyyy-MM-dd HH:mm:ss,SSS} %C{1}:%M - %m%n
+
+# Options are: DEBUG, INFO, WARN, ERROR, FATAL
+# Roller code
+log4j.category.org.apache.roller.planet=INFO
+log4j.category.net.java.roller=INFO
+
+# Roller dependent libraries
+log4j.category.org.hibernate=INFO
+log4j.category.org.apache.struts2=INFO
+log4j.category.com.opensymphony.xwork2=INFO
+# this class has stupid logging which floods tons of pointless messages at INFO level
+log4j.category.com.opensymphony.xwork2.config.providers.XmlConfigurationProvider=WARN
+log4j.category.org.springframework=WARN
+log4j.category.org.acegisecurity=ERROR
+# Velocity talks a lot, so by default it is set to STFU mode
+log4j.category.org.apache.velocity=FATAL
+
+# Roller extras
+log4j.category.com.ecyrd.jspwiki=ERROR
+log4j.category.org.tuckey.web.filters.urlrewrite=DEBUG
+log4j.category.com.opensymphony.oscache=ERROR
+log4j.category.com.danga.MemCached=WARN
+
+
+
+# Configuration for receiving e-mails when ERROR messages occur.
+#log4j.appender.mail=org.apache.log4j.net.SMTPAppender
+#log4j.appender.mail.To=you@yours.com
+#log4j.appender.mail.From=you@yours.com
+#log4j.appender.mail.SMTPHost=127.0.0.1
+#log4j.appender.mail.Threshold=ERROR
+#log4j.appender.mail.BufferSize=1
+#log4j.appender.mail.Subject=Roller Exception
+
+#log4j.appender.mail.layout=org.apache.log4j.PatternLayout
+#log4j.appender.mail.layout.ConversionPattern=%p [%d{yyyy-MM-dd HH:mm:ss,SSS}] %C{1}.%M(%L) | %m%n
Added: roller/trunk/planet-web/src/main/resources/rome.properties
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/resources/rome.properties?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/resources/rome.properties (added)
+++ roller/trunk/planet-web/src/main/resources/rome.properties Sat Mar 20 18:37:51 2010
@@ -0,0 +1,60 @@
+# 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.
+
+
+# Some RSS 0.91 feeds have pubDates in items
+
+WireFeedParser.classes=org.apache.roller.planet.util.rome.PlanetRSS091UParser \
+ org.apache.roller.planet.util.rome.PlanetRSS091NParser
+
+Converter.classes =org.apache.roller.planet.util.rome.PlanetConverterForRSS091U \
+ org.apache.roller.planet.util.rome.PlanetConverterForRSS091N \
+ org.apache.roller.planet.util.rome.PlanetConverterForRSS20
+
+# Handle funky RSS (RSS 2.0 with <dc:date> and/or <content:encoded>)
+
+rss_2.0.feed.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+ org.apache.roller.planet.util.rome.ContentModuleGenerator
+
+rss_2.0.item.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+ org.apache.roller.planet.util.rome.ContentModuleGenerator
+
+rss_2.0.feed.ModuleParser.classes =com.sun.syndication.io.impl.DCModuleParser \
+ org.apache.roller.planet.util.rome.ContentModuleParser
+
+rss_2.0.item.ModuleParser.classes =com.sun.syndication.io.impl.DCModuleParser \
+ org.apache.roller.planet.util.rome.ContentModuleParser
+
+# Handle <content:encoded> in RSS 1.0
+
+rss_1.0.feed.ModuleParser.classes =com.sun.syndication.io.impl.DCModuleParser \
+ org.apache.roller.planet.util.rome.ContentModuleParser
+
+rss_1.0.item.ModuleParser.classes =com.sun.syndication.io.impl.DCModuleParser \
+ org.apache.roller.planet.util.rome.ContentModuleParser
+
+rss_1.0.feed.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+ org.apache.roller.planet.util.rome.ContentModuleGenerator
+
+rss_1.0.item.ModuleGenerator.classes =com.sun.syndication.io.impl.DCModuleGenerator \
+ org.apache.roller.planet.util.rome.ContentModuleGenerator
+
+
+
+
+
+
+
\ No newline at end of file
Added: roller/trunk/planet-web/src/main/resources/struts.properties
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/resources/struts.properties?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/resources/struts.properties (added)
+++ roller/trunk/planet-web/src/main/resources/struts.properties Sat Mar 20 18:37:51 2010
@@ -0,0 +1,9 @@
+
+struts.objectFactory = spring
+
+struts.devMode = true
+
+struts.enable.DynamicMethodInvocation = true
+
+# prevent the damn s:url calls from including undesired query params by default
+struts.url.includeParams=none
Added: roller/trunk/planet-web/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/resources/struts.xml?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/resources/struts.xml (added)
+++ roller/trunk/planet-web/src/main/resources/struts.xml Sat Mar 20 18:37:51 2010
@@ -0,0 +1,46 @@
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
+<struts>
+ <!-- core package space -->
+ <package name="planet" namespace="/planet-ui" extends="struts-default">
+ <action name="Login" class="org.apache.roller.planet.ui.core.struts2.Login">
+ <result>/WEB-INF/jsps/login.jsp</result>
+ </action>
+ <action name="Logout" class="org.apache.roller.planet.ui.core.struts2.Logout">
+ <result>/WEB-INF/jsps/logout.jsp</result>
+ </action>
+ <action name="MainMenu" class="org.apache.roller.planet.ui.core.struts2.MainMenu">
+ <result>/WEB-INF/jsps/MainMenu.jsp</result>
+ </action>
+ </package>
+
+ <!-- site admin package space -->
+ <package name="planetadmin" namespace="/planet-ui/admin" extends="planet">
+
+ <!-- use stack which supports the use of the Preparable interface on actions -->
+ <default-interceptor-ref name="paramsPrepareParamsStack"/>
+
+ <action name="ConfigForm!*" method="{1}"
+ class="org.apache.roller.planet.ui.admin.struts2.ConfigForm">
+ <result name="input">/WEB-INF/jsps/admin/ConfigForm.jsp</result>
+ </action>
+ <action name="PlanetsList!*" method="{1}"
+ class="org.apache.roller.planet.ui.admin.struts2.PlanetsList">
+ <result name="list">/WEB-INF/jsps/admin/PlanetsList.jsp</result>
+ <interceptor-ref name="basicStack"/>
+ </action>
+ <action name="PlanetForm!*" method="{1}"
+ class="org.apache.roller.planet.ui.admin.struts2.PlanetForm">
+ <result name="input">/WEB-INF/jsps/admin/PlanetForm.jsp</result>
+ </action>
+ <action name="PlanetGroupForm!*" method="{1}"
+ class="org.apache.roller.planet.ui.admin.struts2.PlanetGroupForm">
+ <result name="input">/WEB-INF/jsps/admin/PlanetGroupForm.jsp</result>
+ </action>
+ <action name="PlanetSubscriptionForm!*" method="{1}"
+ class="org.apache.roller.planet.ui.admin.struts2.PlanetSubscriptionForm">
+ <result name="input">/WEB-INF/jsps/admin/PlanetSubscriptionForm.jsp</result>
+ </action>
+ </package>
+</struts>
\ No newline at end of file
Added: roller/trunk/planet-web/src/main/webapp/META-INF/context.xml
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/webapp/META-INF/context.xml?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/webapp/META-INF/context.xml (added)
+++ roller/trunk/planet-web/src/main/webapp/META-INF/context.xml Sat Mar 20 18:37:51 2010
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Context path="/planetroller"/>
Added: roller/trunk/planet-web/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/webapp/WEB-INF/applicationContext.xml?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/webapp/WEB-INF/applicationContext.xml (added)
+++ roller/trunk/planet-web/src/main/webapp/WEB-INF/applicationContext.xml Sat Mar 20 18:37:51 2010
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans default-autowire="autodetect">
+ <!-- add your spring beans here -->
+</beans>
Added: roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/MainMenu.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/MainMenu.jsp?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/MainMenu.jsp (added)
+++ roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/MainMenu.jsp Sat Mar 20 18:37:51 2010
@@ -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.
+--%>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title><s:text name="Menu.pageTitle" /></title>
+ <link rel="stylesheet" type="text/css" href="<s:url value="/planet-ui/css/planet.css" />" />
+ </head>
+ <body>
+ <div id="wrapper">
+
+ <h1><s:text name="Menu.heading" /></h1>
+
+ <p><a href='<s:url value="/" />'><s:text name="Menu.mainPlanetLink" /></a></p>
+
+ <p><a href='<s:url action="Register" />'><s:text name="Menu.mainRegistrationLink" /></a></p>
+
+ <p><a href='<s:url action="ConfigForm" namespace="/planet-ui/admin" />'><s:text name="Menu.mainConsoleLink" /></a></p>
+
+ </div>
+ </body>
+</html>
Added: roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/ConfigForm.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/ConfigForm.jsp?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/ConfigForm.jsp (added)
+++ roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/ConfigForm.jsp Sat Mar 20 18:37:51 2010
@@ -0,0 +1,117 @@
+<%--
+ 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.
+--%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<%-- Start by parsing our config defs using the jstl xml toolkit --%>
+<%-- Then we'll progress through the config defs and print out the form --%>
+<x:parse var="configDefs">
+ <%= org.apache.roller.planet.config.PlanetRuntimeConfig.getRuntimeConfigDefsAsString() %>
+</x:parse>
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title><s:text name="ConfigForm.pageTitle" /></title>
+ <link rel="stylesheet" type="text/css" href="<s:url value="/planet-ui/css/planet.css" />" />
+ </head>
+ <body>
+ <div id="wrapper">
+
+ <%-- show the menu bar --%>
+ <%@include file="/WEB-INF/jsps/admin/menu.jsp" %>
+
+ <h2><s:text name="ConfigForm.formTitle" /></h2>
+
+ <p><s:text name="ConfigForm.formHelp" /></p>
+
+ <%-- show a status message if needed --%>
+ <%@include file="/WEB-INF/jsps/admin/statusMessage.jsp" %>
+
+ <s:form name="ConfigForm" action="ConfigForm!save">
+
+ <table class="formtableNoDesc">
+
+ <x:forEach select="$configDefs//config-def[@name='global-properties']/display-group">
+ <c:set var="displayGroupKey"><x:out select="@key"/></c:set>
+
+ <tr>
+ <td colspan="3"><h3><s:text name="${displayGroupKey}" /></h3></td>
+ </tr>
+
+ <x:forEach select="property-def">
+ <c:set var="propLabelKey"><x:out select="@key"/></c:set>
+ <c:set var="name"><x:out select="@name"/></c:set>
+
+ <tr>
+ <td class="label"><s:text name="${propLabelKey}" /></td>
+
+ <%-- choose the right html input element for the display --%>
+ <x:choose>
+
+ <%-- "string" type means use a simple textbox --%>
+ <x:when select="type='string'">
+ <td class="field"><input type="text" name='<c:out value="${name}"/>' value='<s:property value="properties['${name}'].value"/>' size="35" /></td>
+ </x:when>
+
+ <%-- "text" type means use a full textarea --%>
+ <x:when select="type='text'">
+ <td class="field">
+ <textarea name='<c:out value="${name}"/>' rows="<x:out select="rows"/>" cols="<x:out select="cols"/>"><c:out value="${RollerProps[name].value}"/></textarea>
+ </td>
+ </x:when>
+
+ <%-- "boolean" type means use a checkbox --%>
+ <x:when select="type='boolean'">
+ <c:choose>
+ <c:when test="${RollerProps[name].value eq 'true'}">
+ <td class="field"><input type="checkbox" name='<c:out value="${name}"/>' CHECKED></td>
+ </c:when>
+ <c:otherwise>
+ <td class="field"><input type="checkbox" name='<c:out value="${name}"/>'></td>
+ </c:otherwise>
+ </c:choose>
+ </x:when>
+
+ <%-- if it's something we don't understand then use textbox --%>
+ <x:otherwise>
+ <td class="field"><input type="text" name='<c:out value="${name}"/>' size="50" /></td>
+ </x:otherwise>
+ </x:choose>
+
+ <td class="description"><%-- <fmt:message key="" /> --%></td>
+ </tr>
+
+ </x:forEach>
+
+ <tr>
+ <td colspan="2"> </td>
+ </tr>
+
+ </x:forEach>
+
+ </table>
+
+ <s:submit />
+
+ </s:form>
+
+ </div>
+ </body>
+</html>
Added: roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/PlanetForm.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/PlanetForm.jsp?rev=925653&view=auto
==============================================================================
--- roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/PlanetForm.jsp (added)
+++ roller/trunk/planet-web/src/main/webapp/WEB-INF/jsps/admin/PlanetForm.jsp Sat Mar 20 18:37:51 2010
@@ -0,0 +1,89 @@
+<%--
+ 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.
+--%>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title><s:text name="PlanetForm.pageTitle" /></title>
+ <link rel="stylesheet" type="text/css" href="<s:url value="/planet-ui/css/planet.css" />" />
+ <script type="text/javascript">
+ function confirmGroupDelete(groupid, handle) {
+ if (window.confirm('Are you sure you want to remove group: ' + handle)) {
+ document.location.href='<s:url action="PlanetForm" method="deleteGroup" />?groupid='+groupid;
+ }
+ }
+ </script>
+ </head>
+ <body>
+ <div id="wrapper">
+
+ <%-- show the menu bar --%>
+ <%@include file="/WEB-INF/jsps/admin/menu.jsp" %>
+
+ <h2><s:text name="PlanetForm.heading" /></h2>
+
+ <p><s:text name="PlanetForm.help" /></p>
+
+ <%-- show a status message if needed --%>
+ <%@include file="/WEB-INF/jsps/admin/statusMessage.jsp" %>
+
+ <p><a href='<s:url action="PlanetsList" includeParams="get" />'><s:text name="PlanetForm.returnToList"/></a></p>
+
+ <s:form name="PlanetForm" action="PlanetForm!save">
+ <s:hidden name="planetid" />
+ <s:textfield label="%{getText('PlanetForm.handle')}" name="planet.handle" size="40" />
+ <s:textfield label="%{getText('PlanetForm.title')}" name="planet.title" size="40" />
+ <s:textarea label="%{getText('PlanetForm.description')}" name="planet.description" cols="47" rows="3" />
+ <s:submit />
+ </s:form>
+
+
+ <s:if test="planet.id != null">
+
+ <h2><s:text name="PlanetForm.groupsHeading"/></h2>
+
+ <table class="data">
+ <tr>
+ <th><s:text name="PlanetForm.groupTitle" /></th>
+ <th><s:text name="PlanetForm.groupURL" /></th>
+ <th><s:text name="PlanetForm.action" /></th>
+ </tr>
+
+ <s:iterator value="planet.groups" status="status">
+ <s:url id="editgroupurl" action="PlanetGroupForm" >
+ <s:param name="groupid"><s:property value="id"/></s:param>
+ </s:url>
+ <tr class='<s:if test="#status.even">evenRow</s:if><s:else>oddRow</s:else>'>
+ <td><s:a href="%{editgroupurl}"><s:property value="title"/></s:a></td>
+ <td><img src='<s:url value="/planet-ui/images/world_link.png"/>' /><a href='<s:url value="/%{planet.handle}/group/%{handle}/" />'><s:text name="PlanetForm.link" /></a></td>
+ <td><img src='<s:url value="/planet-ui/images/delete.png"/>' /><a href="javascript: void(0);" onclick="confirmGroupDelete('<s:property value="id"/>', '<s:property value="handle"/>');"><s:text name="PlanetForm.deleteGroup"/></a></td>
+ </tr>
+ </s:iterator>
+ </table>
+
+ <s:url id="addurl" action="PlanetGroupForm">
+ <s:param name="planetid"><s:property value="planet.id"/></s:param>
+ </s:url>
+ <p><img src='<s:url value="/planet-ui/images/folder_add.png"/>' /><s:a href="%{addurl}"><s:text name="PlanetForm.addGroup"/></s:a></p>
+
+ </s:if>
+
+ </div>
+ </body>
+</html>