/*
ItsNat Java Web Application Framework
Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
Author: Jose Maria Arranz Santamaria
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. See the GNU Affero General Public
License for more details. See the copy of the GNU Affero General Public License
included in this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.itsnat.impl.core;
import org.w3c.dom.Document;
/**
*
* @author jmarranz
*/
public class PlainNodeTool_RECUPERAR
{
/**
* Creates a new instance of PlainNodeTool_RECUPERAR
*/
public PlainNodeTool_RECUPERAR()
{
}
protected org.w3c.dom.CharacterData createMarkedNode(String markedCode,Document doc)
{
// Para evitar que los tags serializados al serializar de nuevo el elemento contenedor (o desde el padre etc) se conviertan en < > etc
return doc.createCDATASection(markedCode);
}
protected String getMarkedCode(String code)
{
return cachePrefix() + code + cacheSuffix();
}
public static String cachePrefix()
{
return "${itsnat_docfrag_cache_prefix}";
}
public static String cacheSuffix()
{
return "${itsnat_docfrag_cache_suffix}";
}
public static String cachePrefixSerialized()
{
return "<![CDATA[" + cachePrefix();
}
public static String cacheSuffixSerialized()
{
return cacheSuffix() + "]]>";
}
public static String removePrefixSuffixOfCachedFragments(String code)
{
StringBuffer codeRes = new StringBuffer();
// Cogemos el prefijo y sufijo serializado porque tambin hay que quitar el <![CDATA[
// generado al serializar el CDATASection contenedor del markup cacheado
String prefix = cachePrefixSerialized();
String suffix = cacheSuffixSerialized();
int posPrefix = code.indexOf(prefix);
while(posPrefix >= 0)
{
codeRes.append( code.substring(0,posPrefix) );
code = code.substring(posPrefix + prefix.length());
int posSuffix = code.indexOf(suffix); // DEBE ser >= 0 necesariamente
codeRes.append( code.substring(0,posSuffix) );
code = code.substring(posSuffix + suffix.length());
posPrefix = code.indexOf(prefix);
}
codeRes.append( code );
return codeRes.toString();
}
}
|