001: /*
002: * Comment.java March 2006
003: *
004: * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General
016: * Public License along with this library; if not, write to the
017: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
018: * Boston, MA 02111-1307 USA
019: */
020:
021: package simple.page.translate;
022:
023: /**
024: * The <code>Comment</code> object is used to parse a JSP comment.
025: * This performs a very simple parsing of the JSP comment provided.
026: * This is parsed so that it can be included into the source.
027: * <pre>
028: *
029: * <%-- comment --%>
030: *
031: * </pre>
032: * The above expression is parsed an inserted into the JSP source
033: * as an embedded comment starting with "/*" comment tag.
034: *
035: * @author Niall Gallagher
036: */
037: class Comment extends Token {
038:
039: /**
040: * This is used to collect the token parsed from the print.
041: */
042: private TokenBuffer comment;
043:
044: /**
045: * Constructor for the <code>Comment</code> token. This will
046: * create a buffer, which can be used to accumulate the data
047: * extracted from the supplied print token.
048: */
049: public Comment() {
050: this .comment = new TokenBuffer();
051: }
052:
053: /**
054: * Constructor for the <code>Comment</code> token. This will
055: * create a buffer, which can be used to accumulate the data
056: * extracted from the supplied print token before parsing.
057: *
058: * @param token this is the insert token to be parsed
059: */
060: public Comment(String token) {
061: this ();
062: parse(token);
063: }
064:
065: /**
066: * This method will supply code to the document definition that
067: * will allow a comment to be printed by the page. The data
068: * inserted into the definition will be displayed in the body.
069: *
070: * @param source this is the source to push the code into
071: * @param builder this is the builder driving the process
072: */
073: public void process(Definition source, Builder builder) {
074: source.addContent("/*" + comment + "*/");
075: }
076:
077: /**
078: * This will clear the comment token so that the parse can be reused
079: * by the builder. In practice this method just satisfies the
080: * contract of the token so that this object is not abstract.
081: */
082: protected void init() {
083: comment.clear();
084: }
085:
086: /**
087: * This is a very simple parse method which basically extracts the
088: * begining and end values from the token. For instance this will
089: * remove "<%--" and "--%>" from the token supplied.
090: */
091: protected void parse() {
092: if (skip("<%--")) {
093: while (off < count) {
094: if (skip("--%>")) {
095: break;
096: }
097: if (skip("%>")) {
098: break;
099: }
100: comment.append(buf[off++]);
101: }
102: }
103: }
104: }
|