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.html;
15:
16: import org.itsnat.core.ItsNatDocument;
17: import org.itsnat.impl.core.MarkupTemplateVersionDelegateImpl;
18: import org.itsnat.impl.core.DocumentTemplateVersionImpl;
19: import org.itsnat.impl.core.ItsNatDocumentImpl;
20: import org.itsnat.impl.core.ItsNatSessionImpl;
21: import org.itsnat.impl.core.domutil.ItsNatDOMUtilInternal;
22: import org.w3c.dom.Document;
23: import org.w3c.dom.DocumentFragment;
24: import org.w3c.dom.html.HTMLDocument;
25:
26: /**
27: *
28: * @author jmarranz
29: */
30: public class HTMLDocumentTemplateVersionImpl extends
31: DocumentTemplateVersionImpl {
32: protected String serializedOriginalDocument;
33:
34: /**
35: * Creates a new instance of HTMLDocumentTemplateVersionImpl
36: */
37: public HTMLDocumentTemplateVersionImpl(
38: HTMLDocumentTemplateImpl docTemplate, long timeStamp) {
39: super (docTemplate, timeStamp);
40:
41: HTMLTemplateVersionDelegateImpl
42: .normalizeContent(getHTMLDocument()); // Normalizamos después del cacheado pues sólo nos interesa normalizar aquello que es dinámico y por tanto debe coincidir exactamente el DOM cliente y servidor, además es más rápido pues las partes cacheadas son nodos de texto
43: }
44:
45: protected void preCacheDocument() {
46: if (!isFastLoadMode()) {
47: // Serializamos el original antes de que se cacheen los nodos
48: // En el caso fastLoadMode = true no se usa y sería gastar memoria a lo tonto
49: this .serializedOriginalDocument = serializeTemplateDocument();
50: }
51: }
52:
53: protected void doCacheDocument() {
54: HTMLDocument doc = getHTMLDocument();
55: inspectNodeToCache(ItsNatDOMUtilInternal.getHead(doc));
56: inspectNodeToCache(doc.getBody());
57: }
58:
59: public HTMLDocument getHTMLDocument() {
60: return (HTMLDocument) templateDoc;
61: }
62:
63: public String getSerializedOriginalDocument() {
64: return serializedOriginalDocument;
65: }
66:
67: public ItsNatDocumentImpl createItsNatDocument(Document doc,
68: ItsNatSessionImpl session) {
69: return new ItsNatHTMLDocumentImpl((HTMLDocument) doc, this ,
70: session);
71: }
72:
73: protected MarkupTemplateVersionDelegateImpl createMarkupTemplateVersionDelegate() {
74: return new HTMLTemplateVersionDelegateImpl(this );
75: }
76:
77: public DocumentFragment loadFragmentFromSource(String source,
78: ItsNatDocument docTarget) {
79: return HTMLDocFragmentTemplateVersionImpl.convertHTMLFragment(
80: source, docTarget.getDocument(), getEncoding());
81: }
82:
83: }
|