My assumption, yes. Will do!

> Gesendet: Mittwoch, 20. November 2013 um 21:03 Uhr
> Von: "Robert Scholte" <[email protected]>
> An: "Maven Developers List" <[email protected]>
> Betreff: Re: svn commit: r1543585 - in 
> /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet:
>  SnippetMacro.java SnippetReader.java
>
> org.apache.maven.doxia.macro.snippet.SnippetMacroTest
> 
> this class contains a simple test.
> If you can change the testSnippet.txt to a file with some critical  
> characters, you should be able verify the result.
> 
> Robert
> 
> Op Tue, 19 Nov 2013 23:03:23 +0100 schreef Michael-O <[email protected]>:
> 
> > Am 2013-11-19 22:45, schrieb Robert Scholte:
> >> Encoding is always tricky.
> >> Could you think of a JUnit test as well?
> >
> > I think so. Do you have a special idea in mind?
> > What I could do is read a snippet, retrieve the bytes for that specific  
> > encoding and compare them.
> >
> > Guessing an encoding is too tricky and would require ICU4J. Of course,  
> > if a user supplies a wrong encoding, we're lost.
> >
> > Michael
> >
> >
> >> Op Tue, 19 Nov 2013 22:37:30 +0100 schreef <[email protected]>:
> >>
> >>> Author: michaelo
> >>> Date: Tue Nov 19 21:37:30 2013
> >>> New Revision: 1543585
> >>>
> >>> URL: http://svn.apache.org/r1543585
> >>> Log:
> >>> [DOXIA-386] Snippet Macro: Reference file does not support UTF-8 file
> >>> format to generate the page garbage
> >>>
> >>> - Added macro parameter 'encoding' which takes in specific encoding
> >>>
> >>> Modified:
> >>>
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
> >>>
> >>>
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
> >>>
> >>>
> >>> Modified:
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
> >>>
> >>> URL:
> >>> http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java?rev=1543585&r1=1543584&r2=1543585&view=diff
> >>>
> >>> ==============================================================================
> >>>
> >>> ---
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
> >>> (original)
> >>> +++
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
> >>> Tue Nov 19 21:37:30 2013
> >>> @@ -106,6 +106,8 @@ public class SnippetMacro
> >>>              verbatim = Boolean.valueOf( verbatimParam  
> >>> ).booleanValue();
> >>>          }
> >>> +        String encoding = (String) request.getParameter( "encoding" );
> >>> +
> >>>          URL url;
> >>>         if ( !StringUtils.isEmpty( urlParam ) )
> >>> @@ -146,7 +148,7 @@ public class SnippetMacro
> >>>         try
> >>>          {
> >>> -            snippet = getSnippet( url, id );
> >>> +            snippet = getSnippet( url, encoding, id );
> >>>          }
> >>>          catch ( IOException e )
> >>>          {
> >>> @@ -171,11 +173,12 @@ public class SnippetMacro
> >>>       * Return a snippet of the given url.
> >>>       *
> >>>       * @param url The URL to parse.
> >>> +     * @param encoding The encoding of the URL to parse.
> >>>       * @param id  The id of the snippet.
> >>>       * @return The snippet.
> >>>       * @throws IOException if something goes wrong.
> >>>       */
> >>> -    private StringBuffer getSnippet( URL url, String id )
> >>> +    private StringBuffer getSnippet( URL url, String encoding, String
> >>> id )
> >>>          throws IOException
> >>>      {
> >>>          StringBuffer result;
> >>> @@ -195,7 +198,7 @@ public class SnippetMacro
> >>>          {
> >>>              try
> >>>              {
> >>> -                result = new SnippetReader( url ).readSnippet( id );
> >>> +                result = new SnippetReader( url, encoding
> >>> ).readSnippet( id );
> >>>                  cacheSnippet( url, id, result.toString() );
> >>>                  if ( debug )
> >>>                  {
> >>>
> >>> Modified:
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
> >>>
> >>> URL:
> >>> http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java?rev=1543585&r1=1543584&r2=1543585&view=diff
> >>>
> >>> ==============================================================================
> >>>
> >>> ---
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
> >>> (original)
> >>> +++
> >>> maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
> >>> Tue Nov 19 21:37:30 2013
> >>> @@ -42,14 +42,19 @@ public class SnippetReader
> >>>      /** The source. */
> >>>      private URL source;
> >>> +    /** The encoding of the source. */
> >>> +    private String encoding;
> >>> +
> >>>      /**
> >>>       * Constructor.
> >>>       *
> >>> -     * @param src The source.
> >>> +     * @param src The source
> >>> +     * @param encoding The file encoding
> >>>       */
> >>> -    public SnippetReader( URL src )
> >>> +    public SnippetReader( URL src, String encoding )
> >>>      {
> >>>          this.source = src;
> >>> +        this.encoding = encoding;
> >>>      }
> >>>     /**
> >>> @@ -119,8 +124,12 @@ public class SnippetReader
> >>>      private List<String> readLines( String snippetId )
> >>>          throws IOException
> >>>      {
> >>> -        // TODO: DOXIA-386, use InputStreamReader(InputStream in,
> >>> Charset cs)
> >>> -        BufferedReader reader = new BufferedReader( new
> >>> InputStreamReader( source.openStream() ) );
> >>> +        BufferedReader reader;
> >>> +        if ( encoding == null || "".equals(encoding) )
> >>> +            reader = new BufferedReader( new InputStreamReader(
> >>> source.openStream() ) );
> >>> +        else
> >>> +            reader = new BufferedReader( new InputStreamReader(
> >>> source.openStream(), encoding ) );
> >>> +
> >>>          List<String> lines = new ArrayList<String>();
> >>>          try
> >>>          {
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to