001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.impl.comp.html;
015:
016: import java.util.HashMap;
017: import java.util.Map;
018: import org.itsnat.comp.ItsNatComponent;
019: import org.itsnat.comp.ItsNatLabelEditor;
020: import org.itsnat.comp.ItsNatListCellEditor;
021: import org.itsnat.comp.ItsNatTableCellEditor;
022: import org.itsnat.comp.ItsNatTableStructure;
023: import org.itsnat.comp.ItsNatTreeCellEditor;
024: import org.itsnat.comp.html.ItsNatHTMLAnchor;
025: import org.itsnat.comp.html.ItsNatHTMLAnchorLabel;
026: import org.itsnat.comp.html.ItsNatHTMLButton;
027: import org.itsnat.comp.html.ItsNatHTMLButtonLabel;
028: import org.itsnat.comp.html.ItsNatHTMLComponentManager;
029: import org.itsnat.comp.html.ItsNatHTMLForm;
030: import org.itsnat.comp.html.ItsNatHTMLInputButton;
031: import org.itsnat.comp.html.ItsNatHTMLInputCheckBox;
032: import org.itsnat.comp.html.ItsNatHTMLInputFile;
033: import org.itsnat.comp.html.ItsNatHTMLInputHidden;
034: import org.itsnat.comp.html.ItsNatHTMLInputImage;
035: import org.itsnat.comp.html.ItsNatHTMLInputPassword;
036: import org.itsnat.comp.html.ItsNatHTMLInputRadio;
037: import org.itsnat.comp.html.ItsNatHTMLInputReset;
038: import org.itsnat.comp.html.ItsNatHTMLInputSubmit;
039: import org.itsnat.comp.html.ItsNatHTMLInputText;
040: import org.itsnat.comp.html.ItsNatHTMLInputTextFormatted;
041: import org.itsnat.comp.html.ItsNatHTMLLabel;
042: import org.itsnat.comp.html.ItsNatHTMLSelectComboBox;
043: import org.itsnat.comp.html.ItsNatHTMLSelectMult;
044: import org.itsnat.comp.html.ItsNatHTMLTable;
045: import org.itsnat.comp.html.ItsNatHTMLTextArea;
046: import org.itsnat.core.html.ItsNatHTMLDocument;
047: import org.itsnat.core.NameValue;
048: import org.itsnat.impl.comp.FactoryItsNatComponentImpl;
049: import org.itsnat.impl.comp.ItsNatComponentManagerImpl;
050: import org.itsnat.impl.comp.html.editor.ItsNatHTMLLabelEditorDefaultImpl;
051: import org.itsnat.impl.comp.html.editor.ItsNatHTMLListCellEditorDefaultImpl;
052: import org.itsnat.impl.comp.html.editor.ItsNatHTMLTableCellEditorDefaultImpl;
053: import org.itsnat.impl.comp.html.editor.ItsNatHTMLTreeCellEditorDefaultImpl;
054: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLAnchorImpl;
055: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLButtonImpl;
056: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLComponentImpl;
057: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLFormImpl;
058: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputButtonImpl;
059: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputCheckBoxImpl;
060: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputFileImpl;
061: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputHiddenImpl;
062: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputImageImpl;
063: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputImpl;
064: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputPasswordImpl;
065: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputRadioImpl;
066: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputResetImpl;
067: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputSubmitImpl;
068: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLInputTextImpl;
069: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLLabelImpl;
070: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLSelectImpl;
071: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLTableImpl;
072: import org.itsnat.impl.comp.html.factory.FactoryItsNatHTMLTextAreaImpl;
073: import org.itsnat.impl.core.html.ItsNatHTMLDocumentImpl;
074: import org.w3c.dom.Element;
075: import org.w3c.dom.html.HTMLAnchorElement;
076: import org.w3c.dom.html.HTMLButtonElement;
077: import org.w3c.dom.html.HTMLElement;
078: import org.w3c.dom.html.HTMLFormElement;
079: import org.w3c.dom.html.HTMLInputElement;
080: import org.w3c.dom.html.HTMLLabelElement;
081: import org.w3c.dom.html.HTMLSelectElement;
082: import org.w3c.dom.html.HTMLTableElement;
083: import org.w3c.dom.html.HTMLTextAreaElement;
084:
085: /**
086: *
087: * @author jmarranz
088: */
089: public class ItsNatHTMLComponentManagerImpl extends
090: ItsNatComponentManagerImpl implements
091: ItsNatHTMLComponentManager {
092: protected static final Map HTMLFACTORIES = new HashMap(); // No sincronizamos porque va a ser siempre usada en modo lectura
093:
094: static {
095: addHTMLFactory(new FactoryItsNatHTMLAnchorImpl());
096: addHTMLFactory(new FactoryItsNatHTMLButtonImpl());
097: addHTMLFactory(new FactoryItsNatHTMLFormImpl());
098: addHTMLFactory(new FactoryItsNatHTMLInputButtonImpl());
099: addHTMLFactory(new FactoryItsNatHTMLInputCheckBoxImpl());
100: addHTMLFactory(new FactoryItsNatHTMLInputFileImpl());
101: addHTMLFactory(new FactoryItsNatHTMLInputHiddenImpl());
102: addHTMLFactory(new FactoryItsNatHTMLInputImageImpl());
103: addHTMLFactory(new FactoryItsNatHTMLInputPasswordImpl());
104: addHTMLFactory(new FactoryItsNatHTMLInputRadioImpl());
105: addHTMLFactory(new FactoryItsNatHTMLInputResetImpl());
106: addHTMLFactory(new FactoryItsNatHTMLInputSubmitImpl());
107: addHTMLFactory(new FactoryItsNatHTMLInputTextImpl());
108: addHTMLFactory(new FactoryItsNatHTMLLabelImpl());
109: addHTMLFactory(new FactoryItsNatHTMLSelectImpl());
110: addHTMLFactory(new FactoryItsNatHTMLTableImpl());
111: addHTMLFactory(new FactoryItsNatHTMLTextAreaImpl());
112: }
113:
114: protected static void addHTMLFactory(
115: FactoryItsNatHTMLComponentImpl factory) {
116: HTMLFACTORIES.put(factory.getKey(), factory);
117: }
118:
119: protected static FactoryItsNatHTMLComponentImpl getHTMLFactory(
120: HTMLElement elem) {
121: String key;
122: if (elem instanceof HTMLInputElement)
123: key = FactoryItsNatHTMLInputImpl
124: .getKey((HTMLInputElement) elem);
125: else
126: key = FactoryItsNatHTMLComponentImpl.getKey(elem);
127:
128: return (FactoryItsNatHTMLComponentImpl) HTMLFACTORIES.get(key);
129: }
130:
131: /** Creates a new instance of ItsNatHTMLComponentManagerImpl */
132: public ItsNatHTMLComponentManagerImpl(
133: ItsNatHTMLDocumentImpl itsNatDoc) {
134: super (itsNatDoc);
135: }
136:
137: public ItsNatHTMLDocument getItsNatHTMLDocument() {
138: return (ItsNatHTMLDocumentImpl) itsNatDoc;
139: }
140:
141: public ItsNatHTMLDocumentImpl getItsNatHTMLDocumentImpl() {
142: return (ItsNatHTMLDocumentImpl) itsNatDoc;
143: }
144:
145: public ItsNatHTMLFormImpl getItsNatHTMLForm(HTMLFormElement formElem) {
146: ItsNatHTMLFormImpl form = (ItsNatHTMLFormImpl) findItsNatComponent(formElem);
147: //if (form == null)
148: // form = (ItsNatHTMLFormImpl)addItsNatHTMLForm(formElem,null);
149: return form;
150: }
151:
152: public ItsNatComponent newItsNatComponent(Element element,
153: String compType, NameValue[] artifacts,
154: boolean ignoreIsComponentAttr) {
155: // A día de hoy sólo nodos Element pueden ser componentes
156: // Si ignoreIsComponentAttr es true es como si estuviera el atributo isComponent="true"
157: // es el caso en el que explícitamente queremos que un nodo dado SEA un componente (salvo que no pueda serlo de ninguna forma)
158: // Si compType está definido, éste tiene prioridad sobre el tipo de componente
159: // por defecto asociado al tag name.
160: ItsNatComponent comp = super .newItsNatComponent(element,
161: compType, artifacts, ignoreIsComponentAttr);
162: if (comp != null)
163: return comp;
164:
165: if (!(element instanceof HTMLElement))
166: return null;
167:
168: // Buscamos por tag name
169: FactoryItsNatComponentImpl factory = getHTMLFactory((HTMLElement) element);
170: if (factory != null)
171: return factory.createItsNatComponent(element, compType,
172: artifacts, ignoreIsComponentAttr, this );
173:
174: return null;
175: }
176:
177: public static boolean declaredAsHTMLComponent(Element element) {
178: boolean decAsComp = declaredAsComponent(element);
179: if (decAsComp)
180: return true;
181:
182: if (!(element instanceof HTMLElement))
183: return false;
184:
185: // Buscamos por tag name
186: FactoryItsNatHTMLComponentImpl factory = getHTMLFactory((HTMLElement) element);
187: if (factory == null)
188: return false;
189:
190: return factory.declaredAsHTMLComponent(element);
191: }
192:
193: public ItsNatHTMLLabel createItsNatHTMLLabel(
194: HTMLLabelElement element, NameValue[] artifacts) {
195: return new ItsNatHTMLLabelImpl(element, artifacts, this );
196: }
197:
198: public ItsNatHTMLAnchor createItsNatHTMLAnchor(
199: HTMLAnchorElement element, NameValue[] artifacts) {
200: return new ItsNatHTMLAnchorDefaultImpl(element, artifacts, this );
201: }
202:
203: public ItsNatHTMLAnchorLabel createItsNatHTMLAnchorLabel(
204: HTMLAnchorElement element, NameValue[] artifacts) {
205: return new ItsNatHTMLAnchorLabelImpl(element, artifacts, this );
206: }
207:
208: public ItsNatHTMLForm createItsNatHTMLForm(HTMLFormElement element,
209: NameValue[] artifacts) {
210: return new ItsNatHTMLFormImpl(element, artifacts, this );
211: }
212:
213: public ItsNatHTMLInputText createItsNatHTMLInputText(
214: HTMLInputElement element, NameValue[] artifacts) {
215: return new ItsNatHTMLInputTextDefaultImpl(element, artifacts,
216: this );
217: }
218:
219: public ItsNatHTMLInputTextFormatted createItsNatHTMLInputTextFormatted(
220: HTMLInputElement element, NameValue[] artifacts) {
221: return new ItsNatHTMLInputTextFormattedImpl(element, artifacts,
222: this );
223: }
224:
225: public ItsNatHTMLInputPassword createItsNatHTMLInputPassword(
226: HTMLInputElement element, NameValue[] artifacts) {
227: return new ItsNatHTMLInputPasswordImpl(element, artifacts, this );
228: }
229:
230: public ItsNatHTMLInputCheckBox createItsNatHTMLInputCheckBox(
231: HTMLInputElement element, NameValue[] artifacts) {
232: return new ItsNatHTMLInputCheckBoxImpl(element, artifacts, this );
233: }
234:
235: public ItsNatHTMLInputRadio createItsNatHTMLInputRadio(
236: HTMLInputElement element, NameValue[] artifacts) {
237: return new ItsNatHTMLInputRadioImpl(element, artifacts, this );
238: }
239:
240: public ItsNatHTMLInputSubmit createItsNatHTMLInputSubmit(
241: HTMLInputElement element, NameValue[] artifacts) {
242: return new ItsNatHTMLInputSubmitImpl(element, artifacts, this );
243: }
244:
245: public ItsNatHTMLInputReset createItsNatHTMLInputReset(
246: HTMLInputElement element, NameValue[] artifacts) {
247: return new ItsNatHTMLInputResetImpl(element, artifacts, this );
248: }
249:
250: public ItsNatHTMLInputButton createItsNatHTMLInputButton(
251: HTMLInputElement element, NameValue[] artifacts) {
252: return new ItsNatHTMLInputButtonImpl(element, artifacts, this );
253: }
254:
255: public ItsNatHTMLInputImage createItsNatHTMLInputImage(
256: HTMLInputElement element, NameValue[] artifacts) {
257: return new ItsNatHTMLInputImageImpl(element, artifacts, this );
258: }
259:
260: public ItsNatHTMLInputHidden createItsNatHTMLInputHidden(
261: HTMLInputElement element, NameValue[] artifacts) {
262: return new ItsNatHTMLInputHiddenImpl(element, artifacts, this );
263: }
264:
265: public ItsNatHTMLInputFile createItsNatHTMLInputFile(
266: HTMLInputElement element, NameValue[] artifacts) {
267: return new ItsNatHTMLInputFileImpl(element, artifacts, this );
268: }
269:
270: public ItsNatHTMLSelectMult createItsNatHTMLSelectMult(
271: HTMLSelectElement element, NameValue[] artifacts) {
272: return new ItsNatHTMLSelectMultImpl(element, artifacts, this );
273: }
274:
275: public ItsNatHTMLSelectComboBox createItsNatHTMLSelectComboBox(
276: HTMLSelectElement element, NameValue[] artifacts) {
277: return new ItsNatHTMLSelectComboBoxImpl(element, artifacts,
278: this );
279: }
280:
281: public ItsNatHTMLTextArea createItsNatHTMLTextArea(
282: HTMLTextAreaElement element, NameValue[] artifacts) {
283: return new ItsNatHTMLTextAreaImpl(element, artifacts, this );
284: }
285:
286: public ItsNatHTMLButton createItsNatHTMLButton(
287: HTMLButtonElement element, NameValue[] artifacts) {
288: return new ItsNatHTMLButtonDefaultImpl(element, artifacts, this );
289: }
290:
291: public ItsNatHTMLButtonLabel createItsNatHTMLButtonLabel(
292: HTMLButtonElement element, NameValue[] artifacts) {
293: return new ItsNatHTMLButtonLabelImpl(element, artifacts, this );
294: }
295:
296: public ItsNatHTMLTable createItsNatHTMLTable(
297: HTMLTableElement element, ItsNatTableStructure structure,
298: NameValue[] artifacts) {
299: return new ItsNatHTMLTableImpl(element, structure, artifacts,
300: this );
301: }
302:
303: public ItsNatHTMLForm addItsNatHTMLForm(HTMLFormElement element,
304: NameValue[] artifacts) {
305: ItsNatHTMLForm component = createItsNatHTMLForm(element,
306: artifacts);
307: addItsNatComponent(component);
308: return component;
309: }
310:
311: public ItsNatLabelEditor createDefaultItsNatLabelEditor(
312: ItsNatComponent compEditor) {
313: return new ItsNatHTMLLabelEditorDefaultImpl(compEditor, this );
314: }
315:
316: public ItsNatListCellEditor createDefaultItsNatListCellEditor(
317: ItsNatComponent compEditor) {
318: return new ItsNatHTMLListCellEditorDefaultImpl(compEditor, this );
319: }
320:
321: public ItsNatTableCellEditor createDefaultItsNatTableCellEditor(
322: ItsNatComponent compEditor) {
323: return new ItsNatHTMLTableCellEditorDefaultImpl(compEditor,
324: this );
325: }
326:
327: public ItsNatTreeCellEditor createDefaultItsNatTreeCellEditor(
328: ItsNatComponent compEditor) {
329: return new ItsNatHTMLTreeCellEditorDefaultImpl(compEditor, this);
330: }
331:
332: }
|