r1017 - in xwiki/trunk/src/main: java/com/xpn/xwiki/render/macro resources/META-INF/services web web/wiki_editor/plugins
Ludovic Dubost
ludovic at users.forge.objectweb.org
Thu Mar 30 03:04:01 CEST 2006
Author: ludovic
Date: 2006-03-30 03:03:57 +0200 (Thu, 30 Mar 2006)
New Revision: 1017
Added:
xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableBuilder.java
xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableMacro.java
Removed:
xwiki/trunk/src/main/web/error.jsp
Modified:
xwiki/trunk/src/main/resources/META-INF/services/com.xpn.xwiki.render.macro.XWikiMacro
xwiki/trunk/src/main/web/wiki_editor/plugins/core.js
Log:
Fix for bug XWIKI-236 support carriage returns in tables
Removed error.jsp file which makes xwiki not show exceptions in some setups. It will be replaced by a servlet
Added: xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableBuilder.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableBuilder.java 2006-03-30 00:54:14 UTC (rev 1016)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableBuilder.java 2006-03-30 01:03:57 UTC (rev 1017)
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2001-2004 Fraunhofer Gesellschaft, Munich, Germany, for its
+ * Fraunhofer Institute Computer Architecture and Software Technology
+ * (FIRST), Berlin, Germany
+ *
+ * Licensed 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.
+ */
+
+package com.xpn.xwiki.render.macro;
+
+import org.radeox.macro.table.Table;
+import java.util.StringTokenizer;
+
+/**
+ * Built a table from a string
+ *
+ * @author stephan
+ * @version $Id: TableBuilder.java,v 1.3 2003/10/06 08:30:02 stephan Exp $
+ */
+
+public class TableBuilder {
+ public static Table build(String content) {
+ Table table = new Table();
+ StringTokenizer tokenizer = new StringTokenizer(content, "|\n", true);
+ String lastToken = null;
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ String linkToken = "";
+ if(token.indexOf('[') != -1 && token.indexOf(']') == -1) {
+ while(token.indexOf(']') == -1 && tokenizer.hasMoreTokens()) {
+ linkToken += token;
+ token = tokenizer.nextToken();
+ }
+ token = linkToken + token;
+ }
+ if ("\n".equals(token)) {
+ // Handles "\n" - "|\n"
+ lastToken = lastToken.trim();
+ if (!lastToken.endsWith("\\")) {
+ if (null == lastToken || "|".equals(lastToken)) {
+ table.addCell(" ");
+ }
+ table.newRow();
+ } else {
+ String cell = lastToken;
+ while (cell.trim().endsWith("\\")) {
+ token = tokenizer.nextToken();
+ if (!"|".equals(token)) {
+ cell = cell.trim() + token;
+ } else break;
+ }
+ table.addCell(cell);
+ }
+ } else if (!"|".equals(token)) {
+ if (!token.trim().endsWith("\\")) {
+ table.addCell(token);
+ }
+ } else if ("|".equals(token)) {
+ if (null == lastToken || "|".equals(lastToken)) {
+ // Handles "|" "||"
+ table.addCell(" ");
+ } else if (lastToken.trim().endsWith("\\")){
+ table.addCell(lastToken);
+ }
+ }
+ lastToken = token;
+ }
+ return table;
+ }
+}
Added: xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableMacro.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableMacro.java 2006-03-30 00:54:14 UTC (rev 1016)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/render/macro/TableMacro.java 2006-03-30 01:03:57 UTC (rev 1017)
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2001-2004 Fraunhofer Gesellschaft, Munich, Germany, for its
+ * Fraunhofer Institute Computer Architecture and Software Technology
+ * (FIRST), Berlin, Germany
+ *
+ * Licensed 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.
+ */
+
+
+package com.xpn.xwiki.render.macro;
+
+import org.radeox.macro.parameter.MacroParameter;
+import org.radeox.macro.table.Table;
+import org.radeox.macro.BaseLocaleMacro;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/*
+ * Macro for defining and displaying tables. The rows of the table are
+ * devided by newlins and the columns are divided by pipe symbols "|".
+ * The first line of the table is rendered as column headers.
+ * {table}
+ * A|B|C
+ * 1|2|3
+ * {table}
+ *
+ * @author stephan
+ * @team sonicteam
+ * @version $Id: TableMacro.java,v 1.9 2004/04/27 19:30:38 leo Exp $
+ */
+
+public class TableMacro extends BaseLocaleMacro {
+ public String getLocaleKey() {
+ return "macro.table";
+ }
+
+ public void execute(Writer writer, MacroParameter params)
+ throws IllegalArgumentException, IOException {
+
+ String content = params.getContent();
+
+ if (null == content) throw new IllegalArgumentException("TableMacro: missing table content");
+
+ content = content.trim() + "\n";
+
+ Table table = TableBuilder.build(content);
+ table.calc(); // calculate macros like =SUM(A1:A3)
+ table.appendTo(writer);
+ return;
+ }
+}
Modified: xwiki/trunk/src/main/resources/META-INF/services/com.xpn.xwiki.render.macro.XWikiMacro
===================================================================
--- xwiki/trunk/src/main/resources/META-INF/services/com.xpn.xwiki.render.macro.XWikiMacro 2006-03-30 00:54:14 UTC (rev 1016)
+++ xwiki/trunk/src/main/resources/META-INF/services/com.xpn.xwiki.render.macro.XWikiMacro 2006-03-30 01:03:57 UTC (rev 1017)
@@ -20,6 +20,6 @@
org.radeox.macro.MacroListMacro
org.radeox.macro.QuoteMacro
org.radeox.macro.RfcMacro
-org.radeox.macro.TableMacro
+com.xpn.xwiki.render.macro.TableMacro
org.radeox.macro.InterWikiMacro
org.radeox.macro.XrefMacro
Deleted: xwiki/trunk/src/main/web/error.jsp
===================================================================
--- xwiki/trunk/src/main/web/error.jsp 2006-03-30 00:54:14 UTC (rev 1016)
+++ xwiki/trunk/src/main/web/error.jsp 2006-03-30 01:03:57 UTC (rev 1017)
@@ -1,83 +0,0 @@
-<%@ page isErrorPage="true" %>
-<%@ page language="java" %>
-<%@ page import="java.util.*" %>
-<%@ page import="java.io.PrintWriter"%>
-<%
- Object statusCode = request.getAttribute("javax.servlet.error.status_code");
- Object exceptionType = request.getAttribute("javax.servlet.error.exception_type");
- Object message = request.getAttribute("javax.servlet.error.message");
-%>
-
-<html>
-<head>
-<title>XWiki Initialization Error</title>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<script type="text/javascript">
-<!--
-function showhide(divname) {
- var style = document.getElementById(divname).style;
- if ((style.display=='block')||(style.display=='')) {
- style.display='none';
- }
- else {
- style.display='block';
- }
-}
-// -->
-</script>
-</head>
-<body bgcolor="#FFFFFF">
-<H2>XWiki Initialization Error</H2>
-<p>
-An error occured. Please contact the administrator of this server.
-</p>
-<a href="" onclick="showhide('details'); return false;">Show details</a>
-<br />
-<div id="details" style="display:none;">
-<TABLE CELLPADDING="2" CELLSPACING="2" BORDER="1" WIDTH="100%">
- <TR>
- <TD WIDTH="20%"><B>Status Code</B></TD>
- <TD WIDTH="80%"><%= statusCode %></TD>
- </TR>
- <TR>
- <TD WIDTH="20%"><B>Exception Type</B></TD>
- <TD WIDTH="80%"><%= exceptionType %></TD>
- </TR>
- <TR>
- <TD WIDTH="20%"><B>Message</B></TD>
- <TD WIDTH="80%"><%= message %></TD>
- </TR>
- <TR>
- <TD WIDTH="20%"><B>Exception</B></TD>
- <TD WIDTH="80%">
- <%
- if( exception != null )
- {
- out.print("<PRE>");
- exception.printStackTrace(new PrintWriter(out));
- out.print("</PRE>");
- }
- %>
- </TD>
- </TR>
- <TR>
- <TD WIDTH="20%"><B>Root Cause</B></TD>
- <TD>
- <%
- if( (exception != null) && (exception instanceof ServletException) )
- {
- Throwable cause = ((ServletException)exception).getRootCause();
- if( cause != null )
- {
- out.print("<PRE>");
- cause.printStackTrace(new PrintWriter(out));
- out.print("</PRE>");
- }
- }
- %>
- </TD>
- </TR>
-</TABLE>
-</div>
-</body>
-</html>
\ No newline at end of file
Modified: xwiki/trunk/src/main/web/wiki_editor/plugins/core.js
===================================================================
--- xwiki/trunk/src/main/web/wiki_editor/plugins/core.js 2006-03-30 00:54:14 UTC (rev 1016)
+++ xwiki/trunk/src/main/web/wiki_editor/plugins/core.js 2006-03-30 01:03:57 UTC (rev 1017)
@@ -55,7 +55,10 @@
"è|é|ê|ë|ì|í|" +
"î|ï|ñ|ò|ó|ô|" +
"?|õ|ö|ø|ù|ú|" +
- "û|ü|ÿ";
+ "û|ü|ÿ|" +
+ // Commercial symbols:
+ "?|©|®|¢|?|¥|" +
+ "£|¤";
var characterEntityStr = "À|Á|Â|Ã|Ä|Å|" +
"Æ|Ç|È|É|Ê|Ë|" +
"Ì|Í|Î|Ï|Ñ|Ò|" +
@@ -65,13 +68,16 @@
"è|é|ê|ë|ì|í|" +
"î|ï|ñ|ò|ó|ô|" +
"œ|õ|ö|ø|ù|ú|" +
- "û|ü|ÿ";
+ "û|ü|ÿ|" +
+ // Commercial symbols:
+ "™|©|®|¢|€|¥|" +
+ "£|¤";
var characterEntitys = characterEntityStr.split("|");
var chars = charStr.split("|");
for (var i= 0; i< characterEntitys.length; i++) {
- var myRegExp = new RegExp(characterEntitys[i],'g');
- this.addInternalProcessor((myRegExp), chars[i]);
+ var regExp = new RegExp(characterEntitys[i],'g');
+ this.addInternalProcessor((regExp), chars[i]);
}
this.setHtmlTagRemover('removeHtmlTags_Groovy');
@@ -147,7 +153,7 @@
WikiEditor.prototype.convertTableInternal = function(regexp, result, content) {
var text = this.trimString(result[2]);
var str = "";
- str += "{table}\n"
+ str += "{table}\n";
var rows = text.split("<\/tr>");
for(var i=0; i< rows.length; i++) {
rows[i] = rows[i].replace("<tr>","")
@@ -155,17 +161,26 @@
var cols = rows[i].split("<\/td>");
for(var j=0; j< cols.length-1; j++) {
if (cols[j] != null && cols[j] != "") {
- cols[j] = cols[j].replace("<td>","")
+ var r = /<td\s*([^>]*)>/g;
+ cols[j] = cols[j].replace(r,"");
cols[j] = this.trimString(cols[j]);
- if (j != cols.length-2)
+ var r1 = /\r\n\r|\r(?!\\\\)\n \r\n/g;
+ cols[j] = cols[j].replace(r1,'\\\\');
+ var r2 = /\r(?!\\\\)/g;
+ cols[j] = cols[j].replace(r2,'\\\\');
+ var r3 = /\\\\\\\\/g;
+ cols[j] = cols[j].replace(r3,'\\\\');
+ if (j != cols.length-2) {
str += cols[j] + "|" ;
- else str += cols[j] +"\n";
+ } else {
+ str += cols[j] +"\n";
+ }
}
}
}
- str += "{table}"
- return content.replace(regexp, str);
+ str += "{table}";
+ return content.replace(regexp, str);
}
WikiEditor.prototype.convertHeadingInternal = function(regexp, result, content) {
@@ -723,18 +738,31 @@
str += "<table class=\"wiki-table\" cellpadding=\"0\" cellspacing=\"0\">"
for (var i=0; i<rows.length; i++) {
rows[i] = this.trimString(rows[i]);
+ var k = 0;
if (rows[i] != null && rows[i] != "") {
+ while (this.trimString(rows[i]).lastIndexOf("\\\\") == (this.trimString(rows[i]).length-2)) {
+ rows[i] = rows[i].substring(0,rows[i].lastIndexOf("\\\\"));
+ k++;
+ if ("\\\\" == this.trimString(rows[i+k]))
+ rows[i] = rows[i] + "<p> " + rows[i+k];
+ else
+ rows[i] = rows[i] + "<p>" + rows[i+k];
+ }
+ var regExp = new RegExp('\\\\','g');
+ rows[i] = rows[i].replace(regExp,"<p>");
var cols = rows[i].split("|");
str += "<tr>";
for (var j=0; j<cols.length; j++) {
if (i == 0) {
- str += "<td>" + this.trimString(cols[j]) + " <\/td>"
+ str += "<td>" + this.trimString(cols[j]) + " <\/td>"
}
else
- str += "<td>" + this.trimString(cols[j]) + " <\/td>" ;
+ str += "<td>" + this.trimString(cols[j]) + " <\/td>" ;
}
str += "<\/tr>" ;
+
}
+ i += k;
}
str += "<\/table>";
return content.replace(regexp, str) ;
More information about the Xwiki-notifications
mailing list