Desktop tool for browsing account info from EVE-Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OracleV2DOMAdapter.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*--
  2. $Id: OracleV2DOMAdapter.java,v 1.19 2007/11/10 05:28:59 jhunter Exp $
  3. Copyright (C) 2000-2007 Jason Hunter & Brett McLaughlin.
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions, and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions, and the disclaimer that follows
  12. these conditions in the documentation and/or other materials
  13. provided with the distribution.
  14. 3. The name "JDOM" must not be used to endorse or promote products
  15. derived from this software without prior written permission. For
  16. written permission, please contact <request_AT_jdom_DOT_org>.
  17. 4. Products derived from this software may not be called "JDOM", nor
  18. may "JDOM" appear in their name, without prior written permission
  19. from the JDOM Project Management <request_AT_jdom_DOT_org>.
  20. In addition, we request (but do not require) that you include in the
  21. end-user documentation provided with the redistribution and/or in the
  22. software itself an acknowledgement equivalent to the following:
  23. "This product includes software developed by the
  24. JDOM Project (http://www.jdom.org/)."
  25. Alternatively, the acknowledgment may be graphical using the logos
  26. available at http://www.jdom.org/images/logos.
  27. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  28. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  34. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  35. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  36. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38. SUCH DAMAGE.
  39. This software consists of voluntary contributions made by many
  40. individuals on behalf of the JDOM Project and was originally
  41. created by Jason Hunter <jhunter_AT_jdom_DOT_org> and
  42. Brett McLaughlin <brett_AT_jdom_DOT_org>. For more information
  43. on the JDOM Project, please see <http://www.jdom.org/>.
  44. */
  45. package org.jdom.adapters;
  46. import java.io.*;
  47. import java.lang.reflect.*;
  48. import org.jdom.*;
  49. import org.w3c.dom.Document;
  50. import org.xml.sax.*;
  51. /**
  52. * An adapter for the Oracle Version 2 DOM parser.
  53. *
  54. * @version $Revision: 1.19 $, $Date: 2007/11/10 05:28:59 $
  55. * @author Brett McLaughlin
  56. * @author Jason Hunter
  57. */
  58. public class OracleV2DOMAdapter extends AbstractDOMAdapter {
  59. private static final String CVS_ID =
  60. "@(#) $RCSfile: OracleV2DOMAdapter.java,v $ $Revision: 1.19 $ $Date: 2007/11/10 05:28:59 $ $Name: jdom_1_1 $";
  61. /**
  62. * This creates a new <code>{@link Document}</code> from an
  63. * existing <code>InputStream</code> by letting a DOM
  64. * parser handle parsing using the supplied stream.
  65. *
  66. * @param in <code>InputStream</code> to parse.
  67. * @param validate <code>boolean</code> to indicate if validation should occur.
  68. * @return <code>Document</code> - instance ready for use.
  69. * @throws IOException when I/O error occurs.
  70. * @throws JDOMException when errors occur in parsing.
  71. */
  72. public Document getDocument(InputStream in, boolean validate)
  73. throws IOException, JDOMException {
  74. try {
  75. // Load the parser class
  76. Class parserClass = Class.forName("oracle.xml.parser.v2.DOMParser");
  77. Object parser = parserClass.newInstance();
  78. // Parse the document
  79. Method parse =
  80. parserClass.getMethod("parse",
  81. new Class[] {org.xml.sax.InputSource.class});
  82. parse.invoke(parser, new Object[] {new InputSource(in)});
  83. // Get the Document object
  84. Method getDocument = parserClass.getMethod("getDocument", null);
  85. Document doc = (Document)getDocument.invoke(parser, null);
  86. return doc;
  87. } catch (InvocationTargetException e) {
  88. Throwable targetException = e.getTargetException();
  89. if (targetException instanceof org.xml.sax.SAXParseException) {
  90. SAXParseException parseException = (SAXParseException)targetException;
  91. throw new JDOMException("Error on line " + parseException.getLineNumber() +
  92. " of XML document: " + parseException.getMessage(), parseException);
  93. } else if (targetException instanceof IOException) {
  94. IOException ioException = (IOException) targetException;
  95. throw ioException;
  96. } else {
  97. throw new JDOMException(targetException.getMessage(), targetException);
  98. }
  99. } catch (Exception e) {
  100. throw new JDOMException(e.getClass().getName() + ": " +
  101. e.getMessage(), e);
  102. }
  103. }
  104. /**
  105. * This creates an empty <code>Document</code> object based
  106. * on a specific parser implementation.
  107. *
  108. * @return <code>Document</code> - created DOM Document.
  109. * @throws JDOMException when errors occur.
  110. */
  111. public Document createDocument() throws JDOMException {
  112. try {
  113. return
  114. (Document)Class.forName(
  115. "oracle.xml.parser.v2.XMLDocument")
  116. .newInstance();
  117. } catch (Exception e) {
  118. throw new JDOMException(e.getClass().getName() + ": " +
  119. e.getMessage() + " when creating document", e);
  120. }
  121. }
  122. }