cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7024] Optionally keep namespace prefix as is
Date Thu, 25 Aug 2016 16:30:12 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 9ca732471 -> 48c445d20


[CXF-7024] Optionally keep namespace prefix as is


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

Branch: refs/heads/3.1.x-fixes
Commit: 48c445d20165260243b74102610fcf31ee18f388
Parents: 9ca7324
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Aug 25 17:25:00 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Aug 25 17:29:47 2016 +0100

----------------------------------------------------------------------
 .../maven_plugin/javatowadl/Java2WADLMojo.java  |  6 ++++++
 .../cxf/jaxrs/model/wadl/WadlGenerator.java     | 21 +++++++++++++++----
 .../cxf/jaxrs/model/wadl/WadlGeneratorTest.java | 22 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/48c445d2/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
b/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
index dd1fb26..724e80c 100644
--- a/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
+++ b/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
@@ -132,6 +132,11 @@ public class Java2WADLMojo extends AbstractMojo {
     /**
      * @parameter default-value="true"
      */
+    private boolean incrementNamespacePrefix;
+    
+    /**
+     * @parameter default-value="true"
+     */
     private boolean singleResourceMultipleMethods;
    
     /**
@@ -246,6 +251,7 @@ public class Java2WADLMojo extends AbstractMojo {
     
     private void setExtraProperties(WadlGenerator wg) {
         wg.setSingleResourceMultipleMethods(singleResourceMultipleMethods);
+        wg.setIncrementNamespacePrefix(incrementNamespacePrefix);
         wg.setUseSingleSlashResource(useSingleSlashResource);
         wg.setIncludeDefaultWadlSchemaLocation(includeDefaultWadlSchemaLocation);
         wg.setIgnoreForwardSlash(ignoreForwardSlash);

http://git-wip-us.apache.org/repos/asf/cxf/blob/48c445d2/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index ec41cc8..9f13b4b 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -171,6 +171,7 @@ public class WadlGenerator implements ContainerRequestFilter {
     private boolean checkAbsolutePathSlash;
     private boolean keepRelativeDocLinks;
     private boolean usePathParamsToCompareOperations = true;
+    private boolean incrementNamespacePrefix = true;
         
     private boolean ignoreMessageWriters = true;
     private boolean ignoreRequests;
@@ -1563,15 +1564,23 @@ public class WadlGenerator implements ContainerRequestFilter {
 
     private String getPrefix(String ns, Map<Class<?>, QName> clsMap) {
         String prefix = null;
+        int index = 0;
         for (QName name : clsMap.values()) {
+            String currentPrefix = name.getPrefix();
+            if (currentPrefix.startsWith(nsPrefix)) {
+                int currentIndex = currentPrefix.equals(nsPrefix) ? 0 
+                    : Integer.valueOf(currentPrefix.substring(nsPrefix.length()));
+                if (currentIndex > index) {
+                    index = currentIndex;
+                }
+            }
             if (name.getNamespaceURI().equals(ns)) {
-                prefix = name.getPrefix();
+                prefix = currentPrefix;
                 break;
             }
         }
-        if (prefix == null) {
-            int size = new HashSet<>(clsMap.values()).size();
-            prefix = nsPrefix + (size + 1);
+        if (StringUtils.isEmpty(prefix)) {
+            prefix = index == 0 && !incrementNamespacePrefix ? nsPrefix : nsPrefix
+ (index + 1);
         }
         return prefix;
     }
@@ -2237,6 +2246,10 @@ public class WadlGenerator implements ContainerRequestFilter {
         this.convertResourcesToDOM = convertResourcesToDOM;
     }
 
+    public void setIncrementNamespacePrefix(boolean incrementNamespacePrefix) {
+        this.incrementNamespacePrefix = incrementNamespacePrefix;
+    }
+
     private static class SchemaConverter extends DelegatingXMLStreamWriter {
         private static final String SCHEMA_LOCATION = "schemaLocation";
         private final Map<String, String> locsMap;

http://git-wip-us.apache.org/repos/asf/cxf/blob/48c445d2/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
index 2031664..f072c85 100644
--- a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
@@ -223,6 +223,28 @@ public class WadlGeneratorTest extends Assert {
     }
     
     @Test
+    public void testSingleRootResourceNoPrefixIncrement() throws Exception {
+        WadlGenerator wg = new WadlGenerator();
+        wg.setApplicationTitle("My Application");
+        wg.setNamespacePrefix("ns");
+        wg.setIncrementNamespacePrefix(false);
+        ClassResourceInfo cri = 
+            ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true,
true);
+        Message m = mockMessage("http://localhost:8080/baz", "/bookstore/1", WadlGenerator.WADL_QUERY,
cri);
+        Response r = handleRequest(wg, m);
+        checkResponse(r);
+        Document doc = StaxUtils.read(new StringReader(r.getEntity().toString()));
+        checkDocs(doc.getDocumentElement(), "My Application", "", "");
+        checkGrammars(doc.getDocumentElement(), "thebook", "books", "thebook2s", "thebook2",
"thechapter");
+        List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
1);
+        checkBookStoreInfo(els.get(0), 
+                           "ns:thebook", 
+                           "ns:thebook2", 
+                           "ns:thechapter",
+                           "ns:books");
+    }
+    
+    @Test
     public void testTwoSchemasSameNs() throws Exception {
         WadlGenerator wg = new WadlGenerator();
         wg.setApplicationTitle("My Application");


Mime
View raw message