1 /* |
1 /* |
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
28 import java.io.*; |
28 import java.io.*; |
29 import java.util.*; |
29 import java.util.*; |
30 |
30 |
31 import javax.xml.parsers.*; |
31 import javax.xml.parsers.*; |
32 |
32 |
33 import jdk.javadoc.internal.doclets.toolkit.Configuration; |
33 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; |
34 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
34 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
35 import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
35 import jdk.javadoc.internal.doclets.toolkit.util.SimpleDocletException; |
36 import org.xml.sax.*; |
36 import org.xml.sax.*; |
37 import org.xml.sax.helpers.DefaultHandler; |
37 import org.xml.sax.helpers.DefaultHandler; |
38 |
38 |
54 /** |
54 /** |
55 * The map of XML elements that have been parsed. |
55 * The map of XML elements that have been parsed. |
56 */ |
56 */ |
57 private final Map<String,XMLNode> xmlElementsMap; |
57 private final Map<String,XMLNode> xmlElementsMap; |
58 private XMLNode currentNode; |
58 private XMLNode currentNode; |
59 private final Configuration configuration; |
59 private final BaseConfiguration configuration; |
60 private String currentRoot; |
60 private String currentRoot; |
61 private boolean isParsing; |
61 private boolean isParsing; |
62 |
62 |
63 private LayoutParser(Configuration configuration) { |
63 private LayoutParser(BaseConfiguration configuration) { |
64 xmlElementsMap = new HashMap<>(); |
64 xmlElementsMap = new HashMap<>(); |
65 this.configuration = configuration; |
65 this.configuration = configuration; |
66 } |
66 } |
67 |
67 |
68 /** |
68 /** |
69 * Return an instance of the BuilderXML. |
69 * Return an instance of the BuilderXML. |
70 * |
70 * |
71 * @param configuration the current configuration of the doclet. |
71 * @param configuration the current configuration of the doclet. |
72 * @return an instance of the BuilderXML. |
72 * @return an instance of the BuilderXML. |
73 */ |
73 */ |
74 public static LayoutParser getInstance(Configuration configuration) { |
74 public static LayoutParser getInstance(BaseConfiguration configuration) { |
75 return new LayoutParser(configuration); |
75 return new LayoutParser(configuration); |
76 } |
76 } |
77 |
77 |
78 /** |
78 /** |
79 * Parse the XML specifying the layout of the documentation. |
79 * Parse the XML specifying the layout of the documentation. |
93 InputStream in = configuration.getBuilderXML(); |
93 InputStream in = configuration.getBuilderXML(); |
94 saxParser.parse(in, this); |
94 saxParser.parse(in, this); |
95 } catch (IOException | ParserConfigurationException | SAXException e) { |
95 } catch (IOException | ParserConfigurationException | SAXException e) { |
96 String message = (configuration.builderXMLPath == null) |
96 String message = (configuration.builderXMLPath == null) |
97 ? configuration.getResources().getText("doclet.exception.read.resource", |
97 ? configuration.getResources().getText("doclet.exception.read.resource", |
98 Configuration.DEFAULT_BUILDER_XML, e) |
98 BaseConfiguration.DEFAULT_BUILDER_XML, e) |
99 : configuration.getResources().getText("doclet.exception.read.file", |
99 : configuration.getResources().getText("doclet.exception.read.file", |
100 configuration.builderXMLPath, e); |
100 configuration.builderXMLPath, e); |
101 throw new SimpleDocletException(message, e); |
101 throw new SimpleDocletException(message, e); |
102 } |
102 } |
103 } |
103 } |