01: /**********************************************************************************
02: * $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/AnchorMacro.java $
03: * $Id: AnchorMacro.java 29159 2007-04-19 01:46:15Z ajpoland@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package uk.ac.cam.caret.sakai.rwiki.component.macros;
21:
22: import java.io.IOException;
23: import java.io.Writer;
24:
25: import org.radeox.api.macro.MacroParameter;
26: import org.radeox.macro.BaseMacro;
27:
28: import uk.ac.cam.caret.sakai.rwiki.component.Messages;
29:
30: public class AnchorMacro extends BaseMacro {
31:
32: public String[] getParamDescription() {
33: return new String[] { Messages.getString("AnchorMacro.0") }; //$NON-NLS-1$
34: }
35:
36: /*
37: * (non-Javadoc)
38: *
39: * @see org.radeox.macro.Macro#getDescription()
40: */
41: public String getDescription() {
42: return Messages.getString("AnchorMacro.1"); //$NON-NLS-1$ion;
43: }
44:
45: public void execute(Writer writer, MacroParameter params)
46: throws IllegalArgumentException, IOException {
47:
48: writer.write("<a name='"); //$NON-NLS-1$
49:
50: char[] nameChars = params.get(0).toCharArray();
51: int end = 0;
52: for (int i = 0; i < nameChars.length; i++) {
53: if (Character.isLetterOrDigit(nameChars[i])) {
54: nameChars[end++] = nameChars[i];
55: }
56: }
57: if (end > 0) {
58: writer.write(nameChars, 0, end);
59: }
60: writer.write("' class='anchorpoint'>"); //$NON-NLS-1$
61: if (params.getContent() != null) {
62: writer.write(params.getContent());
63: }
64: writer.write("</a>"); //$NON-NLS-1$
65: }
66:
67: public String getName() {
68: return "anchor"; //$NON-NLS-1$
69: }
70:
71: }
|