Repository: empire-db Updated Branches: refs/heads/master b2dff062f -> bcff43b89
EMPIREDB-235 reorganize Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/bcff43b8 Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/bcff43b8 Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/bcff43b8 Branch: refs/heads/master Commit: bcff43b89e7d52d039b46c10365d69bc1cc391ea Parents: b2dff06 Author: Rainer Döbele <[email protected]> Authored: Thu Jan 28 17:56:29 2016 +0100 Committer: Rainer Döbele <[email protected]> Committed: Thu Jan 28 17:56:29 2016 +0100 ---------------------------------------------------------------------- .../jsf2/websample/web/SampleApplication.java | 9 +- .../empire/jsf2/websample/web/SampleUtils.java | 6 +- .../jsf2/websample/web/pages/SamplePages.java | 2 + .../src/main/webapp/WEB-INF/faces-config.xml | 6 +- .../empire/jsf2/app/FacesApplication.java | 507 ------------------- .../empire/jsf2/app/FacesImplementation.java | 88 ---- .../jsf2/app/FacesRequestPhaseListener.java | 27 +- .../empire/jsf2/app/FacesStartupListener.java | 102 ---- .../org/apache/empire/jsf2/app/FacesUtils.java | 184 ++++++- .../apache/empire/jsf2/app/TextResolver.java | 96 +--- .../jsf2/app/impl/MojarraImplementation.java | 99 ---- .../jsf2/app/impl/MyFacesImplementation.java | 81 --- .../java/org/apache/empire/jsf2/pages/Page.java | 8 +- .../empire/jsf2/pages/PageDefinitions.java | 2 +- .../empire/jsf2/pages/PagePhaseListener.java | 2 +- .../empire/jsf2/utils/TagEncodingHelper.java | 14 +- 16 files changed, 211 insertions(+), 1022 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java ---------------------------------------------------------------------- diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java index 57de916..7cb3811 100644 --- a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java +++ b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleApplication.java @@ -26,7 +26,6 @@ import javax.servlet.ServletContext; import javax.sql.DataSource; import org.apache.empire.commons.StringUtils; -import org.apache.empire.db.DBCmdType; import org.apache.empire.db.DBCommand; import org.apache.empire.db.DBDatabase; import org.apache.empire.db.DBDatabaseDriver; @@ -37,7 +36,7 @@ import org.apache.empire.db.hsql.DBDatabaseDriverHSql; import org.apache.empire.db.mysql.DBDatabaseDriverMySQL; import org.apache.empire.db.oracle.DBDatabaseDriverOracle; import org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL; -import org.apache.empire.jsf2.app.FacesApplication; +import org.apache.empire.jsf2.app.WebApplication; import org.apache.empire.jsf2.controls.InputControlManager; import org.apache.empire.jsf2.custom.controls.FileInputControl; import org.apache.empire.jsf2.websample.db.SampleDB; @@ -45,7 +44,7 @@ import org.apache.empire.jsf2.websample.web.pages.SamplePages; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SampleApplication extends FacesApplication { +public class SampleApplication extends WebApplication { // Logger private static final Logger log = LoggerFactory .getLogger(SampleApplication.class); @@ -59,7 +58,7 @@ public class SampleApplication extends FacesApplication { private Connection conn = null; public static SampleApplication get() { - return (SampleApplication)FacesApplication.getInstance(); + return (SampleApplication)WebApplication.getInstance(); } public SampleApplication() { @@ -207,7 +206,7 @@ public class SampleApplication extends FacesApplication { // Show DLL Statements System.out.println(script.toString()); // Execute Script - script.run(driver, conn, false); + script.executeAll(driver, conn, false); sampleDB.commit(conn); // Open again if (!sampleDB.isOpen()) { http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java ---------------------------------------------------------------------- diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java index bfaaab5..70c352a 100644 --- a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java +++ b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/SampleUtils.java @@ -101,19 +101,19 @@ public class SampleUtils extends FacesUtils public static Connection getConnection() { FacesContext fc = getContext(); - return getFacesApplication().getConnectionForRequest(fc, getDatabase()); + return getWebApplication().getConnectionForRequest(fc, getDatabase()); } public static void releaseConnection(boolean commit) { FacesContext fc = getContext(); - getFacesApplication().releaseConnection(fc, getDatabase(), commit); + getWebApplication().releaseConnection(fc, getDatabase(), commit); } public static void releaseConnection() { FacesContext fc = getContext(); - getFacesApplication().releaseConnection(fc, getDatabase()); + getWebApplication().releaseConnection(fc, getDatabase()); } /* Messages */ http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/SamplePages.java ---------------------------------------------------------------------- diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/SamplePages.java b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/SamplePages.java index 291ad71..671e396 100644 --- a/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/SamplePages.java +++ b/empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/pages/SamplePages.java @@ -23,6 +23,8 @@ import org.apache.empire.jsf2.pages.PageDefinitions; public final class SamplePages extends PageDefinitions { + private static final long serialVersionUID = 1L; + public static final PageDefinition LoginPage = new PageDefinition("/pages/loginPage.xhtml", LoginPage.class); public static final PageDefinition EmployeeListPage = new PageDefinition("/pages/employeeListPage.xhtml", EmployeeListPage.class, SamplePages.LoginPage); http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml ---------------------------------------------------------------------- diff --git a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml index c0a856f..7e7d8b2 100644 --- a/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml +++ b/empire-db-examples/empire-db-example-jsf2/src/main/webapp/WEB-INF/faces-config.xml @@ -17,7 +17,7 @@ <application> <!-- System event listener --> <system-event-listener> - <system-event-listener-class>org.apache.empire.jsf2.app.FacesStartupListener</system-event-listener-class> + <system-event-listener-class>org.apache.empire.jsf2.app.WebAppStartupListener</system-event-listener-class> <system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class> </system-event-listener> <!-- locales --> @@ -47,9 +47,9 @@ <phase-listener>org.apache.empire.jsf2.websample.web.AutheticationPhaseListener</phase-listener> </lifecycle> - <!-- Application bean (MUST be named 'facesApplication' for FacesStartupListener!) --> + <!-- Application bean (MUST be named 'webApplication' for WebAppStartupListener!) --> <managed-bean> - <managed-bean-name>facesApplication</managed-bean-name> + <managed-bean-name>webApplication</managed-bean-name> <managed-bean-class>org.apache.empire.jsf2.websample.web.SampleApplication</managed-bean-class> <managed-bean-scope>application</managed-bean-scope> </managed-bean> http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java deleted file mode 100644 index 3a5e759..0000000 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java +++ /dev/null @@ -1,507 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.empire.jsf2.app; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.faces.FactoryFinder; -import javax.faces.application.Application; -import javax.faces.application.ApplicationFactory; -import javax.faces.application.FacesMessage; -import javax.faces.application.FacesMessage.Severity; -import javax.faces.component.NamingContainer; -import javax.faces.component.UIComponent; -import javax.faces.component.UIViewRoot; -import javax.faces.context.FacesContext; -import javax.servlet.ServletContext; -import javax.sql.DataSource; - -import org.apache.empire.commons.StringUtils; -import org.apache.empire.data.DataType; -import org.apache.empire.db.DBDatabase; -import org.apache.empire.exceptions.InternalException; -import org.apache.empire.exceptions.InvalidArgumentException; -import org.apache.empire.exceptions.NotSupportedException; -import org.apache.empire.jsf2.controls.TextAreaInputControl; -import org.apache.empire.jsf2.controls.TextInputControl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -// import com.sun.faces.application.ApplicationImpl; - -public abstract class FacesApplication -{ - private static final Logger log = LoggerFactory.getLogger(FacesApplication.class); - - private static final String CONNECTION_ATTRIBUTE = "dbConnections"; - - public static String APPLICATION_BEAN_NAME = "facesApplication"; - - protected TextResolver[] textResolvers = null; - - private String webRoot = null; - - private FacesImplementation facesImpl = null; - - private static FacesApplication appInstance = null; - - public static FacesApplication getInstance() - { - if (appInstance==null) - log.warn("No FacesApplication instance available. Please add a PostConstructApplicationEvent using FacesStartupListener in your faces-config.xml to create the FacesApplication object."); - // return instance - return appInstance; - } - - protected abstract void init(ServletContext servletContext); - - protected abstract DataSource getAppDataSource(DBDatabase db); - - protected FacesApplication() - { // subscribe - log.info("FacesApplication {0} created", getClass().getName()); - // Must be a singleton - if (appInstance!=null) { - throw new RuntimeException("An attempt was made to create second instance of FacesApplication. FacesApplication must be a singleton!"); - } - // set Instance - appInstance = this; - } - - /** - * Init the Application - * @param servletContext - */ - public final void init(FacesImplementation facesImpl, FacesContext startupContext) - { - // Only call once! - if (this.facesImpl!=null || this.webRoot!=null) - throw new NotSupportedException(this, "init"); - // set imppl - this.facesImpl = facesImpl; - // webRoot - ServletContext servletContext = (ServletContext) startupContext.getExternalContext().getContext(); - webRoot = servletContext.getContextPath(); - servletContext.setAttribute("webRoot", webRoot); - servletContext.setAttribute("app", this); - // Init - init(servletContext); - // text resolvers - log.info("*** initTextResolvers() ***"); - ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); - Application app = appFactory.getApplication(); - initTextResolvers(app); - // Log info - log.info("*** FacesApplication initialization complete ***"); - log.info("JSF-Implementation is '{}'", facesImpl.getClass().getName()); - log.info("WebRoot is '{}'", webRoot); - } - - /* Context handling */ - - /** - * handle request cleanup - * @param ctx - */ - public void onRequestComplete(final FacesContext ctx) - { - releaseAllConnections(ctx); - } - - /** - * handle view change - * @param fc - * @param viewId - */ - public void onChangeView(final FacesContext fc, String viewId) - { - // allow custom view change logic - - // clear page resources - Map<String, Object> sm = FacesUtils.getSessionMap(fc); - if (sm!=null) - sm.remove(FacesUtils.PAGE_RESOURCE_MAP_ATTRIBUTE); - } - - public void addJavascriptCall(final FacesContext fc, String function) - { - throw new NotSupportedException(this, "addJavascriptCall"); - } - - /** - * return the interface for Implementation specific features - * that are specific for Mojarra or MyFaces - */ - public FacesImplementation getFacesImplementation() - { - return facesImpl; - } - - /** - * returns the web context path as returned from ServletContext.getContextPath() - */ - public String getWebRoot() - { - return webRoot; - } - - /** - * returns the active locale for a given FacesContext - */ - public Locale getContextLocale(final FacesContext ctx) - { - UIViewRoot root; - // Start out with the default locale - Locale locale; - Locale defaultLocale = Locale.getDefault(); - locale = defaultLocale; - // See if this FacesContext has a ViewRoot - if (null != (root = ctx.getViewRoot())) - { - // If so, ask it for its Locale - if (null == (locale = root.getLocale())) - { - // If the ViewRoot has no Locale, fall back to the default. - locale = defaultLocale; - } - } - return locale; - } - - public TextResolver getTextResolver(Locale locale) - { - // No text Resolvers provided - if (textResolvers == null || textResolvers.length == 0) - { - throw new NotSupportedException(this, "getTextResolver"); - } - // Lookup resolver for locale - for (int i = 0; i < textResolvers.length; i++) - if (locale.equals(textResolvers[i].getLocale())) - return textResolvers[i]; - // locale not found: return default - return textResolvers[0]; - } - - public TextResolver getTextResolver(FacesContext ctx) - { - return getTextResolver(getContextLocale(ctx)); - } - - /** - * checks if the current context contains an error - * @param fc the FacesContext - * @return true if the context has an error set or false otherwise - */ - public boolean hasError(final FacesContext fc) - { - Iterator<FacesMessage> msgIterator = fc.getMessages(); - if (msgIterator != null) - { // Check Messages - while (msgIterator.hasNext()) - { // Check Severity - Severity fms = msgIterator.next().getSeverity(); - if (fms == FacesMessage.SEVERITY_ERROR || fms == FacesMessage.SEVERITY_FATAL) - return true; - } - } - return false; - } - - /** - * returns true if a form input element has been partially submitted - * @param fc the Faces Context - * @return the componentId or null if no partial submit was been performed - */ - public boolean isPartialSubmit(final FacesContext fc) - { - // Override for your JSF component Framework. e.g. for IceFaces - // Map<String,String> parameterMap = fc.getExternalContext().getRequestParameterMap(); - // return ObjectUtils.getBoolean(parameterMap.get("ice.submit.partial")); - return false; - } - - /** - * returns the componentId for which a partial submit has been performed. - * @param fc the Faces Context - * @return the componentId or null if no partial submit was been performed - */ - public String getPartialSubmitComponentId(final FacesContext fc) - { - // Override for your JSF component Framework. e.g. for IceFaces - // Map<String,String> parameterMap = fc.getExternalContext().getRequestParameterMap(); - // return parameterMap.get("ice.event.captured"); - return null; - } - - /** - * finds the component with the given id that is located in the same NamingContainer as a given component - * @param fc the FacesContext - * @param componentId the component id - * @param nearComponent a component within the same naming container from which to start the search (optional) - * @return the component or null if no component was found - */ - public UIComponent findComponent(FacesContext fc, String componentId, UIComponent nearComponent) - { - if (StringUtils.isEmpty(componentId)) - throw new InvalidArgumentException("componentId", componentId); - // Begin search near given component (if any) - UIComponent component = null; - if (nearComponent != null) - { // Search below the nearest naming container - component = nearComponent.findComponent(componentId); - if (component == null) - { // Recurse upwards - UIComponent nextParent = nearComponent; - while (true) - { - nextParent = nextParent.getParent(); - // search NamingContainers only - while (nextParent != null && !(nextParent instanceof NamingContainer)) - { - nextParent = nextParent.getParent(); - } - if (nextParent == null) - { - break; - } - else - { - component = nextParent.findComponent(componentId); - } - if (component != null) - { - break; - } - } - } - } - // Not found. Search the entire tree - if (component == null) - component = findChildComponent(fc.getViewRoot(), componentId); - // done - return component; - } - - /** - * finds a child component with the given id that is located below the given parent component - * @param parent the parent - * @param componentId the component id - * @return the component or null if no component was found - */ - public static UIComponent findChildComponent(UIComponent parent, String componentId) - { - UIComponent component = null; - if (parent.getChildCount() == 0) - return null; - Iterator<UIComponent> children = parent.getChildren().iterator(); - while (children.hasNext()) - { - UIComponent nextChild = children.next(); - if (nextChild instanceof NamingContainer) - { - component = nextChild.findComponent(componentId); - } - if (component == null) - { - component = findChildComponent(nextChild, componentId); - } - if (component != null) - { - break; - } - } - return component; - } - - /** - * returns the default input control type for a given data Type - * @see org.apache.empire.jsf2.controls.InputControlManager - * @param dataType - * @return an Input Cnotrol type - */ - public String getDefaultControlType(DataType dataType) - { - switch (dataType) - { - case CLOB: - return TextAreaInputControl.NAME; - default: - return TextInputControl.NAME; - } - } - - /* Message handling */ - - protected void initTextResolvers(Application app) - { - int count = 0; - Iterator<Locale> locales = app.getSupportedLocales(); - for (count = 0; locales.hasNext(); count++) - { - locales.next(); - } - - // get message bundles - String messageBundle = app.getMessageBundle(); - textResolvers = new TextResolver[count]; - locales = app.getSupportedLocales(); - for (int i = 0; locales.hasNext(); i++) - { - Locale locale = locales.next(); - textResolvers[i] = new TextResolver(ResourceBundle.getBundle(messageBundle, locale)); - log.info("added TextResolver for {} bundle='{}'", locale.getLanguage(), messageBundle); - } - } - - /** - * returns a connection from the connection pool - * - * @return - */ - protected Connection getConnection(DBDatabase db) - { - // Get From Pool - try - { // Obtain a connection - Connection conn = getAppDataSource(db).getConnection(); - conn.setAutoCommit(false); - return conn; - } - catch (SQLException e) - { - log.error("Failed to get connection from pool.", e); - throw new InternalException(e); - } - } - - /** - * releases a connection from the connection pool - */ - protected void releaseConnection(DBDatabase db, Connection conn, boolean commit) - { - try - { // release connection - if (conn == null) - { - return; - } - // Commit or rollback connection depending on the exit code - if (commit) - { // success: commit all changes - db.commit(conn); - log.debug("REQUEST {}: commited."); - } - else - { // failure: rollback all changes - db.rollback(conn); - log.debug("REQUEST {}: rolled back."); - } - // Release Connection - conn.close(); - // done - if (log.isDebugEnabled()) - log.debug("REQUEST {}: returned connection to pool."); - } - catch (SQLException e) - { - log.error("Error releasing connection", e); - e.printStackTrace(); - } - } - - /** - * returns a connection for the current Request - */ - public Connection getConnectionForRequest(FacesContext fc, DBDatabase db) - { - if (fc == null) - throw new InvalidArgumentException("FacesContext", fc); - if (db == null) - throw new InvalidArgumentException("DBDatabase", db); - // Get Conneciton map - @SuppressWarnings("unchecked") - Map<DBDatabase, Connection> connMap = (Map<DBDatabase, Connection>) FacesUtils.getRequestAttribute(fc, CONNECTION_ATTRIBUTE); - if (connMap != null && connMap.containsKey(db)) - return connMap.get(db); - // Pooled Connection - Connection conn = getConnection(db); - if (conn == null) - return null; - // Add to map - if (connMap == null) - { - connMap = new HashMap<DBDatabase, Connection>(); - FacesUtils.setRequestAttribute(fc, CONNECTION_ATTRIBUTE, connMap); - } - connMap.put(db, conn); - return conn; - } - - /** - * releases the current request connection - * @param fc the FacesContext - * @param commit when true changes are committed otherwise they are rolled back - */ - public void releaseAllConnections(final FacesContext fc, boolean commit) - { - @SuppressWarnings("unchecked") - Map<DBDatabase, Connection> connMap = (Map<DBDatabase, Connection>) FacesUtils.getRequestAttribute(fc, CONNECTION_ATTRIBUTE); - if (connMap != null) - { // Walk the connection map - for (Map.Entry<DBDatabase, Connection> e : connMap.entrySet()) - { - releaseConnection(e.getKey(), e.getValue(), commit); - } - // remove from request map - FacesUtils.setRequestAttribute(fc, CONNECTION_ATTRIBUTE, null); - } - } - - public void releaseAllConnections(final FacesContext fc) - { - releaseAllConnections(fc, !hasError(fc)); - } - - public void releaseConnection(final FacesContext fc, DBDatabase db, boolean commit) - { - @SuppressWarnings("unchecked") - Map<DBDatabase, Connection> connMap = (Map<DBDatabase, Connection>) FacesUtils.getRequestAttribute(fc, CONNECTION_ATTRIBUTE); - if (connMap != null && connMap.containsKey(db)) - { // Walk the connection map - releaseConnection(db, connMap.get(db), commit); - connMap.remove(db); - if (connMap.size() == 0) - FacesUtils.setRequestAttribute(fc, CONNECTION_ATTRIBUTE, null); - } - } - - public void releaseConnection(final FacesContext fc, DBDatabase db) - { - releaseConnection(fc, db, !hasError(fc)); - } - - -} http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java deleted file mode 100644 index accd750..0000000 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesImplementation.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.empire.jsf2.app; - -import javax.el.ValueExpression; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; - -public interface FacesImplementation -{ - /** - * Registers a managed bean - * - * Implementation for Mojarra: - * --------------------------- - * FacesContext fc = FacesContext.getCurrentInstance(); - * BeanManager bm = ApplicationAssociate.getInstance(fc.getExternalContext()).getBeanManager(); - * // check - * if (bm.getRegisteredBeans().containsKey(beanName)) - * throw new ItemExistsException(beanName); - * // register now - * ManagedBeanInfo mbi = new ManagedBeanInfo(beanName, beanClass, "view", null, null, null, null); - * bm.register(mbi); - * - * - * Implementation for MyFaces: - * --------------------------- - * FacesContext fc = FacesContext.getCurrentInstance(); - * RuntimeConfig rc = RuntimeConfig.getCurrentInstance(fc.getExternalContext()); - * // check - * if (rc.getManagedBeans().containsKey(beanName)) - * throw new ItemExistsException(beanName); - * // register now - * ManagedBean mbi = new ManagedBean(); - * mbi.setName(beanName); - * mbi.setBeanClass(beanClass); - * mbi.setScope(scope); - * rc.addManagedBean(beanName, mbi); - * - */ - void registerManagedBean(final String beanName, final String beanClass, final String scope); - - /** - * Returns the parentComponent for a given ValueExpression. - * - * Implementation example: - * ----------------------- - * final ELContext elcontext = fc.getELContext(); - * final Application application = fc.getApplication(); - * return application.getELResolver().getValue(elcontext, null, beanName); - * - */ - public Object getManagedBean(final String beanName, final FacesContext fc); - - /** - * Return the parentComponent for a given ValueExpression. - * - * Implementation for Mojarra: - * --------------------------- - * if (ve instanceof ContextualCompositeValueExpression) - * { - * FacesContext ctx = FacesContext.getCurrentInstance(); - * ContextualCompositeValueExpression ccve = (ContextualCompositeValueExpression)ve; - * CompositeComponentStackManager manager = CompositeComponentStackManager.getManager(ctx); - * UIComponent cc = manager.findCompositeComponentUsingLocation(ctx, ccve.getLocation()); - * // set Parent - * return cc; - * } - */ - UIComponent getValueParentComponent(final ValueExpression ve); - -} http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java index 700b6b3..258cf49 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesRequestPhaseListener.java @@ -47,16 +47,15 @@ public class FacesRequestPhaseListener implements PhaseListener public void beforePhase(PhaseEvent pe) { // Only when rendering the response - if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE) - { - FacesContext facesContext = pe.getFacesContext(); - HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); - response.addHeader("Pragma", "no-cache"); - response.addHeader("Cache-Control", "no-cache"); - response.addHeader("Cache-Control", "no-store"); - response.addHeader("Cache-Control", "must-revalidate"); - } - // default + if (pe.getPhaseId() != PhaseId.RENDER_RESPONSE) + return; + // Add header information + FacesContext facesContext = pe.getFacesContext(); + HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); + response.addHeader("Pragma", "no-cache"); + response.addHeader("Cache-Control", "no-cache"); + response.addHeader("Cache-Control", "no-store"); + response.addHeader("Cache-Control", "must-revalidate"); } /** @@ -65,15 +64,15 @@ public class FacesRequestPhaseListener implements PhaseListener @Override public void afterPhase(PhaseEvent pe) { - // Cleanup + // Check Response complete FacesContext ctx = pe.getFacesContext(); if (pe.getPhaseId() == PhaseId.RENDER_RESPONSE || ctx.getResponseComplete()) - { - FacesApplication app = FacesApplication.getInstance(); + { // Cleanup when response is complete + WebApplication app = WebApplication.getInstance(); if (app!=null) app.onRequestComplete(ctx); else - log.warn("No FacesApplication available to complete and cleanup request. Please create a managed bean of name "+FacesApplication.APPLICATION_BEAN_NAME); + log.warn("No WebApplication available to complete and cleanup request. Please create a managed bean of name "+WebApplication.APPLICATION_BEAN_NAME); } } http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java deleted file mode 100644 index 9c37549..0000000 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesStartupListener.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.empire.jsf2.app; - -import javax.faces.application.Application; -import javax.faces.context.FacesContext; -import javax.faces.event.AbortProcessingException; -import javax.faces.event.PostConstructApplicationEvent; -import javax.faces.event.PreDestroyApplicationEvent; -import javax.faces.event.SystemEvent; -import javax.faces.event.SystemEventListener; -import javax.servlet.ServletContext; - -import org.apache.empire.jsf2.app.impl.MojarraImplementation; -import org.apache.empire.jsf2.app.impl.MyFacesImplementation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FacesStartupListener implements SystemEventListener -{ - private static final Logger log = LoggerFactory.getLogger(FacesStartupListener.class); - - @Override - public boolean isListenerForSource(Object source) - { - return (source instanceof Application); - } - - @Override - public void processEvent(SystemEvent event) - throws AbortProcessingException - { - log.info("ApplicationStartupListener:processEvent"); - if (event instanceof PostConstructApplicationEvent) - { - FacesContext startupContext = FacesContext.getCurrentInstance(); - // detect implementation - FacesImplementation facesImplementation = detectFacesImplementation(); - Object app = facesImplementation.getManagedBean(FacesApplication.APPLICATION_BEAN_NAME, startupContext); - if (!(app instanceof FacesApplication)) - throw new AbortProcessingException("Error: Application is not a "+FacesApplication.class.getName()+" instance. Please create a ApplicationFactory!"); - // Create and Init application - FacesApplication facesApp = (FacesApplication)app; - facesApp.init(facesImplementation, startupContext); - // Set Servlet Attribute - ServletContext servletContext = (ServletContext) startupContext.getExternalContext().getContext(); - if (servletContext.getAttribute(FacesApplication.APPLICATION_BEAN_NAME)!=facesApp) - { - log.warn("WARNING: Ambiguous application definition. An object of name '{}' already exists on application scope!", FacesApplication.APPLICATION_BEAN_NAME); - } - } - else if (event instanceof PreDestroyApplicationEvent) - { - log.info("Processing PreDestroyApplicationEvent"); - } - - } - - /** - * Detects the JSF Implementation and returns an implmentation handler class. - * Supported Implementations are Sun Mojarra (2.2.x) and Apache MyFaces (2.2.x) - * @return - */ - protected FacesImplementation detectFacesImplementation() - { - log.debug("Detecting JSF-Implementation..."); - // Test for Apache MyFaces - try { - Class.forName("org.apache.myfaces.application.ApplicationFactoryImpl"); - return new MyFacesImplementation(); - } catch (ClassNotFoundException e) { - // It's not MyFaces - } - // Test for Sun Mojarra - try { - Class.forName("com.sun.faces.application.ApplicationFactoryImpl"); - return new MojarraImplementation(); - } catch (ClassNotFoundException e) { - // It's not Mojarra - } - // Not found - log.error("JSF-Implementation missing or unknown. Please make sure either Apache MyFaces or Sun Mojarra implementation is provided"); - throw new UnsupportedOperationException(); - } - -} http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java index dd0f373..904cd7d 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java @@ -22,15 +22,24 @@ import java.io.File; import java.io.IOException; import java.sql.Connection; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import javax.el.ValueExpression; import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.component.UIInput; +import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.apache.empire.commons.ObjectUtils; +import org.apache.empire.commons.StringUtils; +import org.apache.empire.data.Column; import org.apache.empire.db.DBDatabase; +import org.apache.empire.exceptions.EmpireException; +import org.apache.empire.exceptions.InternalException; import org.apache.empire.jsf2.pages.Page; import org.apache.empire.jsf2.pages.PageDefinition; import org.apache.empire.jsf2.pages.PageOutcome; @@ -47,9 +56,9 @@ public class FacesUtils /* App */ - public static FacesApplication getFacesApplication() + public static WebApplication getWebApplication() { - return FacesApplication.getInstance(); + return WebApplication.getInstance(); } public static FacesContext getContext() @@ -65,22 +74,51 @@ public class FacesUtils } /* Request */ - - public static Map<String, Object> getRequestMap(final FacesContext fc) - { - return fc.getExternalContext().getRequestMap(); - } public static HttpServletRequest getHttpRequest(final FacesContext fc) { return (HttpServletRequest) fc.getExternalContext().getRequest(); } + + public static String getRequestUserAgent() + { + String agent = null; + Object req = FacesContext.getCurrentInstance().getExternalContext().getRequest(); + if (req instanceof HttpServletRequest) + { + agent = ((HttpServletRequest)req).getHeader("user-agent"); + } + return (agent!=null ? agent : ""); + } + + public static boolean isRequestUserAgentIE() + { + String userAgent = getRequestUserAgent(); + return (userAgent.indexOf("MSIE")>=0); + } + + public static String getRequestContextPath() + { + return FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); + } + + public static Object getRequestAttribute(final String key) + { + FacesContext fc = getContext(); + return getRequestAttribute(fc, key); + } public static Object getRequestAttribute(final FacesContext fc, final String key) { return getHttpRequest(fc).getAttribute(key); } + public static void setRequestAttribute(final String key, Object value) + { + FacesContext fc = getContext(); + setRequestAttribute(fc, key, value); + } + public static void setRequestAttribute(final FacesContext fc, final String key, Object value) { if (value!=null) @@ -94,6 +132,27 @@ public class FacesUtils return context.getExternalContext().getRequestParameterMap().get(param); } + public static Object getRequestParam(final String key) + { + FacesContext fc = getContext(); + return getRequestParam(fc, key); + } + + public static boolean isSkipInputValidation(final FacesContext fc) + { + // Skip validate + String val = FacesUtils.getRequestParam(fc, SKIP_INPUT_VALIDATION_PARAM); + return (val!=null && ObjectUtils.getBoolean(val)); + } + + public static boolean isSkipInputValidation() + { + FacesContext fc = getContext(); + return isSkipInputValidation(fc); + } + + /* Navigation */ + public static void redirectDirectly(final FacesContext fc, final String url) { try @@ -128,17 +187,17 @@ public class FacesUtils public Connection getConnection(final FacesContext fc, DBDatabase db) { - return getFacesApplication().getConnectionForRequest(fc, db); + return getWebApplication().getConnectionForRequest(fc, db); } public void releaseAllConnections(final FacesContext fc, boolean commit) { - getFacesApplication().releaseAllConnections(fc, commit); + getWebApplication().releaseAllConnections(fc, commit); } public void releaseAllConnections(final FacesContext fc, DBDatabase db, boolean commit) { - getFacesApplication().releaseConnection(fc, db, commit); + getWebApplication().releaseConnection(fc, db, commit); } /* Pages */ @@ -164,6 +223,11 @@ public class FacesUtils } return (ParameterMap)pm; } + + public static ParameterMap getParameterMap() + { + return getParameterMap(getContext()); + } /* PageResource-map */ public static final String PAGE_RESOURCE_MAP_ATTRIBUTE = "pageResources"; /** use el-expression: #{pageResources.xxx} **/ @@ -180,6 +244,11 @@ public class FacesUtils return rm; } + public static Map<String, Object> getPageResourceMap() + { + return getPageResourceMap(getContext()); + } + /* Managed Beans */ public static Object getManagedBean(final FacesContext fc, final String name) @@ -197,7 +266,7 @@ public class FacesUtils final Application application = fc.getApplication(); return application.getELResolver().getValue(elcontext, null, name); */ - return getFacesApplication().getFacesImplementation().getManagedBean(name, fc); + return getWebApplication().getFacesImplementation().getManagedBean(name, fc); } public static <T> T getManagedBean(final FacesContext fc, final Class<T> cls) @@ -211,6 +280,12 @@ public class FacesUtils log.warn("Managed Bean {} ist not available.", name); return bean; } + + public static <T> T getManagedBean(final Class<T> cls) + { + FacesContext fc = getContext(); + return getManagedBean(fc, cls); + } /* @SuppressWarnings("unchecked") @@ -232,18 +307,23 @@ public class FacesUtils String realPath = getRealPath(fc, path); return realPath.endsWith(File.separator) ? realPath+file : realPath + File.separator + file ; } - + /* Messages */ public static TextResolver getTextResolver(final FacesContext fc) { - return getFacesApplication().getTextResolver(fc); + return getWebApplication().getTextResolver(fc); } public static String getMessage(final FacesContext fc, String key) { return getTextResolver(fc).resolveKey(key); } + + public static String getMessage(String messageKey) + { + return getMessage(getContext(), messageKey); + } public static void addInfoMessage(FacesContext fc, String clientId, String msg) { @@ -281,12 +361,82 @@ public class FacesUtils fc.getExternalContext().getRequestMap().put("CLEAR_SUBMITTED_VALUES", validate); } */ + + public static FacesMessage getFacesErrorMessage(FacesContext fc, Throwable t) + { + if (!(t instanceof EmpireException)) + t = new InternalException(t); + // Get Message + TextResolver tr = getWebApplication().getTextResolver(fc); + String msg = tr.getExceptionMessage((EmpireException)t); + // create Faces Message + return new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null); + } + + public static void redirectFromError(Page page, Throwable t) + { + PageOutcome pageTarget = page.getPageDefinition().getOutcome(); + // throw new InternalException(e); + FacesContext fc = FacesUtils.getContext(); + boolean committed = fc.getExternalContext().isResponseCommitted(); + if (committed) + { log.warn("Cannot redirect to {} from an already committed response! Error is {}.", pageTarget, t.getMessage()); + return; + } + // redirect to target page + FacesMessage facesMsg = getFacesErrorMessage(fc, t); + ExternalContext ec = fc.getExternalContext(); + ec.getSessionMap().put("PAGE_SESSION_MESSAGE", facesMsg); + // redirect + FacesUtils.redirectDirectly(fc, pageTarget); + } + + + /* Component search */ + public static UIInput findInputComponent(UIComponent parent, Column column) + { + // Get Children + Iterator<UIComponent> children = parent.getFacetsAndChildren(); + while (children.hasNext()) + { // Iterate through all children + UIComponent nextChild = children.next(); + log.info("Checking child {}", nextChild.getClass().getName()); + if (nextChild instanceof UIInput) + { // Check Column Attribute + Object col = nextChild.getAttributes().get("column"); + if (col==null) + { // Check ID + ValueExpression ve = nextChild.getValueExpression("column"); + if (ve!=null) + log.warn("TODO: evaluate Value Expression!"); + } + else if (column.equals(col)) + { // check form + return (UIInput)nextChild; + } + } + else + { // recurse children and facets + UIInput input = findInputComponent(nextChild, column); + if (input!=null) + return input; + } + } + // Not found + return null; + } - public static boolean isSkipInputValidation(final FacesContext fc) + public static UIInput findInputComponent(FacesContext fc, String formId, Column column) { - // Skip validate - String val = FacesUtils.getRequestParam(fc, SKIP_INPUT_VALIDATION_PARAM); - return (val!=null && ObjectUtils.getBoolean(val)); + UIComponent parent = fc.getViewRoot(); + if (StringUtils.isNotEmpty(formId)) + { + parent = WebApplication.findChildComponent(parent, formId); + if (parent==null) + return null; // not found + } + // find + return findInputComponent(parent, column); } } http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/TextResolver.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/TextResolver.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/TextResolver.java index acb925c..b274a66 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/TextResolver.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/TextResolver.java @@ -19,101 +19,17 @@ package org.apache.empire.jsf2.app; import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import org.apache.empire.exceptions.EmpireException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TextResolver +public interface TextResolver { - private static final Logger log = LoggerFactory.getLogger(TextResolver.class); - public static String MSG_KEY_INDICATOR = "!"; - - private final ResourceBundle resBundle; - - public TextResolver(ResourceBundle resBundle) - { - this.resBundle = resBundle; - } - - public final ResourceBundle getResourceBundle() - { - return resBundle; - } - public final Locale getLocale() - { - return resBundle.getLocale(); - } + Locale getLocale(); - public String resolveKey(String key) - { - try - { - String res = resBundle.getString(key); - if (res==null) - throw new MissingResourceException("Message Key not found.", String.class.getSimpleName(), key); - return res; - } - catch (MissingResourceException e) - { - log.error("Message key missing '{}'.", key); - return "["+key+"]"; - } - catch (Exception e) - { - log.error("Error resolving text: {}", e); - return "["+key+"]"; - } - } + String resolveKey(String key); + + String resolveText(String text); - public String resolveText(String text) - { - // Translate - if (text != null && text.startsWith(MSG_KEY_INDICATOR)) - { - String key = text.substring(1); - return resolveKey(key); - } - return text; - } + String getExceptionMessage(Exception e); - public String getExceptionMessage(Exception e) - { - if (e instanceof EmpireException) - { - EmpireException ee = (EmpireException)e; - String key = ee.getErrorType().getKey(); - // get Pattern - String pattern; - if (resBundle.containsKey(key)) - { // Get Pattern - pattern = resBundle.getString(key); - } - else - { // No error message pattern provided. Using default - pattern = ee.getErrorType().getMessagePattern(); - log.error("Error resolving error messsage pattern: {}", key); - } - // get Params and translate - String[] params = ee.getErrorParams(); - if (params!=null) - { for (int i=0; i<params.length; i++) - params[i] = resolveText(params[i]); - } - // Format message - return EmpireException.formatErrorMessage(ee.getErrorType(), pattern, params); - } - else - { // Other exception try to resolve by class name - String key = "exception."+e.getClass().getName(); - if (resBundle.containsKey(key)) - return resBundle.getString(key); - // not provided - return e.getLocalizedMessage(); - } - } } http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java deleted file mode 100644 index 762ee7f..0000000 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MojarraImplementation.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.empire.jsf2.app.impl; - -import java.util.Map; - -import javax.el.ValueExpression; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; - -import org.apache.empire.exceptions.ItemExistsException; -import org.apache.empire.jsf2.app.FacesApplication; -import org.apache.empire.jsf2.app.FacesImplementation; - -import com.sun.faces.application.ApplicationAssociate; -import com.sun.faces.application.ApplicationFactoryImpl; -import com.sun.faces.application.InjectionApplicationFactory; -import com.sun.faces.component.CompositeComponentStackManager; -import com.sun.faces.facelets.el.ContextualCompositeValueExpression; -import com.sun.faces.mgbean.BeanManager; -import com.sun.faces.mgbean.ManagedBeanInfo; - -public class MojarraImplementation implements FacesImplementation -{ - private BeanManager bm; - - /* - @Override - public void initApplication(final FacesApplication application) - { - ApplicationFactoryImpl applFactoryImpl = new ApplicationFactoryImpl(); - // set impl - application.setImplementation(this, applFactoryImpl.getApplication()); - // Application Map - Map<String, Object> appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap(); - appMap.put(InjectionApplicationFactory.class.getName(), application); - // init Bean Manager - FacesContext fc = FacesContext.getCurrentInstance(); - bm = ApplicationAssociate.getInstance(fc.getExternalContext()).getBeanManager(); - } - */ - - @Override - public void registerManagedBean(final String beanName,final String beanClass,final String scope) - { - // check - if (bm.getRegisteredBeans().containsKey(beanName)) - { - throw new ItemExistsException(beanName); - } - // register now - ManagedBeanInfo mbi = new ManagedBeanInfo(beanName, beanClass, "view", null, null, null, null); - bm.register(mbi); - } - - @Override - public Object getManagedBean(final String beanName, final FacesContext fc) - { - // Find Bean - if (bm==null) - bm = ApplicationAssociate.getInstance(fc.getExternalContext()).getBeanManager(); - Object mbean = bm.getBeanFromScope(beanName, fc); - if (mbean==null) - mbean= bm.create(beanName, fc); - return mbean; - } - - @Override - public UIComponent getValueParentComponent(final ValueExpression ve) - { - if (ve instanceof ContextualCompositeValueExpression) - { - FacesContext ctx = FacesContext.getCurrentInstance(); - ContextualCompositeValueExpression ccve = (ContextualCompositeValueExpression)ve; - CompositeComponentStackManager manager = CompositeComponentStackManager.getManager(ctx); - UIComponent cc = manager.findCompositeComponentUsingLocation(ctx, ccve.getLocation()); - // set Parent - return cc; - } - return null; - } - -} http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java deleted file mode 100644 index 3d00caa..0000000 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/impl/MyFacesImplementation.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.empire.jsf2.app.impl; - -import javax.el.ELContext; -import javax.el.ValueExpression; -import javax.faces.application.Application; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; - -import org.apache.empire.exceptions.ItemExistsException; -import org.apache.empire.jsf2.app.FacesImplementation; -import org.apache.myfaces.config.RuntimeConfig; -import org.apache.myfaces.config.impl.digester.elements.ManagedBeanImpl; - -public class MyFacesImplementation implements FacesImplementation -{ - /* - @Override - public void initApplication(FacesApplication application) - { - ApplicationFactoryImpl applFactoryImpl = new ApplicationFactoryImpl(); - // set impl - application.setImplementation(this, applFactoryImpl.getApplication()); - applFactoryImpl.setApplication(application); - } - */ - - @Override - public void registerManagedBean(final String beanName, final String beanClass, final String scope) { - - // get Runtime Config - FacesContext fc = FacesContext.getCurrentInstance(); - RuntimeConfig rc = RuntimeConfig.getCurrentInstance(fc.getExternalContext()); - // check - if (rc.getManagedBeans().containsKey(beanName)) - { - throw new ItemExistsException(beanName); - } - // register now - // ManagedBean mbi = new ManagedBean(); --> Use this for Myfaces 2.1.x - ManagedBeanImpl mbi = new ManagedBeanImpl(); // new since Myfaces 2.2.x - mbi.setName(beanName); - mbi.setBeanClass(beanClass); - mbi.setScope(scope); - rc.addManagedBean(beanName, mbi); - } - - @Override - public Object getManagedBean(final String beanName, final FacesContext fc) - { - // Find Bean - final ELContext elcontext = fc.getELContext(); - final Application application = fc.getApplication(); - return application.getELResolver().getValue(elcontext, null, beanName); - } - - @Override - public UIComponent getValueParentComponent(final ValueExpression ve) - { - /* No implmentation for MyFaces currently available */ - return null; - } - -} http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java index 375acb1..00e07da 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java @@ -37,7 +37,7 @@ import org.apache.empire.exceptions.EmpireException; import org.apache.empire.exceptions.InternalException; import org.apache.empire.exceptions.ItemNotFoundException; import org.apache.empire.exceptions.MiscellaneousErrorException; -import org.apache.empire.jsf2.app.FacesApplication; +import org.apache.empire.jsf2.app.WebApplication; import org.apache.empire.jsf2.app.FacesUtils; import org.apache.empire.jsf2.app.TextResolver; import org.apache.empire.jsf2.utils.ParameterMap; @@ -393,7 +393,7 @@ public abstract class Page implements Serializable */ public Connection getConnection(DBDatabase db) { - FacesApplication app = FacesUtils.getFacesApplication(); + WebApplication app = FacesUtils.getWebApplication(); return app.getConnectionForRequest(FacesUtils.getContext(), db); } @@ -417,7 +417,7 @@ public abstract class Page implements Serializable } // Add Call FacesContext fc = FacesUtils.getContext(); - FacesApplication app = FacesUtils.getFacesApplication(); + WebApplication app = FacesUtils.getWebApplication(); app.addJavascriptCall(fc, function); } @@ -494,6 +494,6 @@ public abstract class Page implements Serializable protected final TextResolver getTextResolver() { FacesContext fc = FacesUtils.getContext(); - return FacesUtils.getFacesApplication().getTextResolver(fc); + return FacesUtils.getWebApplication().getTextResolver(fc); } } http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java index b38be21..eb97139 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java @@ -24,7 +24,7 @@ import java.util.LinkedHashMap; import org.apache.empire.commons.StringUtils; import org.apache.empire.exceptions.ItemExistsException; import org.apache.empire.exceptions.MiscellaneousErrorException; -import org.apache.empire.jsf2.app.FacesImplementation; +import org.apache.empire.jsf2.impl.FacesImplementation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java index daf79c9..9c140b8 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java @@ -92,7 +92,7 @@ public class PagePhaseListener implements PhaseListener Object lastViewId = sessionMap.get(LAST_PAGE_VIEW_ID); if (lastViewId == null || !(((String) lastViewId).equalsIgnoreCase(viewId))) { // view changes - FacesUtils.getFacesApplication().onChangeView(fc, viewId); + FacesUtils.getWebApplication().onChangeView(fc, viewId); if (fc.getResponseComplete()) return; // set view Id http://git-wip-us.apache.org/repos/asf/empire-db/blob/bcff43b8/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java ---------------------------------------------------------------------- diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java index bf26e74..a4ae7af 100644 --- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java +++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java @@ -58,7 +58,7 @@ import org.apache.empire.exceptions.InternalException; import org.apache.empire.exceptions.InvalidArgumentException; import org.apache.empire.exceptions.NotSupportedException; import org.apache.empire.exceptions.PropertyReadOnlyException; -import org.apache.empire.jsf2.app.FacesApplication; +import org.apache.empire.jsf2.app.WebApplication; import org.apache.empire.jsf2.app.FacesUtils; import org.apache.empire.jsf2.app.TextResolver; import org.apache.empire.jsf2.components.ControlTag; @@ -428,7 +428,7 @@ public class TagEncodingHelper implements NamingContainer else { // get from data type DataType dataType = column.getDataType(); - controlType = FacesUtils.getFacesApplication().getDefaultControlType(dataType); + controlType = FacesUtils.getWebApplication().getDefaultControlType(dataType); } // get default control control = InputControlManager.getControl(controlType); @@ -506,7 +506,7 @@ public class TagEncodingHelper implements NamingContainer public boolean isPartialSubmit(FacesContext ctx) { - return FacesUtils.getFacesApplication().isPartialSubmit(ctx); + return FacesUtils.getWebApplication().isPartialSubmit(ctx); } public boolean isSkipValidation() @@ -918,7 +918,7 @@ public class TagEncodingHelper implements NamingContainer if (ve instanceof FacesWrapper<?>) ve = ((FacesWrapper<ValueExpression>)ve).getWrapped(); // find parent - UIComponent valueParent = FacesUtils.getFacesApplication().getFacesImplementation().getValueParentComponent(ve); + UIComponent valueParent = FacesUtils.getWebApplication().getFacesImplementation().getValueParentComponent(ve); if (valueParent!=null) { // use the value parent parent = valueParent; @@ -1098,7 +1098,7 @@ public class TagEncodingHelper implements NamingContainer public TextResolver getTextResolver(FacesContext context) { if (textResolver==null) - textResolver=FacesApplication.getInstance().getTextResolver(context); + textResolver=WebApplication.getInstance().getTextResolver(context); return textResolver; } @@ -1216,7 +1216,7 @@ public class TagEncodingHelper implements NamingContainer // for if (StringUtils.isNotEmpty(forInput) && !forInput.equals("*")) { // Set Label input Id - UIComponent input = FacesUtils.getFacesApplication().findComponent(context, forInput, tag); + UIComponent input = FacesUtils.getWebApplication().findComponent(context, forInput, tag); if (input!=null && (input instanceof InputTag)) { // Check Read-Only InputTag inputTag = ((InputTag)input); @@ -1301,7 +1301,7 @@ public class TagEncodingHelper implements NamingContainer InputTag inputTag = null; if (StringUtils.isNotEmpty(forInput) && !forInput.equals("*")) { // Set Label input Id - UIComponent input = FacesUtils.getFacesApplication().findComponent(context, forInput, tag); + UIComponent input = FacesUtils.getWebApplication().findComponent(context, forInput, tag); if (input!=null && (input instanceof InputTag)) { // Check Read-Only inputTag = ((InputTag)input);
