Wed, 01 Dec 2010 11:02:38 -0800
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg
jjg@589 | 1 | /* |
jjg@589 | 2 | * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@589 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@589 | 4 | * |
jjg@589 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@589 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@589 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@589 | 8 | * particular file as subject to the "Classpath" exception as provided |
jjg@589 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@589 | 10 | * |
jjg@589 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@589 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@589 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@589 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@589 | 15 | * accompanied this code). |
jjg@589 | 16 | * |
jjg@589 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@589 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@589 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@589 | 20 | * |
jjg@589 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@589 | 22 | * or visit www.oracle.com if you need additional information or have any |
jjg@589 | 23 | * questions. |
jjg@589 | 24 | */ |
jjg@589 | 25 | |
jjg@589 | 26 | package com.sun.tools.doclets.internal.toolkit.builders; |
jjg@589 | 27 | |
jjg@589 | 28 | import java.util.ArrayList; |
jjg@589 | 29 | import java.util.HashMap; |
jjg@589 | 30 | import java.util.List; |
jjg@589 | 31 | import java.util.Map; |
jjg@589 | 32 | |
jjg@589 | 33 | /** |
jjg@589 | 34 | * Simple class to represent the attribute and elements of an XML node. |
jjg@589 | 35 | */ |
jjg@589 | 36 | public class XMLNode { |
jjg@589 | 37 | XMLNode(XMLNode parent, String qname) { |
jjg@589 | 38 | this.parent = parent; |
jjg@589 | 39 | name = qname; |
jjg@589 | 40 | attrs = new HashMap<String,String>(); |
jjg@589 | 41 | children = new ArrayList<XMLNode>(); |
jjg@589 | 42 | |
jjg@589 | 43 | if (parent != null) |
jjg@589 | 44 | parent.children.add(this); |
jjg@589 | 45 | } |
jjg@589 | 46 | |
jjg@589 | 47 | @Override |
jjg@589 | 48 | public String toString() { |
jjg@589 | 49 | StringBuilder sb = new StringBuilder(); |
jjg@589 | 50 | sb.append("<"); |
jjg@589 | 51 | sb.append(name); |
jjg@589 | 52 | for (Map.Entry<String,String> e: attrs.entrySet()) |
jjg@589 | 53 | sb.append(" " + e.getKey() + "=\"" + e.getValue() + "\""); |
jjg@589 | 54 | if (children.size() == 0) |
jjg@589 | 55 | sb.append("/>"); |
jjg@589 | 56 | else { |
jjg@589 | 57 | sb.append(">"); |
jjg@589 | 58 | for (XMLNode c: children) |
jjg@589 | 59 | sb.append(c.toString()); |
jjg@589 | 60 | sb.append("</" + name + ">"); |
jjg@589 | 61 | } |
jjg@589 | 62 | return sb.toString(); |
jjg@589 | 63 | } |
jjg@589 | 64 | |
jjg@589 | 65 | final XMLNode parent; |
jjg@589 | 66 | final String name; |
jjg@589 | 67 | final Map<String,String> attrs; |
jjg@589 | 68 | final List<XMLNode> children; |
jjg@589 | 69 | } |