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;
15:
16: import org.w3c.dom.Document;
17:
18: /**
19: *
20: * @author jmarranz
21: */
22: public class PlainNodeTool_RECUPERAR {
23:
24: /**
25: * Creates a new instance of PlainNodeTool_RECUPERAR
26: */
27: public PlainNodeTool_RECUPERAR() {
28: }
29:
30: protected org.w3c.dom.CharacterData createMarkedNode(
31: String markedCode, Document doc) {
32: // Para evitar que los tags serializados al serializar de nuevo el elemento contenedor (o desde el padre etc) se conviertan en < > etc
33: return doc.createCDATASection(markedCode);
34: }
35:
36: protected String getMarkedCode(String code) {
37: return cachePrefix() + code + cacheSuffix();
38: }
39:
40: public static String cachePrefix() {
41: return "${itsnat_docfrag_cache_prefix}";
42: }
43:
44: public static String cacheSuffix() {
45: return "${itsnat_docfrag_cache_suffix}";
46: }
47:
48: public static String cachePrefixSerialized() {
49: return "<![CDATA[" + cachePrefix();
50: }
51:
52: public static String cacheSuffixSerialized() {
53: return cacheSuffix() + "]]>";
54: }
55:
56: public static String removePrefixSuffixOfCachedFragments(String code) {
57: StringBuffer codeRes = new StringBuffer();
58:
59: // Cogemos el prefijo y sufijo serializado porque también hay que quitar el <![CDATA[
60: // generado al serializar el CDATASection contenedor del markup cacheado
61: String prefix = cachePrefixSerialized();
62: String suffix = cacheSuffixSerialized();
63: int posPrefix = code.indexOf(prefix);
64: while (posPrefix >= 0) {
65: codeRes.append(code.substring(0, posPrefix));
66: code = code.substring(posPrefix + prefix.length());
67: int posSuffix = code.indexOf(suffix); // DEBE ser >= 0 necesariamente
68: codeRes.append(code.substring(0, posSuffix));
69: code = code.substring(posSuffix + suffix.length());
70:
71: posPrefix = code.indexOf(prefix);
72: }
73:
74: codeRes.append(code);
75:
76: return codeRes.toString();
77: }
78: }
|