View Javadoc
1   package org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Map;
23  
24  /**
25   * <p>Default JavaDocRenderer implementation which provides a plain JavaDocData rendering, on the form:</p>
26   * <pre>
27   *     [JavaDoc comment]
28   *     (tag1): [tag1 value]
29   *     (tag2): [tag2 value]
30   * </pre>
31   *
32   * @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>, jGuru Europe AB
33   * @since 2.0
34   */
35  public class DefaultJavaDocRenderer implements JavaDocRenderer {
36  
37      /**
38       * {@inheritDoc}
39       */
40      @Override
41      public String render(final JavaDocData nonNullData, final SortableLocation location) {
42  
43          // Compile the XSD documentation string for this Node.
44          final StringBuilder builder = new StringBuilder();
45          builder.append(squashNewlines(nonNullData.getComment())).append("\n");
46          for (Map.Entry<String, String> current : nonNullData.getTag2ValueMap().entrySet()) {
47  
48              final String tagDocumentation = "(" + current.getKey().trim() + "): " + squashNewlines(current.getValue());
49              builder.append(tagDocumentation);
50          }
51  
52          // All done.
53          return builder.toString();
54      }
55  
56      //
57      // Private helpers
58      //
59  
60      private String squashNewlines(final String original) {
61          final String toReturn = original.trim().replaceAll("[\r\n]+", "\n");
62          return toReturn.endsWith("\n") ? toReturn : toReturn + "\n";
63      }
64  }