juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] Akayeshmantha closed pull request #38: adding dto samples to core samples
Date Sat, 15 Dec 2018 11:14:54 GMT
Akayeshmantha closed pull request #38: adding dto samples to core samples
URL: https://github.com/apache/juneau/pull/38
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/dto/DtoExample.java
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/dto/DtoExample.java
new file mode 100644
index 000000000..724f171ea
--- /dev/null
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/dto/DtoExample.java
@@ -0,0 +1,192 @@
+package org.apache.juneau.examples.core.dto;
+
+import org.apache.juneau.dto.atom.Feed;
+import org.apache.juneau.dto.atom.Person;
+import org.apache.juneau.dto.swagger.Swagger;
+import org.apache.juneau.html.HtmlSerializer;
+import org.apache.juneau.http.MediaType;
+import org.apache.juneau.json.JsonSerializer;
+import org.apache.juneau.xml.XmlSerializer;
+
+import static org.apache.juneau.dto.atom.AtomBuilder.*;
+import static org.apache.juneau.dto.html5.HtmlBuilder.*;
+import static org.apache.juneau.dto.swagger.SwaggerBuilder.*;
+
+public class DtoExample {
+
+    public static void main(String[] args) throws Exception {
+
+        //Produces
+        /**
+         * <table>
+         * <tr>
+         * <th>c1</th>
+         * <th>c2</th>
+         * </tr>
+         * <tr>
+         * <td>v1</td>
+         * <td>v2</td>
+         * </tr>
+         * </table>
+         */
+        Object mytable =
+                table(
+                        tr(
+                                th("c1"),
+                                th("c2")
+                        ),
+                        tr(
+                                td("v1"),
+                                td("v2")
+                        )
+                );
+
+        String html = HtmlSerializer.DEFAULT.serialize(mytable);
+
+        Object mainJsp =
+                form().action("main.jsp").method("GET")
+                        .children(
+                                input("text").name("first_name").value("apache"), br(),
+                                input("text").name("last_name").value("juneau"), br(),
+                                button("submit", "Submit"),
+                                button("reset", "Reset")
+                        );
+
+        /**
+         * <form action='main.jsp' method='POST'>
+         * Position (1-10000): <input name='pos' type='number'
+         * value='1'/><br/>
+         * Limit (1-10000): <input name='pos' type='number'
+         * value='100'/><br/>
+         * <button type='submit'>Submit</button>
+         * <button type='reset'>Reset</button>
+         * </form>
+         */
+        html = HtmlSerializer.DEFAULT.serialize(mainJsp);
+
+        /**
+         * Produces
+         * {
+         *    a:{action:'main.jsp',method:'GET'},
+         *    c:[
+         *    {a:{type:'text',name:'first_name',value:'apache'}},{},
+         *    {a:{type:'text',name:'last_name',value:'juneau'}},{},
+         *    {a:{type:'submit'},c:['Submit']},
+         *    {a:{type:'reset'},c:['Reset']}
+         *    ]
+         * }
+         */
+        html =  JsonSerializer.create().simple().sq().build().serialize(mainJsp);
+
+        Feed feed =
+                feed("tag:juneau.apache.org", "Juneau ATOM specification", "2018-12-15T08:52:05Z")
+                        .title("Example apache Juneau feed")
+                        .subtitle(text("html").text("Describes <em>stuff</em>
about Juneau"))
+                        .links(
+                                link("alternate", "text/html", "http://juneau.apache.org/").hreflang("en"),
+                                link("self", "application/atom+xml", "http://juneau.apache.org/feed.atom")
+                        )
+                        .rights("Copyright (c) 2016, Apache Foundation")
+                        .authors(new Person("Juneau_Commiter"))
+                        .updated("2018-12-15T08:52:05Z")
+                        .entries(
+                                entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification
snapshot", "2016-01-02T03:04:05Z")
+                                        .published("2016-01-02T03:04:05Z")
+                                        .content(
+                                                content("xhtml")
+                                                        .lang("en")
+                                                        .base("http://www.apache.org/")
+                                                        .text("<div><p><i>[Update:
Juneau supports ATOM.]</i></p></div>")
+                                        )
+                        );
+
+        // Serialize to ATOM/XML
+        String atomXml = XmlSerializer.DEFAULT.serialize(feed);
+
+
+        Swagger swagger = swagger()
+                .swagger("2.0")
+                .info(
+                        info("Swagger Petstore", "1.0.0")
+                                .description("This is a sample server Petstore server.")
+                                .termsOfService("http://swagger.io/terms/")
+                                .contact(
+                                        contact().email("apiteam@swagger.io")
+                                )
+                                .license(
+                                        license("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")
+                                )
+                )
+                .path("/pet", "post",
+                        operation()
+                                .tags("pet")
+                                .summary("Add a new pet to the store")
+                                .description("")
+                                .operationId("addPet")
+                                .consumes(MediaType.JSON, MediaType.XML)
+                                .produces(MediaType.JSON, MediaType.XML)
+                                .parameters(
+                                        parameterInfo("body", "body")
+                                                .description("Pet object that needs to be
added to the store")
+                                                .required(true)
+                                )
+                                .response("405", responseInfo("Invalid input"))
+                );
+
+        // Serialize to Swagger/JSON
+        /**
+         * Produces
+         * {
+         *  "swagger": "2.0",
+         *  "info": {
+         *      "title": "Swagger Petstore",
+         *      "description": "This is a sample server Petstore server.",
+         *      "version": "1.0.0",
+         *      "termsOfService": "http://swagger.io/terms/",
+         *      "contact": {
+         *          "email": "apiteam@swagger.io"
+         *      },
+         *      "license": {
+         *          "name": "Apache 2.0",
+         *          "url": "http://www.apache.org/licenses/LICENSE-2.0.html"
+         *      }
+         *  },
+         * "paths": {
+         *      "/pet": {
+         *          "post": {
+         *              "tags": [
+         *                  "pet"
+         *               ],
+         *              "summary": "Add a new pet to the store",
+         *              "description": "",
+         *              "operationId": "addPet",
+         *              "consumes": [
+         *                  "application/json",
+         *                  "text/xml"
+         *              ],
+         *              "produces": [
+         *                  "application/json",
+         *                  "text/xml"
+         *              ],
+         *              "parameters": [
+         *                  {
+         *                      "in": "body",
+         *                      "name": "body",
+         *                      "description": "Pet object that needs to be added to the
store",
+         *                      "required": true
+         *                  }
+         *              ],
+         *              "responses": {
+         *                  "405": {
+         *                      "description": "Invalid input"
+         *                  }
+         *              }
+         *         }
+         *      }
+         *  },
+         *  }
+         */
+        String swaggerJson = JsonSerializer.DEFAULT_READABLE.serialize(swagger);
+
+    }
+}
\ No newline at end of file
diff --git a/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/dto/package-info.java
b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/dto/package-info.java
new file mode 100755
index 000000000..cb26e6c03
--- /dev/null
+++ b/juneau-examples/juneau-examples-core/src/main/java/org/apache/juneau/examples/core/dto/package-info.java
@@ -0,0 +1,18 @@
+// ***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.  See the NOTICE file *
+// * distributed with this work for additional information regarding copyright ownership.
 The ASF licenses this file        *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file
except in compliance            *
+// * with the License.  You may obtain a copy of the License at                         
                                    *
+// *                                                                                    
                                    *
+// *  http://www.apache.org/licenses/LICENSE-2.0                                        
                                    *
+// *                                                                                    
                                    *
+// * Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an  *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the        *
+// * specific language governing permissions and limitations under the License.         
                                    *
+// ***************************************************************************************************************************
+
+/**
+ * Examples
+ */
+package org.apache.juneau.examples.core.dto;
+


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message