001    // This file is part of AceWiki.
002    // Copyright 2008-2012, AceWiki developers.
003    //
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    //
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    //
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.aceeditor;
016    
017    import java.util.Enumeration;
018    import java.util.HashMap;
019    import java.util.Map;
020    
021    import nextapp.echo.app.ApplicationInstance;
022    import nextapp.echo.app.Window;
023    import nextapp.echo.webcontainer.WebContainerServlet;
024    import ch.uzh.ifi.attempto.base.APE;
025    import ch.uzh.ifi.attempto.echocomp.Style;
026    
027    /**
028     * This servlet class is used by the web server to start the ACE Editor web application.
029     *
030     * @author Tobias Kuhn
031     */
032    public class ACEEditorServlet extends WebContainerServlet {
033    
034            private static final long serialVersionUID = -2533205689651186115L;
035    
036            /**
037             * Creates a new servlet for the ACE Editor web application.
038             */
039            public ACEEditorServlet() {
040            }
041    
042            public ApplicationInstance newApplicationInstance() {
043    
044                    return new ApplicationInstance() {
045    
046                            private static final long serialVersionUID = 2982410120358060245L;
047    
048                            public Window init() {
049                    Map<String, String> parameters = getInitParameters();
050                                    setStyleSheet(Style.styleSheet);
051                                    APE.setParameters(parameters);
052                                    return new ACEEditor(parameters);
053                            }
054    
055                    };
056    
057            }
058    
059            @SuppressWarnings("rawtypes")
060            private Map<String, String> getInitParameters() {
061                    Map<String, String> initParameters = new HashMap<String, String>();
062                    Enumeration paramEnum = getInitParameterNames();
063                    while (paramEnum.hasMoreElements()) {
064                            String paramName = paramEnum.nextElement().toString();
065                            initParameters.put(paramName, getInitParameter(paramName));
066                    }
067                    return initParameters;
068            }
069    
070    }