2
0

ScriptPackage.java 3.1 KB

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