langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/XMLNode.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 14260 727a84636f12
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5855
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     1
/*
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5855
diff changeset
     2
 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
5855
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     4
 *
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    10
 *
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    15
 * accompanied this code).
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    16
 *
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    20
 *
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    23
 * questions.
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    24
 */
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    25
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    26
package com.sun.tools.doclets.internal.toolkit.builders;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    27
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    28
import java.util.ArrayList;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    29
import java.util.HashMap;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    30
import java.util.List;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    31
import java.util.Map;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    32
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    33
/**
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    34
 * Simple class to represent the attribute and elements of an XML node.
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5855
diff changeset
    35
 *
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5855
diff changeset
    36
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5855
diff changeset
    37
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5855
diff changeset
    38
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5855
diff changeset
    39
 *  deletion without notice.</b>
5855
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    40
 */
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    41
public class XMLNode {
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    42
    XMLNode(XMLNode parent, String qname) {
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    43
        this.parent = parent;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    44
        name = qname;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14260
diff changeset
    45
        attrs = new HashMap<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 14260
diff changeset
    46
        children = new ArrayList<>();
5855
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    47
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    48
        if (parent != null)
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    49
            parent.children.add(this);
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    50
    }
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    51
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    52
    @Override
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    53
    public String toString() {
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    54
        StringBuilder sb = new StringBuilder();
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    55
        sb.append("<");
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    56
        sb.append(name);
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    57
        for (Map.Entry<String,String> e: attrs.entrySet())
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    58
            sb.append(" " + e.getKey() + "=\"" + e.getValue() + "\"");
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    59
        if (children.size() == 0)
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    60
            sb.append("/>");
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    61
        else {
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    62
            sb.append(">");
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    63
            for (XMLNode c: children)
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    64
                sb.append(c.toString());
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    65
            sb.append("</" + name + ">");
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    66
        }
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    67
        return sb.toString();
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    68
    }
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    69
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    70
    final XMLNode parent;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    71
    final String name;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    72
    final Map<String,String> attrs;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    73
    final List<XMLNode> children;
00d9c252e60c 6961178: Allow doclet.xml to contain XML attributes
jjg
parents:
diff changeset
    74
}