ScriptPackage.java 3.1 KB

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