001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util.xml;
016    
017    import com.liferay.util.xml.descriptor.PortletAppDescriptor;
018    import com.liferay.util.xml.descriptor.StrictXMLDescriptor;
019    import com.liferay.util.xml.descriptor.StrutsConfigDescriptor;
020    import com.liferay.util.xml.descriptor.TilesDefsDescriptor;
021    import com.liferay.util.xml.descriptor.WebXML23Descriptor;
022    import com.liferay.util.xml.descriptor.WebXML24Descriptor;
023    import com.liferay.util.xml.descriptor.XMLDescriptor;
024    
025    import org.dom4j.Document;
026    
027    /**
028     * @author Jorge Ferrer
029     */
030    public class XMLTypeDetector {
031    
032            public static final XMLDescriptor[] REGISTERED_DESCRIPTORS = {
033                    new PortletAppDescriptor(), new StrutsConfigDescriptor(),
034                    new TilesDefsDescriptor(), new WebXML23Descriptor(),
035                    new WebXML24Descriptor()
036            };
037    
038            public static XMLDescriptor determineType(String doctype, Document root) {
039                    for (int i = 0; i < REGISTERED_DESCRIPTORS.length; i++) {
040                            XMLDescriptor descriptor = REGISTERED_DESCRIPTORS[i];
041    
042                            if (descriptor.canHandleType(doctype, root)) {
043                                    return descriptor;
044                            }
045                    }
046    
047                    return new StrictXMLDescriptor();
048            }
049    
050    }