JBoss Rich Faces SVN: r6628 - trunk/ui/orderingList/src/main/java/org/richfaces/component.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2008-03-08 09:31:11 -0500 (Sat, 08 Mar 2008)
New Revision: 6628
Modified:
trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
Log:
Changes from r5918 reverted
Update model error messages changed to valid ones
Modified: trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java
===================================================================
--- trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2008-03-08 02:12:08 UTC (rev 6627)
+++ trunk/ui/orderingList/src/main/java/org/richfaces/component/UIOrderingBaseComponent.java 2008-03-08 14:31:11 UTC (rev 6628)
@@ -319,7 +319,7 @@
*
*/
protected void validateValue(FacesContext context, Object newValue) {
- /* // If our value is valid, enforce the required property if present
+ // If our value is valid, enforce the required property if present
if (isValid() && isRequired() && isEmpty(newValue)) {
FacesMessage message = MessageUtil.getMessage(context,
UIInput.REQUIRED_MESSAGE_ID,
@@ -375,7 +375,7 @@
}
}
}
- }*/
+ }
}
/**
@@ -427,14 +427,14 @@
}
protected void updateModel(FacesContext context, UpdateModelCommand command) {
- /*try {
+ try {
command.execute(context);
} catch (EvaluationException e) {
String messageStr = e.getMessage();
FacesMessage message = null;
if (null == messageStr) {
message =
- MessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID,
+ MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
new Object[] {MessageUtil.getLabel(context, this)});
}
else {
@@ -446,26 +446,26 @@
}
catch (FacesException e) {
FacesMessage message =
- MessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID,
+ MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
new Object[] {MessageUtil.getLabel(context, this)});
message.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(getClientId(context), message);
setValid(false);
} catch (IllegalArgumentException e) {
FacesMessage message =
- MessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID,
+ MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
new Object[] {MessageUtil.getLabel(context, this)});
message.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(getClientId(context), message);
setValid(false);
} catch (Exception e) {
FacesMessage message =
- MessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID,
+ MessageUtil.getMessage(context, UIInput.UPDATE_MESSAGE_ID,
new Object[] {MessageUtil.getLabel(context, this)});
message.setSeverity(FacesMessage.SEVERITY_ERROR);
context.addMessage(getClientId(context), message);
setValid(false);
- }*/
+ }
}
/**
@@ -493,7 +493,7 @@
protected void addConversionErrorMessage(FacesContext context,
ConverterException ce, Object value) {
- /* FacesMessage message = ce.getFacesMessage();
+ FacesMessage message = ce.getFacesMessage();
if (message == null) {
message = MessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID,
new Object[] {MessageUtil.getLabel(context, this)});
@@ -503,7 +503,7 @@
}
message.setSeverity(FacesMessage.SEVERITY_ERROR);
- context.addMessage(getClientId(context), message);*/
+ context.addMessage(getClientId(context), message);
}
protected boolean isEmpty(Object value) {
16 years, 10 months
JBoss Rich Faces SVN: r6627 - in trunk/framework/impl/src: main/java/org/ajax4jsf/event and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2008-03-07 21:12:08 -0500 (Fri, 07 Mar 2008)
New Revision: 6627
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
trunk/framework/impl/src/main/java/org/ajax4jsf/event/EventsQueue.java
trunk/framework/impl/src/test/java/org/ajax4jsf/event/EventsQueueTest.java
Log:
Implement EventsQueue as Java Collection
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2008-03-08 01:05:20 UTC (rev 6626)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2008-03-08 02:12:08 UTC (rev 6627)
@@ -132,9 +132,9 @@
// in future, with JSF 1.2 it must be done by invokeOnComponent
// method.
// In 1.1 , events to RENDER_RESPONSE phase not used.
- getAjaxEventsQueue(getFacesContext()).add(event);
+ getAjaxEventsQueue(getFacesContext()).offer(event);
} else {
- getEventsQueue(getFacesContext(), event.getPhaseId()).add(event);
+ getEventsQueue(getFacesContext(), event.getPhaseId()).offer(event);
}
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/event/EventsQueue.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/event/EventsQueue.java 2008-03-08 01:05:20 UTC (rev 6626)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/event/EventsQueue.java 2008-03-08 02:12:08 UTC (rev 6627)
@@ -3,6 +3,8 @@
*/
package org.ajax4jsf.event;
+import java.util.AbstractQueue;
+import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.faces.event.FacesEvent;
@@ -12,7 +14,7 @@
* @author asmirnov
*
*/
-public class EventsQueue {
+public class EventsQueue extends AbstractQueue<FacesEvent>{
private QueueElement first;
@@ -25,24 +27,34 @@
* @return faces event form top of queue
* @throws NoSuchElementException , if queue is empty.
*/
- public FacesEvent remove() throws NoSuchElementException {
- if(isEmpty()){
- throw new NoSuchElementException("Events queue is empty");
+ public FacesEvent poll() {
+ FacesEvent element = null;
+ if (!isEmpty()) {
+ element = first.getElement();
+ first = first.getPrevious();
+ if (null == first) {
+ last = null;
+ size = 0;
+ } else {
+ size--;
+ }
}
- FacesEvent element = first.getElement();
- first = first.getPrevious();
- if(null == first){
- last = null;
+ return element;
+ }
+
+ public FacesEvent peek() {
+ FacesEvent element = null;
+ if (!isEmpty()) {
+ element = first.getElement();
}
- size--;
return element;
}
-
/**
* Add event to queue.
* @param element
+ * @return TODO
*/
- public void add(FacesEvent element) {
+ public boolean offer(FacesEvent element) {
QueueElement queueElement = new QueueElement(element);
if(isEmpty()){
first = last = queueElement;
@@ -51,6 +63,7 @@
last = queueElement;
}
size++;
+ return true;
}
public void clear() {
@@ -100,4 +113,31 @@
}
}
+
+ @Override
+ public Iterator<FacesEvent> iterator() {
+
+ return new Iterator<FacesEvent>(){
+
+ private QueueElement current = first;
+
+ public boolean hasNext() {
+ return null != current;
+ }
+
+ public FacesEvent next() {
+ if(null == current){
+ throw new NoSuchElementException();
+ }
+ FacesEvent event = current.getElement();
+ current = current.getPrevious();
+ return event;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ }
}
Modified: trunk/framework/impl/src/test/java/org/ajax4jsf/event/EventsQueueTest.java
===================================================================
--- trunk/framework/impl/src/test/java/org/ajax4jsf/event/EventsQueueTest.java 2008-03-08 01:05:20 UTC (rev 6626)
+++ trunk/framework/impl/src/test/java/org/ajax4jsf/event/EventsQueueTest.java 2008-03-08 02:12:08 UTC (rev 6627)
@@ -45,10 +45,10 @@
public void testRemove() {
ActionEvent event = new ActionEvent(new UICommand());
EventsQueue queue = new EventsQueue();
- queue.add(event);
+ queue.offer(event);
assertFalse(queue.isEmpty());
ActionEvent event2 = new ActionEvent(new UICommand());
- queue.add(event2);
+ queue.offer(event2);
assertSame(event, queue.remove());
assertSame(event2, queue.remove());
assertTrue(queue.isEmpty());
@@ -61,15 +61,15 @@
}
/**
- * Test method for {@link org.ajax4jsf.event.EventsQueue#add(javax.faces.event.FacesEvent)}.
+ * Test method for {@link org.ajax4jsf.event.EventsQueue#offer(javax.faces.event.FacesEvent)}.
*/
public void testAdd() {
ActionEvent event = new ActionEvent(new UICommand());
EventsQueue queue = new EventsQueue();
- queue.add(event);
+ queue.offer(event);
assertFalse(queue.isEmpty());
ActionEvent event2 = new ActionEvent(new UICommand());
- queue.add(event2);
+ queue.offer(event2);
}
/**
@@ -78,10 +78,10 @@
public void testClear() {
ActionEvent event = new ActionEvent(new UICommand());
EventsQueue queue = new EventsQueue();
- queue.add(event);
+ queue.offer(event);
assertFalse(queue.isEmpty());
ActionEvent event2 = new ActionEvent(new UICommand());
- queue.add(event2);
+ queue.offer(event2);
queue.clear();
assertTrue(queue.isEmpty());
}
16 years, 10 months
JBoss Rich Faces SVN: r6626 - in trunk: framework/api/src/main/java/org/ajax4jsf/application and 5 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2008-03-07 20:05:20 -0500 (Fri, 07 Mar 2008)
New Revision: 6626
Removed:
trunk/framework/api/src/main/java/org/ajax4jsf/application/AjaxSingleException.java
trunk/framework/api/src/main/java/org/ajax4jsf/event/AjaxSingleEvent.java
Modified:
trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_region_attributes.ent
trunk/framework/api/src/main/java/org/ajax4jsf/component/AjaxContainerBase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxActionComponent.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java
Log:
Continue to fix JSF 1.2 compatibility.
Modified: trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_region_attributes.ent
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_region_attributes.ent 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/cdk/generator/src/main/resources/META-INF/schema/entities/ajax_region_attributes.ent 2008-03-08 01:05:20 UTC (rev 6626)
@@ -10,6 +10,12 @@
<name>submitted</name>
<classname>boolean</classname>
</property>
+
+ <property hidden="true">
+ <name>submittedControlId</name>
+ <classname>java.lang.String</classname>
+ </property>
+
<property >
<name>selfRendered</name>
<classname>boolean</classname>
Deleted: trunk/framework/api/src/main/java/org/ajax4jsf/application/AjaxSingleException.java
===================================================================
--- trunk/framework/api/src/main/java/org/ajax4jsf/application/AjaxSingleException.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/api/src/main/java/org/ajax4jsf/application/AjaxSingleException.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -1,33 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.application;
-
-import javax.faces.component.UIComponent;
-
-/**
- * @author asmirnov
- *
- */
-public class AjaxSingleException extends RuntimeException {
-
- private static final long serialVersionUID = 6624397496732241667L;
-
- private UIComponent component;
-
- /**
- * @param component
- */
- public AjaxSingleException(UIComponent componemt) {
-// super();
- this.component = componemt;
- }
-
- /**
- * @return the component
- */
- public UIComponent getComponent() {
- return component;
- }
-
-}
Modified: trunk/framework/api/src/main/java/org/ajax4jsf/component/AjaxContainerBase.java
===================================================================
--- trunk/framework/api/src/main/java/org/ajax4jsf/component/AjaxContainerBase.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/api/src/main/java/org/ajax4jsf/component/AjaxContainerBase.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -88,4 +88,8 @@
*/
// public void renderAjaxRegion(FacesContext context) throws FacesException ;
+ public abstract void setSubmittedControlId(String string);
+
+ public abstract String getSubmittedControlId();
+
}
Deleted: trunk/framework/api/src/main/java/org/ajax4jsf/event/AjaxSingleEvent.java
===================================================================
--- trunk/framework/api/src/main/java/org/ajax4jsf/event/AjaxSingleEvent.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/api/src/main/java/org/ajax4jsf/event/AjaxSingleEvent.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -1,45 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.event;
-
-import javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-import javax.faces.event.PhaseId;
-
-/**
- * @author asmirnov
- *
- */
-public class AjaxSingleEvent extends FacesEvent {
-
- /**
- *
- */
- private static final long serialVersionUID = -3730999641944478334L;
-
- /**
- * @param arg0
- */
- public AjaxSingleEvent(UIComponent arg0) {
- super(arg0);
- }
-
- /* (non-Javadoc)
- * @see javax.faces.event.FacesEvent#isAppropriateListener(javax.faces.event.FacesListener)
- */
- public boolean isAppropriateListener(FacesListener arg0) {
- return false;
- }
-
- /* (non-Javadoc)
- * @see javax.faces.event.FacesEvent#processListener(javax.faces.event.FacesListener)
- */
- public void processListener(FacesListener arg0) {
- }
-
- public PhaseId getPhaseId() {
- return PhaseId.APPLY_REQUEST_VALUES;
- }
-}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxActionComponent.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxActionComponent.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxActionComponent.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -29,11 +29,9 @@
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
-import org.ajax4jsf.application.AjaxSingleException;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.event.AjaxListener;
-import org.ajax4jsf.event.AjaxSingleEvent;
import org.ajax4jsf.event.AjaxSource;
import org.ajax4jsf.renderkit.RendererUtils;
@@ -53,11 +51,6 @@
* @see javax.faces.component.UIComponentBase#broadcast(javax.faces.event.FacesEvent)
*/
public void broadcast(FacesEvent event) throws AbortProcessingException {
- // Hack - throw exception to AjaxViewRoot, to fix state of all iterable
- // components.
- if (event instanceof AjaxSingleEvent) {
- throw new AjaxSingleException(getSingleComponent());
- }
// perform default
super.broadcast(event);
if (event instanceof AjaxEvent) {
@@ -120,10 +113,6 @@
} else {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
}
- // AjaxSingle component process own childrens in event processing.
- if (isAjaxSingle()) {
- super.queueEvent(new AjaxSingleEvent(this));
- }
}
// UICommand set Phase ID for all ActionEvents - bypass it.
getParent().queueEvent(event);
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -80,8 +80,8 @@
private boolean selfRendered = false;
private boolean selfRenderedSet = false;
+ private String submittedControlId;
-
private boolean transientFlag = false;
private UIComponent component ;
@@ -357,6 +357,20 @@
public void setTransient(boolean transientFlag) {
this.transientFlag = transientFlag;
}
+
+ /**
+ * @return the submittedControlId
+ */
+ public String getSubmittedControlId() {
+ return submittedControlId;
+ }
+
+ /**
+ * @param submittedControlId the submittedControlId to set
+ */
+ public void setSubmittedControlId(String submittedControlId) {
+ this.submittedControlId = submittedControlId;
+ }
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -34,7 +34,6 @@
import javax.faces.event.PhaseId;
import org.ajax4jsf.Messages;
-import org.ajax4jsf.application.AjaxSingleException;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.context.AjaxContextImpl;
import org.ajax4jsf.context.InvokerCallback;
@@ -262,7 +261,6 @@
};
- private UIComponent singleComponent = null;
/*
* (non-Javadoc)
@@ -272,13 +270,8 @@
public void processDecodes(FacesContext context) {
if (context == null)
throw new NullPointerException("context");
- singleComponent = null;
AjaxContextImpl.invokeOnRegionOrRoot(this, context, _decodeInvoker);
- try {
- broadcastEvents(context, PhaseId.APPLY_REQUEST_VALUES);
- } catch (AjaxSingleException e) {
- singleComponent = e.getComponent();
- }
+ broadcastEvents(context, PhaseId.APPLY_REQUEST_VALUES);
}
private InvokerCallback _updatesInvoker = new InvokerCallback() {
@@ -301,11 +294,7 @@
public void processUpdates(FacesContext context) {
if (context == null)
throw new NullPointerException("context");
- if (null == singleComponent) {
AjaxContextImpl.invokeOnRegionOrRoot(this, context, _updatesInvoker);
- } else {
- singleComponent.processUpdates(context);
- }
broadcastEvents(context, PhaseId.UPDATE_MODEL_VALUES);
}
@@ -329,11 +318,7 @@
public void processValidators(FacesContext context) {
if (context == null)
throw new NullPointerException("context");
- if (null == singleComponent) {
AjaxContextImpl.invokeOnRegionOrRoot(this, context, _validatorsInvoker);
- } else {
- singleComponent.processValidators(context);
- }
broadcastEvents(context, PhaseId.PROCESS_VALIDATIONS);
}
@@ -543,11 +528,29 @@
}
public void setRenderRegionOnly(boolean reRenderPage) {
- // TODO Auto-generated method stub
-
+ // Ignore for a ViewRoot.
+
}
+
+
- public void encodeAjax(FacesContext context) throws IOException {
+ /**
+ * @return
+ * @see org.ajax4jsf.component.AjaxRegionBrige#getSubmittedControlId()
+ */
+ public String getSubmittedControlId() {
+ return _brige.getSubmittedControlId();
+ }
+
+ /**
+ * @param submittedControlId
+ * @see org.ajax4jsf.component.AjaxRegionBrige#setSubmittedControlId(java.lang.String)
+ */
+ public void setSubmittedControlId(String submittedControlId) {
+ _brige.setSubmittedControlId(submittedControlId);
+ }
+
+ public void encodeAjax(FacesContext context) throws IOException {
String rendererType = getRendererType();
if (rendererType != null) {
((AjaxContainerRenderer) getRenderer(context)).encodeAjax(context,
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -156,6 +156,7 @@
AjaxContainer ajaxContainer = (AjaxContainer) component;
if (null != ajaxParameter && ajaxParameter.equals(clientId)) {
ajaxContainer.setSubmitted(true);
+ ajaxContainer.setSubmittedControlId(paramMap.get(AjaxRendererUtils.AJAX_SINGLE_ATTR));
AjaxEvent event = new AjaxEvent(component);
component.queueEvent(event);
} else {
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -106,17 +106,17 @@
private static final Class<?> OBJECT_ARRAY_CLASS = (new Object[0]).getClass();
- private static final String VALUE_ATTR = "value";
+ public static final String VALUE_ATTR = "value";
public static final String AJAX_AREAS_RENDERED = "org.ajax4jsf.areas.rendered";
- private static final String AJAX_SINGLE_ATTR = "ajaxSingle";
+ public static final String AJAX_SINGLE_ATTR = "ajaxSingle";
public static final String AJAX_QUEUE_ATTR = "eventsQueue";
public static final String AJAX_DELAY_ATTR = "requestDelay";
- private static final String AJAX_ABORT_ATTR = "ignoreDupResponses";
+ public static final String AJAX_ABORT_ATTR = "ignoreDupResponses";
/**
* Static class - protect constructor TODO - make as subclass of chameleon
@@ -204,32 +204,23 @@
Map<String, Object> componentAttributes = uiComponent.getAttributes();
Map<String, Object> options = new HashMap<String, Object>();
Map<String, Object> parameters = new HashMap<String, Object>();
+ UIComponent targetComponent = (uiComponent instanceof AjaxSupport)?uiComponent.getParent():uiComponent;
// UIForm form = getNestingForm(uiComponent);
// "input" - if assigned to html input element.
- boolean input = (uiComponent instanceof AjaxSupport && uiComponent
- .getParent() instanceof EditableValueHolder)
- || uiComponent instanceof EditableValueHolder;
+ boolean input = targetComponent instanceof EditableValueHolder;
// Action component - button etc.
- boolean action = (uiComponent instanceof AjaxSupport && uiComponent
- .getParent() instanceof ActionSource)
- || uiComponent instanceof ActionSource;
- // TODO - disable ( or not ? ) submission of action for disabled default
- // ?
- // if ( action && uiComponent instanceof AjaxSupport) {
- // AjaxSupport support = (AjaxSupport) uiComponent;
- // if (support.isDisableDefault()) {
- // action = false;
- // }
- // }
+// boolean action = targetComponent instanceof ActionSource;
boolean ajaxSingle = Boolean.TRUE.equals(componentAttributes
.get(AJAX_SINGLE_ATTR));
// For input components in single mode or without form submit input
// control )
- if (ajaxSingle && input) { // || action
- // TODO - inside form, put reference :
- // document.forms['form'].controls['control']
- options.put("control", JSReference.THIS);
+ if (ajaxSingle ) {
+ parameters.put(AJAX_SINGLE_ATTR, targetComponent.getClientId(facesContext));
+// options.put("single", JSReference.TRUE);
+ if (input) {
+ options.put("control", JSReference.THIS);
+ }
}
// Control value for submit
String controlName;
@@ -239,10 +230,6 @@
controlName = clientId;
controlValue = clientId;
parameters.put(controlName, controlValue);
- // Move processing of a 'single' attribute to a server-side.
-// if (ajaxSingle) {
-// options.put("single", JSReference.TRUE);
-// }
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(facesContext);
// Setup action URL. For portlet environment, it will be different from
// page.
Modified: trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java
===================================================================
--- trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java 2008-03-07 14:32:02 UTC (rev 6625)
+++ trunk/ui/core/src/main/java/org/ajax4jsf/component/UIAjaxRegion.java 2008-03-08 01:05:20 UTC (rev 6626)
@@ -242,4 +242,38 @@
}
+ /**
+ * @return
+ * @see org.ajax4jsf.component.AjaxRegionBrige#getSubmittedControlId()
+ */
+ public String getSubmittedControlId() {
+ return brige.getSubmittedControlId();
+ }
+
+ /**
+ * @return
+ * @see org.ajax4jsf.component.AjaxRegionBrige#isTransient()
+ */
+ public boolean isTransient() {
+ return brige.isTransient();
+ }
+
+ /**
+ * @param submittedControlId
+ * @see org.ajax4jsf.component.AjaxRegionBrige#setSubmittedControlId(java.lang.String)
+ */
+ public void setSubmittedControlId(String submittedControlId) {
+ brige.setSubmittedControlId(submittedControlId);
+ }
+
+ /**
+ * @param transientFlag
+ * @see org.ajax4jsf.component.AjaxRegionBrige#setTransient(boolean)
+ */
+ public void setTransient(boolean transientFlag) {
+ brige.setTransient(transientFlag);
+ }
+
+
+
}
16 years, 10 months
JBoss Rich Faces SVN: r6625 - trunk/samples/fileUploadDemo/src/main/webapp/WEB-INF.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2008-03-07 09:32:02 -0500 (Fri, 07 Mar 2008)
New Revision: 6625
Modified:
trunk/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml
Log:
remove multipart filter from web.xml
Modified: trunk/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml 2008-03-07 14:13:26 UTC (rev 6624)
+++ trunk/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml 2008-03-07 14:32:02 UTC (rev 6625)
@@ -25,7 +25,15 @@
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
- </filter>
+ <init-param>
+ <param-name>createTempFiles</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <init-param>
+ <param-name>maxRequestSize</param-name>
+ <param-value>20000000</param-value>
+ </init-param>
+ </filter>
<filter>
@@ -34,7 +42,7 @@
<filter-class>org.richfaces.SleepDemoFilter</filter-class>
</filter>
- <filter>
+ <!-- filter>
<display-name>FileUpload Filter</display-name>
<filter-name>fileUpload</filter-name>
<filter-class>org.richfaces.org.jboss.seam.web.MultipartFilter</filter-class>
@@ -46,7 +54,7 @@
<param-name>maxRequestSize</param-name>
<param-value>20000000</param-value>
</init-param>
- </filter>
+ </filter-->
<filter-mapping>
@@ -59,14 +67,14 @@
</filter-mapping>
- <filter-mapping>
+ <!-- filter-mapping>
<filter-name>fileUpload</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
- </filter-mapping>
+ </filter-mapping-->
<filter-mapping>
<filter-name>ajax4jsf</filter-name>
16 years, 10 months
JBoss Rich Faces SVN: r6624 - trunk/docs/userguide/en/src/main/docbook/included.
by richfaces-svn-commits@lists.jboss.org
Author: msorokin
Date: 2008-03-07 09:13:26 -0500 (Fri, 07 Mar 2008)
New Revision: 6624
Modified:
trunk/docs/userguide/en/src/main/docbook/included/progressBar.xml
Log:
http://jira.jboss.com/jira/browse/RF-1690
Macrosubstitution description was added
Modified: trunk/docs/userguide/en/src/main/docbook/included/progressBar.xml
===================================================================
--- trunk/docs/userguide/en/src/main/docbook/included/progressBar.xml 2008-03-07 14:13:22 UTC (rev 6623)
+++ trunk/docs/userguide/en/src/main/docbook/included/progressBar.xml 2008-03-07 14:13:26 UTC (rev 6624)
@@ -161,7 +161,38 @@
<listitem>
<para><property>Client</property> - component updates after its value changed through JavaScript API. </para>
</listitem>
- </itemizedlist>
+ </itemizedlist>
+
+ <para>
+ You can also use macrosubstitution in both Client and Ajax modes,
+ which allows you to pass
+ <emphasis><property>"minValue"</property></emphasis>,
+ <emphasis><property>"maxValue"</property></emphasis>and
+ <emphasis><property>"Value"</property></emphasis>
+ to the facet that is responsible for displaying information on the progress bar, using
+ <emphasis><property>{minValue}</property></emphasis>,
+ <emphasis><property>{maxValue}</property></emphasis> and
+ <emphasis><property>{Value}</property></emphasis>syntax.
+ See the example.
+ </para>
+ <para>
+ <emphasis role="bold">Example:</emphasis>
+ </para>
+ <programlisting role="XML"><![CDATA[...
+<progressBar:progressBar value="#{bean.incValue1}"
+ minValue="400"
+ maxValue="900">
+ <h:outputText value="Min value is {minValue}, current value is {value}, max value is {maxValue}"></h:outputText>
+</progressBar:progressBar>
+ ...]]> </programlisting>
+ <figure>
+ <title>Macrosubstitution</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/progressbar_macrosubs.png"/>
+ </imageobject>
+ </mediaobject>
+ </figure>
</section>
<!-- End. Details of Usage-->
16 years, 10 months
JBoss Rich Faces SVN: r6623 - in trunk/ui/fileUpload/src/main: java/org/richfaces/org/jboss/seam/ui/renderkit and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2008-03-07 09:13:22 -0500 (Fri, 07 Mar 2008)
New Revision: 6623
Removed:
trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/FileUploadException.java
trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java
trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java
Modified:
trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
Log:
RF-2396
Modified: trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
===================================================================
--- trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java 2008-03-07 14:11:23 UTC (rev 6622)
+++ trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java 2008-03-07 14:13:22 UTC (rev 6623)
@@ -12,14 +12,15 @@
import javax.faces.event.FacesEvent;
import javax.servlet.http.HttpServletRequest;
+import org.ajax4jsf.Filter;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.context.AjaxContextImpl;
+import org.ajax4jsf.request.MultipartRequest;
import org.richfaces.event.FileUploadListener;
import org.richfaces.event.UploadEvent;
import org.richfaces.org.jboss.seam.ui.renderkit.FileUploadRendererBase;
-import org.richfaces.org.jboss.seam.web.MultipartFilter;
-import org.richfaces.org.jboss.seam.web.MultipartRequest;
+
/**
* JSF component class
*
@@ -51,7 +52,7 @@
private void setupProgressBarValueExpression(FacesContext context, String uid) {
FileUploadRendererBase renderer = (FileUploadRendererBase)this.getRenderer(context);
UIComponent progressBar = renderer.getProgressBar(context, this);
- String exprStr = "#{" + MultipartFilter.PERCENT_BEAN_NAME + "['"+uid+"']}";
+ String exprStr = "#{" + Filter.PERCENT_BEAN_NAME + "['"+uid+"']}";
ValueExpression ex = context.getApplication().getExpressionFactory()
.createValueExpression(context.getELContext(), exprStr,
Integer.class);
@@ -59,60 +60,7 @@
}
-
- // @Override
- // public void processUpdates(FacesContext context) {
- // ValueExpression dataBinding = getValueExpression("data");
- // if (dataBinding != null) {
- // Class clazz = dataBinding.getType(context.getELContext());
- // if (clazz.isAssignableFrom(InputStream.class)) {
- // dataBinding.setValue(context.getELContext(),
- // getLocalInputStream());
- // } else if (clazz.isAssignableFrom(byte[].class)) {
- // byte[] bytes = null;
- // if (getLocalInputStream() != null) {
- // ByteArrayOutputStream bos = new ByteArrayOutputStream();
- // try {
- // byte[] buffer = new byte[512];
- // int read = getLocalInputStream().read(buffer);
- // while (read != -1) {
- // bos.write(buffer, 0, read);
- // read = getLocalInputStream().read(buffer);
- // }
- // bytes = bos.toByteArray();
- // } catch (IOException e) {
- // throw new RuntimeException(e);
- // }
- // }
- // dataBinding.setValue(context.getELContext(), bytes);
- // }
- //
- // if (getLocalContentType() != null) {
- // ValueExpression valueExpression = getValueExpression("contentType");
- // if (valueExpression != null) {
- // valueExpression.setValue(context.getELContext(),
- // getLocalContentType());
- // }
- // }
- //
- // if (getLocalFileName() != null) {
- // ValueExpression valueExpression = getValueExpression("fileName");
- // if (valueExpression != null) {
- // valueExpression.setValue(context.getELContext(),
- // getLocalFileName());
- // }
- // }
- //
- // if (getLocalFileSize() != null) {
- // ValueExpression valueExpression = getValueExpression("fileSize");
- // if (valueExpression != null) {
- // valueExpression.setValue(context.getELContext(),
- // getLocalFileSize());
- // }
- // }
- // }
- // }
-
+
public String getLocalContentType() {
return localContentType;
}
@@ -206,12 +154,12 @@
&& request.getParameterMap().containsKey(
this.getClientId(facesContext))) {
AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance(facesContext);
- String uid = request.getParameter("uid");
+ String uid = request.getParameter(Filter.UPLOAD_FILES_ID);
Map<String, Object> sessionMap = externalContext.getSessionMap();
Map<String, MultipartRequest> sessions = (Map<String, MultipartRequest>) sessionMap
- .get(MultipartFilter.REQUESTS_SESSIONS_BEAN_NAME);
+ .get(Filter.REQUESTS_SESSIONS_BEAN_NAME);
if (sessions != null) {
MultipartRequest multipartRequest = sessions.get(uid);
if (multipartRequest != null) {
Modified: trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
===================================================================
--- trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java 2008-03-07 14:11:23 UTC (rev 6622)
+++ trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java 2008-03-07 14:13:22 UTC (rev 6623)
@@ -1,6 +1,7 @@
package org.richfaces.org.jboss.seam.ui.renderkit;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -13,10 +14,13 @@
import javax.faces.render.RenderKit;
import javax.faces.render.RenderKitFactory;
import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpSession;
+import org.ajax4jsf.Filter;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.context.AjaxContextImpl;
import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.exception.FileUploadException;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSLiteral;
@@ -24,13 +28,12 @@
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.request.MultipartRequest;
import org.ajax4jsf.resource.CountingOutputWriter;
import org.richfaces.component.UIProgressBar;
import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;
import org.richfaces.org.jboss.seam.ui.component.UIFileUpload;
-import org.richfaces.org.jboss.seam.web.FileUploadException;
-import org.richfaces.org.jboss.seam.web.MultipartRequest;
import org.richfaces.renderkit.TemplateEncoderRendererBase;
/**
@@ -41,9 +44,12 @@
*/
public abstract class FileUploadRendererBase extends
TemplateEncoderRendererBase {
-
+
/** Attribute name where collection of files uploaded will be stored */
private static final String _FILES_UPLOADED_ATTRIBUTE_NAME = "uploadData";
+
+ /** Multipart request class name */
+ private static final String _MULTIPART_REQUEST_CLASS_NAME = MultipartRequest.class.getName();
/*
* (non-Javadoc)
@@ -56,33 +62,41 @@
UIFileUpload fileUpload = (UIFileUpload) component;
ServletRequest request = (ServletRequest) context.getExternalContext()
.getRequest();
-
+
String clientId = component.getClientId(context);
new AjaxEvent(component).queue();
- if (request instanceof MultipartRequest) {
- MultipartRequest multipartRequest = (MultipartRequest) request;
+ Class requestClazz = request.getClass();
+
+ if (_MULTIPART_REQUEST_CLASS_NAME
+ .equals(requestClazz.getName())
+ || "org.jboss.seam.web.MultipartRequest".equals(requestClazz.getName())) {
+
+ HttpSession session = (HttpSession)context.getExternalContext().getSession(false);
+ String uid = request.getParameter(Filter.UPLOAD_FILES_ID);
+ Map<String, MultipartRequest> map = (Map<String, MultipartRequest>)session.getAttribute(Filter.REQUESTS_SESSIONS_BEAN_NAME);
+
+ MultipartRequest multipartRequest = map.get(uid);
+
clientId = clientId + ":file";
- fileUpload.setLocalInputStream(multipartRequest
- .getFileInputStream(clientId));
- fileUpload.setLocalContentType(multipartRequest
- .getFileContentType(clientId));
- fileUpload.setLocalFileName(multipartRequest.getFileName(clientId));
- fileUpload.setLocalFileSize(multipartRequest.getFileSize(clientId));
- onUploadComplete(context, multipartRequest.getFile(clientId),
- fileUpload);
+ String fileName = multipartRequest.getFileName(clientId);
+ Object file = multipartRequest.getFile(clientId);
+ fileUpload.setLocalFileName(fileName);
+ onUploadComplete(context, file, fileUpload);
}
}
-
+
/**
* Method checks if uploaded files count overflowed
+ *
* @param fileUpload
* @param map
* @return
*/
- private boolean checkFileCount (UIFileUpload fileUpload, Collection filesUploaded) {
+ private boolean checkFileCount(UIFileUpload fileUpload,
+ Collection filesUploaded) {
Integer max = fileUpload.getMaxFilesQuantity();
if (filesUploaded != null && filesUploaded.size() >= max) {
fileUpload.reset();
@@ -92,22 +106,27 @@
}
/**
- * Put uploaded file into data attribute defined
+ * Put uploaded file into data attribute defined
+ *
* @param context
* @param fileUpload
* @param file
*/
@SuppressWarnings("unchecked")
- private void storeData(FacesContext context, UIFileUpload fileUpload, Object file) {
- ValueExpression data = fileUpload.getValueExpression(_FILES_UPLOADED_ATTRIBUTE_NAME);
+ private void storeData(FacesContext context, UIFileUpload fileUpload,
+ Object file) {
+ ValueExpression data = fileUpload
+ .getValueExpression(_FILES_UPLOADED_ATTRIBUTE_NAME);
if (data != null) {
if (data.getValue(context.getELContext()) instanceof Collection) {
- Collection collection = (Collection) data.getValue(context.getELContext());
+ Collection collection = (Collection) data.getValue(context
+ .getELContext());
if (checkFileCount(fileUpload, collection)) {
- UploadItem item = new UploadItem(fileUpload.getLocalFileName(), file);
+ UploadItem item = new UploadItem(fileUpload
+ .getLocalFileName(), file);
new UploadEvent(fileUpload, item).queue();
collection.add(item);
- }else {
+ } else {
throw new FileUploadException("Files count overflow");
}
}
@@ -116,18 +135,20 @@
/**
* Call with method after uploading completed
+ *
* @param context
* @param file
* @param fileUpload
*/
private void onUploadComplete(FacesContext context, Object file,
UIFileUpload fileUpload) {
- storeData(context, fileUpload, file);
+ storeData(context, fileUpload, file);
try {
- AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance(context);
+ AjaxContext ajaxContext = AjaxContextImpl
+ .getCurrentInstance(context);
ajaxContext.setAjaxRequest(true);
} catch (Exception e) {
- e.getMessage();
+ e.getMessage();
}
}
@@ -140,9 +161,10 @@
protected Class<? extends UIComponent> getComponentClass() {
return UIFileUpload.class;
}
-
+
/**
- * Generates common JS script by action value
+ * Generates common JS script by action value
+ *
* @param context
* @param component
* @param action
@@ -159,7 +181,7 @@
Map options = AjaxRendererUtils.buildEventOptions(context, component);
Map parameters = (Map) options.get("parameters");
parameters.put("action", action);
- parameters.put("uid", new JSReference("uid"));
+ parameters.put(Filter.UPLOAD_FILES_ID, new JSReference("uid"));
parameters.put(clientId, clientId);
if (oncomplete != null) {
options.put("onbeforedomupdate", oncomplete);
@@ -172,18 +194,20 @@
return function.toScript();
}
-
+
/**
* Return accepted types map
+ *
* @param context
* @param component
* @return
*/
public Object getAcceptedTypes(FacesContext context, UIComponent component) {
- String acceptedTypes = (String)component.getAttributes().get("acceptedTypes");
+ String acceptedTypes = (String) component.getAttributes().get(
+ "acceptedTypes");
if (acceptedTypes != null) {
Map<String, Boolean> accepted = new HashMap<String, Boolean>();
- String [] types = acceptedTypes.split("[,;|]");
+ String[] types = acceptedTypes.split("[,;|]");
if (types != null) {
for (String type : types) {
accepted.put(type.toLowerCase(), true);
@@ -196,6 +220,7 @@
/**
* Generates JS script for stopping uploading process
+ *
* @param context
* @param component
* @return
@@ -206,9 +231,9 @@
return getActionScript(context, component, "stop", null);
}
-
/**
- * Generates JS script for getting file size from server
+ * Generates JS script for getting file size from server
+ *
* @param context
* @param component
* @return
@@ -227,9 +252,10 @@
return getActionScript(context, component, "progress", oncomplete);
}
-
+
/**
* Generates progress label markup
+ *
* @param context
* @param component
* @return
@@ -268,26 +294,31 @@
} catch (Exception e) {
e.getMessage();
}
- return (result != null) ? new JSLiteral(result.toString()) : JSReference.NULL;
+ return (result != null) ? new JSLiteral(result.toString())
+ : JSReference.NULL;
}
/**
* Generate component custom events functions
+ *
* @param context
* @param component
* @param attributeName
* @return
*/
- public String getAsEventHandler(FacesContext context, UIComponent component, String attributeName) {
- Object eventHandler = RendererUtils.getInstance().getAsEventHandler(context, component, attributeName, "");
+ public String getAsEventHandler(FacesContext context,
+ UIComponent component, String attributeName) {
+ Object eventHandler = RendererUtils.getInstance().getAsEventHandler(
+ context, component, attributeName, "");
if (eventHandler != null) {
- return eventHandler.toString();
+ return eventHandler.toString();
}
return JSReference.NULL.toScript();
}
/**
- * Gets progress bar Id
+ * Gets progress bar Id
+ *
* @param context
* @param component
* @return
@@ -299,7 +330,8 @@
}
/**
- * Renders progress bar
+ * Renders progress bar
+ *
* @param context
* @param component
* @throws IOException
@@ -312,6 +344,7 @@
/**
* Creates progress bar component
+ *
* @param context
* @param fileUpload
* @return
@@ -329,6 +362,7 @@
/**
* Returns progress bar
+ *
* @param context
* @param component
* @return
Deleted: trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/FileUploadException.java
===================================================================
--- trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/FileUploadException.java 2008-03-07 14:11:23 UTC (rev 6622)
+++ trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/FileUploadException.java 2008-03-07 14:13:22 UTC (rev 6623)
@@ -1,28 +0,0 @@
-package org.richfaces.org.jboss.seam.web;
-
-/**
- * Thrown when an exception occurs while uploading a file.
- *
- * @author Shane Bryzak
- */
-public class FileUploadException extends RuntimeException
-{
-
- private static final long serialVersionUID = 3142473677581995262L;
-
-
- public FileUploadException()
- {
- this(null, null);
- }
-
- public FileUploadException(String message)
- {
- this(message, null);
- }
-
- public FileUploadException(String message, Throwable cause)
- {
- super(message, cause);
- }
-}
Deleted: trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java
===================================================================
--- trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java 2008-03-07 14:11:23 UTC (rev 6622)
+++ trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java 2008-03-07 14:13:22 UTC (rev 6623)
@@ -1,197 +0,0 @@
-package org.richfaces.org.jboss.seam.web;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-/**
- * A filter for decoding multipart requests, for
- * use with the file upload control.
- *
- * @author Shane Bryzak
- *
- */
-//@Scope(APPLICATION)
-//@Name("org.jboss.seam.web.multipartFilter")
-//@Install(precedence = BUILT_IN)
-//@BypassInterceptors
-//@Filter(within={"org.jboss.seam.web.ajax4jsfFilter", "org.jboss.seam.web.exceptionFilter"})
-public class MultipartFilter implements Filter
-{
- public static final String MULTIPART = "multipart/";
-
- /** Session bean name where multipart requests map will be stored */
- public static final String REQUESTS_SESSIONS_BEAN_NAME = "_richfaces_upload_sessions";
-
- /** Session bean name where progress bar's percent map will be stored */
- public static final String PERCENT_BEAN_NAME = "_richfaces_upload_percents";
-
- /**
- * Flag indicating whether a temporary file should be used to cache the uploaded file
- */
- private boolean createTempFiles = false;
-
- /**
- * The maximum size of a file upload request. 0 means no limit.
- */
- private int maxRequestSize = 0;
-
- public boolean getCreateTempFiles()
- {
- return createTempFiles;
- }
-
- public void setCreateTempFiles(boolean createTempFiles)
- {
- this.createTempFiles = createTempFiles;
- }
-
- public int getMaxRequestSize()
- {
- return maxRequestSize;
- }
-
- public void setMaxRequestSize(int maxFileSize)
- {
- this.maxRequestSize = maxFileSize;
- }
-
- @SuppressWarnings("unchecked")
-public void doFilter(ServletRequest request, ServletResponse response,
- FilterChain chain) throws IOException, ServletException {
- if (!(response instanceof HttpServletResponse)) {
- chain.doFilter(request, response);
- return;
- }
-
- HttpServletRequest httpRequest = (HttpServletRequest) request;
- String uid = httpRequest.getParameter("uid");
- //String componentId = httpRequest.getParameter("clientId");
- if (isMultipartRequest(httpRequest)) {
- MultipartRequest multipartRequest = new MultipartRequest(
- httpRequest, createTempFiles, maxRequestSize, uid);
-
- Map<String, MultipartRequest> sessionsMap = null;
- Map<String, Object> percentMap = null;
- try {
- if (!isFileSizeRestricted(request, maxRequestSize)) {
- HttpSession session = httpRequest.getSession();
- synchronized (session) {
- sessionsMap = (Map<String, MultipartRequest>) session
- .getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
- percentMap = (Map<String, Object>) session.getAttribute(PERCENT_BEAN_NAME);
- if (sessionsMap == null) {
- sessionsMap = Collections.synchronizedMap(new HashMap<String, MultipartRequest>());
- session.setAttribute(
- REQUESTS_SESSIONS_BEAN_NAME, sessionsMap);
- }
- if (percentMap == null) {
- percentMap = new HashMap<String, Object>();
- session.setAttribute(PERCENT_BEAN_NAME, percentMap);
- }
- }
-
- percentMap.put(uid, 0); // associate percent value with file entry uid
- sessionsMap.put(uid, multipartRequest);
-
- if (multipartRequest.parseRequest()) {
- chain.doFilter(multipartRequest, response);
- } else {
- printResponse(response, "<html id=\"_richfaces_file_upload_stopped\"></html>");
- }
- }else {
- printResponse(response, "<html id=\"_richfaces_file_upload_size_restricted\"></html>");
- }
- } finally {
- if (sessionsMap != null) {
- sessionsMap.remove(uid);
- percentMap.remove(uid);
- }
- }
- } else {
- if ("stop".equals(httpRequest.getParameter("action"))) {
- HttpSession session = httpRequest.getSession();
- Map<String, MultipartRequest> sessions = (Map<String, MultipartRequest>) session
- .getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
-
- if (sessions != null) {
- MultipartRequest multipartRequest = sessions.get(uid);
- if (multipartRequest != null) {
- multipartRequest.stop();
- HttpServletResponse httpResponse = (HttpServletResponse) response;
- httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
- httpResponse.getOutputStream().close();
- }
- }
- } else {
- chain.doFilter(request, response);
- }
- }
- }
-
- private boolean isFileSizeRestricted (ServletRequest request, int maxSize) {
- if (request.getContentLength() > maxSize) {
- return true;
- }
- return false;
- }
-
- private void printResponse (ServletResponse response, String message) throws IOException{
- HttpServletResponse httpResponse = (HttpServletResponse) response;
- httpResponse.setStatus(HttpServletResponse.SC_OK);
- httpResponse.setContentType("text/html");
- PrintWriter writer = httpResponse.getWriter();
- writer.write(message);
- writer.close();
- }
-
- private boolean isMultipartRequest(HttpServletRequest request)
- {
- if (!"post".equals(request.getMethod().toLowerCase()))
- {
- return false;
- }
-
- String contentType = request.getContentType();
- if (contentType == null)
- {
- return false;
- }
-
- if (contentType.toLowerCase().startsWith(MULTIPART))
- {
- return true;
- }
-
- return false;
- }
-
-public void destroy() {
-
-}
-
-public void init(FilterConfig filterConfig) throws ServletException {
- String param = filterConfig.getInitParameter("createTempFiles");
- if (param != null) {
- this.createTempFiles = Boolean.parseBoolean(param);
- }
- param = filterConfig.getInitParameter("maxRequestSize");
- if (param != null) {
- this.maxRequestSize = Integer.parseInt(param);
- }
-
-
-}
-}
Deleted: trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java
===================================================================
--- trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java 2008-03-07 14:11:23 UTC (rev 6622)
+++ trunk/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java 2008-03-07 14:13:22 UTC (rev 6623)
@@ -1,653 +0,0 @@
-package org.richfaces.org.jboss.seam.web;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.rmi.server.UID;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-
-/**
- * Request wrapper for supporting multipart requests, used for file uploading.
- *
- * @author Shane Bryzak
- */
-public class MultipartRequest extends HttpServletRequestWrapper {
- private static final String PARAM_NAME = "name";
- private static final String PARAM_FILENAME = "filename";
- private static final String PARAM_CONTENT_TYPE = "Content-Type";
-
- private static final int BUFFER_SIZE = 2048;
- private static final int CHUNK_SIZE = 512;
-
- private boolean createTempFiles;
-
- private String uid;
-
- private String encoding = null;
-
- private Integer contentLength = 0;
-
- private int read = 0;
-
- private Map<String, Param> parameters = null;
-
- private Map<String, Object> percentMap = null;
-
- private enum ReadState {
- BOUNDARY, HEADERS, DATA
- }
-
- private static final byte CR = 0x0d;
- private static final byte LF = 0x0a;
- private static final byte[] CR_LF = { CR, LF };
-
- private abstract class Param {
- private String name;
-
- public Param(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public abstract void appendData(byte[] data, int start, int length)
- throws IOException;
-
- }
-
- private class ValueParam extends Param {
- private Object value = null;
- private ByteArrayOutputStream buf = new ByteArrayOutputStream();
-
- public ValueParam(String name) {
- super(name);
- }
-
- @Override
- public void appendData(byte[] data, int start, int length)
- throws IOException {
- // read += length;
- buf.write(data, start, length);
- }
-
- public void complete() throws UnsupportedEncodingException {
- String val = encoding == null ? new String(buf.toByteArray())
- : new String(buf.toByteArray(), encoding);
- if (value == null) {
- value = val;
- } else {
- if (!(value instanceof List)) {
- List<String> v = new ArrayList<String>();
- v.add((String) value);
- value = v;
- }
-
- ((List) value).add(val);
- }
- buf.reset();
- }
-
- public Object getValue() {
- return value;
- }
- }
-
- private class FileParam extends Param {
- private String filename;
- private String contentType;
- private int fileSize;
-
- private ByteArrayOutputStream bOut = null;
- private FileOutputStream fOut = null;
- private File tempFile = null;
-
- public FileParam(String name) {
- super(name);
- }
-
- public Object getFile() {
- if (null != tempFile) {
- return tempFile;
- }else if (null != bOut) {
- return bOut.toByteArray();
- }
- return null;
- }
-
- public String getFilename() {
- return filename;
- }
-
- public void setFilename(String filename) {
- this.filename = filename;
- }
-
- public String getContentType() {
- return contentType;
- }
-
- public void setContentType(String contentType) {
- this.contentType = contentType;
- }
-
- public int getFileSize() {
- return fileSize;
- }
-
- public File createTempFile() {
- try {
-
- tempFile = File.createTempFile(new UID().toString().replace(
- ":", "-"), ".upload");
- tempFile.deleteOnExit();
- fOut = new FileOutputStream(tempFile);
- } catch (IOException ex) {
- throw new FileUploadException("Could not create temporary file");
- }
- return tempFile;
- }
-
- @Override
- public void appendData(byte[] data, int start, int length)
- throws IOException {
- // read += length;
- if (fOut != null) {
- fOut.write(data, start, length);
- fOut.flush();
- } else {
- if (bOut == null)
- bOut = new ByteArrayOutputStream();
- bOut.write(data, start, length);
- }
-
- fileSize += length;
- }
-
- public byte[] getData() {
- if (fOut != null) {
- try {
- fOut.close();
- } catch (IOException ex) {
- }
- fOut = null;
- }
-
- if (bOut != null) {
- return bOut.toByteArray();
- } else if (tempFile != null) {
- if (tempFile.exists()) {
- try {
- FileInputStream fIn = new FileInputStream(tempFile);
- ByteArrayOutputStream bOut = new ByteArrayOutputStream();
- byte[] buf = new byte[512];
- int read = fIn.read(buf);
- while (read != -1) {
- bOut.write(buf, 0, read);
- read = fIn.read(buf);
- }
- bOut.flush();
-
- fIn.close();
- tempFile.delete();
- return bOut.toByteArray();
- } catch (IOException ex) { /* too bad? */
- }
- }
- }
-
- return null;
- }
-
- public InputStream getInputStream() {
- if (fOut != null) {
- try {
- fOut.close();
- } catch (IOException ex) {
- }
- fOut = null;
- }
-
- if (bOut != null) {
- return new ByteArrayInputStream(bOut.toByteArray());
- } else if (tempFile != null) {
- try {
- return new FileInputStream(tempFile) {
- @Override
- public void close() throws IOException {
- super.close();
- tempFile.delete();
- }
- };
- } catch (FileNotFoundException ex) {
- }
- }
-
- return null;
- }
- }
-
- private HttpServletRequest request;
-
- private boolean shouldStop = false;
-
- public MultipartRequest(HttpServletRequest request,
- boolean createTempFiles, int maxRequestSize, String uid) {
- super(request);
- this.request = request;
- this.createTempFiles = createTempFiles;
- this.uid = uid;
-
- String contentLength = request.getHeader("Content-Length");
- this.contentLength = Integer.parseInt(contentLength);
- if (contentLength != null && maxRequestSize > 0
- && this.contentLength > maxRequestSize) {
- //TODO : we should make decision if can generate exception in this place
- //throw new FileUploadException(
- // "Multipart request is larger than allowed size");
- }
- }
-
- private String decodeFileName(String name) {
- String fileName = null;
- StringBuffer buffer = new StringBuffer();
- String[] codes = name.split(";");
- if (codes != null) {
- for (String code : codes) {
- if (code.startsWith("&")) {
- String sCode = code.replaceAll("[&#]*", "");
- Integer iCode = Integer.parseInt(sCode);
- buffer.append(Character.toChars(iCode));
- }else {
- buffer.append(code);
- }
- }
- fileName = buffer.toString();
- }
- return fileName;
- }
-
- public boolean parseRequest() {
- byte[] boundaryMarker = getBoundaryMarker(request.getContentType());
- if (boundaryMarker == null) {
- throw new FileUploadException("The request was rejected because "
- + "no multipart boundary was found");
- }
-
- encoding = request.getCharacterEncoding();
-
- parameters = new HashMap<String, Param>();
- File file = null;
- this.percentMap = getProgressData();
-
- try {
- byte[] buffer = new byte[BUFFER_SIZE];
- Map<String, String> headers = new HashMap<String, String>();
-
- ReadState readState = ReadState.BOUNDARY;
-
- InputStream input = request.getInputStream();
- if (!shouldStop) {
-
- int read = input.read(buffer);
- int pos = 0;
-
- Param p = null;
-
- while (read != -1) {
- for (int i = 0; i < read; i++) {
- switch (readState) {
- case BOUNDARY: {
- if (checkSequence(buffer, i, boundaryMarker)
- && checkSequence(buffer, i + 2, CR_LF)) {
- readState = ReadState.HEADERS;
- i += 2;
- pos = i + 1;
-
- }
- break;
- }
- case HEADERS: {
- if (checkSequence(buffer, i, CR_LF)) {
- String param = (encoding == null) ? new String(
- buffer, pos, i - pos - 1) : new String(
- buffer, pos, i - pos - 1, encoding);
- parseParams(param, "; ", headers);
-
- if (checkSequence(buffer, i + CR_LF.length, CR_LF)) {
- readState = ReadState.DATA;
- i += CR_LF.length;
- pos = i + 1;
-
- String paramName = headers.get(PARAM_NAME);
- if (paramName != null) {
- if (headers.containsKey(PARAM_FILENAME)) {
- FileParam fp = new FileParam(paramName);
- if (createTempFiles)
- file = fp.createTempFile();
- fp.setContentType(headers
- .get(PARAM_CONTENT_TYPE));
- fp.setFilename(decodeFileName(headers
- .get(PARAM_FILENAME)));
- p = fp;
- } else {
- if (parameters.containsKey(paramName)) {
- p = parameters.get(paramName);
- } else {
- p = new ValueParam(paramName);
- }
- }
-
- if (!parameters.containsKey(paramName)) {
- parameters.put(paramName, p);
- }
- }
-
- headers.clear();
- } else {
- pos = i + 1;
- }
- }
- break;
- }
- case DATA: {
- // If we've encountered another boundary...
- if (checkSequence(buffer, i - boundaryMarker.length
- - CR_LF.length, CR_LF)
- && checkSequence(buffer, i, boundaryMarker)) {
- // Write any data before the boundary (that hasn't
- // already been written) to the param
- if (pos < i - boundaryMarker.length - CR_LF.length
- - 1) {
- p.appendData(buffer, pos, i - pos
- - boundaryMarker.length - CR_LF.length
- - 1);
- }
-
- if (p instanceof ValueParam)
- ((ValueParam) p).complete();
-
- if (checkSequence(buffer, i + CR_LF.length, CR_LF)) {
- i += CR_LF.length;
- pos = i + 1;
- } else {
- pos = i;
- }
-
- readState = ReadState.HEADERS;
- }
- // Otherwise write whatever data we have to the param
- else if (i > (pos + boundaryMarker.length + CHUNK_SIZE + CR_LF.length)) {
- p.appendData(buffer, pos, CHUNK_SIZE);
- pos += CHUNK_SIZE;
-
- }
- break;
- }
- }
- }
-
- if (!shouldStop) {
- if (pos < read) {
- // move the bytes that weren't read to the start of the
- // buffer
- int bytesNotRead = read - pos;
- System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);
- read = input.read(buffer, bytesNotRead, buffer.length
- - bytesNotRead);
- read += bytesNotRead;
- } else {
- read = input.read(buffer);
- }
- this.read += pos;
- pos = 0;
- fillProgressInfo();
- } else {
- if (file != null) {
- file.delete();
- }
- return false;
- }
- }
-
- return true;
- } else {
- if (file != null) {
- file.delete();
- }
- return false;
- }
- } catch (IOException ex) {
- throw new FileUploadException("IO Error parsing multipart request",
- ex);
- }
- }
-
- @SuppressWarnings("unchecked")
- private Map<String, Object> getProgressData () {
- percentMap = (Map<String, Object>)getSession().getAttribute(MultipartFilter.PERCENT_BEAN_NAME);
- return percentMap;
- }
-
- private void fillProgressInfo () {
- Double percent = (Double) (100.0 * this.read / this.contentLength);
- percentMap.put(uid, percent);
- //this.percent = percent;
- }
-
- private byte[] getBoundaryMarker(String contentType) {
- Map<String, String> params = parseParams(contentType, ";");
- String boundaryStr = (String) params.get("boundary");
-
- if (boundaryStr == null)
- return null;
-
- try {
- return boundaryStr.getBytes("ISO-8859-1");
- } catch (UnsupportedEncodingException e) {
- return boundaryStr.getBytes();
- }
- }
-
- /**
- * Checks if a specified sequence of bytes ends at a specific position
- * within a byte array.
- *
- * @param data
- * @param pos
- * @param seq
- * @return boolean indicating if the sequence was found at the specified
- * position
- */
- private boolean checkSequence(byte[] data, int pos, byte[] seq) {
- if (pos - seq.length < -1 || pos >= data.length)
- return false;
-
- for (int i = 0; i < seq.length; i++) {
- if (data[(pos - seq.length) + i + 1] != seq[i])
- return false;
- }
-
- return true;
- }
-
- private static final Pattern PARAM_VALUE_PATTERN = Pattern
- .compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
-
- private static final Pattern FILE_NAME_PATTERN = Pattern
- .compile(".*filename=\"(.*)\"");
-
- private Map<String, String> parseParams(String paramStr, String separator) {
- Map<String, String> paramMap = new HashMap<String, String>();
- parseParams(paramStr, separator, paramMap);
- return paramMap;
- }
-
- private void parseParams(String paramStr, String separator, Map<String, String> paramMap) {
- String[] parts = paramStr.split(separator);
-
- for (String part : parts) {
- Matcher m = PARAM_VALUE_PATTERN.matcher(part);
- if (m.matches()) {
- String key = m.group(1);
- String value = m.group(2);
-
- // Strip double quotes
- if (value.startsWith("\"") && value.endsWith("\""))
- value = value.substring(1, value.length() - 1);
- if (!"filename".equals(key)) {
- paramMap.put(key, value);
- }else {
- paramMap.put(key, parseFileName(paramStr));
- }
- }
- }
- }
-
- private String parseFileName(String parseStr) {
- Matcher m = FILE_NAME_PATTERN.matcher(parseStr);
- if (m.matches()) {
- String name = m.group(1);
- if (name.startsWith("&")) {
- return decodeFileName(name);
- } else{
- return name;
- }
- }
- return null;
- }
-
- private Param getParam(String name) {
- if (parameters == null)
- parseRequest();
- return parameters.get(name);
- }
-
-
- public Integer getSize() {
- return contentLength;
- }
-
- @Override
- public Enumeration getParameterNames() {
- if (parameters == null)
- parseRequest();
-
- return Collections.enumeration(parameters.keySet());
- }
-
- public byte[] getFileBytes(String name) {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ? ((FileParam) p)
- .getData() : null;
- }
-
- public InputStream getFileInputStream(String name) {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ? ((FileParam) p)
- .getInputStream() : null;
- }
-
- public String getFileContentType(String name) {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ? ((FileParam) p)
- .getContentType() : null;
- }
-
- public Object getFile(String name) {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ? ((FileParam) p)
- .getFile() : null;
- }
-
-
- public String getFileName(String name) {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ? ((FileParam) p)
- .getFilename() : null;
- }
-
- public int getFileSize(String name) {
- Param p = getParam(name);
- return (p != null && p instanceof FileParam) ? ((FileParam) p)
- .getFileSize() : -1;
- }
-
- @Override
- public String getParameter(String name) {
- Param p = getParam(name);
- if (p != null && p instanceof ValueParam) {
- ValueParam vp = (ValueParam) p;
- if (vp.getValue() instanceof String)
- return (String) vp.getValue();
- } else if (p != null && p instanceof FileParam) {
- return "---BINARY DATA---";
- } else {
- return super.getParameter(name);
- }
-
- return null;
- }
-
- @Override
- public String[] getParameterValues(String name) {
- Param p = getParam(name);
- if (p != null && p instanceof ValueParam) {
- ValueParam vp = (ValueParam) p;
- if (vp.getValue() instanceof List) {
- List vals = (List) vp.getValue();
- String[] values = new String[vals.size()];
- vals.toArray(values);
- return values;
- } else {
- return new String[] { (String) vp.getValue() };
- }
- } else {
- return super.getParameterValues(name);
- }
- }
-
- @Override
- public Map getParameterMap() {
- if (parameters == null)
- parseRequest();
-
- Map<String, Object> params = new HashMap<String, Object>(super
- .getParameterMap());
-
- for (String name : parameters.keySet()) {
- Param p = parameters.get(name);
- if (p instanceof ValueParam) {
- ValueParam vp = (ValueParam) p;
- if (vp.getValue() instanceof String) {
- params.put(name, vp.getValue());
- } else if (vp.getValue() instanceof List) {
- params.put(name, getParameterValues(name));
- }
- }
- }
-
- return params;
- }
-
- public void stop() {
- shouldStop = true;
- }
-}
Modified: trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
--- trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-03-07 14:11:23 UTC (rev 6622)
+++ trunk/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js 2008-03-07 14:13:22 UTC (rev 6623)
@@ -839,7 +839,7 @@
parentForm.encoding = "multipart/form-data";
parentForm.enctype = "multipart/form-data";
parentForm.target = this.id;
- parentForm.action = oldAction + (/\?/.test(oldAction) ? '&uid' : '?uid') + '=' + encodeURI(entry.uid);
+ parentForm.action = oldAction + (/\?/.test(oldAction) ? '&_richfaces_upload_uid' : '?_richfaces_upload_uid') + '=' + encodeURI(entry.uid);
try {
var inputs = parentForm.elements;
16 years, 10 months
JBoss Rich Faces SVN: r6622 - in trunk/framework/impl/src/main/java/org/ajax4jsf: exception and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2008-03-07 09:11:23 -0500 (Fri, 07 Mar 2008)
New Revision: 6622
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/exception/
trunk/framework/impl/src/main/java/org/ajax4jsf/exception/FileUploadException.java
trunk/framework/impl/src/main/java/org/ajax4jsf/request/
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java
Log:
extend ajax4jsf filter by multipart file upload processing
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java 2008-03-07 12:20:45 UTC (rev 6621)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/FastFilter.java 2008-03-07 14:11:23 UTC (rev 6622)
@@ -21,7 +21,200 @@
package org.ajax4jsf;
-public class FastFilter extends
- org.ajax4jsf.webapp.NekkoFilter {
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.ajax4jsf.request.MultipartRequest;
+
+public class FastFilter extends org.ajax4jsf.webapp.NekkoFilter {
+
+ /** Multipart request start */
+ public static final String MULTIPART = "multipart/";
+
+ /** Session bean name where multipart requests map will be stored */
+ public static final String REQUESTS_SESSIONS_BEAN_NAME = "_richfaces_upload_sessions";
+
+ /** Session bean name where progress bar's percent map will be stored */
+ public static final String PERCENT_BEAN_NAME = "_richfaces_upload_percents";
+
+ /**
+ * Request parameter that indicates if multipart request forced by rich file
+ * upload component
+ */
+ public static final String UPLOAD_FILES_ID = "_richfaces_upload_uid";
+
+ /**
+ * Flag indicating whether a temporary file should be used to cache the
+ * uploaded file
+ */
+ private boolean createTempFiles = false;
+
+ /**
+ * The maximum size of a file upload request. 0 means no limit.
+ */
+ private int maxRequestSize = 0;
+
+ /***************************************************************************
+ * Method catches upload files request. Request parameter
+ * <b>org.ajax4jsf.Filter.UPLOAD_FILES_ID</b> indicates if request
+ * generated by rich-upload component. If it was detected custom parsing
+ * request should be done. Processing information about percent of
+ * completion and file size will be put into session scope. In other case
+ * super filter's method will be invoked for request processing.
+ *
+ * @param request
+ * @param response
+ * @param chain
+ */
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ if (!(response instanceof HttpServletResponse)) {
+ chain.doFilter(request, response);
+ return;
+ }
+
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ String uid = httpRequest.getParameter(UPLOAD_FILES_ID);
+ if (uid != null) {
+ if (isMultipartRequest(httpRequest)) {
+ MultipartRequest multipartRequest = new MultipartRequest(
+ httpRequest, createTempFiles, maxRequestSize, uid);
+
+ Map<String, MultipartRequest> sessionsMap = null;
+ Map<String, Object> percentMap = null;
+ try {
+ if (!isFileSizeRestricted(request, maxRequestSize)) {
+ HttpSession session = httpRequest.getSession();
+ synchronized (session) {
+ sessionsMap = (Map<String, MultipartRequest>) session
+ .getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
+ percentMap = (Map<String, Object>) session
+ .getAttribute(PERCENT_BEAN_NAME);
+ if (sessionsMap == null) {
+ sessionsMap = Collections
+ .synchronizedMap(new HashMap<String, MultipartRequest>());
+ session.setAttribute(
+ REQUESTS_SESSIONS_BEAN_NAME,
+ sessionsMap);
+ }
+ if (percentMap == null) {
+ percentMap = new HashMap<String, Object>();
+ session.setAttribute(PERCENT_BEAN_NAME,
+ percentMap);
+ }
+ }
+
+ percentMap.put(uid, 0); // associate percent value with
+ // file
+ // entry uid
+ sessionsMap.put(uid, multipartRequest);
+
+ if (multipartRequest.parseRequest()) {
+ super.doFilter(multipartRequest, response, chain);
+ } else {
+ printResponse(response,
+ "<html id=\"_richfaces_file_upload_stopped\"></html>");
+ }
+ } else {
+ printResponse(response,
+ "<html id=\"_richfaces_file_upload_size_restricted\"></html>");
+ }
+ } finally {
+ if (sessionsMap != null) {
+ sessionsMap.remove(uid);
+ percentMap.remove(uid);
+ }
+ }
+ } else {
+ if ("stop".equals(httpRequest.getParameter("action"))) {
+ HttpSession session = httpRequest.getSession();
+ Map<String, MultipartRequest> sessions = (Map<String, MultipartRequest>) session
+ .getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
+
+ if (sessions != null) {
+ MultipartRequest multipartRequest = sessions.get(uid);
+ if (multipartRequest != null) {
+ multipartRequest.stop();
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ httpResponse
+ .setStatus(HttpServletResponse.SC_NO_CONTENT);
+ httpResponse.getOutputStream().close();
+ }
+ }
+ } else {
+ super.doFilter(request, response, chain);
+ }
+ }
+ } else {
+ super.doFilter(request, response, chain);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.BaseFilter#init(javax.servlet.FilterConfig)
+ */
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ super.init(filterConfig);
+ String param = filterConfig.getInitParameter("createTempFiles");
+ if (param != null) {
+ this.createTempFiles = Boolean.parseBoolean(param);
+ }else {
+ this.createTempFiles = true;
+ }
+ param = filterConfig.getInitParameter("maxRequestSize");
+ if (param != null) {
+ this.maxRequestSize = Integer.parseInt(param);
+ }
+ }
+
+ private boolean isMultipartRequest(HttpServletRequest request) {
+ if (!"post".equals(request.getMethod().toLowerCase())) {
+ return false;
+ }
+
+ String contentType = request.getContentType();
+ if (contentType == null) {
+ return false;
+ }
+
+ if (contentType.toLowerCase().startsWith(MULTIPART)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isFileSizeRestricted(ServletRequest request, int maxSize) {
+ if (maxSize != 0 && request.getContentLength() > maxSize) {
+ return true;
+ }
+ return false;
+ }
+
+ private void printResponse(ServletResponse response, String message)
+ throws IOException {
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ httpResponse.setStatus(HttpServletResponse.SC_OK);
+ httpResponse.setContentType("text/html");
+ PrintWriter writer = httpResponse.getWriter();
+ writer.write(message);
+ writer.close();
+ }
+
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java 2008-03-07 12:20:45 UTC (rev 6621)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/Filter.java 2008-03-07 14:11:23 UTC (rev 6622)
@@ -21,14 +21,203 @@
package org.ajax4jsf;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.ajax4jsf.request.MultipartRequest;
import org.ajax4jsf.webapp.ConfigurableFilter;
/**
* Proxy for resource/ajax xml parsing filter.
+ *
* @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:29 $
- *
+ *
*/
public class Filter extends ConfigurableFilter {
+ /** Multipart request start */
+ public static final String MULTIPART = "multipart/";
+
+ /** Session bean name where multipart requests map will be stored */
+ public static final String REQUESTS_SESSIONS_BEAN_NAME = "_richfaces_upload_sessions";
+
+ /** Session bean name where progress bar's percent map will be stored */
+ public static final String PERCENT_BEAN_NAME = "_richfaces_upload_percents";
+
+ /** Request parameter that indicates if multipart request forced by rich file upload component */
+ public static final String UPLOAD_FILES_ID = "_richfaces_upload_uid";
+
+ /**
+ * Flag indicating whether a temporary file should be used to cache the
+ * uploaded file
+ */
+ private boolean createTempFiles = false;
+
+ /**
+ * The maximum size of a file upload request. 0 means no limit.
+ */
+ private int maxRequestSize = 0;
+
+ /***
+ * Method catches upload files request.
+ * Request parameter <b>org.ajax4jsf.Filter.UPLOAD_FILES_ID</b> indicates if request generated by rich-upload component.
+ * If it was detected custom parsing request should be done.
+ * Processing information about percent of completion and file size will be put into session scope.
+ * In other case super filter's method will be invoked for request processing.
+ * @param request
+ * @param response
+ * @param chain
+ */
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ if (!(response instanceof HttpServletResponse)) {
+ chain.doFilter(request, response);
+ return;
+ }
+
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ String uid = httpRequest.getParameter(UPLOAD_FILES_ID);
+ if (uid != null) {
+ if (isMultipartRequest(httpRequest)) {
+ MultipartRequest multipartRequest = new MultipartRequest(
+ httpRequest, createTempFiles, maxRequestSize, uid);
+
+ Map<String, MultipartRequest> sessionsMap = null;
+ Map<String, Object> percentMap = null;
+ try {
+ if (!isFileSizeRestricted(request, maxRequestSize)) {
+ HttpSession session = httpRequest.getSession();
+ synchronized (session) {
+ sessionsMap = (Map<String, MultipartRequest>) session
+ .getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
+ percentMap = (Map<String, Object>) session
+ .getAttribute(PERCENT_BEAN_NAME);
+ if (sessionsMap == null) {
+ sessionsMap = Collections
+ .synchronizedMap(new HashMap<String, MultipartRequest>());
+ session.setAttribute(
+ REQUESTS_SESSIONS_BEAN_NAME,
+ sessionsMap);
+ }
+ if (percentMap == null) {
+ percentMap = new HashMap<String, Object>();
+ session.setAttribute(PERCENT_BEAN_NAME,
+ percentMap);
+ }
+ }
+
+ percentMap.put(uid, 0); // associate percent value with
+ // file
+ // entry uid
+ sessionsMap.put(uid, multipartRequest);
+
+ if (multipartRequest.parseRequest()) {
+ super.doFilter(multipartRequest, response, chain);
+ } else {
+ printResponse(response,
+ "<html id=\"_richfaces_file_upload_stopped\"></html>");
+ }
+ } else {
+ printResponse(response,
+ "<html id=\"_richfaces_file_upload_size_restricted\"></html>");
+ }
+ } finally {
+ if (sessionsMap != null) {
+ sessionsMap.remove(uid);
+ percentMap.remove(uid);
+ }
+ }
+ } else {
+ if ("stop".equals(httpRequest.getParameter("action"))) {
+ HttpSession session = httpRequest.getSession();
+ Map<String, MultipartRequest> sessions = (Map<String, MultipartRequest>) session
+ .getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
+
+ if (sessions != null) {
+ MultipartRequest multipartRequest = sessions.get(uid);
+ if (multipartRequest != null) {
+ multipartRequest.stop();
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ httpResponse
+ .setStatus(HttpServletResponse.SC_NO_CONTENT);
+ httpResponse.getOutputStream().close();
+ }
+ }
+ } else {
+ super.doFilter(request, response, chain);
+ }
+ }
+ } else {
+ super.doFilter(request, response, chain);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.webapp.BaseFilter#init(javax.servlet.FilterConfig)
+ */
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ super.init(filterConfig);
+ String param = filterConfig.getInitParameter("createTempFiles");
+ if (param != null) {
+ this.createTempFiles = Boolean.parseBoolean(param);
+ }else {
+ this.createTempFiles = true;
+ }
+ param = filterConfig.getInitParameter("maxRequestSize");
+ if (param != null) {
+ this.maxRequestSize = Integer.parseInt(param);
+ }
+ }
+
+ private boolean isMultipartRequest(HttpServletRequest request) {
+ if (!"post".equals(request.getMethod().toLowerCase())) {
+ return false;
+ }
+
+ String contentType = request.getContentType();
+ if (contentType == null) {
+ return false;
+ }
+
+ if (contentType.toLowerCase().startsWith(MULTIPART)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isFileSizeRestricted(ServletRequest request, int maxSize) {
+ if (maxSize != 0 && request.getContentLength() > maxSize) {
+ return true;
+ }
+ return false;
+ }
+
+ private void printResponse(ServletResponse response, String message)
+ throws IOException {
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ httpResponse.setStatus(HttpServletResponse.SC_OK);
+ httpResponse.setContentType("text/html");
+ PrintWriter writer = httpResponse.getWriter();
+ writer.write(message);
+ writer.close();
+ }
+
}
Added: trunk/framework/impl/src/main/java/org/ajax4jsf/exception/FileUploadException.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/exception/FileUploadException.java (rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/exception/FileUploadException.java 2008-03-07 14:11:23 UTC (rev 6622)
@@ -0,0 +1,24 @@
+package org.ajax4jsf.exception;
+
+/**
+ * Thrown when an exception occurs while uploading a file.
+ *
+ * @author Shane Bryzak
+ */
+public class FileUploadException extends RuntimeException
+{
+ public FileUploadException()
+ {
+ this(null, null);
+ }
+
+ public FileUploadException(String message)
+ {
+ this(message, null);
+ }
+
+ public FileUploadException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Added: trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java (rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java 2008-03-07 14:11:23 UTC (rev 6622)
@@ -0,0 +1,656 @@
+package org.ajax4jsf.request;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.rmi.server.UID;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.ajax4jsf.Filter;
+import org.ajax4jsf.exception.FileUploadException;
+
+/**
+ * Request wrapper for supporting multipart requests, used for file uploading.
+ *
+ * @author Shane Bryzak
+ */
+public class MultipartRequest extends HttpServletRequestWrapper {
+ private static final String PARAM_NAME = "name";
+ private static final String PARAM_FILENAME = "filename";
+ private static final String PARAM_CONTENT_TYPE = "Content-Type";
+
+ private static final int BUFFER_SIZE = 2048;
+ private static final int CHUNK_SIZE = 512;
+
+ private boolean createTempFiles;
+
+ private String uid;
+
+ private String encoding = null;
+
+ private Integer contentLength = 0;
+
+ private int read = 0;
+
+ private Map<String, Param> parameters = null;
+
+ private Map<String, Object> percentMap = null;
+
+ private enum ReadState {
+ BOUNDARY, HEADERS, DATA
+ }
+
+ private static final byte CR = 0x0d;
+ private static final byte LF = 0x0a;
+ private static final byte[] CR_LF = { CR, LF };
+
+ private abstract class Param {
+ private String name;
+
+ public Param(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public abstract void appendData(byte[] data, int start, int length)
+ throws IOException;
+
+ }
+
+ private class ValueParam extends Param {
+ private Object value = null;
+ private ByteArrayOutputStream buf = new ByteArrayOutputStream();
+
+ public ValueParam(String name) {
+ super(name);
+ }
+
+ @Override
+ public void appendData(byte[] data, int start, int length)
+ throws IOException {
+ // read += length;
+ buf.write(data, start, length);
+ }
+
+ public void complete() throws UnsupportedEncodingException {
+ String val = encoding == null ? new String(buf.toByteArray())
+ : new String(buf.toByteArray(), encoding);
+ if (value == null) {
+ value = val;
+ } else {
+ if (!(value instanceof List)) {
+ List<String> v = new ArrayList<String>();
+ v.add((String) value);
+ value = v;
+ }
+
+ ((List) value).add(val);
+ }
+ buf.reset();
+ }
+
+ public Object getValue() {
+ return value;
+ }
+ }
+
+ private class FileParam extends Param {
+ private String filename;
+ private String contentType;
+ private int fileSize;
+
+ private ByteArrayOutputStream bOut = null;
+ private FileOutputStream fOut = null;
+ private File tempFile = null;
+
+ public FileParam(String name) {
+ super(name);
+ }
+
+ public Object getFile() {
+ if (null != tempFile) {
+ return tempFile;
+ }else if (null != bOut) {
+ return bOut.toByteArray();
+ }
+ return null;
+ }
+
+ public String getFilename() {
+ return filename;
+ }
+
+ public void setFilename(String filename) {
+ this.filename = filename;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public int getFileSize() {
+ return fileSize;
+ }
+
+ public File createTempFile() {
+ try {
+
+ tempFile = File.createTempFile(new UID().toString().replace(
+ ":", "-"), ".upload");
+ tempFile.deleteOnExit();
+ fOut = new FileOutputStream(tempFile);
+ } catch (IOException ex) {
+ throw new FileUploadException("Could not create temporary file");
+ }
+ return tempFile;
+ }
+
+ @Override
+ public void appendData(byte[] data, int start, int length)
+ throws IOException {
+ // read += length;
+ if (fOut != null) {
+ fOut.write(data, start, length);
+ fOut.flush();
+ } else {
+ if (bOut == null)
+ bOut = new ByteArrayOutputStream();
+ bOut.write(data, start, length);
+ }
+
+ fileSize += length;
+ }
+
+ public byte[] getData() {
+ if (fOut != null) {
+ try {
+ fOut.close();
+ } catch (IOException ex) {
+ }
+ fOut = null;
+ }
+
+ if (bOut != null) {
+ return bOut.toByteArray();
+ } else if (tempFile != null) {
+ if (tempFile.exists()) {
+ try {
+ FileInputStream fIn = new FileInputStream(tempFile);
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+ byte[] buf = new byte[512];
+ int read = fIn.read(buf);
+ while (read != -1) {
+ bOut.write(buf, 0, read);
+ read = fIn.read(buf);
+ }
+ bOut.flush();
+
+ fIn.close();
+ tempFile.delete();
+ return bOut.toByteArray();
+ } catch (IOException ex) { /* too bad? */
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public InputStream getInputStream() {
+ if (fOut != null) {
+ try {
+ fOut.close();
+ } catch (IOException ex) {
+ }
+ fOut = null;
+ }
+
+ if (bOut != null) {
+ return new ByteArrayInputStream(bOut.toByteArray());
+ } else if (tempFile != null) {
+ try {
+ return new FileInputStream(tempFile) {
+ @Override
+ public void close() throws IOException {
+ super.close();
+ tempFile.delete();
+ }
+ };
+ } catch (FileNotFoundException ex) {
+ }
+ }
+
+ return null;
+ }
+ }
+
+ private HttpServletRequest request;
+
+ private boolean shouldStop = false;
+
+ public MultipartRequest(HttpServletRequest request,
+ boolean createTempFiles, int maxRequestSize, String uid) {
+ super(request);
+ this.request = request;
+ this.createTempFiles = createTempFiles;
+ this.uid = uid;
+
+ String contentLength = request.getHeader("Content-Length");
+ this.contentLength = Integer.parseInt(contentLength);
+ if (contentLength != null && maxRequestSize > 0
+ && this.contentLength > maxRequestSize) {
+ //TODO : we should make decision if can generate exception in this place
+ //throw new FileUploadException(
+ // "Multipart request is larger than allowed size");
+ }
+ }
+
+ private String decodeFileName(String name) {
+ String fileName = null;
+ StringBuffer buffer = new StringBuffer();
+ String[] codes = name.split(";");
+ if (codes != null) {
+ for (String code : codes) {
+ if (code.startsWith("&")) {
+ String sCode = code.replaceAll("[&#]*", "");
+ Integer iCode = Integer.parseInt(sCode);
+ buffer.append(Character.toChars(iCode));
+ }else {
+ buffer.append(code);
+ }
+ }
+ fileName = buffer.toString();
+ }
+ return fileName;
+ }
+
+ public boolean parseRequest() {
+ byte[] boundaryMarker = getBoundaryMarker(request.getContentType());
+ if (boundaryMarker == null) {
+ throw new FileUploadException("The request was rejected because "
+ + "no multipart boundary was found");
+ }
+
+ encoding = request.getCharacterEncoding();
+
+ parameters = new HashMap<String, Param>();
+ File file = null;
+ this.percentMap = getProgressData();
+
+ try {
+ byte[] buffer = new byte[BUFFER_SIZE];
+ Map<String, String> headers = new HashMap<String, String>();
+
+ ReadState readState = ReadState.BOUNDARY;
+
+ InputStream input = request.getInputStream();
+ if (!shouldStop) {
+
+ int read = input.read(buffer);
+ int pos = 0;
+
+ Param p = null;
+
+ while (read != -1) {
+ for (int i = 0; i < read; i++) {
+ switch (readState) {
+ case BOUNDARY: {
+ if (checkSequence(buffer, i, boundaryMarker)
+ && checkSequence(buffer, i + 2, CR_LF)) {
+ readState = ReadState.HEADERS;
+ i += 2;
+ pos = i + 1;
+
+ }
+ break;
+ }
+ case HEADERS: {
+ if (checkSequence(buffer, i, CR_LF)) {
+ String param = (encoding == null) ? new String(
+ buffer, pos, i - pos - 1) : new String(
+ buffer, pos, i - pos - 1, encoding);
+ parseParams(param, "; ", headers);
+
+ if (checkSequence(buffer, i + CR_LF.length, CR_LF)) {
+ readState = ReadState.DATA;
+ i += CR_LF.length;
+ pos = i + 1;
+
+ String paramName = headers.get(PARAM_NAME);
+ if (paramName != null) {
+ if (headers.containsKey(PARAM_FILENAME)) {
+ FileParam fp = new FileParam(paramName);
+ if (createTempFiles)
+ file = fp.createTempFile();
+ fp.setContentType(headers
+ .get(PARAM_CONTENT_TYPE));
+ fp.setFilename(decodeFileName(headers
+ .get(PARAM_FILENAME)));
+ p = fp;
+ } else {
+ if (parameters.containsKey(paramName)) {
+ p = parameters.get(paramName);
+ } else {
+ p = new ValueParam(paramName);
+ }
+ }
+
+ if (!parameters.containsKey(paramName)) {
+ parameters.put(paramName, p);
+ }
+ }
+
+ headers.clear();
+ } else {
+ pos = i + 1;
+ }
+ }
+ break;
+ }
+ case DATA: {
+ // If we've encountered another boundary...
+ if (checkSequence(buffer, i - boundaryMarker.length
+ - CR_LF.length, CR_LF)
+ && checkSequence(buffer, i, boundaryMarker)) {
+ // Write any data before the boundary (that hasn't
+ // already been written) to the param
+ if (pos < i - boundaryMarker.length - CR_LF.length
+ - 1) {
+ p.appendData(buffer, pos, i - pos
+ - boundaryMarker.length - CR_LF.length
+ - 1);
+ }
+
+ if (p instanceof ValueParam)
+ ((ValueParam) p).complete();
+
+ if (checkSequence(buffer, i + CR_LF.length, CR_LF)) {
+ i += CR_LF.length;
+ pos = i + 1;
+ } else {
+ pos = i;
+ }
+
+ readState = ReadState.HEADERS;
+ }
+ // Otherwise write whatever data we have to the param
+ else if (i > (pos + boundaryMarker.length + CHUNK_SIZE + CR_LF.length)) {
+ p.appendData(buffer, pos, CHUNK_SIZE);
+ pos += CHUNK_SIZE;
+
+ }
+ break;
+ }
+ }
+ }
+
+ if (!shouldStop) {
+ if (pos < read) {
+ // move the bytes that weren't read to the start of the
+ // buffer
+ int bytesNotRead = read - pos;
+ System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);
+ read = input.read(buffer, bytesNotRead, buffer.length
+ - bytesNotRead);
+ read += bytesNotRead;
+ } else {
+ read = input.read(buffer);
+ }
+ this.read += pos;
+ pos = 0;
+ fillProgressInfo();
+ } else {
+ if (file != null) {
+ file.delete();
+ }
+ return false;
+ }
+ }
+
+ return true;
+ } else {
+ if (file != null) {
+ file.delete();
+ }
+ return false;
+ }
+ } catch (IOException ex) {
+ throw new FileUploadException("IO Error parsing multipart request",
+ ex);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> getProgressData () {
+ percentMap = (Map<String, Object>)getSession().getAttribute(Filter.PERCENT_BEAN_NAME);
+ return percentMap;
+ }
+
+ private void fillProgressInfo () {
+ Double percent = (Double) (100.0 * this.read / this.contentLength);
+ percentMap.put(uid, percent);
+ //this.percent = percent;
+ }
+
+ private byte[] getBoundaryMarker(String contentType) {
+ Map<String, String> params = parseParams(contentType, ";");
+ String boundaryStr = (String) params.get("boundary");
+
+ if (boundaryStr == null)
+ return null;
+
+ try {
+ return boundaryStr.getBytes("ISO-8859-1");
+ } catch (UnsupportedEncodingException e) {
+ return boundaryStr.getBytes();
+ }
+ }
+
+ /**
+ * Checks if a specified sequence of bytes ends at a specific position
+ * within a byte array.
+ *
+ * @param data
+ * @param pos
+ * @param seq
+ * @return boolean indicating if the sequence was found at the specified
+ * position
+ */
+ private boolean checkSequence(byte[] data, int pos, byte[] seq) {
+ if (pos - seq.length < -1 || pos >= data.length)
+ return false;
+
+ for (int i = 0; i < seq.length; i++) {
+ if (data[(pos - seq.length) + i + 1] != seq[i])
+ return false;
+ }
+
+ return true;
+ }
+
+ private static final Pattern PARAM_VALUE_PATTERN = Pattern
+ .compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
+
+ private static final Pattern FILE_NAME_PATTERN = Pattern
+ .compile(".*filename=\"(.*)\"");
+
+ private Map<String, String> parseParams(String paramStr, String separator) {
+ Map<String, String> paramMap = new HashMap<String, String>();
+ parseParams(paramStr, separator, paramMap);
+ return paramMap;
+ }
+
+ private void parseParams(String paramStr, String separator, Map<String, String> paramMap) {
+ String[] parts = paramStr.split(separator);
+
+ for (String part : parts) {
+ Matcher m = PARAM_VALUE_PATTERN.matcher(part);
+ if (m.matches()) {
+ String key = m.group(1);
+ String value = m.group(2);
+
+ // Strip double quotes
+ if (value.startsWith("\"") && value.endsWith("\""))
+ value = value.substring(1, value.length() - 1);
+ if (!"filename".equals(key)) {
+ paramMap.put(key, value);
+ }else {
+ paramMap.put(key, parseFileName(paramStr));
+ }
+ }
+ }
+ }
+
+ private String parseFileName(String parseStr) {
+ Matcher m = FILE_NAME_PATTERN.matcher(parseStr);
+ if (m.matches()) {
+ String name = m.group(1);
+ if (name.startsWith("&")) {
+ return decodeFileName(name);
+ } else{
+ return name;
+ }
+ }
+ return null;
+ }
+
+ private Param getParam(String name) {
+ if (parameters == null)
+ parseRequest();
+ return parameters.get(name);
+ }
+
+
+ public Integer getSize() {
+ return contentLength;
+ }
+
+ @Override
+ public Enumeration getParameterNames() {
+ if (parameters == null)
+ parseRequest();
+
+ return Collections.enumeration(parameters.keySet());
+ }
+
+ public byte[] getFileBytes(String name) {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ? ((FileParam) p)
+ .getData() : null;
+ }
+
+ public InputStream getFileInputStream(String name) {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ? ((FileParam) p)
+ .getInputStream() : null;
+ }
+
+ public String getFileContentType(String name) {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ? ((FileParam) p)
+ .getContentType() : null;
+ }
+
+ public Object getFile(String name) {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ? ((FileParam) p)
+ .getFile() : null;
+ }
+
+
+ public String getFileName(String name) {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ? ((FileParam) p)
+ .getFilename() : null;
+ }
+
+ public int getFileSize(String name) {
+ Param p = getParam(name);
+ return (p != null && p instanceof FileParam) ? ((FileParam) p)
+ .getFileSize() : -1;
+ }
+
+ @Override
+ public String getParameter(String name) {
+ Param p = getParam(name);
+ if (p != null && p instanceof ValueParam) {
+ ValueParam vp = (ValueParam) p;
+ if (vp.getValue() instanceof String)
+ return (String) vp.getValue();
+ } else if (p != null && p instanceof FileParam) {
+ return "---BINARY DATA---";
+ } else {
+ return super.getParameter(name);
+ }
+
+ return null;
+ }
+
+ @Override
+ public String[] getParameterValues(String name) {
+ Param p = getParam(name);
+ if (p != null && p instanceof ValueParam) {
+ ValueParam vp = (ValueParam) p;
+ if (vp.getValue() instanceof List) {
+ List vals = (List) vp.getValue();
+ String[] values = new String[vals.size()];
+ vals.toArray(values);
+ return values;
+ } else {
+ return new String[] { (String) vp.getValue() };
+ }
+ } else {
+ return super.getParameterValues(name);
+ }
+ }
+
+ @Override
+ public Map getParameterMap() {
+ if (parameters == null)
+ parseRequest();
+
+ Map<String, Object> params = new HashMap<String, Object>(super
+ .getParameterMap());
+
+ for (String name : parameters.keySet()) {
+ Param p = parameters.get(name);
+ if (p instanceof ValueParam) {
+ ValueParam vp = (ValueParam) p;
+ if (vp.getValue() instanceof String) {
+ params.put(name, vp.getValue());
+ } else if (vp.getValue() instanceof List) {
+ params.put(name, getParameterValues(name));
+ }
+ }
+ }
+
+ return params;
+ }
+
+ public void stop() {
+ shouldStop = true;
+ }
+}
16 years, 10 months
JBoss Rich Faces SVN: r6621 - trunk/framework/impl/src/main/java/org/ajax4jsf/component.
by richfaces-svn-commits@lists.jboss.org
Author: maksimkaszynski
Date: 2008-03-07 07:20:45 -0500 (Fri, 07 Mar 2008)
New Revision: 6621
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/component/EventValueExpression.java
Log:
Added for JSF 1.2 compat
Added: trunk/framework/impl/src/main/java/org/ajax4jsf/component/EventValueExpression.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/EventValueExpression.java (rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/EventValueExpression.java 2008-03-07 12:20:45 UTC (rev 6621)
@@ -0,0 +1,199 @@
+/**
+ *
+ */
+package org.ajax4jsf.component;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class EventValueExpression extends ValueExpression implements
+ StateHolder {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6583167387542332290L;
+
+ private String componentId;
+
+ /**
+ * current update component. transient since saved state as component.
+ */
+ transient private AjaxSupport component = null;
+
+
+ public EventValueExpression() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public EventValueExpression(AjaxSupport component) {
+ super();
+ this.component = component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ private AjaxSupport getComponent(FacesContext facesContext)
+ throws ELException {
+
+ if (component == null) {
+ UIComponent uiComponent = facesContext.getViewRoot().findComponent(
+ componentId);
+ if (null != uiComponent && uiComponent instanceof AjaxSupport) {
+ component = (AjaxSupport) uiComponent;
+ } else {
+ throw new ELException(Messages.getMessage(
+ Messages.COMPONENT_NOT_FOUND, componentId));
+ }
+
+ }
+
+ return component;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getExpectedType()
+ */
+ @Override
+ public Class<?> getExpectedType() {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#getExpressionString()
+ */
+ @Override
+ public String getExpressionString() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getType(javax.el.ELContext)
+ */
+ @Override
+ public Class<?> getType(ELContext context) {
+ return String.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getValue(javax.el.ELContext)
+ */
+ @Override
+ public Object getValue(ELContext context) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ AjaxSupport component = getComponent(facesContext);
+ if (((UIComponent) component).isRendered()) {
+ return component.getEventString();
+
+ } else {
+ return null;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#isLiteralText()
+ */
+ @Override
+ public boolean isLiteralText() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
+ */
+ @Override
+ public boolean isReadOnly(ELContext context) {
+ return true;
+ }
+
+ public boolean isTransient() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext,
+ * java.lang.Object)
+ */
+ public void restoreState(FacesContext context, Object state) {
+ componentId = (String) state;
+ }
+
+ public Object saveState(FacesContext context) {
+ if (null == component) {
+ return componentId;
+ } else {
+ return AjaxRendererUtils
+ .getAbsoluteId((UIComponent) getComponent(context));
+ }
+ }
+
+ /**
+ * @param component
+ * the component to set
+ */
+ public void setComponent(AjaxSupport component) {
+ this.component = component;
+ }
+
+ public void setTransient(boolean newTransientValue) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#setValue(javax.el.ELContext,
+ * java.lang.Object)
+ */
+ @Override
+ public void setValue(ELContext context, Object value) {
+ throw new ELException(Messages.getMessage(Messages.EVENT_IS_READ_ONLY));
+ }
+
+}
16 years, 10 months
JBoss Rich Faces SVN: r6620 - in trunk/framework/impl/src: main/java/org/ajax4jsf/context and 5 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: maksimkaszynski
Date: 2008-03-07 07:17:43 -0500 (Fri, 07 Mar 2008)
New Revision: 6620
Added:
trunk/framework/impl/src/test/java/org/ajax4jsf/framework/util/javascript/
trunk/framework/impl/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java
trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
trunk/framework/impl/src/main/java/org/ajax4jsf/javascript/JSMin.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttrCheckImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttributeTable.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Configuration.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EncodingNameMapper.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EntityTable.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Lexer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/ParsePropertyImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Report.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TagTable.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Tidy.java
trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TidyMessage.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxViewRootRenderer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitFactory.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentUtils.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/PrototypeBasedRendererBase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
Log:
fixed syntax for J5
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxRegionBrige.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -21,18 +21,18 @@
package org.ajax4jsf.component;
+import javax.el.ELContext;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.component.StateHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.ValueBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import org.ajax4jsf.Messages;
-import org.ajax4jsf.component.AjaxContainerBase;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.event.AjaxEvent;
import org.ajax4jsf.event.AjaxListener;
@@ -69,7 +69,7 @@
/**
* Listener for call on Ajax Requests
*/
- private MethodBinding ajaxListener = null;
+ private MethodExpression ajaxListener = null;
/**
* Flag for immediate call listeners
@@ -103,7 +103,7 @@
*
* @see org.ajax4jsf.components.custom.ajax.AjaxContainer#getAjaxListener()
*/
- public MethodBinding getAjaxListener() {
+ public MethodExpression getAjaxListener() {
return this.ajaxListener;
}
@@ -112,7 +112,7 @@
*
* @see ogr.apache.myfaces.custom.ajax.AjaxContainer#setAjaxListener(javax.faces.el.MethodBinding)
*/
- public void setAjaxListener(MethodBinding ajaxListener) {
+ public void setAjaxListener(MethodExpression ajaxListener) {
//
if (log.isDebugEnabled())
{
@@ -130,9 +130,9 @@
if (this.immediateSet) {
return (this.immediate);
}
- ValueBinding vb = component.getValueBinding("immediate");
+ ValueExpression vb = component.getValueExpression("immediate");
if (vb != null) {
- return (Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance())));
+ return (Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance().getELContext())));
} else {
return (this.immediate);
}
@@ -158,9 +158,9 @@
if (this.selfRenderedSet) {
return (this.selfRendered);
}
- ValueBinding vb = component.getValueBinding("selfRendered");
+ ValueExpression vb = component.getValueExpression("selfRendered");
if (vb != null) {
- return (Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance())));
+ return (Boolean.TRUE.equals(vb.getValue(FacesContext.getCurrentInstance().getELContext())));
} else {
return (this.selfRendered);
}
@@ -227,10 +227,11 @@
}
// Notify the specified action listener method (if any)
- MethodBinding mb = getAjaxListener();
+ MethodExpression mb = getAjaxListener();
if (mb != null) {
FacesContext context = FacesContext.getCurrentInstance();
- mb.invoke(context, new Object[] { event });
+ ELContext elContext = context.getELContext();
+ mb.invoke(elContext, new Object[] { event });
}
// TODO - perform special rendering, withowt RENDER_VIEW phase.
if(isSelfRendered()) {
@@ -266,7 +267,7 @@
// super.restoreState(context, values[0]);
this.immediate = ((Boolean) values[0]).booleanValue();
this.immediateSet = ((Boolean) values[1]).booleanValue();
- this.ajaxListener = (MethodBinding) UIComponentBase.restoreAttachedState(context, values[2]);
+ this.ajaxListener = (MethodExpression) UIComponentBase.restoreAttachedState(context, values[2]);
this.selfRendered = ((Boolean) values[3]).booleanValue();
this.selfRenderedSet = ((Boolean) values[4]).booleanValue();
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -24,11 +24,11 @@
import java.io.IOException;
import java.util.NoSuchElementException;
+import javax.el.MethodExpression;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
@@ -96,7 +96,7 @@
*
* @see org.ajax4jsf.framework.ajax.AjaxViewBrige#getAjaxListener()
*/
- public MethodBinding getAjaxListener() {
+ public MethodExpression getAjaxListener() {
return getBrige().getAjaxListener();
}
@@ -452,7 +452,7 @@
*
* @see org.ajax4jsf.framework.ajax.AjaxViewBrige#setAjaxListener(javax.faces.el.MethodBinding)
*/
- public void setAjaxListener(MethodBinding ajaxListener) {
+ public void setAjaxListener(MethodExpression ajaxListener) {
getBrige().setAjaxListener(ajaxListener);
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/SequenceDataAdaptor.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -7,7 +7,6 @@
import java.util.Collections;
import java.util.List;
-import javax.faces.context.FacesContext;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
@@ -55,7 +54,7 @@
} else if (current instanceof DataModel) {
model = new SequenceDataModel((DataModel) current);
} else if (current instanceof List) {
- model = new SequenceDataModel(new ListDataModel((List) current));
+ model = new SequenceDataModel(new ListDataModel((List<?>) current));
} else if (Object[].class.isAssignableFrom(current.getClass())) {
model = new SequenceDataModel(new ArrayDataModel((Object[]) current));
} else if (current instanceof ResultSet) {
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/component/UIDataAdaptor.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -29,7 +29,10 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
+import javax.el.ELContext;
+import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.component.EditableValueHolder;
@@ -39,7 +42,6 @@
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
@@ -90,7 +92,7 @@
throws IOException {
setRowKey(context, rowKey);
if (isRowAvailable()) {
- Iterator childIterator = dataChildren();
+ Iterator<UIComponent> childIterator = dataChildren();
while (childIterator.hasNext()) {
UIComponent component = (UIComponent) childIterator.next();
processComponent(context, component, argument);
@@ -112,7 +114,7 @@
public void processComponent(FacesContext context, UIComponent c,
Object argument) {
if (c instanceof UIColumn || c instanceof Column) {
- for (Iterator children = c.getChildren().iterator(); children.hasNext(); ) {
+ for (Iterator<UIComponent> children = c.getChildren().iterator(); children.hasNext(); ) {
UIComponent child = (UIComponent) children.next();
child.processDecodes(context);;
}
@@ -131,7 +133,7 @@
public void processComponent(FacesContext context, UIComponent c,
Object argument) {
if (c instanceof UIColumn || c instanceof Column) {
- for (Iterator children = c.getChildren().iterator(); children.hasNext(); ) {
+ for (Iterator<UIComponent> children = c.getChildren().iterator(); children.hasNext(); ) {
UIComponent child = (UIComponent) children.next();
child.processValidators(context);
}
@@ -150,7 +152,7 @@
public void processComponent(FacesContext context, UIComponent c,
Object argument) {
if (c instanceof UIColumn || c instanceof Column) {
- for (Iterator children = c.getChildren().iterator(); children.hasNext(); ) {
+ for (Iterator<UIComponent> children = c.getChildren().iterator(); children.hasNext(); ) {
UIComponent child = (UIComponent) children.next();
child.processUpdates(context);
}
@@ -165,14 +167,14 @@
* Base client id's of this component, for wich invoked encode... methods.
* Component will save state and serialisable models for this keys only.
*/
- private Set _encoded;
+ private Set<String> _encoded;
/**
* Storage for data model instances with different client id's of this
* component. In case of child for UIData component, this map will keep data
* models for different iterations between phases.
*/
- private Map _modelsMap = new HashMap();
+ private Map<String, ExtendedDataModel> _modelsMap = new HashMap<String, ExtendedDataModel>();
/**
* Reference for curent data model
@@ -182,7 +184,7 @@
/**
* States of this component for diferent iterations, same as for models.
*/
- private Map _statesMap = new HashMap();
+ private Map<String, DataComponentState> _statesMap = new HashMap<String, DataComponentState>();
/**
* Reference for current component state.
@@ -204,16 +206,16 @@
/**
* Values of row keys, encoded on ajax response rendering.
*/
- private Set _ajaxKeys = null;
+ private Set<Object> _ajaxKeys = null;
/**
* Internal set of row keys, encoded on ajax response rendering and cleared after response complete
*/
- private Set _ajaxRequestKeys = null;
+ private Set<Object> _ajaxRequestKeys = null;
private Object _ajaxRowKey = null;
- private Map _ajaxRowKeysMap = new HashMap();
+ private Map<String, Object> _ajaxRowKeysMap = new HashMap<String, Object>();
/**
* Get name of EL variable for component state.
@@ -378,35 +380,36 @@
*
* @see org.ajax4jsf.ajax.repeat.AjaxDataEncoder#getAjaxKeys()
*/
- public Set getAjaxKeys() {
- Set keys = null;
+ @SuppressWarnings("unchecked")
+ public Set<Object> getAjaxKeys() {
+ Set<Object> keys = null;
if (this._ajaxKeys != null) {
keys = (this._ajaxKeys);
} else {
- ValueBinding vb = getValueBinding("ajaxKeys");
+ ValueExpression vb = getValueExpression("ajaxKeys");
if (vb != null) {
- keys = (Set) (vb.getValue(getFacesContext()));
+ keys = (Set<Object>) (vb.getValue(getFacesContext().getELContext()));
} else if (null != _ajaxRowKey) {
// If none of above exist , use row with submitted AjaxComponent
- keys = new HashSet(1);
+ keys = new HashSet<Object>(1);
keys.add(_ajaxRowKey);
}
}
return keys;
}
- public Set getAllAjaxKeys() {
- Set ajaxKeys = getAjaxKeys();
+ public Set<Object> getAllAjaxKeys() {
+ Set<Object> ajaxKeys = getAjaxKeys();
- Set allAjaxKeys = null;
+ Set<Object> allAjaxKeys = null;
if (ajaxKeys != null) {
- allAjaxKeys = new HashSet();
+ allAjaxKeys = new HashSet<Object>();
allAjaxKeys.addAll(ajaxKeys);
}
if (_ajaxRequestKeys != null) {
if (allAjaxKeys == null) {
- allAjaxKeys = new HashSet();
+ allAjaxKeys = new HashSet<Object>();
}
allAjaxKeys.addAll(_ajaxRequestKeys);
@@ -420,7 +423,7 @@
*
* @see org.ajax4jsf.ajax.repeat.AjaxDataEncoder#setAjaxKeys(java.util.Set)
*/
- public void setAjaxKeys(Set ajaxKeys) {
+ public void setAjaxKeys(Set<Object> ajaxKeys) {
this._ajaxKeys = ajaxKeys;
}
@@ -431,7 +434,7 @@
* java.lang.String, java.util.Set, java.util.Set)
*/
public void encodeAjaxChild(FacesContext context, String path,
- final Set ids, final Set renderedAreas) throws IOException {
+ final Set<String> ids, final Set<String> renderedAreas) throws IOException {
resetDataModel();
Renderer renderer = getRenderer(context);
@@ -460,7 +463,7 @@
}
};
- Set ajaxKeys = getAllAjaxKeys();
+ Set<Object> ajaxKeys = getAllAjaxKeys();
if (null != ajaxKeys) {
if(_log.isDebugEnabled()){
_log.debug("Component "+getClientId(context)+" Encode children components for a keys "+ajaxKeys);
@@ -468,13 +471,13 @@
captureOrigValue();
Object savedKey = getRowKey();
setRowKey(context, null);
- Iterator fixedChildren = fixedChildren();
+ Iterator<UIComponent> fixedChildren = fixedChildren();
while (fixedChildren.hasNext()) {
- UIComponent component = (UIComponent) fixedChildren.next();
+ UIComponent component = fixedChildren.next();
ajaxVisitor.processComponent(context, component, null);
}
- for (Iterator iter = ajaxKeys.iterator(); iter.hasNext();) {
- Object key = (Object) iter.next();
+ for (Iterator<Object> iter = ajaxKeys.iterator(); iter.hasNext();) {
+ Object key = iter.next();
ajaxVisitor.process(context, key, null);
}
setRowKey(context,savedKey);
@@ -504,7 +507,7 @@
if (_childrenRenderer == null) {
_childrenRenderer = new AjaxChildrenRenderer() {
- protected Class getComponentClass() {
+ protected Class<? extends UIComponent> getComponentClass() {
return UIDataAdaptor.class;
}
@@ -519,9 +522,9 @@
* @return Set of values for clientId's of this component, for wich was
* invoked "encode" methods.
*/
- protected Set getEncodedIds() {
+ protected Set<String> getEncodedIds() {
if (_encoded == null) {
- _encoded = new HashSet();
+ _encoded = new HashSet<String>();
}
return _encoded;
@@ -541,7 +544,7 @@
*/
protected void setupVariable(FacesContext faces, DataModel localModel,
boolean rowSelected) {
- Map attrs = faces.getExternalContext().getRequestMap();
+ Map<String, Object> attrs = faces.getExternalContext().getRequestMap();
if (rowSelected/*&& isRowAvailable()*/) {
// Current row data.
setupVariable(getVar(), attrs, localModel.getRowData());
@@ -562,7 +565,7 @@
* @param attrs
* @param rowData
*/
- private void setupVariable(String var, Map attrs, Object rowData) {
+ private void setupVariable(String var, Map<String, Object> attrs, Object rowData) {
if (var != null) {
attrs.put(var, rowData);
}
@@ -573,7 +576,7 @@
* @param attrs
* @param rowData
*/
- private void removeVariable(String var, Map attrs) {
+ private void removeVariable(String var, Map<String, Object> attrs) {
if (var != null) {
attrs.remove(var);
}
@@ -647,17 +650,18 @@
DataComponentState state = null;
if (this._currentState == null) {
// Check for binding state to user bean.
- ValueBinding valueBinding = getValueBinding(UIDataAdaptor.COMPONENT_STATE_ATTRIBUTE);
+ ValueExpression valueBinding = getValueExpression(UIDataAdaptor.COMPONENT_STATE_ATTRIBUTE);
FacesContext facesContext = getFacesContext();
+ ELContext elContext = facesContext.getELContext();
if (null != valueBinding) {
state = (DataComponentState) valueBinding
- .getValue(facesContext);
+ .getValue(elContext);
if (null == state) {
// Create default state
state = createComponentState();
- if (!valueBinding.isReadOnly(facesContext)) {
+ if (!valueBinding.isReadOnly(elContext)) {
// Store created state in user bean.
- valueBinding.setValue(facesContext, state);
+ valueBinding.setValue(elContext, state);
}
}
} else {
@@ -795,7 +799,7 @@
public void captureOrigValue(FacesContext faces) {
String var = getVar();
if (var != null) {
- Map attrs = faces.getExternalContext().getRequestMap();
+ Map<String, Object> attrs = faces.getExternalContext().getRequestMap();
this.origValue = attrs.get(var);
}
}
@@ -816,7 +820,7 @@
public void restoreOrigValue(FacesContext faces) {
String var = getVar();
if (var != null) {
- Map attrs = faces.getExternalContext().getRequestMap();
+ Map<String, Object> attrs = faces.getExternalContext().getRequestMap();
if (this.origValue != null) {
attrs.put(var, this.origValue);
} else {
@@ -828,21 +832,21 @@
/**
* Saved values of {@link EditableValueHolder} fields per iterations.
*/
- private Map childState;
+ private Map<String, Map<String, SavedState>> childState;
/**
* @param faces
* @return Saved values of {@link EditableValueHolder} fields per
* iterations.
*/
- protected Map getChildState(FacesContext faces) {
+ protected Map<String, SavedState> getChildState(FacesContext faces) {
if (this.childState == null) {
- this.childState = new HashMap();
+ this.childState = new HashMap<String, Map<String,SavedState>>();
}
String baseClientId = getBaseClientId(faces);
- Map currentChildState = (Map) childState.get(baseClientId);
+ Map<String, SavedState> currentChildState = childState.get(baseClientId);
if (null == currentChildState) {
- currentChildState = new HashMap();
+ currentChildState = new HashMap<String, SavedState>();
childState.put(baseClientId, currentChildState);
}
return currentChildState;
@@ -856,9 +860,9 @@
*/
protected void saveChildState(FacesContext faces) {
- Iterator itr = dataChildren();
+ Iterator<UIComponent> itr = dataChildren();
while (itr.hasNext()) {
- Map childState = this.getChildState(faces);
+ Map<String, SavedState> childState = this.getChildState(faces);
this.saveChildState(faces, (UIComponent) itr.next(), childState);
}
}
@@ -872,11 +876,11 @@
* @param childState
*/
private void saveChildState(FacesContext faces, UIComponent c,
- Map childState) {
+ Map<String, SavedState> childState) {
if (c instanceof EditableValueHolder && !c.isTransient()) {
String clientId = c.getClientId(faces);
- SavedState ss = (SavedState) childState.get(clientId);
+ SavedState ss = childState.get(clientId);
if (ss == null) {
ss = new SavedState();
childState.put(clientId, ss);
@@ -885,7 +889,7 @@
}
// continue hack
- Iterator itr = c.getChildren().iterator();
+ Iterator<UIComponent> itr = c.getChildren().iterator();
while (itr.hasNext()) {
saveChildState(faces, (UIComponent) itr.next(), childState);
}
@@ -905,9 +909,9 @@
*/
protected void restoreChildState(FacesContext faces) {
- Iterator itr = dataChildren();
+ Iterator<UIComponent> itr = dataChildren();
while (itr.hasNext()) {
- Map childState = this.getChildState(faces);
+ Map<String, SavedState> childState = this.getChildState(faces);
this.restoreChildState(faces, (UIComponent) itr.next(), childState);
}
}
@@ -922,7 +926,7 @@
*
*/
private void restoreChildState(FacesContext faces, UIComponent c,
- Map childState) {
+ Map<String, SavedState> childState) {
// reset id
String id = c.getId();
c.setId(id);
@@ -931,7 +935,7 @@
if (c instanceof EditableValueHolder) {
EditableValueHolder evh = (EditableValueHolder) c;
String clientId = c.getClientId(faces);
- SavedState ss = (SavedState) childState.get(clientId);
+ SavedState ss = childState.get(clientId);
if (ss != null) {
ss.apply(evh);
} else {
@@ -940,7 +944,7 @@
}
// continue hack
- Iterator itr = c.getChildren().iterator();
+ Iterator<UIComponent> itr = c.getChildren().iterator();
while (itr.hasNext()) {
restoreChildState(faces, (UIComponent) itr.next(), childState);
}
@@ -961,12 +965,12 @@
*/
private boolean keepSaved(FacesContext context) {
- Iterator clientIds = this.getChildState(context).keySet().iterator();
+ Iterator<String> clientIds = this.getChildState(context).keySet().iterator();
while (clientIds.hasNext()) {
- String clientId = (String) clientIds.next();
- Iterator messages = context.getMessages(clientId);
+ String clientId = clientIds.next();
+ Iterator<FacesMessage> messages = context.getMessages(clientId);
while (messages.hasNext()) {
- FacesMessage message = (FacesMessage) messages.next();
+ FacesMessage message = messages.next();
if (message.getSeverity()
.compareTo(FacesMessage.SEVERITY_ERROR) >= 0) {
return (true);
@@ -994,9 +998,9 @@
this.captureOrigValue(faces);
this.setRowKey(faces, null);
try {
- Iterator fixedChildren = fixedChildren();
+ Iterator<UIComponent> fixedChildren = fixedChildren();
while (fixedChildren.hasNext()) {
- UIComponent component = (UIComponent) fixedChildren.next();
+ UIComponent component = fixedChildren.next();
visitor.processComponent(faces, component, argument);
}
@@ -1101,7 +1105,7 @@
*
* @return iterator for all components not sensitive for row data.
*/
- protected abstract Iterator fixedChildren();
+ protected abstract Iterator<UIComponent> fixedChildren();
/**
* This method must create iterator for all children components, processed
@@ -1109,7 +1113,7 @@
*
* @return iterator for all components processed per row.
*/
- protected abstract Iterator dataChildren();
+ protected abstract Iterator<UIComponent> dataChildren();
private final static SavedState NullState = new SavedState();
@@ -1315,15 +1319,15 @@
private Object superState;
- private Map componentStates = new HashMap();
+ private Map<String, PerIdState> componentStates = new HashMap<String, PerIdState>();
- private Set ajaxKeys;
+ private Set<Object> ajaxKeys;
public String rowKeyVar;
public String stateVar;
- private Map childStates;
+ private Map<String, Map<String, SavedState>> childStates;
}
@@ -1356,17 +1360,17 @@
DataState state = (DataState) object;
super.restoreState(faces, state.superState);
this._ajaxKeys = state.ajaxKeys;
- this._statesMap = new HashMap();
+ this._statesMap = new HashMap<String, DataComponentState>();
this._rowKeyVar = state.rowKeyVar;
this._stateVar = state.stateVar;
this.childState = state.childStates;
// Restore serializable models and component states for all rows of
// parent UIData ( single if this
// component not child of iterable )
- for (Iterator iter = state.componentStates.entrySet().iterator(); iter
+ for (Iterator<Entry<String, PerIdState>> iter = state.componentStates.entrySet().iterator(); iter
.hasNext();) {
- Map.Entry stateEntry = (Map.Entry) iter.next();
- PerIdState idState = (PerIdState) stateEntry.getValue();
+ Entry<String, PerIdState> stateEntry = iter.next();
+ PerIdState idState = stateEntry.getValue();
DataComponentState compState;
if (idState.stateInHolder) {
// TODO - change RichFaces Tree component, for remove reference
@@ -1377,7 +1381,7 @@
} else {
compState = (DataComponentState) idState.componentState;
}
- Object key = stateEntry.getKey();
+ String key = stateEntry.getKey();
this._statesMap.put(key, compState);
this._modelsMap.put(key, idState.model);
}
@@ -1390,17 +1394,16 @@
state.rowKeyVar = this._rowKeyVar;
state.stateVar = this._stateVar;
state.childStates = this.childState;
- Set encodedIds = getEncodedIds();
+ Set<String> encodedIds = getEncodedIds();
// Save all states of component and data model for all valies of
// clientId, encoded in this request.
// this._statesMap.put(getBaseClientId(faces), this._currentState);
// this._modelsMap.put(getBaseClientId(faces), this._currentModel);
- for (Iterator iter = this._statesMap.entrySet().iterator(); iter
+ for (Iterator<Entry<String, DataComponentState>> iter = this._statesMap.entrySet().iterator(); iter
.hasNext();) {
- Map.Entry stateEntry = (Map.Entry) iter.next();
- DataComponentState dataComponentState = ((DataComponentState) stateEntry
- .getValue());
- Object stateKey = stateEntry.getKey();
+ Entry<String, DataComponentState> stateEntry = iter.next();
+ DataComponentState dataComponentState = stateEntry.getValue();
+ String stateKey = stateEntry.getKey();
if (encodedIds.isEmpty() || encodedIds.contains(stateKey)) {
PerIdState idState = new PerIdState();
// Save component state , depended if implemented interfaces.
@@ -1443,7 +1446,7 @@
*/
public void addRequestKey(Object key) {
if (_ajaxRequestKeys == null) {
- _ajaxRequestKeys = new HashSet();
+ _ajaxRequestKeys = new HashSet<Object>();
}
_ajaxRequestKeys.add(key);
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -79,6 +79,7 @@
* @version $Revision: 1.1.2.7 $ $Date: 2007/02/08 19:07:16 $
*
*/
+@SuppressWarnings("deprecation")
public class AjaxContextImpl extends AjaxContext {
public static final String RESOURCES_PROCESSED = "org.ajax4jsf.framework.HEADER_PROCESSED";
@@ -91,11 +92,12 @@
private static ComponentInvoker invoker;
+ //TODO: what is it?
private static Map contextClasses = new HashMap();
- Set ajaxAreasToRender = new HashSet();
+ Set<String> ajaxAreasToRender = new HashSet<String>();
- Set ajaxRenderedAreas = new LinkedHashSet();
+ Set<String> ajaxRenderedAreas = new LinkedHashSet<String>();
boolean ajaxRequest = false;
@@ -111,9 +113,9 @@
ViewIdHolder viewIdHolder = null;
- Map responseDataMap = new HashMap();
+ Map<String, Object> responseDataMap = new HashMap<String, Object> ();
- Map commonAjaxParameters = new HashMap();
+ Map<String, Object> commonAjaxParameters = new HashMap<String, Object> ();
Object oncomplete = null;
@@ -128,9 +130,9 @@
public void release() {
- ajaxAreasToRender = new HashSet();
+ ajaxAreasToRender = new HashSet<String>();
- ajaxRenderedAreas = new LinkedHashSet();
+ ajaxRenderedAreas = new LinkedHashSet<String>();
ajaxRequest = false;
@@ -146,9 +148,9 @@
viewIdHolder = null;
- responseDataMap = new HashMap();
+ responseDataMap = new HashMap<String, Object>();
- commonAjaxParameters = new HashMap();
+ commonAjaxParameters = new HashMap<String, Object>();
}
@@ -356,7 +358,7 @@
public void processHeadResources(FacesContext context)
throws FacesException {
ExternalContext externalContext = context.getExternalContext();
- Map requestMap = externalContext.getRequestMap();
+ Map<String,Object> requestMap = externalContext.getRequestMap();
if (!Boolean.TRUE.equals(requestMap.get(RESOURCES_PROCESSED))) {
if (null != requestMap.get(BaseFilter.RESPONSE_WRAPPER_ATTRIBUTE)) {
if (log.isDebugEnabled()) {
@@ -507,13 +509,13 @@
}
viewResources.collect(context);
- Set scripts = viewResources.getScripts();
+ Set<String> scripts = viewResources.getScripts();
if (scripts.size() > 0) {
if (log.isDebugEnabled()) {
StringBuffer buff = new StringBuffer(
"Scripts for insert into head : \n");
- for (Iterator iter = scripts.iterator(); iter.hasNext();) {
- String script = (String) iter.next();
+ for (Iterator<String> iter = scripts.iterator(); iter.hasNext();) {
+ String script = iter.next();
buff.append(script).append("\n");
}
log.debug(buff.toString());
@@ -521,12 +523,12 @@
requestMap.put(SCRIPTS_PARAMETER, scripts);
}
- Set styles = viewResources.getStyles();
+ Set<String> styles = viewResources.getStyles();
if (styles.size() > 0) {
if (log.isDebugEnabled()) {
StringBuffer buff = new StringBuffer(
"Styles for insert into head : \n");
- for (Iterator iter = styles.iterator(); iter.hasNext();) {
+ for (Iterator<String> iter = styles.iterator(); iter.hasNext();) {
String style = (String) iter.next();
buff.append(style).append("\n");
}
@@ -535,12 +537,12 @@
requestMap.put(STYLES_PARAMETER, styles);
}
- Set usersStyles = viewResources.getUserStyles();
+ Set<String> usersStyles = viewResources.getUserStyles();
if (usersStyles.size() > 0) {
if (log.isDebugEnabled()) {
StringBuffer buff = new StringBuffer(
"User styles for insert into head : \n");
- for (Iterator iter = usersStyles.iterator(); iter.hasNext();) {
+ for (Iterator<String> iter = usersStyles.iterator(); iter.hasNext();) {
String style = (String) iter.next();
buff.append(style).append("\n");
}
@@ -556,12 +558,13 @@
}
}
-
+
+ @SuppressWarnings("deprecation")
public void saveViewState(FacesContext context) throws IOException {
// TODO - for facelets environment, we need to remove transient
// components.
try {
- Application.class.getMethod("getExpressionFactory", null);
+ Application.class.getMethod("getExpressionFactory", (Class<?>) null);
} catch (NoSuchMethodException e) {
// JSF 1.1 !
}
@@ -633,7 +636,7 @@
/**
* @return Returns the ajaxAreasToRender.
*/
- public Set getAjaxAreasToRender() {
+ public Set<String> getAjaxAreasToRender() {
return this.ajaxAreasToRender;
}
@@ -644,7 +647,7 @@
*/
public void addRegionsFromComponent(UIComponent component) {
// First step - find parent ajax view
- Set ajaxRegions = AjaxRendererUtils.getAjaxAreas(component);
+ Set<String> ajaxRegions = AjaxRendererUtils.getAjaxAreas(component);
// if (ajaxRegions == null){
// FacesContext context = FacesContext.getCurrentInstance();
// ajaxRegions = AjaxRendererUtils.getAbsoluteId(context,component);
@@ -654,7 +657,7 @@
component.getId()));
}
if (ajaxRegions != null) {
- for (Iterator iter = ajaxRegions.iterator(); iter.hasNext();) {
+ for (Iterator<String> iter = ajaxRegions.iterator(); iter.hasNext();) {
String id = iter.next().toString();
ajaxAreasToRender.add(convertId(component, id));
}
@@ -698,7 +701,7 @@
/**
* @return Returns the ajaxRenderedAreas.
*/
- public Set getAjaxRenderedAreas() {
+ public Set<String> getAjaxRenderedAreas() {
return ajaxRenderedAreas;
}
@@ -718,7 +721,7 @@
ExternalContext externalContext = context.getExternalContext();
if (null == externalContext.getRequestMap().get(
"javax.servlet.error.exception")) {
- Map requestParameterMap = externalContext
+ Map<String, String> requestParameterMap = externalContext
.getRequestParameterMap();
this.submittedRegionClientId = (String) requestParameterMap
.get(AjaxContainerRenderer.AJAX_PARAMETER_NAME);
@@ -792,7 +795,7 @@
/**
* @return the responseDataMap
*/
- public Map getResponseDataMap() {
+ public Map<String, Object> getResponseDataMap() {
return responseDataMap;
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/context/ViewResources.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -24,10 +24,10 @@
*/
public class ViewResources {
- LinkedHashSet scripts = new LinkedHashSet();
- LinkedHashSet styles = new LinkedHashSet();
- LinkedHashSet userScripts = new LinkedHashSet();
- LinkedHashSet userStyles = new LinkedHashSet();
+ LinkedHashSet<String> scripts = new LinkedHashSet<String>();
+ LinkedHashSet<String> styles = new LinkedHashSet<String>();
+ LinkedHashSet<String> userScripts = new LinkedHashSet<String>();
+ LinkedHashSet<String> userStyles = new LinkedHashSet<String>();
boolean processStyles = true;
boolean processScripts = true;
RenderKit renderKit = null;
@@ -58,14 +58,14 @@
if ((processScripts || processStyles ) && renderer instanceof HeaderResourceProducer) {
HeaderResourceProducer producer = (HeaderResourceProducer) renderer;
if (processScripts) {
- Set set = producer.getHeaderScripts(context, root);
+ Set<String> set = producer.getHeaderScripts(context, root);
if (null != set) {
scripts.addAll(set);
}
}
if (processStyles) {
- Set set = producer.getHeaderStyles(context, root);
+ Set<String> set = producer.getHeaderStyles(context, root);
if (null != set) {
styles.addAll(set);
}
@@ -73,7 +73,7 @@
}
} else if (renderer instanceof UserResourceRenderer) {
UserResourceRenderer producer = (UserResourceRenderer) renderer;
- Set set = producer.getHeaderScripts(context, root);
+ Set<String> set = producer.getHeaderScripts(context, root);
if (null != set) {
userScripts.addAll(set);
}
@@ -84,13 +84,13 @@
}
}
- for (Iterator iter = root.getFacets().values().iterator(); iter
+ for (Iterator<UIComponent> iter = root.getFacets().values().iterator(); iter
.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
+ UIComponent child = iter.next();
processHeadResources(context, child);
}
- for (Iterator iter = root.getChildren().iterator(); iter.hasNext();) {
- UIComponent child = (UIComponent) iter.next();
+ for (Iterator<UIComponent> iter = root.getChildren().iterator(); iter.hasNext();) {
+ UIComponent child = iter.next();
processHeadResources(context, child);
}
}
@@ -145,21 +145,21 @@
/**
* @return the scripts
*/
- public Set getScripts() {
+ public Set<String> getScripts() {
return scripts;
}
/**
* @return the styles
*/
- public Set getStyles() {
+ public Set<String> getStyles() {
return styles;
}
/**
* @return user styles
*/
- public Set getUserStyles() {
+ public Set<String> getUserStyles() {
return userStyles;
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/javascript/JSMin.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/javascript/JSMin.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/javascript/JSMin.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -308,18 +308,21 @@
out.flush();
}
+ @SuppressWarnings("serial")
static class UnterminatedCommentException extends Exception {
public UnterminatedCommentException(int line,int column) {
super("Unterminated comment at line "+line+" and column "+column);
}
}
+ @SuppressWarnings("serial")
static class UnterminatedStringLiteralException extends Exception {
public UnterminatedStringLiteralException(int line,int column) {
super("Unterminated string literal at line "+line+" and column "+column);
}
}
+ @SuppressWarnings("serial")
static class UnterminatedRegExpLiteralException extends Exception {
public UnterminatedRegExpLiteralException(int line,int column) {
super("Unterminated regular expression at line "+line+" and column "+column);
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttrCheckImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttrCheckImpl.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttrCheckImpl.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -77,6 +77,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
/**
@@ -881,7 +882,7 @@
/**
* valid html colors.
*/
- private static final Map COLORS = new HashMap();
+ private static final Map<String, String> COLORS = new HashMap<String, String>();
static
{
@@ -920,11 +921,11 @@
String given = attval.value;
- Iterator colorIter = COLORS.entrySet().iterator();
+ Iterator<Entry<String, String>> colorIter = COLORS.entrySet().iterator();
while (colorIter.hasNext())
{
- Map.Entry color = (Map.Entry) colorIter.next();
+ Entry<String,String> color = colorIter.next();
if (given.charAt(0) == '#')
{
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttributeTable.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttributeTable.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/AttributeTable.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -345,7 +345,7 @@
/**
* Map containing all the installed attributes.
*/
- private Map attributeHashtable = new Hashtable();
+ private Map<String, Attribute> attributeHashtable = new Hashtable<String, Attribute>();
/**
* lookup an installed Attribute.
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Configuration.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Configuration.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Configuration.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -240,7 +240,7 @@
* Map containg all the valid configuration options and the related parser. Tag entry contains String(option
* name)-Flag instance.
*/
- private static final Map OPTIONS = new HashMap();
+ private static final Map<String, Flag> OPTIONS = new HashMap<String, Flag>();
/**
* serial version UID for this class.
@@ -772,7 +772,7 @@
*/
public void addProps(Properties p)
{
- Enumeration propEnum = p.propertyNames();
+ Enumeration<?> propEnum = p.propertyNames();
while (propEnum.hasMoreElements())
{
String key = (String) propEnum.nextElement();
@@ -825,7 +825,7 @@
*/
private void parseProps()
{
- Iterator iterator = properties.keySet().iterator();
+ Iterator<Object> iterator = properties.keySet().iterator();
while (iterator.hasNext())
{
@@ -950,10 +950,10 @@
Flag configItem;
// sort configuration options
- List values = new ArrayList(OPTIONS.values());
+ List<Flag> values = new ArrayList<Flag>(OPTIONS.values());
Collections.sort(values);
- Iterator iterator = values.iterator();
+ Iterator<Flag> iterator = values.iterator();
while (iterator.hasNext())
{
@@ -1012,7 +1012,7 @@
/**
* A configuration option.
*/
- static class Flag implements Comparable
+ static class Flag implements Comparable<Flag>
{
/**
@@ -1113,7 +1113,7 @@
/**
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
- public int compareTo(Object o)
+ public int compareTo(Flag o)
{
return this.name.compareTo(((Flag) o).name);
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EncodingNameMapper.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EncodingNameMapper.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EncodingNameMapper.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -90,7 +90,7 @@
/**
* Map containing uppercase alias - {standard iana, standard java}.
*/
- private static Map encodingNameMap = new HashMap();
+ private static Map<String, String[]> encodingNameMap = new HashMap<String, String[]>();
static
{
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EntityTable.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EntityTable.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/EntityTable.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -354,7 +354,7 @@
/**
* Entity map.
*/
- private Map entityHashtable = new Hashtable();
+ private Map<String, Entity> entityHashtable = new Hashtable<String, Entity>();
/**
* use getDefaultEntityTable to get an entity table instance.
@@ -443,7 +443,7 @@
{
String name = null;
Entity ent;
- Iterator en = this.entityHashtable.values().iterator();
+ Iterator<Entity> en = this.entityHashtable.values().iterator();
while (en.hasNext())
{
ent = (Entity) en.next();
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Lexer.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Lexer.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Lexer.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -372,7 +372,7 @@
/**
* stack.
*/
- protected Stack istack;
+ protected Stack<IStack> istack;
/**
* start of frame.
@@ -412,7 +412,7 @@
/**
* node list.
*/
- private List nodeList;
+ private List<Node> nodeList;
/**
* Instantiates a new Lexer.
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/ParsePropertyImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/ParsePropertyImpl.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/ParsePropertyImpl.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -511,14 +511,14 @@
return "";
}
- List tagList = configuration.tt.findAllDefinedTag(tagType);
+ List<String> tagList = configuration.tt.findAllDefinedTag(tagType);
if (tagList.isEmpty())
{
return "";
}
StringBuffer buffer = new StringBuffer();
- Iterator iterator = tagList.iterator();
+ Iterator<String> iterator = tagList.iterator();
while (iterator.hasNext())
{
buffer.append(iterator.next());
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Report.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Report.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Report.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -84,7 +84,6 @@
import org.ajax4jsf.org.w3c.tidy.TidyMessage.Level;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.impl.NoOpLog;
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TagTable.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TagTable.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TagTable.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -668,7 +668,7 @@
/**
* hashTable containing tags.
*/
- private Map tagHashtable = new Hashtable();
+ private Map<String, Dict> tagHashtable = new Hashtable<String, Dict>();
/**
* Instantiates a new tag table with known tags.
@@ -894,11 +894,11 @@
* @param tagType one of Dict.TAGTYPE_EMPTY | Dict.TAGTYPE_INLINE | Dict.TAGTYPE_BLOCK | Dict.TAGTYPE_PRE
* @return List containing all the user-defined tag names
*/
- List findAllDefinedTag(short tagType)
+ List<String> findAllDefinedTag(short tagType)
{
- List tagNames = new ArrayList();
+ List<String> tagNames = new ArrayList<String>();
- Iterator iterator = tagHashtable.values().iterator();
+ Iterator<Dict> iterator = tagHashtable.values().iterator();
while (iterator.hasNext())
{
Dict curDictEntry = (Dict) iterator.next();
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Tidy.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Tidy.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/Tidy.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -111,7 +111,7 @@
/**
* Alias for configuration options accepted in command line.
*/
- private static final Map CMDLINE_ALIAS = new HashMap();
+ private static final Map<String, String> CMDLINE_ALIAS = new HashMap<String, String>();
static
{
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TidyMessage.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TidyMessage.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/org/w3c/tidy/TidyMessage.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -183,7 +183,7 @@
* @author fgiust
* @version $Revision: 1.1.2.1 $ ($Author: alexsmirnov $)
*/
- public static final class Level implements Comparable
+ public static final class Level implements Comparable<Level>
{
/**
@@ -255,7 +255,7 @@
/**
* @see java.lang.Comparable#compareTo(Object)
*/
- public int compareTo(Object object)
+ public int compareTo(Level object)
{
return this.code - ((Level) object).code;
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxChildrenRenderer.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -65,14 +65,14 @@
* @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 {
+ public void encodeAjaxChild(FacesContext context, UIComponent component, String path, Set<String> ids, Set<String> renderedAreas) throws IOException {
encodeAjaxChildren(context, component, path, ids, renderedAreas);
}
/* (non-Javadoc)
* @see org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String, java.util.Set, java.util.Set)
*/
- public void encodeAjaxChildren(FacesContext context, UIComponent component, String path, Set ids, Set renderedAreas) throws IOException {
+ public void encodeAjaxChildren(FacesContext context, UIComponent component, String path, Set<String> ids, Set<String> renderedAreas) throws IOException {
if (log.isDebugEnabled()) {
log.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO,
path, component.getId()));
@@ -81,7 +81,7 @@
if (component instanceof NamingContainer) {
currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
}
- for (Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
+ for (Iterator<UIComponent> it = component.getFacetsAndChildren(); it.hasNext();) {
UIComponent element = (UIComponent) it.next();
encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
}
@@ -90,7 +90,7 @@
/* (non-Javadoc)
* @see org.ajax4jsf.renderkit.AjaxRenderer#encodeAjaxComponent(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String, java.util.Set, java.util.Set)
*/
- public void encodeAjaxComponent(FacesContext context, UIComponent component, String currentPath, Set ids, Set renderedAreas) throws IOException {
+ public void encodeAjaxComponent(FacesContext context, UIComponent component, String currentPath, Set<String> ids, Set<String> renderedAreas) throws IOException {
if (component.isRendered()) { // skip not-rendered components.
boolean found = false;
if (!ids.isEmpty()) {
@@ -145,7 +145,7 @@
}
}
- private Set _specialComponentTypes = null;
+ private Set<String> _specialComponentTypes = null;
/**
* Detect component as special control case - such as messages bundle
@@ -159,7 +159,7 @@
*/
private boolean isSpecialElement(FacesContext context, UIComponent component) {
if (_specialComponentTypes == null) {
- _specialComponentTypes = new HashSet(10);
+ _specialComponentTypes = new HashSet<String>(10);
for (int i = 0; i < SPECIAL_COMPONENTS_TYPES.length; i++) {
_specialComponentTypes.add(SPECIAL_COMPONENTS_TYPES[i]);
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxContainerRenderer.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -77,6 +77,7 @@
*
* @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
*/
+ @SuppressWarnings("unchecked")
protected Class getComponentClass() {
// TODO Auto-generated method stub
return AjaxContainer.class;
@@ -108,8 +109,8 @@
// Iterate over all childrens, render it if nessesary...
log.debug(Messages.getMessage(Messages.RENDER_CHILDREN_AJAX_INFO));
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- Set ids = ajaxContext.getAjaxAreasToRender();
- Set renderedAreas = ajaxContext.getAjaxRenderedAreas();
+ Set<String> ids = ajaxContext.getAjaxAreasToRender();
+ Set<String> renderedAreas = ajaxContext.getAjaxRenderedAreas();
if (((AjaxContainer) component).isRenderRegionOnly()) {
root = component;
} else {
@@ -144,7 +145,7 @@
*/
protected void doDecode(FacesContext context, UIComponent component) {
String clientId = component.getClientId(context);
- Map paramMap = context.getExternalContext().getRequestParameterMap();
+ Map<String, String> paramMap = context.getExternalContext().getRequestParameterMap();
if (log.isDebugEnabled()) {
log.debug(Messages.getMessage(
Messages.DECODE_AJAX_REQUEST_STATUS_INFO, clientId));
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxRendererUtils.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -104,7 +104,7 @@
public static final String AJAX_REGIONS_ATTRIBUTE = "reRender";
- private static final Class OBJECT_ARRAY_CLASS = (new Object[0]).getClass();
+ private static final Class<?> OBJECT_ARRAY_CLASS = (new Object[0]).getClass();
private static final String VALUE_ATTR = "value";
@@ -116,7 +116,7 @@
public static final String AJAX_DELAY_ATTR = "requestDelay";
- private static final Object AJAX_ABORT_ATTR = "ignoreDupResponses";
+ private static final String AJAX_ABORT_ATTR = "ignoreDupResponses";
/**
* Static class - protect constructor TODO - make as subclass of chameleon
@@ -198,12 +198,12 @@
* @param uiComponent
* @return
*/
- public static Map buildEventOptions(FacesContext facesContext,
+ public static Map<String, Object> buildEventOptions(FacesContext facesContext,
UIComponent uiComponent) {
String clientId = uiComponent.getClientId(facesContext);
- Map componentAttributes = uiComponent.getAttributes();
- Map options = new HashMap();
- Map parameters = new HashMap();
+ Map<String, Object> componentAttributes = uiComponent.getAttributes();
+ Map<String, Object> options = new HashMap<String, Object>();
+ Map<String, Object> parameters = new HashMap<String, Object>();
// UIForm form = getNestingForm(uiComponent);
// "input" - if assigned to html input element.
boolean input = (uiComponent instanceof AjaxSupport && uiComponent
@@ -250,8 +250,8 @@
// Add application-wide Ajax parameters
parameters.putAll(ajaxContext.getCommonAjaxParameters());
// add child parameters
- for (Iterator it = uiComponent.getChildren().iterator(); it.hasNext();) {
- UIComponent child = (UIComponent) it.next();
+ for (Iterator<UIComponent> it = uiComponent.getChildren().iterator(); it.hasNext();) {
+ UIComponent child = it.next();
if (child instanceof UIParameter) {
String name = ((UIParameter) child).getName();
Object value = ((UIParameter) child).getValue();
@@ -280,10 +280,10 @@
}
// parameter to render only current list of areas.
if (isAjaxLimitToList(uiComponent)) {
- Set ajaxAreas = getAjaxAreas(uiComponent);
- Set areasIds = new HashSet();
+ Set<? extends Object> ajaxAreas = getAjaxAreas(uiComponent);
+ Set<String> areasIds = new HashSet<String>();
if (null != ajaxAreas) {
- for (Iterator iter = ajaxAreas.iterator(); iter.hasNext();) {
+ for (Iterator<? extends Object> iter = ajaxAreas.iterator(); iter.hasNext();) {
String id = (String) iter.next();
UIComponent comp = RendererUtils.getInstance().
findComponentFor(uiComponent, id);
@@ -298,10 +298,7 @@
}
String oncomplete = getAjaxOncomplete(uiComponent);
if (null != oncomplete) {
- JSFunctionDefinition function = new JSFunctionDefinition();
- function.addParameter("request");
- function.addParameter("event");
- function.addParameter("data");
+ JSFunctionDefinition function = new JSFunctionDefinition("request", "event", "data");
function.addToBody(oncomplete);
options.put(ONCOMPLETE_ATTR_NAME, function);
@@ -309,10 +306,7 @@
String beforeupdate = getAjaxOnBeforeDomUpdate(uiComponent);
if (null != beforeupdate) {
- JSFunctionDefinition function = new JSFunctionDefinition();
- function.addParameter("request");
- function.addParameter("event");
- function.addParameter("data");
+ JSFunctionDefinition function = new JSFunctionDefinition("request", "event", "data");
function.addToBody(beforeupdate);
options.put(ONBEFOREDOMUPDATE_ATTR_NAME, function);
@@ -474,7 +468,7 @@
* @param uiComponent
* @return List of areas Id's , updated by this component.
*/
- public static Set getAjaxAreas(UIComponent uiComponent) {
+ public static Set<String> getAjaxAreas(UIComponent uiComponent) {
Object areas;
if (uiComponent instanceof AjaxComponent) {
areas = ((AjaxComponent) uiComponent).getReRender();
@@ -495,29 +489,29 @@
* obect for convert to List.
* @return - list of strings.
*/
- public static Set asSet(Object valueToSet) {
+ public static Set<String> asSet(Object valueToSet) {
if (null != valueToSet) {
// Simplest case - set.
if (valueToSet instanceof Set) {
- return (Set) valueToSet;
+ return (Set<String>) valueToSet;
}
// Other collections.
else if (valueToSet instanceof Collection) {
- return new HashSet((Collection) valueToSet);
+ return new HashSet<String>((Collection<String>) valueToSet);
}
// Array
else if (OBJECT_ARRAY_CLASS.isAssignableFrom(valueToSet.getClass())) {
- return new HashSet(Arrays.asList((Object[]) valueToSet));
+ return new HashSet<String>(Arrays.asList((String[]) valueToSet));
}
// Tokenize string.
else if (valueToSet instanceof String) {
String areasString = (String) valueToSet;
if (areasString.indexOf(",") > 0) {
- return new HashSet(Arrays.asList(areasString.trim().split(
+ return new HashSet<String>(Arrays.asList(areasString.trim().split(
"(\\s)*,(\\s)*")));
} else {
- Set areasSet = new HashSet(5);
+ Set<String> areasSet = new HashSet<String>(5);
areasSet.add(areasString.trim());
return areasSet;
}
@@ -700,8 +694,8 @@
UIComponent component) throws IOException {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
ExternalContext externalContext = context.getExternalContext();
- Map requestMap = externalContext.getRequestMap();
- Set rendered = ajaxContext.getAjaxRenderedAreas();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+ Set<String> rendered = ajaxContext.getAjaxRenderedAreas();
StringBuffer senderString = new StringBuffer();
// write special area for list of rendered elements. Client-side
// Java
@@ -719,7 +713,7 @@
component);
out.writeAttribute(HTML.NAME_ATTRIBUTE,
AjaxContainerRenderer.AJAX_UPDATE_HEADER, null);
- for (Iterator it = rendered.iterator(); it.hasNext();) {
+ for (Iterator<String> it = rendered.iterator(); it.hasNext();) {
String id = (String) it.next();
// out.startElement(AJAX_RESULT_TAG, component);
// out.writeText(id,null);
@@ -779,12 +773,12 @@
Messages.OBTAIN_RESPONSE_SET_HEADER_ERROR, e));
}
}
- Map responseDataMap = ajaxContext.getResponseDataMap();
+ Map<String, Object> responseDataMap = ajaxContext.getResponseDataMap();
// Get data serializer instance
AJAXDataSerializer serializer = (AJAXDataSerializer) ServicesUtils
.getServiceInstance(AJAXDataSerializer.SERVICE);
// Put data to JavaScript handlers, inside <span> elements.
- for (Iterator dataIterator = responseDataMap.keySet().iterator(); dataIterator
+ for (Iterator<String> dataIterator = responseDataMap.keySet().iterator(); dataIterator
.hasNext();) {
Object dataKey = dataIterator.next();
out.startElement(HTML.SPAN_ELEM, component);
@@ -881,12 +875,12 @@
*/
private static void loadBundles(FacesContext context, UIComponent component) {
// Iterate over cildrens
- for (Iterator iter = component.getChildren().iterator(); iter.hasNext();) {
+ for (Iterator<UIComponent> iter = component.getChildren().iterator(); iter.hasNext();) {
UIComponent child = (UIComponent) iter.next();
loadCildBundles(context, child);
}
// Iterate over facets
- for (Iterator iter = component.getFacets().values().iterator(); iter
+ for (Iterator<UIComponent> iter = component.getFacets().values().iterator(); iter
.hasNext();) {
UIComponent child = (UIComponent) iter.next();
loadCildBundles(context, child);
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxViewRootRenderer.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxViewRootRenderer.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/AjaxViewRootRenderer.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -21,6 +21,8 @@
package org.ajax4jsf.renderkit;
+import javax.faces.component.UIComponent;
+
import org.ajax4jsf.component.AjaxViewRoot;
import org.ajax4jsf.resource.InternetResource;
@@ -67,7 +69,7 @@
*
* @see org.ajax4jsf.renderkit.AjaxContainerRenderer#getComponentClass()
*/
- protected Class getComponentClass() {
+ protected Class<? extends UIComponent> getComponentClass() {
return AjaxViewRoot.class;
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitFactory.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitFactory.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitFactory.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -125,7 +125,7 @@
/**
* @return
*/
- public Iterator getRenderKitIds() {
+ public Iterator<String> getRenderKitIds() {
return defaultFactory.getRenderKitIds();
}
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitImpl.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ChameleonRenderKitImpl.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -49,14 +49,14 @@
private RenderKit defaultRenderKit = null;
public static final String RENDER_KIT_ID = "AJAX_HTML_BASIC";
- private Map renderers;
+ private Map<String, Renderer> renderers;
//~ Constructors -------------------------------------------------------------------------------
public ChameleonRenderKitImpl()
{
- renderers = new HashMap();
+ renderers = new HashMap<String, Renderer>();
}
//~ Methods ------------------------------------------------------------------------------------
@@ -73,7 +73,7 @@
public void addRenderer(String family, String rendererType,
Renderer renderer) {
if (renderer instanceof ChameleonRenderer) {
- ChameleonRenderer chameleonRenderer = (ChameleonRenderer) renderer;
+// ChameleonRenderer chameleonRenderer = (ChameleonRenderer) renderer;
// chameleonRenderer.setConfiguration(getConfiguration().getRendererConfiguration(family,rendererType));
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentUtils.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentUtils.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentUtils.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -24,11 +24,11 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import javax.el.MethodNotFoundException;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.faces.el.MethodNotFoundException;
import org.ajax4jsf.Messages;
import org.apache.commons.beanutils.MethodUtils;
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/ComponentVariables.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
+import java.util.Map;
/**
* storing tempates variables
@@ -32,7 +33,11 @@
*/
public class ComponentVariables implements Serializable {
- private transient HashMap variablesMap = new HashMap();
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4310787278096026676L;
+ private transient Map<String, Object> variablesMap = new HashMap<String, Object>();
/**
* setting variable
@@ -88,6 +93,6 @@
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException{
- variablesMap = new HashMap();
+ variablesMap = new HashMap<String, Object>();
}
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/PrototypeBasedRendererBase.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/PrototypeBasedRendererBase.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/PrototypeBasedRendererBase.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -40,8 +40,8 @@
protected static final String[] EMPTY_ARRAY = {};
private InternetResource prototypeScript = getResource(PrototypeScript.class.getName());
- public LinkedHashSet getHeaderScripts(FacesContext context, UIComponent component) {
- LinkedHashSet scripts = new LinkedHashSet() ; // Collections.singleton(ajaxScript.getUri(context, null));
+ public LinkedHashSet<String> getHeaderScripts(FacesContext context, UIComponent component) {
+ LinkedHashSet<String> scripts = new LinkedHashSet<String>() ; // Collections.singleton(ajaxScript.getUri(context, null));
scripts.add(prototypeScript.getUri(context, null));
String[] additionalScripts = getAdditionalScripts();
for (int i = 0; i < additionalScripts.length; i++) {
@@ -54,7 +54,7 @@
/* (non-Javadoc)
* @see org.ajax4jsf.renderkit.HeaderResourceProducer#getHeaderStyles(javax.faces.context.FacesContext)
*/
- public LinkedHashSet getHeaderStyles(FacesContext context, UIComponent component) {
+ public LinkedHashSet<String> getHeaderStyles(FacesContext context, UIComponent component) {
// TODO Auto-generated method stub
return null;
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-03-07 12:17:26 UTC (rev 6619)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -42,9 +42,6 @@
import org.ajax4jsf.Messages;
import org.ajax4jsf.javascript.JSFunctionDefinition;
-import org.ajax4jsf.javascript.JSReference;
-import org.ajax4jsf.javascript.ScriptString;
-import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.compiler.TemplateContext;
import org.ajax4jsf.resource.InternetResource;
import org.ajax4jsf.resource.Java2Dresource;
@@ -67,7 +64,7 @@
/**
* Substitutions for components properies names and HTML attributes names.
*/
- private static Map substitutions = new HashMap();
+ private static Map<String, String> substitutions = new HashMap<String, String>();
static {
substitutions.put(HTML.class_ATTRIBUTE, "styleClass");
@@ -357,7 +354,7 @@
public void encodePassThruWithExclusionsArray(FacesContext context,
UIComponent component, String[] exclusions) throws IOException {
ResponseWriter writer = context.getResponseWriter();
- Map attributes = component.getAttributes();
+ Map<String, Object> attributes = component.getAttributes();
Arrays.sort(exclusions);
for (int i = 0; i < HTML.PASS_THRU.length; i++) {
String attribute = HTML.PASS_THRU[i];
@@ -377,7 +374,7 @@
* @param attribute
* @throws IOException
*/
- public void encodePassThruAttribute(FacesContext context, Map attributes,
+ public void encodePassThruAttribute(FacesContext context, Map<String, Object> attributes,
ResponseWriter writer, String attribute) throws IOException {
Object value = attributeValue(attribute, attributes
.get(getComponentAttributeName(attribute)));
@@ -396,7 +393,7 @@
public void encodeAttributesFromArray(FacesContext context,
UIComponent component, String[] attrs) throws IOException {
ResponseWriter writer = context.getResponseWriter();
- Map attributes = component.getAttributes();
+ Map<String, Object> attributes = component.getAttributes();
for (int i = 0; i < attrs.length; i++) {
String attribute = attrs[i];
encodePassThruAttribute(context, attributes, writer, attribute);
@@ -874,7 +871,7 @@
private UIComponent findUIComponentBelow(UIComponent root, String id) {
UIComponent target = null;
- for (Iterator iter = root.getFacetsAndChildren(); iter.hasNext();) {
+ for (Iterator<UIComponent> iter = root.getFacetsAndChildren(); iter.hasNext();) {
UIComponent child = (UIComponent) iter.next();
if (child instanceof NamingContainer) {
try {
Added: trunk/framework/impl/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java
===================================================================
--- trunk/framework/impl/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java (rev 0)
+++ trunk/framework/impl/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java 2008-03-07 12:17:43 UTC (rev 6620)
@@ -0,0 +1,218 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - 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.util.javascript;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.ajax4jsf.javascript.ScriptUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * @author shura
+ *
+ */
+public class ScriptUtilsTest extends TestCase {
+
+ /**
+ * @author shura
+ *
+ */
+ public static class Bean {
+
+ int _integer;
+ boolean _bool;
+ Object _foo;
+
+ /**
+ *
+ */
+ public Bean() {
+ }
+ /**
+ * @param ineger
+ * @param bool
+ * @param foo
+ */
+ public Bean(int ineger, boolean bool, Object foo) {
+ this._integer = ineger;
+ this._bool = bool;
+ this._foo = foo;
+ }
+ /**
+ * @return the bool
+ */
+ public boolean isBool() {
+ return this._bool;
+ }
+ /**
+ * @param bool the bool to set
+ */
+ public void setBool(boolean bool) {
+ this._bool = bool;
+ }
+ /**
+ * @return the ineger
+ */
+ public int getInteger() {
+ return this._integer;
+ }
+ /**
+ * @param ineger the ineger to set
+ */
+ public void setInteger(int ineger) {
+ this._integer = ineger;
+ }
+ /**
+ * @return the foo
+ */
+ public Object getFoo() {
+ return this._foo;
+ }
+ /**
+ * @param foo the foo to set
+ */
+ public void setFoo(Object foo) {
+ this._foo = foo;
+ }
+
+ }
+
+ /**
+ * @param name
+ */
+ public ScriptUtilsTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testStringToScript() {
+ Object obj = "foo";
+ assertEquals("'foo'", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testArrayToScript() {
+ int[] obj = {1,2,3,4,5};
+ assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
+ }
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testTwoDimentionalArrayToScript() {
+ int[][] obj = {{1,2},{3,4}};
+ assertEquals("[[1,2] ,[3,4] ] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testTwoDimentionalStringArrayToScript() {
+ String[][] obj = {{"one","two"},{"three","four"}};
+ assertEquals("[['one','two'] ,['three','four'] ] ", ScriptUtils.toScript(obj));
+ Map map = new TreeMap();
+ map.put("a", obj);
+ map.put("b", "c");
+ assertEquals("{'a':[['one','two'] ,['three','four'] ] ,'b':'c'} ", ScriptUtils.toScript(map));
+ }
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testListToScript() {
+ List obj = new ArrayList();
+ obj.add(new Integer(1));
+ obj.add(new Integer(2));
+ obj.add(new Integer(3));
+ obj.add(new Integer(4));
+ obj.add(new Integer(5));
+ assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testSetToScript() {
+ Set obj = new TreeSet();
+ obj.add(new Integer(1));
+ obj.add(new Integer(2));
+ obj.add(new Integer(3));
+ obj.add(new Integer(4));
+ obj.add(new Integer(5));
+ assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
+ }
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testObjectArrayToScript() {
+ Bean[] obj = {new Bean(1,true,"foo"),new Bean(2,false,"bar")};
+ assertEquals("[{'bool':true,'foo':'foo',\'integer\':1} ,{'bool':false,'foo':'bar','integer':2} ] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testObjectListToScript() {
+ Bean[] array = {new Bean(1,true,"foo"),new Bean(2,false,"bar")};
+ List obj = Arrays.asList(array);
+ assertEquals("[{'bool':true,'foo':'foo',\'integer\':1} ,{'bool':false,'foo':'bar','integer':2} ] ", ScriptUtils.toScript(obj));
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
+ */
+ public void testMapToScript() {
+ TreeMap obj = new TreeMap();
+ obj.put("a", "foo");
+ obj.put("b", "bar");
+ obj.put("c", "baz");
+ assertEquals("{'a':'foo','b':'bar','c':'baz'} ", ScriptUtils.toScript(obj));
+ }
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncodedString(java.lang.StringBuffer, java.lang.Object)}.
+ */
+ public void testAddEncodedString() {
+ StringBuilder buff = new StringBuilder();
+ ScriptUtils.addEncodedString(buff, "foo");
+ assertEquals("'foo'", buff.toString());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncoded(java.lang.StringBuffer, java.lang.Object)}.
+ */
+ public void testAddEncoded() {
+ StringBuilder buff = new StringBuilder();
+ ScriptUtils.addEncoded(buff, "foo\"\'");
+ assertEquals("foo\\\"\\\'", buff.toString());
+ }
+
+
+}
16 years, 10 months
JBoss Rich Faces SVN: r6619 - trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller.
by richfaces-svn-commits@lists.jboss.org
Author: maksimkaszynski
Date: 2008-03-07 07:17:26 -0500 (Fri, 07 Mar 2008)
New Revision: 6619
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/DataTableScrollerBean.java
Log:
fixed syntax for J5
Modified: trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/DataTableScrollerBean.java
===================================================================
--- trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/DataTableScrollerBean.java 2008-03-07 12:17:22 UTC (rev 6618)
+++ trunk/samples/richfaces-demo/src/main/java/org/richfaces/datatablescroller/DataTableScrollerBean.java 2008-03-07 12:17:26 UTC (rev 6619)
@@ -167,9 +167,9 @@
public String takeSelection() {
getSelectedCars().clear();
- Iterator<SimpleRowKey> iterator = getSelection().getKeys();
+ Iterator<Object> iterator = getSelection().getKeys();
while (iterator.hasNext()){
- SimpleRowKey key = iterator.next();
+ Object key = iterator.next();
table.setRowKey(key);
if (table.isRowAvailable()) {
getSelectedCars().add((DemoInventoryItem) table.getRowData());
16 years, 10 months