123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /*
- * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.addons.ui_web;
-
- import com.dmdirc.Channel;
- import com.dmdirc.FrameContainer;
- import com.dmdirc.Query;
- import com.dmdirc.Server;
- import com.dmdirc.WritableFrameContainer;
- import com.dmdirc.addons.ui_web.uicomponents.WebMainWindow;
- import com.dmdirc.addons.ui_web.uicomponents.WebStatusBar;
- import com.dmdirc.config.prefs.PreferencesInterface;
- import com.dmdirc.ui.core.components.StatusBarManager;
- import com.dmdirc.ui.core.dialogs.sslcertificate.SSLCertificateDialogModel;
- import com.dmdirc.ui.interfaces.ChannelWindow;
- import com.dmdirc.ui.interfaces.InputWindow;
- import com.dmdirc.ui.interfaces.MainWindow;
- import com.dmdirc.ui.interfaces.QueryWindow;
- import com.dmdirc.ui.interfaces.ServerWindow;
- import com.dmdirc.ui.interfaces.StatusBar;
- import com.dmdirc.ui.interfaces.UIController;
- import com.dmdirc.ui.interfaces.UpdaterDialog;
- import com.dmdirc.ui.interfaces.Window;
- import com.dmdirc.updater.Update;
-
- import java.net.URI;
- import java.util.List;
-
- import org.mortbay.jetty.Handler;
- import org.mortbay.jetty.security.Constraint;
- import org.mortbay.jetty.security.ConstraintMapping;
- import org.mortbay.jetty.security.SecurityHandler;
-
- /**
- * Creates and manages the web server and handles UI-wide events.
- *
- * @author chris
- */
- public class WebInterfaceUI implements UIController {
-
- /** The domain used for config settings. */
- public static final String DOMAIN = "plugin-webui";
-
- /** The web server we're using. */
- private final org.mortbay.jetty.Server webServer;
-
- /** The window manager for this UI. */
- private final WebWindowManager windowManager;
-
- /**
- * Creates a new WebInterfaceUI belonging to the specified plugin.
- *
- * @param plugin The plugin which owns this Web UI
- */
- public WebInterfaceUI(final WebInterfacePlugin plugin) {
- final SecurityHandler sh = new SecurityHandler();
- final Constraint constraint = new Constraint();
- final ConstraintMapping cm = new ConstraintMapping();
-
- constraint.setName("DMDirc Web UI");
- constraint.setRoles(new String[]{"user"});
- constraint.setAuthenticate(true);
-
- cm.setConstraint(constraint);
- cm.setPathSpec("/*");
-
- sh.setUserRealm(new WebUserRealm());
- sh.setConstraintMappings(new ConstraintMapping[]{cm});
-
- webServer = new org.mortbay.jetty.Server(5978);
-
- webServer.setHandlers(new Handler[]{
- sh,
- new RootRequestHandler(),
- new StaticRequestHandler(),
- new DMDircRequestHandler(),
- new DynamicRequestHandler(this),
- });
-
- try {
- webServer.start();
- } catch (Exception ex) {
- // Break horribly!
- }
-
- windowManager = new WebWindowManager(this);
-
- StatusBarManager.getStatusBarManager().registerStatusBar(new WebStatusBar());
- }
-
- public WebWindowManager getWindowManager() {
- return windowManager;
- }
-
- /**
- * Adds the specified handler to the webserver.
- *
- * @param newHandler The handler to add.
- */
- public void addWebHandler(final Handler newHandler) {
- webServer.addHandler(newHandler);
- }
-
- /** {@inheritDoc} */
- @Override
- public MainWindow getMainWindow() {
- return new WebMainWindow();
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Should not be used externally - use the
- * {@link com.dmdirc.ui.core.components.StatusBarManager} instead.
- */
- @Override
- @Deprecated
- public StatusBar getStatusBar() {
- return new WebStatusBar();
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Controllers should listen for window events using a
- * {@link FrameListener} and create windows as needed.
- */
- @Override @Deprecated
- public ChannelWindow getChannel(final Channel channel) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Controllers should listen for window events using a
- * {@link FrameListener} and create windows as needed.
- */
- @Override @Deprecated
- public ServerWindow getServer(final Server server) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Controllers should listen for window events using a
- * {@link FrameListener} and create windows as needed.
- */
- @Override @Deprecated
- public QueryWindow getQuery(final Query query) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Controllers should listen for window events using a
- * {@link FrameListener} and create windows as needed.
- */
- @Override @Deprecated
- public Window getWindow(final FrameContainer<?> owner) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Controllers should listen for window events using a
- * {@link FrameListener} and create windows as needed.
- */
- @Override @Deprecated
- public InputWindow getInputWindow(final WritableFrameContainer<?> owner) {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override
- public UpdaterDialog getUpdaterDialog(final List<Update> updates) {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- /** {@inheritDoc} */
- @Override
- public void showFirstRunWizard() {
- // Do nothing
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Migration wizard is no longer used or needed
- */
- @Override
- @Deprecated
- public void showMigrationWizard() {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- /** {@inheritDoc} */
- @Override
- public void showChannelSettingsDialog(final Channel channel) {
- // Do nothing
- }
-
- /** {@inheritDoc} */
- @Override
- public void showServerSettingsDialog(final Server server) {
- // Do nothing
- }
-
- /** {@inheritDoc} */
- @Override
- public void initUISettings() {
- // Do nothing
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Use {@link WindowManager#getActiveWindow()} instead
- */
- @Override @Deprecated
- public Window getActiveWindow() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @deprecated Use {@link WindowManager#getActiveWindow()} instead
- */
- @Override @Deprecated
- public Server getActiveServer() {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- /** {@inheritDoc} */
- @Override
- public void showURLDialog(final URI url) {
- // Do nothing
- }
-
- /** {@inheritDoc} */
- @Override
- public void showFeedbackNag() {
- // Do nothing
- }
-
- /** {@inheritDoc} */
- @Override
- public void showMessageDialog(final String title, final String message) {
- // Do nothing
- }
-
- /** {@inheritDoc} */
- @Override
- public String getUserInput(final String prompt) {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- /** {@inheritDoc} */
- @Override
- public void showSSLCertificateDialog(final SSLCertificateDialogModel model) {
- // Do nothing
- }
-
- @Override
- public PreferencesInterface getPluginPrefsPanel() {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public PreferencesInterface getUpdatesPrefsPanel() {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public PreferencesInterface getUrlHandlersPrefsPanel() {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- @Override
- public PreferencesInterface getThemesPrefsPanel() {
- //TODO FIXME
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- }
|