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 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.FrameContainer;
  25. import com.dmdirc.Query;
  26. import com.dmdirc.Server;
  27. import com.dmdirc.WritableFrameContainer;
  28. import com.dmdirc.commandparser.parsers.CommandParser;
  29. import com.dmdirc.config.prefs.PreferencesInterface;
  30. import com.dmdirc.ui.core.dialogs.sslcertificate.SSLCertificateDialogModel;
  31. import com.dmdirc.ui.interfaces.ChannelWindow;
  32. import com.dmdirc.ui.interfaces.InputWindow;
  33. import com.dmdirc.ui.interfaces.MainWindow;
  34. import com.dmdirc.ui.interfaces.QueryWindow;
  35. import com.dmdirc.ui.interfaces.ServerWindow;
  36. import com.dmdirc.ui.interfaces.StatusBar;
  37. import com.dmdirc.ui.interfaces.UIController;
  38. import com.dmdirc.ui.interfaces.UpdaterDialog;
  39. import com.dmdirc.ui.interfaces.Window;
  40. import com.dmdirc.ui.WindowManager;
  41. import com.dmdirc.updater.Update;
  42. import com.dmdirc.addons.ui_web.uicomponents.WebChannelWindow;
  43. import com.dmdirc.addons.ui_web.uicomponents.WebFrameManager;
  44. import com.dmdirc.addons.ui_web.uicomponents.WebInputWindow;
  45. import com.dmdirc.addons.ui_web.uicomponents.WebMainWindow;
  46. import com.dmdirc.addons.ui_web.uicomponents.WebQueryWindow;
  47. import com.dmdirc.addons.ui_web.uicomponents.WebServerWindow;
  48. import com.dmdirc.addons.ui_web.uicomponents.WebStatusBar;
  49. import com.dmdirc.addons.ui_web.uicomponents.WebWindow;
  50. import java.net.URI;
  51. import java.util.List;
  52. import org.mortbay.jetty.Handler;
  53. import org.mortbay.jetty.security.Constraint;
  54. import org.mortbay.jetty.security.ConstraintMapping;
  55. import org.mortbay.jetty.security.SecurityHandler;
  56. /**
  57. * Creates and manages the web server and handles UI-wide events.
  58. *
  59. * @author chris
  60. */
  61. public class WebInterfaceUI implements UIController {
  62. /** The domain used for config settings. */
  63. public static final String DOMAIN = "plugin-webui";
  64. /**
  65. * The active window.
  66. * @Deprecated Should be done client side
  67. */
  68. public static WebWindow active;
  69. /** The web server we're using. */
  70. private final org.mortbay.jetty.Server webServer;
  71. /**
  72. * Creates a new WebInterfaceUI belonging to the specified plugin.
  73. *
  74. * @param plugin The plugin which owns this Web UI
  75. */
  76. public WebInterfaceUI(final WebInterfacePlugin plugin) {
  77. WindowManager.addFrameListener(new WebFrameManager());
  78. final SecurityHandler sh = new SecurityHandler();
  79. final Constraint constraint = new Constraint();
  80. final ConstraintMapping cm = new ConstraintMapping();
  81. constraint.setName("DMDirc Web UI");
  82. constraint.setRoles(new String[]{"user"});
  83. constraint.setAuthenticate(true);
  84. cm.setConstraint(constraint);
  85. cm.setPathSpec("/*");
  86. sh.setUserRealm(new WebUserRealm());
  87. sh.setConstraintMappings(new ConstraintMapping[]{cm});
  88. webServer = new org.mortbay.jetty.Server(5978);
  89. webServer.setHandlers(new Handler[]{
  90. sh,
  91. new RootRequestHandler(),
  92. new StaticRequestHandler(),
  93. new DMDircRequestHandler(),
  94. new DynamicRequestHandler(),
  95. });
  96. try {
  97. webServer.start();
  98. } catch (Exception ex) {
  99. // Break horribly!
  100. }
  101. }
  102. /**
  103. * Adds the specified handler to the webserver.
  104. *
  105. * @param newHandler The handler to add.
  106. */
  107. public void addWebHandler(final Handler newHandler) {
  108. webServer.addHandler(newHandler);
  109. }
  110. /** {@inheritDoc} */
  111. @Override
  112. public MainWindow getMainWindow() {
  113. return new WebMainWindow();
  114. }
  115. /** {@inheritDoc} */
  116. @Override
  117. public StatusBar getStatusBar() {
  118. return new WebStatusBar();
  119. }
  120. /** {@inheritDoc} */
  121. @Override
  122. public ChannelWindow getChannel(final Channel channel) {
  123. return new WebChannelWindow(channel);
  124. }
  125. /** {@inheritDoc} */
  126. @Override
  127. public ServerWindow getServer(final Server server) {
  128. return new WebServerWindow(server);
  129. }
  130. /** {@inheritDoc} */
  131. @Override
  132. public QueryWindow getQuery(final Query query) {
  133. return new WebQueryWindow(query);
  134. }
  135. /** {@inheritDoc} */
  136. @Override
  137. public Window getWindow(final FrameContainer owner) {
  138. return new WebWindow(owner);
  139. }
  140. /** {@inheritDoc} */
  141. @Override
  142. public InputWindow getInputWindow(final WritableFrameContainer owner,
  143. final CommandParser commandParser) {
  144. return new WebInputWindow(owner, commandParser);
  145. }
  146. /** {@inheritDoc} */
  147. @Override
  148. public UpdaterDialog getUpdaterDialog(final List<Update> updates) {
  149. //TODO FIXME
  150. throw new UnsupportedOperationException("Not supported yet.");
  151. }
  152. /** {@inheritDoc} */
  153. @Override
  154. public void showFirstRunWizard() {
  155. //TODO FIXME
  156. throw new UnsupportedOperationException("Not supported yet.");
  157. }
  158. /** {@inheritDoc} */
  159. @Override
  160. public void showMigrationWizard() {
  161. //TODO FIXME
  162. throw new UnsupportedOperationException("Not supported yet.");
  163. }
  164. /** {@inheritDoc} */
  165. @Override
  166. public void showChannelSettingsDialog(final Channel channel) {
  167. //TODO FIXME
  168. throw new UnsupportedOperationException("Not supported yet.");
  169. }
  170. /** {@inheritDoc} */
  171. @Override
  172. public void showServerSettingsDialog(final Server server) {
  173. //TODO FIXME
  174. throw new UnsupportedOperationException("Not supported yet.");
  175. }
  176. /** {@inheritDoc} */
  177. @Override
  178. public void initUISettings() {
  179. // Do nothing
  180. }
  181. /** {@inheritDoc} */
  182. @Override @Deprecated
  183. public Window getActiveWindow() {
  184. return active;
  185. }
  186. /** {@inheritDoc} */
  187. @Override @Deprecated
  188. public Server getActiveServer() {
  189. //TODO FIXME
  190. throw new UnsupportedOperationException("Not supported yet.");
  191. }
  192. /** {@inheritDoc} */
  193. @Override
  194. public void showURLDialog(final URI url) {
  195. //TODO FIXME
  196. throw new UnsupportedOperationException("Not supported yet.");
  197. }
  198. /** {@inheritDoc} */
  199. @Override
  200. public void showFeedbackNag() {
  201. //TODO FIXME
  202. throw new UnsupportedOperationException("Not supported yet.");
  203. }
  204. /** {@inheritDoc} */
  205. @Override
  206. public void showMessageDialog(final String title, final String message) {
  207. //TODO FIXME
  208. throw new UnsupportedOperationException("Not supported yet.");
  209. }
  210. /** {@inheritDoc} */
  211. @Override
  212. public String getUserInput(final String prompt) {
  213. //TODO FIXME
  214. throw new UnsupportedOperationException("Not supported yet.");
  215. }
  216. /** {@inheritDoc} */
  217. @Override
  218. public void showSSLCertificateDialog(final SSLCertificateDialogModel model) {
  219. //TODO FIXME
  220. throw new UnsupportedOperationException("Not supported yet.");
  221. }
  222. @Override
  223. public PreferencesInterface getPluginPrefsPanel() {
  224. //TODO FIXME
  225. throw new UnsupportedOperationException("Not supported yet.");
  226. }
  227. @Override
  228. public PreferencesInterface getUpdatesPrefsPanel() {
  229. //TODO FIXME
  230. throw new UnsupportedOperationException("Not supported yet.");
  231. }
  232. @Override
  233. public PreferencesInterface getUrlHandlersPrefsPanel() {
  234. //TODO FIXME
  235. throw new UnsupportedOperationException("Not supported yet.");
  236. }
  237. @Override
  238. public PreferencesInterface getThemesPrefsPanel() {
  239. //TODO FIXME
  240. throw new UnsupportedOperationException("Not supported yet.");
  241. }
  242. }