ScriptPackage.java 3.0 KB

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