|
From: <jbo...@li...> - 2005-08-18 18:49:09
|
Author: ral...@jb...
Date: 2005-08-18 14:48:58 -0400 (Thu, 18 Aug 2005)
New Revision: 899
Modified:
trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java
Log:
camelCaseLinksAdded
Modified: trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java
===================================================================
--- trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java 2005-08-18 18:35:12 UTC (rev 898)
+++ trunk/forge/portal-extensions/forge-wiki/src/java/org/jboss/wiki/plugins/HTMLTranslator.java 2005-08-18 18:48:58 UTC (rev 899)
@@ -69,12 +69,18 @@
private int m_listlevel = 0;
private int m_numlistlevel = 0;
+ private boolean m_camelCaseLinks = true; //camelCase enabled
/** Tag that gets closed at EOL. */
private String m_closeTag = null;
/** Allow this many characters to be pushed back in the stream. */
private static final int PUSHBACK_BUFFER_SIZE = 8;
+ /**
+ * These characters constitute word separators when trying
+ * to find CamelCase links.
+ */
+ private static final String WORD_SEPARATORS = ",.|:;+=&";
private PushbackReader m_in;
@@ -127,6 +133,69 @@
continue;
}
//
+ // CamelCase detection, a non-trivial endeavour.
+ // We keep track of all white-space separated entities, which we
+ // hereby refer to as "words". We then check for an existence
+ // of a CamelCase format text string inside the "word", and
+ // if one exists, we replace it with a proper link.
+ //
+
+ if( m_camelCaseLinks )
+ {
+ // Quick parse of start of a word boundary.
+
+ if( word == null &&
+ (Character.isWhitespace( (char)previousCh ) ||
+ WORD_SEPARATORS.indexOf( (char)previousCh ) != -1 ||
+ newLine ) &&
+ !Character.isWhitespace( (char) ch ) )
+ {
+ word = new StringBuffer();
+ }
+
+ // Are we currently tracking a word?
+ if( word != null )
+ {
+ //
+ // Check for the end of the word.
+ //
+
+ if( Character.isWhitespace( (char)ch ) ||
+ ch == -1 ||
+ WORD_SEPARATORS.indexOf( (char) ch ) != -1 )
+ {
+ String potentialLink = word.toString();
+
+ String camelCase = parseCamelCase(potentialLink);
+
+ if( camelCase != null )
+ {
+ // System.out.println("Buffer is "+buf);
+
+ // System.out.println(" Replacing "+camelCase+" with proper link.");
+ start = buf.toString().lastIndexOf( camelCase );
+ buf.replace(start,
+ start+camelCase.length(),
+ handleHyperlinks(camelCase) );
+
+ // System.out.println(" Resulting with "+buf);
+ }
+
+ // We've ended a word boundary, so time to reset.
+ word = null;
+ }
+ else
+ {
+ // This should only be appending letters and digits.
+ word.append( (char)ch );
+ } // if end of word
+ } // if word's not null
+
+ // Always set the previous character to test for word starts.
+ previousCh = ch;
+
+ } // if m_camelCaseLinks
+ //
// Check if any lists need closing down.
//
@@ -290,7 +359,27 @@
return translatedContent;
}
+
+ public String parseCamelCase(String link) {
+ String camelCasepattern = "^([\\p{Alnum}]*|\\~)([\\p{Upper}]+[\\p{Lower}]+[\\p{Upper}]+[\\p{Alnum}]*)[^\\p{Alnum}]*$";
+ Pattern camelCase = Pattern.compile(camelCasepattern);
+ Matcher camelMatch = camelCase.matcher(link);
+ if (camelMatch.matches()) {
+ String result = camelMatch.group(2); //get the camel case words
+ if (camelMatch.group(1) != null)
+ {
+ if ((camelMatch.group(1).equals("~"))
+ || (camelMatch.group(1).indexOf('[') != -1))
+ {
+ return null; //this is camelCase escape or [...] link
+ }
+ }
+ return result;
+ }//if match
+ return null;
+ }
+
/* a collection of all media formats allowed on wiki */
private Collection getImagePatterns() {
ArrayList patterns = new ArrayList();
|