KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > jsp > parse > A_CmsConfiguredHtmlParser


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/parse/A_CmsConfiguredHtmlParser.java,v $
3  * Date : $Date: 2006/09/19 14:28:18 $
4  * Version: $Revision: 1.4 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.jsp.parse;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsException;
36 import org.opencms.util.I_CmsHtmlNodeVisitor;
37
38 import java.util.List JavaDoc;
39
40 import org.htmlparser.util.ParserException;
41
42 /**
43  * Base class for all classes that are specified for the <cms:parse parserClass="name"
44  * param="config" /&gt; tag in the parserClass Attribute.<p>
45  *
46  * Entry point for the tag implementation ({@link org.opencms.jsp.CmsJspTagParse}). The tag will
47  * provide a valid {@link org.opencms.file.CmsObject} and it's configuration parameter String to
48  * subclasses of this instances. Implementations just choose the type of
49  * {@link org.opencms.util.I_CmsHtmlNodeVisitor} they will use for visiting the content to be
50  * parsed.<p>
51  *
52  * To implement a custom class that may be used with the <nobr>&lt;cms:parse parserClass="name"
53  * param="config" /&gt;</nobr> tag the only thing that has to be done is to implement the method
54  * {@link #createVisitorInstance()} and return the desired {@link org.opencms.util.I_CmsHtmlNodeVisitor}
55  * implementation.<p>
56  *
57  * @author Achim Westermann
58  *
59  * @version $Revision: 1.4 $
60  *
61  * @since 6.1.7
62  */

63 public abstract class A_CmsConfiguredHtmlParser {
64
65     /** The internal cms object for accessing core functionality. */
66     private CmsObject m_cmsObject;
67
68     /** The attribute value of the attribute param of the &lt;cms:parse&gt; tag. */
69     private String JavaDoc m_param;
70
71     /** The internal visitor implementation that will do the parsing. */
72     private I_CmsHtmlNodeVisitor m_visitor;
73
74     /**
75      * Default constructor that initializes the internal visitor by using the abstract template
76      * method {@link #createVisitorInstance()}.<p>
77      */

78     protected A_CmsConfiguredHtmlParser() {
79
80         // nop
81
}
82
83     /**
84      * Subclasses have to create their desired instance for parsing the html here.<p>
85      *
86      * You have access to {@link #getCmsObject()} and {@link #getParam()} already here and may pass those to
87      * the visitor to return.<p>
88      *
89      * @return the instance to be used for parsing the html
90      *
91      * @throws CmsException if sth. goes wrong
92      */

93     protected abstract I_CmsHtmlNodeVisitor createVisitorInstance() throws CmsException;
94
95     /**
96      * Returns the result of subsequent parsing to the &lt;cms:parse&lt; tag implementation.<p>
97      *
98      * @param encoding the encoding to use for parsing
99      * @param html the html content to parse
100      * @param noAutoCloseTags a list of upper case tag names for which parsing / visiting should not correct missing closing tags.
101      *
102      * @return the result of subsequent parsing to the &lt;cms:parse&lt; tag implementation
103      *
104      * @throws ParserException if sth. goes wrong at parsing
105      * @throws CmsException if sth. goes wrong at accessing OpenCms core functionality
106      */

107     public String JavaDoc doParse(String JavaDoc html, String JavaDoc encoding, List JavaDoc noAutoCloseTags) throws ParserException, CmsException {
108
109         m_visitor = createVisitorInstance();
110         m_visitor.setNoAutoCloseTags(noAutoCloseTags);
111         String JavaDoc result = "";
112         m_visitor.process(html, encoding);
113         result = m_visitor.getResult();
114         // fool Checkstyle - we need to grant this exception for more complex subclasses that e.g.
115
// have to be configured from VFS:
116
if (false) {
117             throw new CmsException(null);
118         }
119         return result;
120     }
121
122     /**
123      * Returns the internal cms object for accessing core functionality.<p>
124      *
125      * This value will be initialized by the &lt;cms:parse&gt; tag.<p>
126      *
127      * @return the internal cms object for accessing core functionality
128      */

129     protected CmsObject getCmsObject() {
130
131         return m_cmsObject;
132     }
133
134     /**
135      * Returns the param.<p>
136      *
137      * @return the param
138      */

139     protected String JavaDoc getParam() {
140
141         return m_param;
142     }
143
144     /**
145      * Returns the visitor.<p>
146      *
147      * @return the visitor
148      */

149     protected I_CmsHtmlNodeVisitor getVisitor() {
150
151         return m_visitor;
152     }
153
154     /**
155      * Sets the internal cms object for accessing core functionality.<p>
156      *
157      * This will be invokde by the &tl;cms:parse&gt; tag implementation.<p>
158      *
159      * @param cmsObject the internal cms object for accessing core functionality to set
160      */

161     public void setCmsObject(CmsObject cmsObject) {
162
163         m_cmsObject = cmsObject;
164     }
165
166     /**
167      * The attribute value of the attribute param of the &lt;cms:parse&gt; tag.<p>
168      *
169      * Will be set by the &lt;cms:parse&gt; implementation.<p>
170      *
171      * @param param the param to set
172      */

173     public void setParam(String JavaDoc param) {
174
175         m_param = param;
176     }
177 }
Popular Tags