01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2006 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the
09: * Free Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: *
21: *
22: * $Id$
23: */
24: package com.bostechcorp.cbesb.ui.util;
25:
26: import java.io.File;
27:
28: import javax.xml.parsers.DocumentBuilder;
29: import javax.xml.parsers.DocumentBuilderFactory;
30:
31: import org.eclipse.swt.SWT;
32: import org.eclipse.swt.widgets.MessageBox;
33: import org.eclipse.ui.PlatformUI;
34: import org.w3c.dom.Document;
35: import org.xml.sax.SAXException;
36: import org.xml.sax.SAXParseException;
37:
38: public class XMLValidation {
39: public static void check(String fileName) {
40: Document doc;
41:
42: try {
43: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
44: .newInstance();
45: DocumentBuilder docBuilder = docBuilderFactory
46: .newDocumentBuilder();
47:
48: doc = docBuilder.parse(new File(fileName));
49:
50: doc.getDocumentElement().normalize();
51: } catch (SAXParseException err) {
52: MessageBox msgBox = new MessageBox(PlatformUI
53: .getWorkbench().getActiveWorkbenchWindow()
54: .getShell(), SWT.ICON_WARNING | SWT.OK);
55: msgBox.setText("Error");
56: msgBox.setMessage("Error found in " + fileName + " "
57: + "\nLine Number: " + err.getLineNumber()
58: + "\nColumn Number: " + err.getColumnNumber()
59: + "\nDetail Message: " + err.getMessage());
60: msgBox.open();
61:
62: } catch (SAXException e) {
63: Exception x = e.getException();
64: ((x == null) ? e : x).printStackTrace();
65: } catch (Throwable t) {
66: t.printStackTrace();
67: }
68:
69: return;
70: }
71: }
|