sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1454431 - in /sis/ip-review: StringConverter.Charset.xhtml rev/30615/ rev/30615/HEADER.html rev/30615/StringConverter.Charset.xhtml
Date Fri, 08 Mar 2013 15:40:29 GMT
Author: desruisseaux
Date: Fri Mar  8 15:40:29 2013
New Revision: 1454431

URL: http://svn.apache.org/r1454431
Log:
IP review for StringConverter.Charset.

Added:
    sis/ip-review/StringConverter.Charset.xhtml   (with props)
    sis/ip-review/rev/30615/
    sis/ip-review/rev/30615/HEADER.html   (with props)
    sis/ip-review/rev/30615/StringConverter.Charset.xhtml   (with props)

Added: sis/ip-review/StringConverter.Charset.xhtml
URL: http://svn.apache.org/viewvc/sis/ip-review/StringConverter.Charset.xhtml?rev=1454431&view=auto
==============================================================================
--- sis/ip-review/StringConverter.Charset.xhtml (added)
+++ sis/ip-review/StringConverter.Charset.xhtml Fri Mar  8 15:40:29 2013
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>StringConverter.Charset history</title>
+    <style type="text/css" media="all">
+      @import url("./reports.css");
+    </style>
+  </head>
+  <body>
+    <div>
+      <h1>StringConverter.Charset history</h1>
+  <p>Click on the commit message for inspecting the <code>diff</code> and
how the code has been rewritten.</p>
+<p><b>Command line:</b></p>
+<blockquote><code>svn log -r31996:1 http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/CharsetConverterFactory.java</code></blockquote>
+<table>
+  <tr>
+    <th>Rev.</th>
+    <th>Date</th>
+    <th>Author</th>
+    <th class="last">Message</th>
+  </tr>
+<tr><td class="rev">30648</td><td>2008-06-12</td><td>acuster</td><td>Copyright
headers: lib/main, this time with feeling (and the el in Toolkit)</td></tr>
+<tr><td class="rev">30615</td><td>2008-06-12</td><td class="unav">jdeolive</td><td><a
href="rev/30615/StringConverter.Charset.xhtml">added charset converter factory</a></td></tr>
+</table>
+    </div>
+  </body>
+</html>

Propchange: sis/ip-review/StringConverter.Charset.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/ip-review/StringConverter.Charset.xhtml
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: sis/ip-review/rev/30615/HEADER.html
URL: http://svn.apache.org/viewvc/sis/ip-review/rev/30615/HEADER.html?rev=1454431&view=auto
==============================================================================
--- sis/ip-review/rev/30615/HEADER.html (added)
+++ sis/ip-review/rev/30615/HEADER.html Fri Mar  8 15:40:29 2013
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>Revision 30615</title>
+  </head>
+  <body>
+    <div>
+      <h1>Revision 30615</h1>
+<table>
+  <tr><td><b>Author:</b></td><td>jdeolive</td></tr>
+  <tr><td><b>Date:</b></td><td>2008-06-12</td></tr>
+  <tr><td><b>Message:</b></td><td>added charset converter
factory</td></tr>
+</table>
+    </div>
+  </body>
+</html>

