ScriptDocument.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.script;
  16. import java.io.IOException;
  17. import java.io.InputStream;
  18. import javax.xml.parsers.DocumentBuilder;
  19. import javax.xml.parsers.DocumentBuilderFactory;
  20. import javax.xml.parsers.ParserConfigurationException;
  21. import org.w3c.dom.Document;
  22. import org.xml.sax.SAXException;
  23. /**
  24. *
  25. *
  26. */
  27. public class ScriptDocument
  28. {
  29. private Document _document;
  30. private String _name;
  31. public ScriptDocument(String name, InputStream input)
  32. {
  33. _name = name;
  34. DocumentBuilderFactory factory =
  35. DocumentBuilderFactory.newInstance();
  36. try {
  37. DocumentBuilder builder = factory.newDocumentBuilder();
  38. _document = builder.parse( input );
  39. } catch (SAXException sxe) {
  40. // Error generated during parsing)
  41. Exception x = sxe;
  42. if (sxe.getException() != null)
  43. x = sxe.getException();
  44. x.printStackTrace();
  45. } catch (ParserConfigurationException pce) {
  46. // Parser with specified options can't be built
  47. pce.printStackTrace();
  48. } catch (IOException ioe) {
  49. // I/O error
  50. ioe.printStackTrace();
  51. }
  52. }
  53. public Document getDocument()
  54. {
  55. return _document;
  56. }
  57. /**
  58. * @return Returns the _name.
  59. */
  60. public String getName()
  61. {
  62. return _name;
  63. }
  64. @Override
  65. public String toString()
  66. {
  67. return _name;
  68. }
  69. }