001 /*
002 * This file is part of the Echo Point Project. This project is a collection
003 * of Components that have extended the Echo Web Application Framework.
004 *
005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006 *
007 * The contents of this file are subject to the Mozilla Public License Version
008 * 1.1 (the "License"); you may not use this file except in compliance with
009 * the License. You may obtain a copy of the License at
010 * http://www.mozilla.org/MPL/
011 *
012 * Software distributed under the License is distributed on an "AS IS" basis,
013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014 * for the specific language governing rights and limitations under the
015 * License.
016 *
017 * Alternatively, the contents of this file may be used under the terms of
018 * either the GNU General Public License Version 2 or later (the "GPL"), or
019 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020 * in which case the provisions of the GPL or the LGPL are applicable instead
021 * of those above. If you wish to allow use of your version of this file only
022 * under the terms of either the GPL or the LGPL, and not to allow others to
023 * use your version of this file under the terms of the MPL, indicate your
024 * decision by deleting the provisions above and replace them with the notice
025 * and other provisions required by the GPL or the LGPL. If you do not delete
026 * the provisions above, a recipient may use your version of this file under
027 * the terms of any one of the MPL, the GPL or the LGPL.
028 */
029 package echopoint.template;
030
031 import java.util.HashMap;
032 import java.util.Map;
033
034 /**
035 * <code>SimpleTemplateCompilerHints</code> by default sets all boolean
036 * properties to false except for <code>namespaceAware</code> which is set to
037 * true. There are by default no custom attributes.
038 * <p>
039 * Some XML parses such as Xerces will automatically go to the Internet to get the XHTML
040 * DTD from the W3C if a DOCTYPE is specified in the template data, irrespective of whether
041 * validating is true or not. You can stop this on Xerces by setting a custom property
042 * as follows :
043 * <pre>
044 * setValidating(false);
045 * setAttributeValue("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.valueOf(false));
046 * </pre>
047 */
048 public class SimpleTemplateCompilerHints implements TemplateCompilerHints {
049
050 Map attributes = null;
051
052 private boolean coalescing = false;
053
054 private boolean expandEntityReferences = false;
055
056 private boolean ignoringComments = false;
057
058 private boolean ignoringElementContentWhitespace = false;
059
060 private boolean namespaceAware = true;
061
062 private boolean validating = false;
063
064 /**
065 * Constructs a <code>SimpleTemplateCompilerHints</code>
066 */
067 public SimpleTemplateCompilerHints() {
068 }
069
070 /**
071 * @see echopoint.template.TemplateCompilerHints#getAttributeNames()
072 */
073 public String[] getAttributeNames() {
074 if (attributes == null) {
075 return new String[0];
076 }
077 return (String[]) attributes.keySet().toArray(new String[attributes.keySet().size()]);
078 }
079
080 /**
081 * @see echopoint.template.TemplateCompilerHints#getAttributeValue(java.lang.String)
082 */
083 public Object getAttributeValue(String attributeName) {
084 if (attributes == null) {
085 return null;
086 }
087 return attributes.get(attributeName);
088 }
089
090 /**
091 * @see echopoint.template.TemplateCompilerHints#isCoalescing()
092 */
093 public boolean isCoalescing() {
094 return coalescing;
095 }
096
097 /**
098 * @see echopoint.template.TemplateCompilerHints#isExpandEntityReferences()
099 */
100 public boolean isExpandEntityReferences() {
101 return expandEntityReferences;
102 }
103
104 /**
105 * @see echopoint.template.TemplateCompilerHints#isIgnoringComments()
106 */
107 public boolean isIgnoringComments() {
108 return ignoringComments;
109 }
110
111 /**
112 * @see echopoint.template.TemplateCompilerHints#isIgnoringElementContentWhitespace()
113 */
114 public boolean isIgnoringElementContentWhitespace() {
115 return ignoringElementContentWhitespace;
116 }
117
118 /**
119 * @see echopoint.template.TemplateCompilerHints#isNamespaceAware()
120 */
121 public boolean isNamespaceAware() {
122 return namespaceAware;
123 }
124
125 /**
126 * @see echopoint.template.TemplateCompilerHints#isValidating()
127 */
128 public boolean isValidating() {
129 return validating;
130 }
131
132 /**
133 * Sets an attribute value against a given attribute name
134 *
135 * @param attributeName -
136 * the name of the attribute
137 * @param attributeValue -
138 * its value
139 */
140 public void setAttributeValue(String attributeName, Object attributeValue) {
141 if (attributes == null) {
142 attributes = new HashMap();
143 }
144 attributes.put(attributeName, attributeValue);
145 }
146
147 /**
148 * @param coalescing
149 * The boolean value to set.
150 * @see TemplateCompilerHints#isCoalescing()
151 */
152 public void setCoalescing(boolean coalescing) {
153 this.coalescing = coalescing;
154 }
155
156 /**
157 * @param expandEntityReferences
158 * The boolean value to set.
159 * @see TemplateCompilerHints#isExpandEntityReferences()
160 */
161 public void setExpandEntityReferences(boolean expandEntityReferences) {
162 this.expandEntityReferences = expandEntityReferences;
163 }
164
165 /**
166 * @param ignoringComments
167 * The boolean value to set.
168 * @see TemplateCompilerHints#isIgnoringComments()
169 */
170 public void setIgnoringComments(boolean ignoringComments) {
171 this.ignoringComments = ignoringComments;
172 }
173
174 /**
175 * @param ignoringElementContentWhitespace
176 * The boolean value to set.
177 * @see TemplateCompilerHints#isIgnoringElementContentWhitespace()
178 */
179 public void setIgnoringElementContentWhitespace(boolean ignoringElementContentWhitespace) {
180 this.ignoringElementContentWhitespace = ignoringElementContentWhitespace;
181 }
182
183 /**
184 * @param namespaceAware
185 * The boolean value to set.
186 * @see TemplateCompilerHints#isNamespaceAware()
187 */
188 public void setNamespaceAware(boolean namespaceAware) {
189 this.namespaceAware = namespaceAware;
190 }
191
192 /**
193 * @param validating
194 * The boolean value to set.
195 * @see TemplateCompilerHints#isValidating()
196 */
197 public void setValidating(boolean validating) {
198 this.validating = validating;
199 }
200 }