Fixed unpreserved leading/trailing space in misc.xml values (JDOM 2.0.5 bug)
This commit is contained in:
parent
a5383766ef
commit
8a934027f1
3 changed files with 19 additions and 9 deletions
2
pom.xml
2
pom.xml
|
@ -44,7 +44,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jdom</groupId>
|
<groupId>org.jdom</groupId>
|
||||||
<artifactId>jdom2</artifactId>
|
<artifactId>jdom2</artifactId>
|
||||||
<version>2.0.5</version>
|
<version>2.0.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-cli</groupId>
|
<groupId>commons-cli</groupId>
|
||||||
|
|
|
@ -205,18 +205,24 @@ Advanced XML
|
||||||
|
|
||||||
Raw 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
|
FTL is quirky. Occasionally you may need to include non-standard XML in a
|
||||||
mod without elaborate parsing. For instance, "misc.xml" defines phrases
|
mod without elaborate parsing.
|
||||||
for localization, which may begin/end with a space. Normally, this
|
|
||||||
whitespace would be trimmed away, leading to ugly results in-game.
|
|
||||||
|
|
||||||
If your mod has a file named "misc.xml.rawappend", the content of that
|
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
|
file will be tacked onto the end of "misc.xml". Line-endings and encoding
|
||||||
will be standardized, but Slipstream will make no attempt to
|
will be standardized. Root <FTL> tags, if present, will be removed before
|
||||||
(mis)understand the tags of either file.
|
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
|
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
|
Similarly a file named "misc.xml.rawclobber" will entirely replace the
|
||||||
original "misc.xml".
|
original "misc.xml".
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.jdom2.util.NamespaceStack;
|
||||||
*/
|
*/
|
||||||
public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
|
public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
|
||||||
|
|
||||||
|
|
||||||
// Copied from AbstractXMLOutputProcessor in JDOM 2.0.5, with modification.
|
// Copied from AbstractXMLOutputProcessor in JDOM 2.0.5, with modification.
|
||||||
@Override
|
@Override
|
||||||
protected void printElement( Writer out, FormatStack fstack, NamespaceStack nstack, Element element ) throws IOException {
|
protected void printElement( Writer out, FormatStack fstack, NamespaceStack nstack, Element element ) throws IOException {
|
||||||
|
@ -79,6 +80,7 @@ public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Always null!? And what about other TextModes?
|
||||||
final String space = element.getAttributeValue( "space", Namespace.XML_NAMESPACE );
|
final String space = element.getAttributeValue( "space", Namespace.XML_NAMESPACE );
|
||||||
if ( "default".equals( space ) ) {
|
if ( "default".equals( space ) ) {
|
||||||
fstack.setTextMode( fstack.getDefaultMode() );
|
fstack.setTextMode( fstack.getDefaultMode() );
|
||||||
|
@ -86,6 +88,7 @@ public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
|
||||||
else if ( "preserve".equals( space ) ) {
|
else if ( "preserve".equals( space ) ) {
|
||||||
fstack.setTextMode( Format.TextMode.PRESERVE );
|
fstack.setTextMode( Format.TextMode.PRESERVE );
|
||||||
}
|
}
|
||||||
|
//if ( space != null ) System.out.println( space );
|
||||||
|
|
||||||
Walker walker = buildWalker( fstack, content, true );
|
Walker walker = buildWalker( fstack, content, true );
|
||||||
if ( !walker.hasNext() ) {
|
if ( !walker.hasNext() ) {
|
||||||
|
@ -154,6 +157,7 @@ public class SloppyXMLOutputProcessor extends AbstractXMLOutputProcessor {
|
||||||
*/
|
*/
|
||||||
public static void sloppyPrint( Document doc, Writer writer, String encoding ) throws IOException {
|
public static void sloppyPrint( Document doc, Writer writer, String encoding ) throws IOException {
|
||||||
Format format = Format.getPrettyFormat();
|
Format format = Format.getPrettyFormat();
|
||||||
|
format.setTextMode( Format.TextMode.PRESERVE ); // Permit leading/trailing space.
|
||||||
format.setExpandEmptyElements( false );
|
format.setExpandEmptyElements( false );
|
||||||
format.setOmitDeclaration( false );
|
format.setOmitDeclaration( false );
|
||||||
format.setIndent( "\t" );
|
format.setIndent( "\t" );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue