cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1095674 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Date Thu, 21 Apr 2011 12:21:25 GMT
Author: sergeyb
Date: Thu Apr 21 12:21:25 2011
New Revision: 1095674

URL: http://svn.apache.org/viewvc?rev=1095674&view=rev
Log:
Merged revisions 1095666 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1095666 | sergeyb | 2011-04-21 12:49:56 +0100 (Thu, 21 Apr 2011) | 1 line
  
  [CXF-3468] Updating WADLGenerator with properties for setting the app title/etc
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Apr 21 12:21:25 2011
@@ -1 +1 @@
-/cxf/trunk:1094926,1094992,1095349
+/cxf/trunk:1094926,1094992,1095349,1095666

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1095674&r1=1095673&r2=1095674&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Thu Apr 21 12:21:25 2011
@@ -109,11 +109,13 @@ public class WadlGenerator implements Re
     private static final String JAXB_DEFAULT_NAMESPACE = "##default";
     private static final String JAXB_DEFAULT_NAME = "##default";
     private static final String CLASSPATH_PREFIX = "classpath:";
-    
+    private static final String DEFAULT_NS_PREFIX = "prefix";
+
     private String wadlNamespace;
     private boolean ignoreMessageWriters = true;
     private boolean singleResourceMultipleMethods = true;
     private boolean useSingleSlashResource;
+    private boolean ignoreForwardSlash;
     private boolean addResourceAndMethodIds;
     
     private boolean useJaxbContextForQnames = true;
@@ -123,7 +125,9 @@ public class WadlGenerator implements Re
     private Map<String, List<String>> externalQnamesMap; 
     private ElementQNameResolver resolver;
     private List<String> privateAddresses;
-    
+    private String applicationTitle;
+    private String nsPrefix = DEFAULT_NS_PREFIX;
+
     public WadlGenerator() {
         
     }
@@ -191,6 +195,7 @@ public class WadlGenerator implements Re
         
         sbGrammars.append("</grammars>");
         sbMain.append(">");
+        handleApplicationDocs(sbMain);
         sbMain.append(sbGrammars.toString());
         sbMain.append(sbResources.toString());
         sbMain.append("</application>");
@@ -256,7 +261,7 @@ public class WadlGenerator implements Re
     }
     
     private void startResourceTag(StringBuilder sb, Class<?> serviceClass, String path)
{
-        sb.append("<resource path=\"").append(path).append("\"");
+        sb.append("<resource path=\"").append(getPath(path)).append("\"");
         if (addResourceAndMethodIds) {
             QName jaxbQname = null;
             if (useJaxbContextForQnames) {
@@ -271,6 +276,14 @@ public class WadlGenerator implements Re
         sb.append(">");
     }
     
+    private String getPath(String path) {
+        if (ignoreForwardSlash && path.startsWith("/") && path.length() >
0) {
+            return path.substring(1);
+        } else {
+            return path;
+        }
+    }
+    
     private void startMethodTag(StringBuilder sb, OperationResourceInfo ori) {
         sb.append("<method name=\"").append(ori.getHttpMethod()).append("\"");
         if (addResourceAndMethodIds) {
@@ -300,7 +313,7 @@ public class WadlGenerator implements Re
                     path = path.substring(1); 
                 }
             }
-            sb.append("<resource path=\"").append(path).append("\">");
+            sb.append("<resource path=\"").append(getPath(path)).append("\">");
             handlePathAndMatrixParams(sb, ori);
         } else if (index == 0) {
             handlePathAndMatrixParams(sb, ori);
@@ -673,7 +686,7 @@ public class WadlGenerator implements Re
         }    
         if (prefix == null) {
             int size = new HashSet<QName>(clsMap.values()).size();
-            prefix = "prefix" + (size + 1);
+            prefix = nsPrefix + (size + 1);
         }
         return prefix;
     }
@@ -796,6 +809,12 @@ public class WadlGenerator implements Re
         this.ignoreMessageWriters = ignoreMessageWriters;
     }
 
+    private void handleApplicationDocs(StringBuilder sbApp) {
+        if (applicationTitle != null) {
+            sbApp.append("<doc title=\"" + applicationTitle + "\"/>");
+        }
+    }
+    
     private void handleDocs(Annotation[] anns, StringBuilder sb) {
         for (Annotation a : anns) {
             if (a.annotationType() == Description.class) {
@@ -1142,6 +1161,18 @@ public class WadlGenerator implements Re
         return annMethod != null ? annMethod : ori.getMethodToInvoke();
     }
     
+    public void setApplicationTitle(String applicationTitle) {
+        this.applicationTitle = applicationTitle;
+    }
+
+    public void setNamespacePrefix(String prefix) {
+        this.nsPrefix = prefix;
+    }
+
+    public void setIgnoreForwardSlash(boolean ignoreForwardSlash) {
+        this.ignoreForwardSlash = ignoreForwardSlash;
+    }
+
     private static class SchemaConverter extends DelegatingXMLStreamWriter {
         private static final String SCHEMA_LOCATION = "schemaLocation";
         private Map<String, String> locsMap;    

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1095674&r1=1095673&r2=1095674&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Thu Apr 21 12:21:25 2011
@@ -193,7 +193,8 @@ public class WadlGeneratorTest extends A
     @Test
     public void testSingleRootResource() throws Exception {
         WadlGenerator wg = new WadlGenerator();
-        
+        wg.setApplicationTitle("My Application");
+        wg.setNamespacePrefix("ns");
         ClassResourceInfo cri = 
             ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true,
true);
         Message m = mockMessage("http://localhost:8080/baz", "/bar", WadlGenerator.WADL_QUERY,
null);
@@ -201,10 +202,10 @@ public class WadlGeneratorTest extends A
         Response r = wg.handleRequest(m, cri);
         checkResponse(r);
         Document doc = DOMUtils.readXml(new StringReader(r.getEntity().toString()));
+        checkDocs(doc.getDocumentElement(), "My Application", "", "");
         checkGrammars(doc.getDocumentElement(), "thebook", "thebook2", "thechapter");
         List<Element> els = getWadlResourcesInfo(doc, "http://localhost:8080/baz",
1);
-        checkBookStoreInfo(els.get(0), "prefix1:thebook", "prefix1:thebook2", "prefix1:thechapter");
-        
+        checkBookStoreInfo(els.get(0), "ns1:thebook", "ns1:thebook2", "ns1:thechapter");
     }
     
     @Test
@@ -263,6 +264,16 @@ public class WadlGeneratorTest extends A
         assertEquals("/orders", orderResource.getAttribute("path"));
     }
 
+    private void checkDocs(Element el, String title, String value, String language) {
+        List<Element> docsEls = DOMUtils.getChildrenWithName(el, 
+                                                             WadlGenerator.WADL_NS, "doc");
+        assertEquals(1, docsEls.size());
+        assertEquals(title, docsEls.get(0).getAttribute("title"));
+        assertEquals(value, docsEls.get(0).getTextContent());
+        assertEquals(language, 
+            docsEls.get(0).getAttributeNS("http://www.w3.org/XML/1998/namespace", "lang"));
+    }
+    
     private void checkGrammars(Element appElement, String bookEl, String book2El, String
chapterEl) {
         List<Element> grammarEls = DOMUtils.getChildrenWithName(appElement, WadlGenerator.WADL_NS,

                                                                 "grammars");



Mime
View raw message