| <!-- |
| /*************************************************************************************************************************** |
| * 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. |
| ***************************************************************************************************************************/ |
| --> |
| |
| HTML-Schema Support |
| |
| <p> |
| The {@link oaj.html.HtmlSchemaSerializer} class is the HTML-equivalent to the |
| {@link oaj.json.JsonSchemaSerializer} class. |
| It's used to generate HTML versions of JSON-Schema documents that describe the output generated by the |
| {@link oaj.json.JsonSerializer} class. |
| </p> |
| <h5 class='figure'>Sample Beans</h5> |
| <p class='bpcode w800'> |
| <jk>public class</jk> Person { |
| |
| <jc>// Bean properties</jc> |
| <jk>public</jk> String <jf>name</jf>; |
| <jk>public</jk> Calendar <jf>birthDate</jf>; |
| <jk>public</jk> List<Address> <jf>addresses</jf>; |
| |
| <jc>// Getters/setters omitted</jc> |
| } |
| |
| <jk>public class</jk> Address { |
| |
| <jc>// Bean properties</jc> |
| <jk>public</jk> String <jf>street</jf>, <jf>city</jf>; |
| <jk>public</jk> StateEnum <jf>state</jf>; |
| <jk>public int</jk> <jf>zip</jf>; |
| <jk>public boolean</jk> <jf>isCurrent</jf>; |
| |
| <jc>// Getters/setters omitted</jc> |
| } |
| </p> |
| <p> |
| The code for creating our POJO model and generating HTML-Schema is shown below: |
| </p> |
| <p class='bpcode w800'> |
| <jc>// Get the one of the default schema serializers.</jc> |
| HtmlSchemaSerializer s = HtmlSchemaSerializer.<jsf>DEFAULT_SIMPLE_READABLE</jsf>; |
| |
| <jc>// Get the HTML Schema for the POJO.</jc> |
| String htmlSchema = s.serialize(<jk>new</jk> Person()); |
| |
| <jc>// This also works.</jc> |
| htmlSchema = s.serialize(Person.<jk>class</jk>); |
| </p> |
| <p> |
| The result is the HTML table shown below: |
| </p> |
| <table class='bordered unstyled w800'> |
| <tr> |
| <td>type</td> |
| <td>object</td> |
| </tr> |
| <tr> |
| <td>properties</td> |
| <td> |
| <table> |
| <tr> |
| <td>name</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>string</td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td>birthDate</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>string</td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td>addresses</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>array</td> |
| </tr> |
| <tr> |
| <td>items</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>object</td> |
| </tr> |
| <tr> |
| <td>properties</td> |
| <td> |
| <table> |
| <tr> |
| <td>street</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>string</td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td>city</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>string</td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td>state</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>string</td> |
| </tr> |
| <tr> |
| <td>enum</td> |
| <td> |
| <ul> |
| <li>AL</li> |
| <li>PA</li> |
| <li>NC</li> |
| </ul> |
| </td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td>zip</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>integer</td> |
| </tr> |
| <tr> |
| <td>format</td> |
| <td>int32</td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td>isCurrent</td> |
| <td> |
| <table> |
| <tr> |
| <td>type</td> |
| <td>boolean</td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| </table> |