You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Robert Scholte <rf...@apache.org> on 2013/11/19 22:45:46 UTC

Re: svn commit: r1543585 - in /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet: SnippetMacro.java SnippetReader.java

Encoding is always tricky.
Could you think of a JUnit test as well?

Robert

Op Tue, 19 Nov 2013 22:37:30 +0100 schreef <mi...@apache.org>:

> 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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Aw: Re: svn commit: r1543585 - in /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet: SnippetMacro.java SnippetReader.java

Posted by Michael-O <19...@gmx.net>.
My assumption, yes. Will do!

> Gesendet: Mittwoch, 20. November 2013 um 21:03 Uhr
> Von: "Robert Scholte" <rf...@apache.org>
> An: "Maven Developers List" <de...@maven.apache.org>
> 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 <19...@gmx.net>:
> 
> > 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 <mi...@apache.org>:
> >>
> >>> 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: dev-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: dev-help@maven.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > For additional commands, e-mail: dev-help@maven.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r1543585 - in /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet: SnippetMacro.java SnippetReader.java

Posted by Robert Scholte <rf...@apache.org>.
two thumbs up!

Op Thu, 21 Nov 2013 22:59:31 +0100 schreef Michael-O <19...@gmx.net>:

> Am 2013-11-20 21:03, schrieb Robert Scholte:
>> 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.
>
>
> Done with r1544338.
>
>> Op Tue, 19 Nov 2013 23:03:23 +0100 schreef Michael-O  
>> <19...@gmx.net>:
>>
>>> 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 <mi...@apache.org>:
>>>>
>>>>> 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: dev-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: dev-help@maven.apache.org
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r1543585 - in /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet: SnippetMacro.java SnippetReader.java

Posted by Michael-O <19...@gmx.net>.
Am 2013-11-20 21:03, schrieb Robert Scholte:
> 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.


Done with r1544338.

> Op Tue, 19 Nov 2013 23:03:23 +0100 schreef Michael-O <19...@gmx.net>:
>
>> 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 <mi...@apache.org>:
>>>
>>>> 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: dev-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: dev-help@maven.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r1543585 - in /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet: SnippetMacro.java SnippetReader.java

Posted by Robert Scholte <rf...@apache.org>.
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 <19...@gmx.net>:

> 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 <mi...@apache.org>:
>>
>>> 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: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r1543585 - in /maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet: SnippetMacro.java SnippetReader.java

Posted by Michael-O <19...@gmx.net>.
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 <mi...@apache.org>:
>
>> 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: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org