ScriptPackage.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * TODO To change the template for this generated type comment go to
  26. * Window - Preferences - Java - Code Style - Code Templates
  27. */
  28. public class ScriptPackage
  29. {
  30. private List<ScriptDocument> _scriptFiles;
  31. private List<String> _otherFiles;
  32. private String _name;
  33. public ScriptPackage(ZipFile pack)
  34. {
  35. _scriptFiles = new FastList<ScriptDocument>();
  36. _otherFiles = new FastList<String>();
  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 scriptFiles The scriptFiles to set.
  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. ScriptDocument newScript = new ScriptDocument(entry.getName(), pack.getInputStream(entry));
  66. _scriptFiles.add(newScript);
  67. } catch (IOException e1) {
  68. // TODO Auto-generated catch block
  69. e1.printStackTrace();
  70. }
  71. }
  72. else if (!entry.isDirectory())
  73. {
  74. _otherFiles.add(entry.getName());
  75. }
  76. }
  77. }
  78. /**
  79. * @return Returns the name.
  80. */
  81. public String getName()
  82. {
  83. return _name;
  84. }
  85. @Override
  86. public String toString()
  87. {
  88. if (getScriptFiles().isEmpty() && getOtherFiles().isEmpty())
  89. return "Empty Package.";
  90. String out = "Package Name: "+getName()+"\n";
  91. if (!getScriptFiles().isEmpty())
  92. {
  93. out += "Xml Script Files...\n";
  94. for (ScriptDocument script : getScriptFiles())
  95. {
  96. out += script.getName()+"\n";
  97. }
  98. }
  99. if (!getOtherFiles().isEmpty())
  100. {
  101. out += "Other Files...\n";
  102. for (String fileName : getOtherFiles())
  103. {
  104. out += fileName+"\n";
  105. }
  106. }
  107. return out;
  108. }
  109. }