001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/rwiki/tags/sakai_2-4-1/rwiki-impl/impl/src/java/uk/ac/cam/caret/sakai/rwiki/component/macros/SpanMacro.java $
003: * $Id: SpanMacro.java 29159 2007-04-19 01:46:15Z ajpoland@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package uk.ac.cam.caret.sakai.rwiki.component.macros;
021:
022: import java.io.IOException;
023: import java.io.Writer;
024:
025: import org.radeox.api.macro.MacroParameter;
026: import org.radeox.macro.BaseMacro;
027:
028: import uk.ac.cam.caret.sakai.rwiki.component.Messages;
029:
030: public class SpanMacro extends BaseMacro {
031:
032: public String[] getParamDescription() {
033: return new String[] { Messages.getString("SpanMacro.0"), //$NON-NLS-1$
034: Messages.getString("SpanMacro.1"), //$NON-NLS-1$
035: Messages.getString("SpanMacro.2") }; //$NON-NLS-1$
036: }
037:
038: /*
039: * (non-Javadoc)
040: *
041: * @see org.radeox.macro.Macro#getDescription()
042: */
043: public String getDescription() {
044: return Messages.getString("SpanMacro.3"); //$NON-NLS-1$
045: }
046:
047: public String getName() {
048: return "span"; //$NON-NLS-1$
049: }
050:
051: /*
052: * (non-Javadoc)
053: *
054: * @see org.radeox.macro.Macro#execute(java.io.Writer,
055: * org.radeox.macro.parameter.MacroParameter)
056: */
057: public void execute(Writer writer, MacroParameter params)
058: throws IllegalArgumentException, IOException {
059:
060: String cssClass = params.get("class"); //$NON-NLS-1$
061: if (cssClass == null) {
062: cssClass = params.get(0);
063: if (cssClass.startsWith("id=")) //$NON-NLS-1$
064: {
065: cssClass = null;
066: } else if (cssClass.startsWith("name=")) //$NON-NLS-1$
067: {
068: cssClass = null;
069: }
070: }
071: String id = params.get("id"); //$NON-NLS-1$
072:
073: String anchorName = params.get("name"); //$NON-NLS-1$
074:
075: writer.write("<span"); //$NON-NLS-1$
076: if (cssClass != null && !cssClass.equals("")) //$NON-NLS-1$
077: {
078: writer.write(" class='"); //$NON-NLS-1$
079: writer.write(cssClass.replaceAll("'", "'")); //$NON-NLS-1$ //$NON-NLS-2$
080: writer.write('\'');
081: }
082: if (id != null && !id.equals("")) //$NON-NLS-1$
083: {
084: writer.write(" id='"); //$NON-NLS-1$
085: char[] nameChars = id.toCharArray();
086: int end = 0;
087: for (int i = 0; i < nameChars.length; i++) {
088: if (Character.isLetterOrDigit(nameChars[i])) {
089: nameChars[end++] = nameChars[i];
090: }
091: }
092: if (end > 0) {
093: writer.write(nameChars, 0, end);
094: }
095: writer.write('\'');
096: }
097: writer.write('>');
098: if (anchorName != null && !anchorName.equals("")) //$NON-NLS-1$
099: {
100: writer.write("<a name=\""); //$NON-NLS-1$
101: char[] nameChars = anchorName.toCharArray();
102: int end = 0;
103: for (int i = 0; i < nameChars.length; i++) {
104: if (Character.isLetterOrDigit(nameChars[i])) {
105: nameChars[end++] = nameChars[i];
106: }
107: }
108: if (end > 0) {
109: writer.write(nameChars, 0, end);
110: }
111: writer.write("'>"); //$NON-NLS-1$
112: writer.write("<!-- --></a>"); //$NON-NLS-1$
113: }
114: if (params.getContent() != null) {
115: writer.write(params.getContent());
116: }
117: writer.write("</span>"); //$NON-NLS-1$
118: }
119: }
|