You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebInterfaceUI.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_web;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.ServerManager;
  26. import com.dmdirc.addons.ui_web.uicomponents.WebStatusBar;
  27. import com.dmdirc.interfaces.config.IdentityController;
  28. import com.dmdirc.interfaces.ui.UIController;
  29. import com.dmdirc.interfaces.ui.Window;
  30. import com.dmdirc.plugins.PluginDomain;
  31. import com.dmdirc.plugins.PluginManager;
  32. import com.dmdirc.ui.WindowManager;
  33. import com.dmdirc.ui.core.components.StatusBarManager;
  34. import java.net.URI;
  35. import javax.inject.Inject;
  36. import org.mortbay.jetty.Handler;
  37. import org.mortbay.jetty.security.Constraint;
  38. import org.mortbay.jetty.security.ConstraintMapping;
  39. import org.mortbay.jetty.security.SecurityHandler;
  40. /**
  41. * Creates and manages the web server and handles UI-wide events.
  42. */
  43. @SuppressWarnings("PMD.UnusedPrivateField")
  44. public class WebInterfaceUI implements UIController {
  45. /** The web server we're using. */
  46. private final org.mortbay.jetty.Server webServer;
  47. /** The window manager for this UI. */
  48. private final WebWindowManager windowManager;
  49. /** The dynamic request handler in use. */
  50. private final DynamicRequestHandler handler;
  51. /** The plugin manager used to find other plugins. */
  52. private final PluginManager pluginManager;
  53. /**
  54. * Creates a new WebInterfaceUI belonging to the specified plugin.
  55. *
  56. * @param domain The domain to retrieve config settings from
  57. * @param identityController The controller to read/write settings with.
  58. * @param serverManager The manager to use to find and create servers
  59. * @param pluginManager The manager to use to find other plugins
  60. * @param coreWindowManager Window management
  61. * @param statusBarManager The status bar manager.
  62. * @param staticRequestHandler Status request handler
  63. */
  64. @Inject
  65. public WebInterfaceUI(
  66. @PluginDomain(WebInterfacePlugin.class) final String domain,
  67. final IdentityController identityController,
  68. final ServerManager serverManager,
  69. final PluginManager pluginManager,
  70. final WindowManager coreWindowManager,
  71. final StatusBarManager statusBarManager,
  72. final StaticRequestHandler staticRequestHandler) {
  73. super();
  74. this.pluginManager = pluginManager;
  75. final SecurityHandler sh = new SecurityHandler();
  76. final Constraint constraint = new Constraint();
  77. final ConstraintMapping cm = new ConstraintMapping();
  78. handler = new DynamicRequestHandler(this, identityController, serverManager);
  79. constraint.setName("DMDirc Web UI");
  80. constraint.setRoles(new String[]{"user"});
  81. constraint.setAuthenticate(true);
  82. cm.setConstraint(constraint);
  83. cm.setPathSpec("/*");
  84. sh.setUserRealm(new WebUserRealm(identityController, domain));
  85. sh.setConstraintMappings(new ConstraintMapping[]{cm});
  86. webServer = new org.mortbay.jetty.Server(5978);
  87. webServer.setHandlers(new Handler[]{
  88. sh,
  89. new RootRequestHandler(),
  90. staticRequestHandler,
  91. new DMDircRequestHandler(),
  92. handler,});
  93. try {
  94. webServer.start();
  95. } catch (Exception ex) {
  96. // Break horribly!
  97. }
  98. windowManager = new WebWindowManager(this, coreWindowManager);
  99. statusBarManager.registerStatusBar(new WebStatusBar(handler));
  100. }
  101. public WebWindowManager getWindowManager() {
  102. return windowManager;
  103. }
  104. public DynamicRequestHandler getHandler() {
  105. return handler;
  106. }
  107. public PluginManager getPluginManager() {
  108. return pluginManager;
  109. }
  110. /**
  111. * Adds the specified handler to the webserver.
  112. *
  113. * @param newHandler The handler to add.
  114. */
  115. public void addWebHandler(final Handler newHandler) {
  116. webServer.addHandler(newHandler);
  117. }
  118. /** {@inheritDoc} */
  119. @Override
  120. public void showFirstRunWizard() {
  121. // Do nothing
  122. }
  123. /** {@inheritDoc} */
  124. @Override
  125. public void showChannelSettingsDialog(final Channel channel) {
  126. // Do nothing
  127. }
  128. /** {@inheritDoc} */
  129. @Override
  130. public void showServerSettingsDialog(final Server server) {
  131. // Do nothing
  132. }
  133. /** {@inheritDoc} */
  134. @Override
  135. public void showURLDialog(final URI url) {
  136. // Do nothing
  137. }
  138. /** {@inheritDoc} */
  139. @Override
  140. public void showFeedbackNag() {
  141. // Do nothing
  142. }
  143. /** {@inheritDoc} */
  144. @Override
  145. public void requestWindowFocus(final Window window) {
  146. // TODO: Tell clients to focus
  147. }
  148. }