Exemplo n.º 1
0
 private void printInput() {
   MethodParameter inputParameter = method.getInputParameter();
   if (inputParameter == null) return;
   open("dt");
   around("b", "Input:");
   close("dt");
   if (inputParameter.isWrapped()) {
     open("dd");
     String typeName = inputParameter.getWrappedType();
     JaxType returnType = null;
     try {
       returnType = Utils.parseType(typeName, method.getJavaDoc().containingClass(), doclet);
     } catch (InvalidJaxTypeException e) {
       doclet.warn("Invalid @returnWrapped type: " + typeName);
       e.printStackTrace();
     }
     if (returnType != null) printOutputType(returnType);
     else around("tt", escape(typeName));
   } else {
     open("dd");
     Type returnType = inputParameter.getType();
     printOutputType(returnType);
   }
   String doc = inputParameter.getDoc();
   if (!Utils.isEmptyOrNull(doc)) {
     print(" - ");
     print(doc);
   }
   close("dd");
 }
Exemplo n.º 2
0
  private void printHTTPExample(String httpMethod) {
    around("b", "HTTP Example:");
    open("pre");
    String absPath = Utils.getAbsolutePath(this, resource);

    print(httpMethod + " " + absPath);
    Map<String, MethodParameter> matrixParameters = method.getMatrixParameters();
    if (!matrixParameters.isEmpty()) {
      for (String name : matrixParameters.keySet()) {
        print(";");
        print(name);
        print("=…");
      }
    }
    Map<String, MethodParameter> queryParameters = method.getQueryParameters();
    if (!queryParameters.isEmpty()) {
      print("?");
      boolean first = true;
      for (String name : queryParameters.keySet()) {
        if (!first) print("&amp;");
        print(name);
        print("=…");
        first = false;
      }
    }
    print("\n");

    Map<String, MethodParameter> headerParameters = method.getHeaderParameters();
    if (!headerParameters.isEmpty()) {
      for (String name : headerParameters.keySet()) {
        print(name);
        print(": …\n");
      }
    }
    Map<String, MethodParameter> cookieParameters = method.getCookieParameters();
    if (!cookieParameters.isEmpty()) {
      for (String name : cookieParameters.keySet()) {
        print("Cookie: ");
        print(name);
        print("=…\n");
      }
    }

    Map<String, MethodParameter> formParameters = method.getFormParameters();
    if (!formParameters.isEmpty()) {
      print("\n");
      boolean first = true;
      for (String name : formParameters.keySet()) {
        if (!first) print("&amp;");
        print(name);
        print("=…");
        first = false;
      }
    }
    print("\n");
    close("pre");
  }
Exemplo n.º 3
0
 private void printAPIExample() {
   around("b", "API Example:");
   /*
    * We are using tt instead of pre to avoid whitespace issues in the doc's
    * first sentence tags that would show up in a pre and would not in a tt.
    * This is annoying.
    */
   open("p");
   open("tt");
   print(method.getAPIFunctionName());
   print("({");
   boolean hasOne = printAPIParameters(method.getMatrixParameters(), false);
   hasOne |= printAPIParameters(method.getQueryParameters(), hasOne);
   hasOne |= printAPIParameters(method.getPathParameters(), hasOne);
   hasOne |= printAPIParameters(method.getHeaderParameters(), hasOne);
   hasOne |= printAPIParameters(method.getCookieParameters(), hasOne);
   hasOne |= printAPIParameters(method.getFormParameters(), hasOne);
   MethodParameter input = method.getInputParameter();
   if (input != null) {
     printAPIParameter("$entity", input, hasOne);
   }
   print("});");
   close("tt");
   close("p");
 }
Exemplo n.º 4
0
 /*
  * Path won't be to jaxb class private void printSees() { MethodDoc javaDoc =
  * method.getJavaDoc(); TagletOutputImpl output = new TagletOutputImpl("");
  * Set<String> tagletsSet = new HashSet<String>(); tagletsSet.add("see");
  * Utils.genTagOuput(configuration.tagletManager, javaDoc,
  * configuration.tagletManager.getCustomTags(javaDoc), writer
  * .getTagletWriterInstance(false), output, tagletsSet);
  * writer.print(output.toString()); }
  */
 private void printTaglets(String tagletName) {
   MethodDoc javaDoc = method.getJavaDoc();
   TagletOutputImpl output = new TagletOutputImpl("");
   Set<String> tagletsSet = new HashSet<String>();
   tagletsSet.add(tagletName);
   Utils.genTagOuput(
       configuration.parentConfiguration.tagletManager,
       javaDoc,
       configuration.parentConfiguration.tagletManager.getCustomTags(javaDoc),
       writer.getTagletWriterInstance(false),
       output,
       tagletsSet);
   writer.print(output.toString());
 }
Exemplo n.º 5
0
  private void printOutput() {
    open("dt");
    around("b", "Output:");
    close("dt");

    MethodOutput output = method.getOutput();

    if (output.isOutputWrapped()) {
      for (int i = 0; i < output.getOutputWrappedCount(); i++) {
        open("dd");
        String typeName = output.getWrappedOutputType(i);
        JaxType returnType = null;
        try {
          returnType = Utils.parseType(typeName, method.getJavaDoc().containingClass(), doclet);
        } catch (InvalidJaxTypeException e) {
          doclet.warn("Invalid @returnWrapped type: " + typeName);
          e.printStackTrace();
        }
        if (returnType != null) printOutputType(returnType);
        else around("tt", escape(typeName));
        if (output.getOutputDoc(i) != null) {
          print(" - ");
          print(output.getOutputDoc(i));
        }
        close("dd");
      }
    } else {
      open("dd");
      Type returnType = output.getOutputType();
      printOutputType(returnType);
      if (output.getOutputDoc() != null) {
        print(" - ");
        print(output.getOutputDoc());
      }
      close("dd");
    }
  }
Exemplo n.º 6
0
 private void printMethod(String httpMethod) {
   around("a name='" + httpMethod + "'", "");
   if (getJAXRSConfiguration().enableHTTPExample
       || getJAXRSConfiguration().enableJavaScriptExample) {
     open("table class='examples'", "tr");
     if (getJAXRSConfiguration().enableHTTPExample) {
       open("td");
       printHTTPExample(httpMethod);
       close("td");
     }
     if (getJAXRSConfiguration().enableJavaScriptExample) {
       open("td");
       printAPIExample();
       close("td");
     }
     close("tr", "table");
   }
   if (!Utils.isEmptyOrNull(method.getDoc())) {
     open("p");
     print(method.getDoc());
     close("p");
   }
   printIncludes();
   open("dl");
   printInput();
   printOutput();
   printParameters(method.getQueryParameters(), "Query");
   // done on resource
   // printParameters(method.getPathParameters(), "Path");
   printParameters(method.getMatrixParameters(), "Matrix");
   printParameters(method.getFormParameters(), "Form");
   printParameters(method.getCookieParameters(), "Cookie");
   printParameters(method.getHeaderParameters(), "Header");
   printMIMEs(method.getProduces(), "Produces");
   printMIMEs(method.getConsumes(), "Consumes");
   printHTTPCodes();
   printHTTPRequestHeaders();
   printHTTPResponseHeaders();
   // printSees();
   close("dl");
 }
Exemplo n.º 7
0
 private void printIncludes() {
   MethodDoc javaDoc = method.getJavaDoc();
   Tag[] includes = Utils.getTags(javaDoc, "include");
   if (includes == null) return;
   File relativeTo = javaDoc.containingClass().position().file().getParentFile();
   for (Tag include : includes) {
     String fileName = include.text();
     File file = new File(relativeTo, fileName);
     if (!file.exists()) {
       doclet.printError(include.position(), "Missing included file: " + fileName);
       continue;
     }
     String text = Utils.readResource(file);
     print(text);
   }
 }
Exemplo n.º 8
0
 public void print() {
   for (String httpMethod : method.getMethods()) {
     printMethod(httpMethod);
   }
 }
Exemplo n.º 9
0
 public static String getDisplayURL(
     DocletWriter writer, Resource resource, ResourceMethod method) {
   return addContextPath(writer.getConfiguration(), method.getURL(resource));
 }