# redMine - project management software # Copyright (C) 2006-2007 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module Redmine module WikiFormatting module Macros module Definitions def exec_macro(name, obj, args) method_name = "macro_#{name}" send(method_name, obj, args) if respond_to?(method_name) end def extract_macro_options(args, *keys) options = {} while args.last.to_s.strip =~ %r{^(.+)\=(.+)$} && keys.include?($1.downcase.to_sym) options[$1.downcase.to_sym] = $2 args.pop end return [args, options] end end @@available_macros = {} class << self # Called with a block to define additional macros. # Macro blocks accept 2 arguments: # * obj: the object that is rendered # * args: macro arguments # # Plugins can use this method to define new macros: # # Redmine::WikiFormatting::Macros.register do # desc "This is my macro" # macro :my_macro do |obj, args| # "My macro output" # end # end def register(&block) class_eval(&block) if block_given? end private # Defines a new macro with the given name and block. def macro(name, &block) name = name.to_sym if name.is_a?(String) @@available_macros[name] = @@desc || '' @@desc = nil raise "Can not create a macro without a block!" unless block_given? Definitions.send :define_method, "macro_#{name}".downcase, &block end # Sets description for the next macro to be defined def desc(txt) @@desc = txt end end # Builtin macros desc "Sample macro." macro :hello_world do |obj, args| "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}") end desc "Displays a list of all available macros, including description if available." macro :macro_list do out = '' @@available_macros.keys.collect(&:to_s).sort.each do |macro| out << content_tag('dt', content_tag('code', macro)) out << content_tag('dd', textilizable(@@available_macros[macro.to_sym])) end content_tag('dl', out) end desc "Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:\n\n" + " !{{child_pages}} -- can be used from a wiki page only\n" + " !{{child_pages(Foo)}} -- lists all children of page Foo\n" + " !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo" macro :child_pages do |obj, args| args, options = extract_macro_options(args, :parent) page = nil if args.size > 0 page = Wiki.find_page(args.first.to_s, :project => @project) elsif obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version) page = obj.page else raise 'With no argument, this macro can be called from wiki pages only.' end raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project) pages = ([page] + page.descendants).group_by(&:parent_id) render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id) end desc "Include a wiki page. Example:\n\n !{{include(Foo)}}\n\nor to include a page of a specific project wiki:\n\n !{{include(projectname:Foo)}}" macro :include do |obj, args| page = Wiki.find_page(args.first.to_s, :project => @project) raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project) @included_wiki_pages ||= [] raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title) @included_wiki_pages << page.title out = textilizable(page.content, :text, :attachments => page.attachments) @included_wiki_pages.pop out end end end end Vaadin 6, 7, 8 is a Java framework for modern Java web applications: https://github.com/vaadin/frameworkwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java
blob: 92024227bc5d65751f761b4ceb17ef0d91f3b4ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright 2000-2018 Vaadin Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.vaadin.server;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import com.vaadin.util.ReflectTools;

public class LegacyVaadinServlet extends VaadinServlet {

    private static final UIProvider PROVIDER = new LegacyApplicationUIProvider() {
        @Override
        protected LegacyApplication createApplication() {

            VaadinServlet servlet = VaadinServlet.getCurrent();
            if (servlet instanceof LegacyVaadinServlet) {
                LegacyVaadinServlet legacyServlet = (LegacyVaadinServlet) servlet;
                HttpServletRequest request = VaadinServletService
                        .getCurrentServletRequest();
                try {
                    if (legacyServlet.shouldCreateApplication(request)) {
                        return legacyServlet.getNewApplication(request);
                    }
                } catch (ServletException e) {
                    throw new RuntimeException(e);
                }
            }
            return null;
        }
    };

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);

        getService().addSessionInitListener((SessionInitEvent event) -> {
            try {
                onVaadinSessionStarted(event.getRequest(), event.getSession());
            } catch (ServletException e) {
                throw new ServiceException(e);
            }
        });
    }

    protected Class<? extends LegacyApplication> getApplicationClass()
            throws ClassNotFoundException {
        try {
            return ServletPortletHelper.getLegacyApplicationClass(getService());
        } catch (ServiceException e) {
            throw new RuntimeException(e);
        }
    }

    protected LegacyApplication getNewApplication(HttpServletRequest request)
            throws ServletException {
        try {
            Class<? extends LegacyApplication> applicationClass = getApplicationClass();
            return ReflectTools.createInstance(applicationClass);
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }

    protected boolean shouldCreateApplication(HttpServletRequest request)
            throws ServletException {
        return true;
    }

    private void onVaadinSessionStarted(VaadinRequest request,
            VaadinSession session) throws ServletException {
        session.addUIProvider(PROVIDER);
    }

}