ScriptPackage.java 2.8 KB

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