langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/LayoutParser.java
changeset 868 d0f233085cbb
parent 10 06bc494ca11e
child 1264 076a3cde30d5
equal deleted inserted replaced
867:1dff24b5f407 868:d0f233085cbb
    43 public class LayoutParser extends DefaultHandler {
    43 public class LayoutParser extends DefaultHandler {
    44 
    44 
    45     /**
    45     /**
    46      * The map of XML elements that have been parsed.
    46      * The map of XML elements that have been parsed.
    47      */
    47      */
    48     private Map xmlElementsMap;
    48     private Map<String,List<Object>> xmlElementsMap;
    49 
    49 
    50     private Configuration configuration;
    50     private Configuration configuration;
    51     private static LayoutParser instance;
    51     private static LayoutParser instance;
    52     private String currentRoot;
    52     private String currentRoot;
    53     private boolean isParsing;
    53     private boolean isParsing;
    54 
    54 
    55     /**
    55     /**
    56      * This class is a singleton.
    56      * This class is a singleton.
    57      */
    57      */
    58     private LayoutParser(Configuration configuration) {
    58     private LayoutParser(Configuration configuration) {
    59         xmlElementsMap = new HashMap();
    59         xmlElementsMap = new HashMap<String,List<Object>>();
    60         this.configuration = configuration;
    60         this.configuration = configuration;
    61     }
    61     }
    62 
    62 
    63     /**
    63     /**
    64      * Return an instance of the BuilderXML.
    64      * Return an instance of the BuilderXML.
    81     public List parseXML(String root) {
    81     public List parseXML(String root) {
    82         if (xmlElementsMap.containsKey(root)) {
    82         if (xmlElementsMap.containsKey(root)) {
    83             return (List) xmlElementsMap.get(root);
    83             return (List) xmlElementsMap.get(root);
    84         }
    84         }
    85         try {
    85         try {
    86             List xmlElements = new ArrayList();
    86             List<Object> xmlElements = new ArrayList<Object>();
    87             xmlElementsMap.put(root, xmlElements);
    87             xmlElementsMap.put(root, xmlElements);
    88             currentRoot = root;
    88             currentRoot = root;
    89             isParsing = false;
    89             isParsing = false;
    90             SAXParserFactory factory = SAXParserFactory.newInstance();
    90             SAXParserFactory factory = SAXParserFactory.newInstance();
    91             SAXParser saxParser = factory.newSAXParser();
    91             SAXParser saxParser = factory.newSAXParser();
   104     public void startElement(String namespaceURI, String sName, String qName,
   104     public void startElement(String namespaceURI, String sName, String qName,
   105         Attributes attrs)
   105         Attributes attrs)
   106     throws SAXException {
   106     throws SAXException {
   107         if (isParsing || qName.equals(currentRoot)) {
   107         if (isParsing || qName.equals(currentRoot)) {
   108             isParsing = true;
   108             isParsing = true;
   109             List xmlElements = (List) xmlElementsMap.get(currentRoot);
   109             List<Object> xmlElements = xmlElementsMap.get(currentRoot);
   110             xmlElements.add(qName);
   110             xmlElements.add(qName);
   111         }
   111         }
   112     }
   112     }
   113 
   113 
   114     /**
   114     /**
   118     throws SAXException {
   118     throws SAXException {
   119         if (! isParsing) {
   119         if (! isParsing) {
   120             isParsing = false;
   120             isParsing = false;
   121             return;
   121             return;
   122         }
   122         }
   123         List xmlElements = (List) xmlElementsMap.get(currentRoot);
   123         List<Object> xmlElements = xmlElementsMap.get(currentRoot);
   124         if (xmlElements.get(xmlElements.size()-1).equals(qName)) {
   124         if (xmlElements.get(xmlElements.size()-1).equals(qName)) {
   125             return;
   125             return;
   126         } else {
   126         } else {
   127             List subElements = new ArrayList();
   127             List<Object> subElements = new ArrayList<Object>();
   128             int targetIndex = xmlElements.indexOf(qName);
   128             int targetIndex = xmlElements.indexOf(qName);
   129             int size = xmlElements.size();
   129             int size = xmlElements.size();
   130             for (int i = targetIndex; i < size; i++) {
   130             for (int i = targetIndex; i < size; i++) {
   131                 subElements.add(xmlElements.get(targetIndex));
   131                 subElements.add(xmlElements.get(targetIndex));
   132                 xmlElements.remove(targetIndex);
   132                 xmlElements.remove(targetIndex);