author | jjg |
Thu, 15 Nov 2012 09:18:36 -0800 | |
changeset 14542 | 7062120649c2 |
parent 14260 | 727a84636f12 |
child 19667 | fdfce85627a9 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
14258 | 2 |
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
package com.sun.tools.doclets.internal.toolkit.builders; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
14258 | 29 |
|
30 |
import javax.xml.parsers.*; |
|
31 |
||
10 | 32 |
import org.xml.sax.*; |
33 |
import org.xml.sax.helpers.DefaultHandler; |
|
14258 | 34 |
|
35 |
import com.sun.tools.doclets.internal.toolkit.*; |
|
36 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
|
10 | 37 |
|
38 |
/** |
|
39 |
* Parse the XML that specified the order of operation for the builders. This |
|
40 |
* Parser uses SAX parsing. |
|
41 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
42 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
43 |
* 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:
14258
diff
changeset
|
44 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
45 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
46 |
* |
10 | 47 |
* @author Jamie Ho |
48 |
* @since 1.5 |
|
49 |
* @see SAXParser |
|
50 |
*/ |
|
51 |
public class LayoutParser extends DefaultHandler { |
|
52 |
||
53 |
/** |
|
54 |
* The map of XML elements that have been parsed. |
|
55 |
*/ |
|
5855 | 56 |
private Map<String,XMLNode> xmlElementsMap; |
57 |
private XMLNode currentNode; |
|
14542 | 58 |
private final Configuration configuration; |
10 | 59 |
private String currentRoot; |
60 |
private boolean isParsing; |
|
61 |
||
62 |
private LayoutParser(Configuration configuration) { |
|
5855 | 63 |
xmlElementsMap = new HashMap<String,XMLNode>(); |
10 | 64 |
this.configuration = configuration; |
65 |
} |
|
66 |
||
67 |
/** |
|
68 |
* Return an instance of the BuilderXML. |
|
69 |
* |
|
70 |
* @param configuration the current configuration of the doclet. |
|
71 |
* @return an instance of the BuilderXML. |
|
72 |
*/ |
|
73 |
public static LayoutParser getInstance(Configuration configuration) { |
|
14542 | 74 |
return new LayoutParser(configuration); |
10 | 75 |
} |
76 |
||
77 |
/** |
|
78 |
* Parse the XML specifying the layout of the documentation. |
|
79 |
* |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5855
diff
changeset
|
80 |
* @return the list of XML elements parsed. |
10 | 81 |
*/ |
5855 | 82 |
public XMLNode parseXML(String root) { |
10 | 83 |
if (xmlElementsMap.containsKey(root)) { |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1264
diff
changeset
|
84 |
return xmlElementsMap.get(root); |
10 | 85 |
} |
86 |
try { |
|
87 |
currentRoot = root; |
|
88 |
isParsing = false; |
|
89 |
SAXParserFactory factory = SAXParserFactory.newInstance(); |
|
90 |
SAXParser saxParser = factory.newSAXParser(); |
|
91 |
InputStream in = configuration.getBuilderXML(); |
|
92 |
saxParser.parse(in, this); |
|
5855 | 93 |
return xmlElementsMap.get(root); |
10 | 94 |
} catch (Throwable t) { |
95 |
t.printStackTrace(); |
|
96 |
throw new DocletAbortException(); |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
/** |
|
101 |
* {@inheritDoc} |
|
102 |
*/ |
|
5855 | 103 |
@Override |
10 | 104 |
public void startElement(String namespaceURI, String sName, String qName, |
105 |
Attributes attrs) |
|
106 |
throws SAXException { |
|
107 |
if (isParsing || qName.equals(currentRoot)) { |
|
108 |
isParsing = true; |
|
5855 | 109 |
currentNode = new XMLNode(currentNode, qName); |
110 |
for (int i = 0; i < attrs.getLength(); i++) |
|
111 |
currentNode.attrs.put(attrs.getLocalName(i), attrs.getValue(i)); |
|
112 |
if (qName.equals(currentRoot)) |
|
113 |
xmlElementsMap.put(qName, currentNode); |
|
10 | 114 |
} |
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* {@inheritDoc} |
|
119 |
*/ |
|
5855 | 120 |
@Override |
10 | 121 |
public void endElement(String namespaceURI, String sName, String qName) |
122 |
throws SAXException { |
|
123 |
if (! isParsing) { |
|
124 |
return; |
|
125 |
} |
|
5855 | 126 |
currentNode = currentNode.parent; |
10 | 127 |
isParsing = ! qName.equals(currentRoot); |
128 |
} |
|
129 |
} |