Fixed unpreserved leading/trailing space in misc.xml values (JDOM 2.0.5 bug)

This commit is contained in:
Vhati 2017-12-06 17:10:34 -05:00
parent a5383766ef
commit 8a934027f1
3 changed files with 19 additions and 9 deletions

View file

@ -44,7 +44,7 @@
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom2</artifactId>
<version>2.0.5</version>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>

View file

@ -205,18 +205,24 @@ Advanced XML
Raw XML
This feature was a workaround for a bug that was fixed in Slipstream 1.7.
The bug caused Slipstream to trim off leading/trailing space in XML values.
This was problematic for "misc.xml" (in FTL 1.5.4-1.5.13), which defined
phrases for localization. Some phrases had spaces, which led to ugly results
in-game if trimmed.
FTL is quirky. Occasionally you may need to include non-standard XML in a
mod without elaborate parsing. For instance, "misc.xml" defines phrases
for localization, which may begin/end with a space. Normally, this
whitespace would be trimmed away, leading to ugly results in-game.
mod without elaborate parsing.
If your mod has a file named "misc.xml.rawappend", the content of that
file will be tacked onto the end of "misc.xml". Line-endings and encoding
will be standardized, but Slipstream will make no attempt to
(mis)understand the tags of either file.
will be standardized. Root <FTL> tags, if present, will be removed before
appending and restored after, but Slipstream will make no attempt to
(mis)understand the tags of either file for advanced modding.
You can still override existing tags by adding your own with the same
name attribute, since FTL honors the last it sees.
'name' attribute, since FTL honors the last it sees.
Similarly a file named "misc.xml.rawclobber" will entirely replace the
original "misc.xml".

View file

@ -37,6 +37,7 @@ import org.jdom2.util.NamespaceStack;
*/
public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
// Copied from AbstractXMLOutputProcessor in JDOM 2.0.5, with modification.
@Override
protected void printElement( Writer out, FormatStack fstack, NamespaceStack nstack, Element element ) throws IOException {
@ -79,13 +80,15 @@ public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
}
try {
// Always null!? And what about other TextModes?
final String space = element.getAttributeValue( "space", Namespace.XML_NAMESPACE );
if ( "default".equals(space) ) {
if ( "default".equals( space ) ) {
fstack.setTextMode( fstack.getDefaultMode() );
}
else if ( "preserve".equals(space) ) {
else if ( "preserve".equals( space ) ) {
fstack.setTextMode( Format.TextMode.PRESERVE );
}
//if ( space != null ) System.out.println( space );
Walker walker = buildWalker( fstack, content, true );
if ( !walker.hasNext() ) {
@ -154,6 +157,7 @@ public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
*/
public static void sloppyPrint( Document doc, Writer writer, String encoding ) throws IOException {
Format format = Format.getPrettyFormat();
format.setTextMode( Format.TextMode.PRESERVE ); // Permit leading/trailing space.
format.setExpandEmptyElements( false );
format.setOmitDeclaration( false );
format.setIndent( "\t" );