Author: ltheussl
Date: Sat Feb 16 01:56:29 2008
New Revision: 628259
URL: http://svn.apache.org/viewvc?rev=628259&view=rev
Log:
[DOXIA-59] Doxia creates files with inconsistent new lines.
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java?rev=628259&r1=628258&r2=628259&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java
Sat Feb 16 01:56:29 2008
@@ -21,6 +21,7 @@
import org.apache.maven.doxia.logging.Log;
import org.apache.maven.doxia.logging.SystemStreamLog;
+import org.apache.maven.doxia.markup.Markup;
/**
* An abstract base class that defines some convenience methods for sinks.
@@ -31,7 +32,7 @@
* @since 1.0-beta-1
*/
public abstract class AbstractSink
- implements Sink
+ implements Sink, Markup
{
private Log log;
@@ -55,5 +56,48 @@
}
return log;
+ }
+
+ /**
+ * Parses the given String and replaces all occurrences of
+ * '\n', '\r' and '\r\n' with the system EOL. All Sinks should
+ * make sure that text output is filtered through this method.
+ *
+ * @param text the text to scan.
+ * @return a String that contains only System EOLs.
+ */
+ protected String unifyEOLs( String text )
+ {
+ if ( text == null )
+ {
+ return null;
+ }
+
+ int length = text.length();
+
+ StringBuffer buffer = new StringBuffer( length );
+
+ for ( int i = 0; i < length; i++ )
+ {
+ if ( text.charAt(i) == '\r' )
+ {
+ if ( ( i + 1 ) < length && text.charAt( i + 1 ) == '\n' )
+ {
+ i++;
+ }
+
+ buffer.append( EOL );
+ }
+ else if ( text.charAt( i ) == '\n' )
+ {
+ buffer.append( EOL );
+ }
+ else
+ {
+ buffer.append( text.charAt( i ) );
+ }
+ }
+
+ return buffer.toString();
}
}
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java?rev=628259&r1=628258&r2=628259&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
Sat Feb 16 01:56:29 2008
@@ -1221,7 +1221,7 @@
/** {@inheritDoc} */
protected void write( String text )
{
- writer.write( text );
+ writer.write( unifyEOLs( text ) );
}
}
|