Propchange: sis/ip-review/rev/30615/HEADER.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/ip-review/rev/30615/HEADER.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: sis/ip-review/rev/30615/StringConverter.Charset.xhtml
URL: http://svn.apache.org/viewvc/sis/ip-review/rev/30615/StringConverter.Charset.xhtml?rev=1454431&view=auto
==============================================================================
--- sis/ip-review/rev/30615/StringConverter.Charset.xhtml (added)
+++ sis/ip-review/rev/30615/StringConverter.Charset.xhtml Fri Mar  8 15:40:29 2013
@@ -0,0 +1,118 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta charset="UTF-8"/>
+    <title>StringConverter.Charset changes for revisions 30614:30615</title>
+    <style type="text/css" media="all">
+      @import url("../../reports.css");
+    </style>
+  </head>
+  <body>
+    <div>
+      <h1>StringConverter.Charset changes for revisions 30614:30615</h1>
+
+<p>While the idea to provide a converter from <code>String</code> to <code>Charset</code>
was found in GeoTools,
+the code has been rewritten using a different strategy (types are resolved more accurately
when searching for a
+converter, and the various kind of conversions are separated in different <code>convert(S)</code>
methods,
+so there is no sequences of <code>if</code> … <code>else</code>
statements). The only common code is the following
+line, inside a <code>try</code> … <code>catch</code> block performing
a different work in case of failure:</p>
+
+<blockquote><pre>return Charset.forName(source);</pre></blockquote>
+
+<p>There is no reasonable way to write the above line differently.
+The table below compares the GeoTools code with the Geotoolkit.org one.</p>
+
+<p><b>Command line:</b></p>
+<blockquote><code>svn cat -r30615 http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/CharsetConverterFactory.java</code></blockquote>
+<table class="changes">
+<tr><th>Revision 30615</th><th>Geotoolkit.org</th></tr>
+<tr><td><pre><span class="add">package org.geotools.util;
+
+import java.nio.charset.Charset;
+import java.nio.charset.UnsupportedCharsetException;
+
+import org.geotools.factory.Hints;
+
+/**
+ * Converter for going from a String to a {@link Charset} and vice versa.
+ *
+ * @author Justin Deoliveira, The Open Planning Project
+ * @since 2.5
+ */
+public class CharsetConverterFactory implements ConverterFactory {
+
+    public Converter createConverter(Class&lt;?&gt; source, Class&lt;?&gt;
target,
+            Hints hints) {
+
+        if ( CharSequence.class.isAssignableFrom( source ) &amp;&amp;
+                Charset.class.isAssignableFrom( target ) ) {
+            return new Converter() {
+                public &lt;T&gt; T convert(Object source, Class&lt;T&gt;
target) throws Exception {
+                    try {
+                        return(T) Charset.forName( (String) source );
+                    }
+                    catch( UnsupportedCharsetException e ) {
+                        //TODO: log this
+                        return null;
+                    }
+                }
+            };
+        }
+        if ( Charset.class.isAssignableFrom( source ) &amp;&amp;
+                CharSequence.class.isAssignableFrom( target ) ) {
+            return new Converter() {
+                public &lt;T&gt; T convert(Object source, Class&lt;T&gt;
target) throws Exception {
+                    return (T) ((Charset)source).toString();
+                }
+
+            };
+        }
+
+        return null;
+    }
+
+}</span></pre></td>
+<td><pre>/**
+ * Converter from {@link java.lang.String} to {@link java.nio.charset.Charset}.
+ *
+ * @author Justin Deoliveira (TOPP)
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.02
+ *
+ * @since 2.4
+ */
+@Immutable
+static final class Charset extends StringConverter&lt;java.nio.charset.Charset&gt;
{
+    private static final long serialVersionUID = 4539755855992944656L;
+    public static final Charset INSTANCE = new Charset();
+    private Charset() {
+    }
+
+    @Override
+    public Class&lt;java.nio.charset.Charset&gt; getTargetClass() {
+        return java.nio.charset.Charset.class;
+    }
+
+    @Override
+    public java.nio.charset.Charset convert(String source) throws NonconvertibleObjectException
{
+        if (source == null) {
+            return null;
+        }
+        source = source.trim();
+        try {
+            return java.nio.charset.Charset.forName(source);
+        }
+        catch (UnsupportedCharsetException e) {
+            throw new NonconvertibleObjectException(e);
+        }
+    }
+
+    /** Returns the singleton instance on deserialization. */
+    protected Object readResolve() throws ObjectStreamException {
+        return INSTANCE;
+    }
+}</pre></td></tr>
+</table>
+    </div>
+  </body>
+</html>

Propchange: sis/ip-review/rev/30615/StringConverter.Charset.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/ip-review/rev/30615/StringConverter.Charset.xhtml
------------------------------------------------------------------------------
    svn:mime-type = text/html



Mime
View raw message