001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.xml;
016    
017    /**
018     * @author Brian Wing Shun Chan
019     */
020    public class XMLConverter {
021    
022            public static javax.xml.namespace.QName toJavaxQName(
023                    org.dom4j.QName dom4jQName) {
024    
025                    javax.xml.namespace.QName javaxQName = new javax.xml.namespace.QName(
026                            dom4jQName.getNamespaceURI(), dom4jQName.getName(),
027                            dom4jQName.getNamespacePrefix());
028    
029                    return javaxQName;
030            }
031    
032            public static org.w3c.dom.Document toW3CDocument(
033                            org.dom4j.Document dom4jDoc)
034                    throws org.dom4j.DocumentException {
035    
036                    org.dom4j.io.DOMWriter dom4jWriter = new org.dom4j.io.DOMWriter();
037    
038                    org.w3c.dom.Document w3cDoc = dom4jWriter.write(dom4jDoc);
039    
040                    return w3cDoc;
041            }
042    
043            public static org.w3c.dom.Element toW3CElement(org.dom4j.Element dom4jEl)
044                    throws org.dom4j.DocumentException {
045    
046                    org.dom4j.Document dom4jDoc =
047                            org.dom4j.DocumentFactory.getInstance().createDocument();
048    
049                    dom4jDoc.setRootElement(dom4jEl.createCopy());
050    
051                    org.w3c.dom.Document w3cDoc = toW3CDocument(dom4jDoc);
052    
053                    return w3cDoc.getDocumentElement();
054            }
055    
056    }