ScriptDocument.java 2.3 KB

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