ScriptPackage.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.util.ArrayList;
  22. import java.util.Enumeration;
  23. import java.util.List;
  24. import java.util.logging.Logger;
  25. import java.util.zip.ZipEntry;
  26. import java.util.zip.ZipFile;
  27. import com.l2jserver.Config;
  28. /**
  29. * @author Luis Arias
  30. */
  31. public class ScriptPackage
  32. {
  33. private static final Logger _log = Logger.getLogger(ScriptPackage.class.getName());
  34. private final List<ScriptDocument> _scriptFiles = new ArrayList<>();
  35. private final List<String> _otherFiles = new ArrayList<>();
  36. private final String _name;
  37. public ScriptPackage(ZipFile pack)
  38. {
  39. _name = pack.getName();
  40. addFiles(pack);
  41. }
  42. /**
  43. * @return Returns the otherFiles.
  44. */
  45. public List<String> getOtherFiles()
  46. {
  47. return _otherFiles;
  48. }
  49. /**
  50. * @return Returns the scriptFiles.
  51. */
  52. public List<ScriptDocument> getScriptFiles()
  53. {
  54. return _scriptFiles;
  55. }
  56. /**
  57. * @param pack
  58. */
  59. private void addFiles(ZipFile pack)
  60. {
  61. for (Enumeration<? extends ZipEntry> e = pack.entries(); e.hasMoreElements();)
  62. {
  63. ZipEntry entry = e.nextElement();
  64. if (entry.getName().endsWith(".xml"))
  65. {
  66. try
  67. {
  68. _scriptFiles.add(new ScriptDocument(entry.getName(), pack.getInputStream(entry)));
  69. }
  70. catch (IOException io)
  71. {
  72. _log.warning(getClass().getSimpleName() + ": " + io.getMessage());
  73. }
  74. }
  75. else if (!entry.isDirectory())
  76. {
  77. _otherFiles.add(entry.getName());
  78. }
  79. }
  80. }
  81. /**
  82. * @return Returns the name.
  83. */
  84. public String getName()
  85. {
  86. return _name;
  87. }
  88. @Override
  89. public String toString()
  90. {
  91. if (getScriptFiles().isEmpty() && getOtherFiles().isEmpty())
  92. {
  93. return "Empty Package.";
  94. }
  95. StringBuilder out = new StringBuilder();
  96. out.append("Package Name: ");
  97. out.append(getName());
  98. out.append(Config.EOL);
  99. if (!getScriptFiles().isEmpty())
  100. {
  101. out.append("Xml Script Files..." + Config.EOL);
  102. for (ScriptDocument script : getScriptFiles())
  103. {
  104. out.append(script.getName());
  105. out.append(Config.EOL);
  106. }
  107. }
  108. if (!getOtherFiles().isEmpty())
  109. {
  110. out.append("Other Files..." + Config.EOL);
  111. for (String fileName : getOtherFiles())
  112. {
  113. out.append(fileName);
  114. out.append(Config.EOL);
  115. }
  116. }
  117. return out.toString();
  118. }
  119. }