Skip to content

Instantly share code, notes, and snippets.

@commuterjoy
Created March 25, 2014 20:43
Show Gist options
  • Save commuterjoy/9770897 to your computer and use it in GitHub Desktop.
Save commuterjoy/9770897 to your computer and use it in GitHub Desktop.
Rome RSS errors
! @6hk87e8mf - Internal server error, for (GET) [/profile/sukhdev-sandhu/rss] ->
play.api.Application$$anon$1: Execution exception[[IllegalDataException: The data "'Possessed' by his subjects … Philip Hoare. Photograph: Andrew Sutton for the Guardian." is not legal for a JDOM character content: 0xf is not a legal XML character.]]
at play.api.Application$class.handleError(Application.scala:293) ~[frontend-facia.jar:1-SNAPSHOT]
at play.api.DefaultApplication.handleError(Application.scala:399) [frontend-facia.jar:1-SNAPSHOT]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:165) [frontend-facia.jar:1-SNAPSHOT]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:162) [frontend-facia.jar:1-SNAPSHOT]
Caused by: org.jdom.IllegalDataException: The data "'Possessed' by his subjects … Philip Hoare. Photograph: Andrew Sutton for the Guardian." is not legal for a JDOM character content: 0xf is not a legal XML character.
at org.jdom.Text.setText(Text.java:188) ~[frontend-facia.jar:1-SNAPSHOT]
at org.jdom.Text.<init>(Text.java:99) ~[frontend-facia.jar:1-SNAPSHOT]
at org.jdom.Element.addContent(Element.java:799) ~[frontend-facia.jar:1-SNAPSHOT]
at com.sun.syndication.feed.module.mediarss.io.MediaModuleGenerator.generateSimpleElement(MediaModuleGenerator.java:257) ~[frontend-facia.jar:1-SNAPSHOT]
! @6hk87n5l6 - Internal server error, for (GET) [/education/lecturers/rss] ->
play.api.Application$$anon$1: Execution exception[[IllegalDataException: The data "Studies show how tweeting out papers and research findings can boost citation count. Photograph: Kacper Pempel/Reuters" is not legal for a JDOM character content: 0x12 is not a legal XML character.]]
at play.api.Application$class.handleError(Application.scala:293) ~[frontend-facia.jar:1-SNAPSHOT]
at play.api.DefaultApplication.handleError(Application.scala:399) [frontend-facia.jar:1-SNAPSHOT]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:165) [frontend-facia.jar:1-SNAPSHOT]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:162) [frontend-facia.jar:1-SNAPSHOT]
Caused by: org.jdom.IllegalDataException: The data "Studies show how tweeting out papers and research findings can boost citation count. Photograph: Kacper Pempel/Reuters" is not legal for a JDOM character content: 0x12 is not a legal XML character.
at org.jdom.Text.setText(Text.java:188) ~[frontend-facia.jar:1-SNAPSHOT]
at org.jdom.Text.<init>(Text.java:99) ~[frontend-facia.jar:1-SNAPSHOT]
at org.jdom.Element.addContent(Element.java:799) ~[frontend-facia.jar:1-SNAPSHOT]
at com.sun.syndication.feed.module.mediarss.io.MediaModuleGenerator.generateS
@commuterjoy
Copy link
Author

/**
* This method ensures that the output String has only
* valid XML unicode characters as specified by the
* XML 1.0 standard. For reference, please see
* the
* standard
. This method will return an empty
* String if the input is null or empty.
*
* @param in The String whose non-valid characters we want to remove.
* @return The in String, stripped of non-valid characters.
*/
public String stripNonValidXMLCharacters(String in) {
StringBuffer out = new StringBuffer(); // Used to hold the output.
char current; // Used to reference the current character.

    if (in == null || ("".equals(in))) return ""; // vacancy test.
    for (int i = 0; i < in.length(); i++) {
        current = in.charAt(i); // NOTE: No IndexOutOfBoundsException caught here; it should not happen.
        if ((current == 0x9) ||
            (current == 0xA) ||
            (current == 0xD) ||
            ((current >= 0x20) && (current <= 0xD7FF)) ||
            ((current >= 0xE000) && (current <= 0xFFFD)) ||
            ((current >= 0x10000) && (current <= 0x10FFFF)))
            out.append(current);
    }
    return out.toString();
}    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment