ScriptDocument.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import javax.xml.parsers.DocumentBuilder;
  21. import javax.xml.parsers.DocumentBuilderFactory;
  22. import javax.xml.parsers.ParserConfigurationException;
  23. import org.w3c.dom.Document;
  24. import org.xml.sax.SAXException;
  25. /**
  26. *
  27. *
  28. */
  29. public class ScriptDocument
  30. {
  31. protected static final Logger _log = Logger.getLogger(ScriptDocument.class.getName());
  32. private Document _document;
  33. private String _name;
  34. public ScriptDocument(String name, InputStream input)
  35. {
  36. _name = name;
  37. DocumentBuilderFactory factory =
  38. DocumentBuilderFactory.newInstance();
  39. try {
  40. DocumentBuilder builder = factory.newDocumentBuilder();
  41. _document = builder.parse( input );
  42. } catch (SAXException sxe) {
  43. // Error generated during parsing)
  44. Exception x = sxe;
  45. if (sxe.getException() != null)
  46. x = sxe.getException();
  47. x.printStackTrace();
  48. } catch (ParserConfigurationException pce) {
  49. // Parser with specified options can't be built
  50. _log.log(Level.WARNING, "", pce);
  51. } catch (IOException ioe) {
  52. // I/O error
  53. _log.log(Level.WARNING, "", ioe);
  54. }
  55. }
  56. public Document getDocument()
  57. {
  58. return _document;
  59. }
  60. /**
  61. * @return Returns the _name.
  62. */
  63. public String getName()
  64. {
  65. return _name;
  66. }
  67. @Override
  68. public String toString()
  69. {
  70. return _name;
  71. }
  72. }