KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > util > XmlW3CHelper


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Mar 3, 2006
14  * @author James Dixon
15  */

16
17 package org.pentaho.core.util;
18
19 import javax.xml.parsers.DocumentBuilder JavaDoc;
20 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
21
22 import org.pentaho.messages.Messages;
23 import org.pentaho.util.logging.Logger;
24 import org.w3c.dom.Document JavaDoc;
25 import org.xml.sax.InputSource JavaDoc;
26
27 public class XmlW3CHelper {
28
29     public static final Document JavaDoc getDomFromString(String JavaDoc str) {
30         DocumentBuilderFactory JavaDoc dbf;
31         DocumentBuilder JavaDoc db;
32         Document JavaDoc doc;
33
34         try {
35             // Check and open XML document
36
dbf = DocumentBuilderFactory.newInstance();
37             db = dbf.newDocumentBuilder();
38             doc = db.parse(new InputSource JavaDoc(new java.io.StringReader JavaDoc(str)));
39
40             return doc;
41         } catch (Exception JavaDoc e) {
42             Logger.error(XmlW3CHelper.class.getName(), Messages.getErrorString("XmlHelper.ERROR_0008_GET_DOM_FROM_STRING_ERROR", e.getMessage()), e); //$NON-NLS-1$
43
}
44         return null;
45     }
46
47     public static Document JavaDoc getDomFromResource(String JavaDoc path) {
48         String JavaDoc str = XmlHelper.getContentFromSolutionResource(path);
49         return getDomFromString(str);
50     }
51
52 }
53
Popular Tags