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