ScriptDocument.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. public class ScriptDocument
  29. {
  30. private static final Logger _log = Logger.getLogger(ScriptDocument.class.getName());
  31. private Document _document;
  32. private String _name;
  33. public ScriptDocument(String name, InputStream input)
  34. {
  35. _name = name;
  36. DocumentBuilderFactory factory =
  37. DocumentBuilderFactory.newInstance();
  38. try {
  39. DocumentBuilder builder = factory.newDocumentBuilder();
  40. _document = builder.parse( input );
  41. }
  42. catch (SAXException sxe)
  43. {
  44. // Error generated during parsing)
  45. Exception x = sxe;
  46. if (sxe.getException() != null)
  47. {
  48. x = sxe.getException();
  49. }
  50. _log.warning(getClass().getSimpleName() + ": " + x.getMessage());
  51. }
  52. catch (ParserConfigurationException pce)
  53. {
  54. // Parser with specified options can't be built
  55. _log.log(Level.WARNING, "", pce);
  56. }
  57. catch (IOException ioe)
  58. {
  59. // I/O error
  60. _log.log(Level.WARNING, "", ioe);
  61. }
  62. }
  63. public Document getDocument()
  64. {
  65. return _document;
  66. }
  67. /**
  68. * @return Returns the _name.
  69. */
  70. public String getName()
  71. {
  72. return _name;
  73. }
  74. @Override
  75. public String toString()
  76. {
  77. return _name;
  78. }
  79. }