Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

WebInterfaceUI.java 9.0KB

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