Wed, 10 Oct 2012 16:48:21 -0700
8000665: fix "internal API" comments on javadoc files
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.tools.doclets.internal.toolkit.builders;
27 import java.io.*;
28 import java.util.*;
30 import javax.xml.parsers.*;
32 import org.xml.sax.*;
33 import org.xml.sax.helpers.DefaultHandler;
35 import com.sun.tools.doclets.internal.toolkit.*;
36 import com.sun.tools.doclets.internal.toolkit.util.*;
38 /**
39 * Parse the XML that specified the order of operation for the builders. This
40 * Parser uses SAX parsing.
41 *
42 * <p><b>This is NOT part of any supported API.
43 * If you write code that depends on this, you do so at your own risk.
44 * This code and its internal interfaces are subject to change or
45 * deletion without notice.</b>
46 *
47 * @author Jamie Ho
48 * @since 1.5
49 * @see SAXParser
50 */
51 public class LayoutParser extends DefaultHandler {
53 /**
54 * The map of XML elements that have been parsed.
55 */
56 private Map<String,XMLNode> xmlElementsMap;
57 private XMLNode currentNode;
58 private Configuration configuration;
59 private static LayoutParser instance;
60 private String currentRoot;
61 private boolean isParsing;
63 /**
64 * This class is a singleton.
65 */
66 private LayoutParser(Configuration configuration) {
67 xmlElementsMap = new HashMap<String,XMLNode>();
68 this.configuration = configuration;
69 }
71 /**
72 * Return an instance of the BuilderXML.
73 *
74 * @param configuration the current configuration of the doclet.
75 * @return an instance of the BuilderXML.
76 */
77 public static LayoutParser getInstance(Configuration configuration) {
78 if (instance == null) {
79 instance = new LayoutParser(configuration);
80 }
81 return instance;
82 }
84 /**
85 * Parse the XML specifying the layout of the documentation.
86 *
87 * @return the list of XML elements parsed.
88 */
89 public XMLNode parseXML(String root) {
90 if (xmlElementsMap.containsKey(root)) {
91 return xmlElementsMap.get(root);
92 }
93 try {
94 currentRoot = root;
95 isParsing = false;
96 SAXParserFactory factory = SAXParserFactory.newInstance();
97 SAXParser saxParser = factory.newSAXParser();
98 InputStream in = configuration.getBuilderXML();
99 saxParser.parse(in, this);
100 return xmlElementsMap.get(root);
101 } catch (Throwable t) {
102 t.printStackTrace();
103 throw new DocletAbortException();
104 }
105 }
107 /**
108 * {@inheritDoc}
109 */
110 @Override
111 public void startElement(String namespaceURI, String sName, String qName,
112 Attributes attrs)
113 throws SAXException {
114 if (isParsing || qName.equals(currentRoot)) {
115 isParsing = true;
116 currentNode = new XMLNode(currentNode, qName);
117 for (int i = 0; i < attrs.getLength(); i++)
118 currentNode.attrs.put(attrs.getLocalName(i), attrs.getValue(i));
119 if (qName.equals(currentRoot))
120 xmlElementsMap.put(qName, currentNode);
121 }
122 }
124 /**
125 * {@inheritDoc}
126 */
127 @Override
128 public void endElement(String namespaceURI, String sName, String qName)
129 throws SAXException {
130 if (! isParsing) {
131 return;
132 }
133 currentNode = currentNode.parent;
134 isParsing = ! qName.equals(currentRoot);
135 }
136 }