01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.domutil;
15:
16: import org.itsnat.core.domutil.ElementListStructure;
17: import org.itsnat.core.domutil.ElementList;
18: import org.itsnat.core.domutil.ItsNatTreeWalker;
19: import org.itsnat.impl.core.util.*;
20: import org.w3c.dom.Element;
21: import org.w3c.dom.html.HTMLTableCellElement;
22: import org.w3c.dom.html.HTMLTableRowElement;
23:
24: /**
25: * @author jmarranz
26: */
27: public class ElementListStructureDefaultImpl implements
28: ElementListStructure {
29: public static final ElementListStructureDefaultImpl SINGLETON = new ElementListStructureDefaultImpl();
30:
31: /**
32: * Creates a new instance of ElementListStructureDefaultImpl
33: */
34: private ElementListStructureDefaultImpl() {
35: }
36:
37: public static ElementListStructureDefaultImpl newElementListStructureDefault() {
38: // A día de hoy no se guarda estado por lo que el SINGLETON ayuda a disminuir el número de objetos
39: return SINGLETON;
40: }
41:
42: public static Element getContentElement(int index, Element elem) {
43: if (elem instanceof HTMLTableRowElement) {
44: /*
45: Ejemplo de patrón:
46: <table>
47: <tbody id="someId">
48: <tr> <-- elem
49: <td>Cell Pattern</td>
50: </tr>
51: </tbody>
52: </table>
53: */
54: return (HTMLTableCellElement) ItsNatTreeWalker
55: .getFirstChildElement(elem);
56: } else
57: return elem;
58: }
59:
60: public Element getContentElement(ElementList list, int index,
61: Element elem) {
62: if (elem == null)
63: elem = list.getElementAt(index);
64:
65: return getContentElement(index, elem);
66: }
67:
68: }
|