Author: alexsmirnov
Date: 2007-06-29 12:37:49 -0400 (Fri, 29 Jun 2007)
New Revision: 1411
Added:
branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
Removed:
branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
Log:
Move AjaxChildrenRenderer to API
Copied:
branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
(from rev 1393,
branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java)
===================================================================
---
branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
(rev 0)
+++
branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java 2007-06-29
16:37:49 UTC (rev 1411)
@@ -0,0 +1,205 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.framework.renderer;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.ajax.UILoadBundle;
+import org.ajax4jsf.framework.ajax.AjaxChildrenEncoder;
+import org.ajax4jsf.framework.ajax.AjaxOutput;
+import org.ajax4jsf.framework.util.message.Messages;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author shura
+ *
+ */
+public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase {
+
+ public static final Log log = LogFactory.getLog(AjaxChildrenRenderer.class);
+
+ public static final String[] SPECIAL_COMPONENTS_TYPES = {
+ UILoadBundle.COMPONENT_TYPE, "org.apache.myfaces.AliasBean",
+ "org.apache.myfaces.AliasBeansScope" };
+ private static final String SPECIAL_TYPES_PARAMETER =
"org.ajax4jsf.CONTROL_COMPONENTS";
+
+ /**
+ * Iterate over all childs of components. If component id contains in list ,
+ * or, if list is empty, compotents is submitted form - render it. TODO -
+ * Instead of calculate full path for every component, build current Path
+ * for componet and send as parameter.
+ *
+ * @param context -
+ * current context
+ * @param component -
+ * curent faces component.
+ * @param ids -
+ * list of Id to render.
+ * @throws IOException
+ * @deprecated Use {@link #encodeAjaxChildren(FacesContext,UIComponent,String,Set,Set)}
instead
+ */
+ public void encodeAjaxChild(FacesContext context, UIComponent component, String path,
Set ids, Set renderedAreas) throws IOException {
+ encodeAjaxChildren(context, component, path, ids, renderedAreas);
+ }
+
+ /**
+ * Iterate over all childs of components. If component id contains in list ,
+ * or, if list is empty, compotents is submitted form - render it. TODO -
+ * Instead of calculate full path for every component, build current Path
+ * for componet and send as parameter.
+ *
+ * @param context -
+ * current context
+ * @param component -
+ * curent faces component.
+ * @param ids -
+ * list of Id to render.
+ * @throws IOException
+ */
+ public void encodeAjaxChildren(FacesContext context, UIComponent component, String path,
Set ids, Set renderedAreas) throws IOException {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO,
+ path, component.getId()));
+ }
+ String currentPath = path;
+ if (component instanceof NamingContainer) {
+ currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
+ }
+ for (Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
+ UIComponent element = (UIComponent) it.next();
+ encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
+ }
+ }
+
+ /**
+ * @param context
+ * @param component
+ * @param currentPath
+ * @param ids
+ * @param renderedAreas
+ * @throws IOException
+ */
+ public void encodeAjaxComponent(FacesContext context, UIComponent component, String
currentPath, Set ids, Set renderedAreas) throws IOException {
+ if (component.isRendered()) { // skip not-rendered components.
+ boolean found = false;
+ if (!ids.isEmpty()) {
+ // list for rendering may contains absolute id ( best ),
+ // component Id or client ID
+ String elementId = component.getId();
+ String absoluteId = currentPath + elementId;
+ // String clientId = element.getClientId(context);
+ if (ids.contains(absoluteId) || ids.contains(elementId)) {
+ if (log.isDebugEnabled()) {
+ log
+ .debug(Messages.getMessage(
+ Messages.RENDER_AJAX_AREA_INFO,
+ absoluteId));
+ }
+ // renderChild(context, element);
+ found = true;
+ }
+ }
+ if (!found && component instanceof AjaxOutput) {
+ if (((AjaxOutput) component).isAjaxRendered()) {
+ // renderChild(context, element);
+ found = true;
+ }
+
+ }
+
+ if (!found) {
+ if (component instanceof AjaxChildrenEncoder) {
+ ((AjaxChildrenEncoder) component).encodeAjaxChild(
+ context, currentPath, ids, renderedAreas);
+ } else {
+ // Special case - for control components, not produced
+ // html code - such as message bundles loaders,
+ // MyFaces aliases etc. we call encodeBegin/end methods
+ // even if components not in rendered areas.
+ boolean special = isSpecialElement(context, component);
+ if (special) {
+ component.encodeBegin(context);
+ }
+ encodeAjaxChildren(context, component, currentPath, ids,
+ renderedAreas);
+ if (special) {
+ component.encodeEnd(context);
+ }
+
+ }
+ } else {
+ renderedAreas.add(component.getClientId(context));
+ renderChild(context, component);
+ }
+ }
+ }
+
+ private Set _specialComponentTypes = null;
+
+ /**
+ * Detect component as special control case - such as messages bundle
+ * loader, alias bean components etc. Type of component get by reflection
+ * from static field COMPONENT_TYPE
+ *
+ * @param context
+ * @param component
+ * @return true if encode methods must be called for this component even in
+ * not-rendered parts.
+ */
+ private boolean isSpecialElement(FacesContext context, UIComponent component) {
+ if (_specialComponentTypes == null) {
+ _specialComponentTypes = new HashSet(10);
+ for (int i = 0; i < SPECIAL_COMPONENTS_TYPES.length; i++) {
+ _specialComponentTypes.add(SPECIAL_COMPONENTS_TYPES[i]);
+ }
+ String special = context.getExternalContext().getInitParameter(
+ SPECIAL_TYPES_PARAMETER);
+ if (null != special) {
+ String[] split = special.split(",");
+ for (int i = 0; i < split.length; i++) {
+ _specialComponentTypes.add(split[i]);
+ }
+ }
+ }
+ boolean result;
+ try {
+ String componentType = (String) component.getClass().getField(
+ "COMPONENT_TYPE").get(null);
+ result = _specialComponentTypes.contains(componentType);
+ } catch (Exception e) {
+ // exception occurs if component not have accesible COMPONENT_TYPE
+ // constant
+ // we assume that component not in special types.
+ result = false;
+ }
+ return result;
+ }
+
+}
Deleted:
branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
===================================================================
---
branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java 2007-06-29
16:15:16 UTC (rev 1410)
+++
branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java 2007-06-29
16:37:49 UTC (rev 1411)
@@ -1,205 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.framework.renderer;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.ajax.UILoadBundle;
-import org.ajax4jsf.framework.ajax.AjaxChildrenEncoder;
-import org.ajax4jsf.framework.ajax.AjaxOutput;
-import org.ajax4jsf.framework.util.message.Messages;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author shura
- *
- */
-public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase {
-
- public static final Log log = LogFactory.getLog(AjaxChildrenRenderer.class);
-
- public static final String[] SPECIAL_COMPONENTS_TYPES = {
- UILoadBundle.COMPONENT_TYPE, "org.apache.myfaces.AliasBean",
- "org.apache.myfaces.AliasBeansScope" };
- private static final String SPECIAL_TYPES_PARAMETER =
"org.ajax4jsf.CONTROL_COMPONENTS";
-
- /**
- * Iterate over all childs of components. If component id contains in list ,
- * or, if list is empty, compotents is submitted form - render it. TODO -
- * Instead of calculate full path for every component, build current Path
- * for componet and send as parameter.
- *
- * @param context -
- * current context
- * @param component -
- * curent faces component.
- * @param ids -
- * list of Id to render.
- * @throws IOException
- * @deprecated Use {@link #encodeAjaxChildren(FacesContext,UIComponent,String,Set,Set)}
instead
- */
- public void encodeAjaxChild(FacesContext context, UIComponent component, String path,
Set ids, Set renderedAreas) throws IOException {
- encodeAjaxChildren(context, component, path, ids, renderedAreas);
- }
-
- /**
- * Iterate over all childs of components. If component id contains in list ,
- * or, if list is empty, compotents is submitted form - render it. TODO -
- * Instead of calculate full path for every component, build current Path
- * for componet and send as parameter.
- *
- * @param context -
- * current context
- * @param component -
- * curent faces component.
- * @param ids -
- * list of Id to render.
- * @throws IOException
- */
- public void encodeAjaxChildren(FacesContext context, UIComponent component, String path,
Set ids, Set renderedAreas) throws IOException {
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO,
- path, component.getId()));
- }
- String currentPath = path;
- if (component instanceof NamingContainer) {
- currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
- }
- for (Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
- UIComponent element = (UIComponent) it.next();
- encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
- }
- }
-
- /**
- * @param context
- * @param component
- * @param currentPath
- * @param ids
- * @param renderedAreas
- * @throws IOException
- */
- public void encodeAjaxComponent(FacesContext context, UIComponent component, String
currentPath, Set ids, Set renderedAreas) throws IOException {
- if (component.isRendered()) { // skip not-rendered components.
- boolean found = false;
- if (!ids.isEmpty()) {
- // list for rendering may contains absolute id ( best ),
- // component Id or client ID
- String elementId = component.getId();
- String absoluteId = currentPath + elementId;
- // String clientId = element.getClientId(context);
- if (ids.contains(absoluteId) || ids.contains(elementId)) {
- if (log.isDebugEnabled()) {
- log
- .debug(Messages.getMessage(
- Messages.RENDER_AJAX_AREA_INFO,
- absoluteId));
- }
- // renderChild(context, element);
- found = true;
- }
- }
- if (!found && component instanceof AjaxOutput) {
- if (((AjaxOutput) component).isAjaxRendered()) {
- // renderChild(context, element);
- found = true;
- }
-
- }
-
- if (!found) {
- if (component instanceof AjaxChildrenEncoder) {
- ((AjaxChildrenEncoder) component).encodeAjaxChild(
- context, currentPath, ids, renderedAreas);
- } else {
- // Special case - for control components, not produced
- // html code - such as message bundles loaders,
- // MyFaces aliases etc. we call encodeBegin/end methods
- // even if components not in rendered areas.
- boolean special = isSpecialElement(context, component);
- if (special) {
- component.encodeBegin(context);
- }
- encodeAjaxChildren(context, component, currentPath, ids,
- renderedAreas);
- if (special) {
- component.encodeEnd(context);
- }
-
- }
- } else {
- renderedAreas.add(component.getClientId(context));
- renderChild(context, component);
- }
- }
- }
-
- private Set _specialComponentTypes = null;
-
- /**
- * Detect component as special control case - such as messages bundle
- * loader, alias bean components etc. Type of component get by reflection
- * from static field COMPONENT_TYPE
- *
- * @param context
- * @param component
- * @return true if encode methods must be called for this component even in
- * not-rendered parts.
- */
- private boolean isSpecialElement(FacesContext context, UIComponent component) {
- if (_specialComponentTypes == null) {
- _specialComponentTypes = new HashSet(10);
- for (int i = 0; i < SPECIAL_COMPONENTS_TYPES.length; i++) {
- _specialComponentTypes.add(SPECIAL_COMPONENTS_TYPES[i]);
- }
- String special = context.getExternalContext().getInitParameter(
- SPECIAL_TYPES_PARAMETER);
- if (null != special) {
- String[] split = special.split(",");
- for (int i = 0; i < split.length; i++) {
- _specialComponentTypes.add(split[i]);
- }
- }
- }
- boolean result;
- try {
- String componentType = (String) component.getClass().getField(
- "COMPONENT_TYPE").get(null);
- result = _specialComponentTypes.contains(componentType);
- } catch (Exception e) {
- // exception occurs if component not have accesible COMPONENT_TYPE
- // constant
- // we assume that component not in special types.
- result = false;
- }
- return result;
- }
-
-}