cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-6057] Passing the encoding property to the JAXB compiler, thanks to Dan
Date Tue, 21 Oct 2014 20:11:15 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes cfd162b0f -> af21b4656


[CXF-6057] Passing the encoding property to the JAXB compiler, thanks to Dan


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/af21b465
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/af21b465
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/af21b465

Branch: refs/heads/2.7.x-fixes
Commit: af21b46563b8578f3f7cc41119007c988acc4aa4
Parents: cfd162b
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Oct 21 21:00:59 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Oct 21 21:10:48 2014 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/cxf/common/jaxb/JAXBUtils.java | 12 +++++++++++-
 .../apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java   |  1 +
 .../apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java  | 10 ++++++++--
 3 files changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/af21b465/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java b/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
index 31cf54c..8ff3334 100644
--- a/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
+++ b/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
@@ -699,8 +699,10 @@ public final class JAXBUtils {
         }
         return classes;
     }
-    
     public static Object createFileCodeWriter(File f) throws JAXBException {
+        return createFileCodeWriter(f, "UTF-8");
+    }
+    public static Object createFileCodeWriter(File f, String encoding) throws JAXBException
{
         try {
             Class<?> cls;
             try {
@@ -710,6 +712,14 @@ public final class JAXBUtils {
                 cls = Class.forName("com.sun.codemodel.internal.writer.FileCodeWriter",
                                     true, getXJCClassLoader());
             }
+            if (encoding != null) {
+                try {
+                    return cls.getConstructor(File.class, String.class)
+                              .newInstance(f, encoding);
+                } catch (Exception ex) {
+                    // try a single argument constructor
+                }
+            }
             return cls.getConstructor(File.class).newInstance(f);
         } catch (Exception ex) {
             throw new JAXBException(ex);

http://git-wip-us.apache.org/repos/asf/cxf/blob/af21b465/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
index 07a628e..917354d 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/JAXRSContainer.java
@@ -125,6 +125,7 @@ public class JAXRSContainer extends AbstractCXFToolContainer {
         }
         sg.setPackageName((String)context.get(WadlToolConstants.CFG_PACKAGENAME));
         sg.setResourceName((String)context.get(WadlToolConstants.CFG_RESOURCENAME));
+        sg.setEncoding((String)context.get(WadlToolConstants.CFG_ENCODING));
 
         String wadlNs = (String)context.get(WadlToolConstants.CFG_WADL_NAMESPACE);
         if (wadlNs != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/af21b465/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
----------------------------------------------------------------------
diff --git a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
index 7ecbdfa..7f1b8be 100644
--- a/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
+++ b/tools/wadlto/jaxrs/src/main/java/org/apache/cxf/tools/wadlto/jaxrs/SourceGenerator.java
@@ -220,6 +220,7 @@ public class SourceGenerator {
     private boolean supportMultipleXmlReps;
     private boolean validateWadl;    
     private SchemaCollection schemaCollection = new SchemaCollection();
+    private String encoding;
     
     public SourceGenerator() {
         this(Collections.<String, String>emptyMap());
@@ -1439,7 +1440,8 @@ public class SourceGenerator {
             file.createNewFile();
             Writer writer = null;
             try {
-                writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
+                writer = new OutputStreamWriter(new FileOutputStream(file), 
+                                                encoding == null ? "UTF-8" : encoding);
                 writer.write(content);
                 writer.flush();
             } finally {
@@ -1491,7 +1493,7 @@ public class SourceGenerator {
     
     private void generateClassesFromSchema(JCodeModel codeModel, File src) {
         try {
-            Object writer = JAXBUtils.createFileCodeWriter(src);
+            Object writer = JAXBUtils.createFileCodeWriter(src, encoding == null ? "UTF-8"
: encoding);
             codeModel.build(writer);
             generatedTypeClasses = JAXBUtils.getGeneratedClassNames(codeModel);
         } catch (Exception e) {
@@ -1743,6 +1745,10 @@ public class SourceGenerator {
         this.validateWadl = validateWadl;
     }
 
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
     private static class GrammarInfo {
         private Map<String, String> nsMap = new HashMap<String, String>();
         private Map<String, String> elementTypeMap = new HashMap<String, String>();


Mime
View raw message