01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * 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;
20: import javax.xml.parsers.DocumentBuilderFactory;
21:
22: import org.pentaho.messages.Messages;
23: import org.pentaho.util.logging.Logger;
24: import org.w3c.dom.Document;
25: import org.xml.sax.InputSource;
26:
27: public class XmlW3CHelper {
28:
29: public static final Document getDomFromString(String str) {
30: DocumentBuilderFactory dbf;
31: DocumentBuilder db;
32: Document doc;
33:
34: try {
35: // Check and open XML document
36: dbf = DocumentBuilderFactory.newInstance();
37: db = dbf.newDocumentBuilder();
38: doc = db.parse(new InputSource(
39: new java.io.StringReader(str)));
40:
41: return doc;
42: } catch (Exception e) {
43: Logger
44: .error(
45: XmlW3CHelper.class.getName(),
46: Messages
47: .getErrorString(
48: "XmlHelper.ERROR_0008_GET_DOM_FROM_STRING_ERROR", e.getMessage()), e); //$NON-NLS-1$
49: }
50: return null;
51: }
52:
53: public static Document getDomFromResource(String path) {
54: String str = XmlHelper.getContentFromSolutionResource(path);
55: return getDomFromString(str);
56: }
57:
58: }
|