1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.util.xml;
16  
17  import com.liferay.util.xml.descriptor.PortletAppDescriptor;
18  import com.liferay.util.xml.descriptor.StrictXMLDescriptor;
19  import com.liferay.util.xml.descriptor.StrutsConfigDescriptor;
20  import com.liferay.util.xml.descriptor.TilesDefsDescriptor;
21  import com.liferay.util.xml.descriptor.WebXML23Descriptor;
22  import com.liferay.util.xml.descriptor.WebXML24Descriptor;
23  import com.liferay.util.xml.descriptor.XMLDescriptor;
24  
25  import org.dom4j.Document;
26  
27  /**
28   * <a href="XMLTypeDetector.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Jorge Ferrer
31   */
32  public class XMLTypeDetector {
33  
34      public static final XMLDescriptor[] REGISTERED_DESCRIPTORS = {
35          new PortletAppDescriptor(), new StrutsConfigDescriptor(),
36          new TilesDefsDescriptor(), new WebXML23Descriptor(),
37          new WebXML24Descriptor()
38      };
39  
40      public static XMLDescriptor determineType(String doctype, Document root) {
41          for (int i = 0; i < REGISTERED_DESCRIPTORS.length; i++) {
42              XMLDescriptor descriptor = REGISTERED_DESCRIPTORS[i];
43  
44              if (descriptor.canHandleType(doctype, root)) {
45                  return descriptor;
46              }
47          }
48  
49          return new StrictXMLDescriptor();
50      }
51  
52  }