mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 14:03:17 +00:00
Stop JDOM errors if we try to output metadata with illegal characters
git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@2874 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -50,6 +50,7 @@ import org.dspace.core.Constants;
|
|||||||
import org.dspace.core.SelfNamedPlugin;
|
import org.dspace.core.SelfNamedPlugin;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.Namespace;
|
import org.jdom.Namespace;
|
||||||
|
import org.jdom.Verifier;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -238,9 +239,31 @@ public class XHTMLHeadDisseminationCrosswalk extends SelfNamedPlugin implements
|
|||||||
{
|
{
|
||||||
Element e = new Element("meta", XHTML_NAMESPACE);
|
Element e = new Element("meta", XHTML_NAMESPACE);
|
||||||
e.setAttribute("name", name);
|
e.setAttribute("name", name);
|
||||||
|
if (v.value == null)
|
||||||
|
{
|
||||||
|
e.setAttribute("content", "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Check that we can output the content
|
||||||
|
String reason = Verifier.checkCharacterData(v.value);
|
||||||
|
if (reason == null)
|
||||||
|
{
|
||||||
// TODO: Check valid encoding? We assume UTF-8
|
// TODO: Check valid encoding? We assume UTF-8
|
||||||
// TODO: Check escaping "<>&
|
// TODO: Check escaping "<>&
|
||||||
e.setAttribute("content", v.value == null ? "" : v.value);
|
e.setAttribute("content", v.value == null ? "" : v.value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Warn that we found invalid characters
|
||||||
|
log.warn("Invalid attribute characters in Metadata: " + reason);
|
||||||
|
|
||||||
|
// Strip any characters that we can, and if the result is valid, output it
|
||||||
|
String simpleText = v.value.replaceAll("\\p{Cntrl}", "");
|
||||||
|
if (Verifier.checkCharacterData(simpleText) == null)
|
||||||
|
e.setAttribute("content", simpleText);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (v.language != null && !v.language.equals(""))
|
if (v.language != null && !v.language.equals(""))
|
||||||
{
|
{
|
||||||
e.setAttribute("lang", v.language, Namespace.XML_NAMESPACE);
|
e.setAttribute("lang", v.language, Namespace.XML_NAMESPACE);
|
||||||
|
Reference in New Issue
Block a user