Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. /*
  2. * This file is part of DrFTPD, Distributed FTP Daemon.
  3. *
  4. * DrFTPD is free software; you can redistribute it and/or modify it under the
  5. * terms of the GNU General Public License as published by the Free Software
  6. * Foundation; either version 2 of the License, or (at your option) any later
  7. * version.
  8. *
  9. * DrFTPD is distributed in the hope that it will be useful, but WITHOUT ANY
  10. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * DrFTPD; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  15. * Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. package org.drftpd.plugins.sitebot.announce.archive;
  18.  
  19. import java.util.ResourceBundle;
  20. import java.util.StringTokenizer;
  21.  
  22. import org.bushe.swing.event.annotation.AnnotationProcessor;
  23. import org.bushe.swing.event.annotation.EventSubscriber;
  24. import org.drftpd.plugins.archive.event.ArchiveFailedEvent;
  25. import org.drftpd.plugins.archive.event.ArchiveStartEvent;
  26. import org.drftpd.plugins.archive.event.ArchiveFinishEvent;
  27. import org.drftpd.plugins.sitebot.AnnounceInterface;
  28. import org.drftpd.plugins.sitebot.AnnounceWriter;
  29. import org.drftpd.plugins.sitebot.OutputWriter;
  30. import org.drftpd.plugins.sitebot.SiteBot;
  31. import org.drftpd.plugins.sitebot.config.AnnounceConfig;
  32. import org.drftpd.util.ReplacerUtils;
  33. import org.tanesha.replacer.ReplacerEnvironment;
  34.  
  35. /**
  36. * @author CyBeR
  37. * @version $Id: ArchiveAnnouncer.java 2072 2010-09-18 22:01:23Z djb61 $
  38. */
  39. public class ArchiveAnnouncer implements AnnounceInterface {
  40.  
  41. private AnnounceConfig _config;
  42.  
  43. private ResourceBundle _bundle;
  44.  
  45. private String _keyPrefix;
  46.  
  47. public void initialise(AnnounceConfig config, ResourceBundle bundle) {
  48. _config = config;
  49. _bundle = bundle;
  50. _keyPrefix = this.getClass().getName();
  51. // Subscribe to events
  52. AnnotationProcessor.process(this);
  53. }
  54.  
  55. public void stop() {
  56. AnnotationProcessor.unprocess(this);
  57. }
  58.  
  59. public String[] getEventTypes() {
  60. return new String[] { "archivestartevent","archivefinishevent","archivefailedevent" };
  61. }
  62.  
  63. public void setResourceBundle(ResourceBundle bundle) {
  64. _bundle = bundle;
  65. }
  66.  
  67. @EventSubscriber
  68. public void onArchiveStartEvent(ArchiveStartEvent event) {
  69. AnnounceWriter writer = _config.getPathWriter("archivestartevent", event.getArchiveType().getDirectory());
  70. if (writer != null) {
  71. ReplacerEnvironment env = new ReplacerEnvironment(SiteBot.GLOBAL_ENV);
  72.  
  73. env.add("type", event.getArchiveType().getClass().getSimpleName());
  74. env.add("rls", event.getArchiveType().getDirectory().getName());
  75. env.add("files", event.getJobs().size());
  76. env.add("srcdir", event.getArchiveType().getDirectory().getParent().getPath());
  77.  
  78. sayOutput(ReplacerUtils.jprintf(_keyPrefix+".start", env, _bundle), writer);
  79. }
  80. }
  81.  
  82. @EventSubscriber
  83. public void onArchiveFinishEvent(ArchiveFinishEvent event) {
  84. AnnounceWriter writer = _config.getPathWriter("archivefinishevent", event.getArchiveType().getDirectory());
  85. if (writer != null) {
  86. ReplacerEnvironment env = new ReplacerEnvironment(SiteBot.GLOBAL_ENV);
  87.  
  88. env.add("type", event.getArchiveType().getClass().getSimpleName());
  89. env.add("rls", event.getArchiveType().getDirectory().getName());
  90. env.add("time", event.getArchiveTime());
  91. env.add("srcdir", event.getArchiveType().getDirectory().getParent().getPath());
  92.  
  93. if (event.getArchiveType().getDestinationDirectory().getPath() != null) {
  94. env.add("destdir", event.getArchiveType().getDestinationDirectory().getPath());
  95. sayOutput(ReplacerUtils.jprintf(_keyPrefix+".finish.move", env, _bundle), writer);
  96. } else {
  97. sayOutput(ReplacerUtils.jprintf(_keyPrefix+".finish", env, _bundle), writer);
  98. }
  99. }
  100. }
  101.  
  102. @EventSubscriber
  103. public void onArchiveFailedEvent(ArchiveFailedEvent event) {
  104. AnnounceWriter writer = _config.getPathWriter("archivefailedevent", event.getArchiveType().getDirectory());
  105. if (writer != null) {
  106. ReplacerEnvironment env = new ReplacerEnvironment(SiteBot.GLOBAL_ENV);
  107.  
  108. env.add("type", event.getArchiveType().getClass().getSimpleName());
  109. env.add("rls", event.getArchiveType().getDirectory().getName());
  110. env.add("time", event.getArchiveTime());
  111. env.add("srcdir", event.getArchiveType().getDirectory().getParent().getPath());
  112. env.add("reason", event.getFailReason());
  113.  
  114. sayOutput(ReplacerUtils.jprintf(_keyPrefix+".failed", env, _bundle), writer);
  115. }
  116. }
  117.  
  118. private void sayOutput(String output, AnnounceWriter writer) {
  119. StringTokenizer st = new StringTokenizer(output,"\n");
  120. while (st.hasMoreTokens()) {
  121. String token = st.nextToken();
  122. for (OutputWriter oWriter : writer.getOutputWriters()) {
  123. oWriter.sendMessage(token);
  124. }
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement