org.digidoc4j.ddoc.c14n.TinyXMLCanonicalizerHandler_TextStringNormalizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ddoc4j Show documentation
Show all versions of ddoc4j Show documentation
DDoc4J is Java Library for validating DDOC documents. It's not recommended to use it directly but rather through DigiDoc4J's API.
The newest version!
package org.digidoc4j.ddoc.c14n;
import org.digidoc4j.ddoc.c14n.common.Convert;
import org.digidoc4j.ddoc.c14n.common.Helper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class TinyXMLCanonicalizerHandler_TextStringNormalizer implements EntityParser_Handler
{
public boolean IsAttribute;
private static Logger m_logger = LoggerFactory.getLogger(TinyXMLCanonicalizerHandler_TextStringNormalizer.class);
public TinyXMLCanonicalizerHandler_TextStringNormalizer()
{
}
public String ResolveEntity(EntityParser_Entity e)
{
if(m_logger.isDebugEnabled())
m_logger.debug("Resolve entity orig: " + e.get_OriginalString() + " text: " + e.get_Text() + " attr: " + this.IsAttribute);
if (e.get_IsNumeric())
{
if (!this.IsAttribute)
{
if ((e.get_IntegerValue() == 10))
{
return "\n";
}
}
if ((e.get_IntegerValue() == 32))
{
return " ";
}
if (Helper.IsVisibleChar(e.get_IntegerValue()))
{
return Convert.ToString(((char)e.get_IntegerValue()));
}
return ""+ e.get_HexValue()+ ";";
}
// VS: replace ' -> ' also in element body
//if (this.IsAttribute) {
if (e.get_Text().equals("apos"))
{
return "\'";
}
//}
return e.get_OriginalString();
}
public String ResolveText(String e)
{
TinyXMLCanonicalizerHandler_TextStringNormalizer_EntityHelper h;
h = new TinyXMLCanonicalizerHandler_TextStringNormalizer_EntityHelper(e);
h.set_Item("&", "&");
h.set_Item("\r", "
");
if (this.IsAttribute)
{
h.set_Item("\"", """);
h.set_Item("\t", " ");
h.set_Item("\n", "
");
}
else
{
h.set_Item("<", "<");
h.set_Item(">", ">");
}
if(m_logger.isDebugEnabled())
m_logger.debug("Resolve: \n" + e + "\nTO:\n" + h.Text);
return h.Text;
}
public static String StaticResolveTextCData(String e)
{
TinyXMLCanonicalizerHandler_TextStringNormalizer_EntityHelper h;
h = new TinyXMLCanonicalizerHandler_TextStringNormalizer_EntityHelper(e);
h.set_Item("&", "&");
h.set_Item("<", "<");
h.set_Item(">", ">");
h.set_Item("\r", "
");
if(m_logger.isDebugEnabled())
m_logger.debug("Normalize: \n" + e + "\nTO:\n" + h.Text);
return h.Text;
}
}