cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1095666 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Date Thu, 21 Apr 2011 11:49:57 GMT
Author: sergeyb
Date: Thu Apr 21 11:49:56 2011
New Revision: 1095666

URL: http://svn.apache.org/viewvc?rev=1095666&view=rev
Log:
[CXF-3468] Updating WADLGenerator with properties for setting the app title/etc

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1095666&r1=1095665&r2=1095666&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Thu Apr 21 11:49:56 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) {
@@ -302,7 +315,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("\">");
             handleDocs(anns, sb, DocTarget.RESOURCE, false);
             handlePathAndMatrixParams(sb, ori);
         } else if (index == 0) {
@@ -718,7 +731,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;
     }
@@ -840,6 +853,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, String category, boolean
allowDefault) {
         for (Annotation a : anns) {
             if (a.annotationType() == Descriptions.class) {
@@ -1196,6 +1215,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/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1095666&r1=1095665&r2=1095666&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Thu Apr 21 11:49:56 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



Mime
View raw message