Skip to main content
summaryrefslogtreecommitdiffstats
blob: 84a5bb2031724798ff650ce28fc50465624b12c8 (plain) (blame)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*******************************************************************************
 * Copyright (c) 2008 Oracle Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Cameron Bateman - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.facelet.core.internal.facet;

import java.util.Iterator;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jst.jsf.facelet.core.internal.FaceletCoreTraceOptions;
import org.eclipse.jst.jsf.facesconfig.emf.ApplicationType;
import org.eclipse.jst.jsf.facesconfig.emf.FacesConfigType;
import org.eclipse.jst.jsf.facesconfig.emf.ViewHandlerType;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.common.project.facet.core.IDelegate;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;

/**
 * The super-class of all Facelet facet change delegates.  The only expected 
 * delegates at this time are install and uninstall.  Each super-class must
 * decide the meaning of "change" and implement the abstract members 
 * appropriately.
 * 
 * @author cbateman
 *
 */
public abstract class FaceletChangeDelegate implements IDelegate
{
    /**
     * The default name of the Facelet runtime view handler
     */
    protected static final String RUNTIME_VIEWHANDLER_CLASS_NAME = "com.sun.facelets.FaceletViewHandler"; //$NON-NLS-1$

    public void execute(final IProject project, final IProjectFacetVersion fv,
            final Object config, final IProgressMonitor monitor)
            throws CoreException
    {
        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable()
        {
            public void run()
            {
                final FacetChangeModel model = (FacetChangeModel) config;

                // XXX: look at glassfish changes
                handleDesignTimeViewHandler(project);

                if (model.isChgViewHandler())
                {
                    maybeChangeFaceletViewHandler(project, monitor);
				}
				
				final WebAppConfigurator configurator = WebAppConfigurator
                        .getConfigurator(project);

                if (configurator != null)
                {
                    maybeChangeDefaultSuffix(model, configurator);
                    maybeChangeConfigureListener(model, configurator);
                    maybeChangeWebLifecycleListener(model, configurator);
                }
                else if (FaceletCoreTraceOptions.TRACE_FACETCHANGEDELEGATE)
                {
                    FaceletCoreTraceOptions
                            .log("FaceletChangeDelegate: No web configurator"); //$NON-NLS-1$
                }
            }
        });
    }

    /**
     * Performs the change to the web lifecycle listener configuration of of the
     * web.xml model using configurator, if applicable.
     * 
     * @param model
     * @param configurator
     */
    protected abstract void maybeChangeWebLifecycleListener(
            FacetChangeModel model, WebAppConfigurator configurator);

    /**
     * Performs the change to the configure listener configuration of the
     * web.xml model using configurator, if applicable.
     * 
     * @param model
     * @param configurator
     */
    protected abstract void maybeChangeConfigureListener(
            FacetChangeModel model, WebAppConfigurator configurator);

    /**
     * Performs the change to the DEFAULT_SUFFIX configuration of the web.xml
     * model using configurator, if applicable.
     * 
     * @param model
     * @param configurator
     */
    protected abstract void maybeChangeDefaultSuffix(FacetChangeModel model,
            WebAppConfigurator configurator);

    /**
     * Changes the runtime view handler settings on project if applicable.
     * 
     * @param project
     * @param monitor
     * 
     */
    protected abstract void maybeChangeFaceletViewHandler(IProject project,
            IProgressMonitor monitor);

    /**
     * Change the designtime view handler if applicable.
     * 
     * @param project
     */
    protected abstract void handleDesignTimeViewHandler(final IProject project);

    /**
     * @return a user displayable name of the sub-classing change delegate.
     */
    protected abstract String getDisplayName();

    /**
     * @param root
     * @return true if the Facelet view handler is already present in the
     *         WEB-INF/faces-config.xml file.
     */
    protected final boolean isViewHandlerPresent(final FacesConfigType root)
    {
        final EList<?> applications = root.getApplication();
        for (final Object name : applications)
        {
            final ApplicationType app = (ApplicationType) name;
            if (app != null)
            {
                for (final Iterator<?> viewIt = app.getViewHandler().iterator(); viewIt
                        .hasNext();)
                {
                    final ViewHandlerType viewHandler = (ViewHandlerType) viewIt
                            .next();
                    if (viewHandler != null
                            && RUNTIME_VIEWHANDLER_CLASS_NAME
                                    .equals(viewHandler.getTextContent().trim()))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}

Back to the top