001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.wiki.translators;
016    
017    /**
018     * @author Jorge Ferrer
019     */
020    public class ClassicToCreoleTranslator extends BaseTranslator {
021    
022            public ClassicToCreoleTranslator() {
023                    initRegexps();
024            }
025    
026            protected void initRegexps() {
027    
028                    // Bold and italics
029    
030                    regexps.put(
031                            "'''''((?s:.)*?)('''''|(\n\n|\r\r|\r\n\r\n))", "**//$1//**$3");
032    
033                    // Bold
034    
035                    regexps.put("'''((?s:.)*?)('''|(\n\n|\r\r|\r\n\r\n))", "**$1**$3");
036    
037                    // Italics
038    
039                    regexps.put("''((?s:.)*?)(''|(\n\n|\r\r|\r\n\r\n))", "//$1//$3");
040    
041                    // Link
042    
043                    regexps.put("\\[([^ ]*)\\]", "[[$1]]");
044    
045                    // Link with label
046    
047                    regexps.put("\\[([^ ]+) (.*)\\]", "[[$1|$2]]");
048    
049                    // Monospace
050    
051                    regexps.put("(^ (.+))(\\n (.+))*", "{{{\n$0\n}}}");
052    
053                    // List item
054    
055                    regexps.put("^\\t[\\*] (.*)", "* $1");
056    
057                    // List subitem
058    
059                    regexps.put("^\\t\\t[\\*] (.*)", "** $1");
060    
061                    // List subsubitem
062    
063                    regexps.put("^\\t\\t\\t[\\*] (.*)", "*** $1");
064    
065                    // List subsubsubitem
066    
067                    regexps.put("^\\t\\t\\t\\t[\\*] (.*)", "**** $1");
068    
069                    // Ordered list item
070    
071                    regexps.put("^\\t1 (.*)", "# $1");
072    
073                    // Ordered list subitem
074    
075                    regexps.put("^\\t\\t1 (.*)", "## $1");
076    
077                    // Ordered list subsubitem
078    
079                    regexps.put("^\\t\\t\\t1 (.*)", "### $1");
080    
081                    // Ordered list subsubsubitem
082    
083                    regexps.put("^\\t\\t\\t\\t1 (.*)", "#### $1");
084    
085                    // Term and definition
086    
087                    regexps.put("^\\t([\\w]+):\\t(.*)", "**$1**:\n$2");
088    
089                    // Indented paragraph
090    
091                    regexps.put("^\\t:\\t(.*)", "$1");
092    
093                    // CamelCase
094    
095                    regexps.put(
096                            "(^|\\p{Punct}|\\p{Space})((\\p{Lu}\\p{Ll}+){2,})" +
097                                    "(\\z|\\n|\\p{Punct}|\\p{Space})", " [[$2]] ");
098            }
099    
100    }