[Yanel-commits] rev 34010 - in public/yanel/trunk/src:
core/java/org/wyona/yanel/core/attributes/viewable
impl/java/org/wyona/yanel/impl/resources/usecase
impl/java/org/wyona/yanel/impl/resources/xml
webapp/src/java/org/wyona/yanel/servlet
simon at wyona.com
simon at wyona.com
Tue Mar 25 16:26:25 CET 2008
Author: simon
Date: 2008-03-25 16:26:24 +0100 (Tue, 25 Mar 2008)
New Revision: 34010
Modified:
public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java
public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java
public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/xml/ConfigurableViewDescriptor.java
public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
Log:
see: http://bugzilla.wyona.com/cgi-bin/bugzilla/show_bug.cgi?id=6183
thanks to josias!
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java 2008-03-25 15:23:04 UTC (rev 34009)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/attributes/viewable/View.java 2008-03-25 15:26:24 UTC (rev 34010)
@@ -17,6 +17,7 @@
package org.wyona.yanel.core.attributes.viewable;
import java.io.InputStream;
+import java.util.HashMap;
/**
*
@@ -27,7 +28,12 @@
private String encoding = null;
private InputStream is;
private boolean isResponse = true;
+ private HashMap httpHeaders = null;
+ public View() {
+ this.httpHeaders = new HashMap();
+ }
+
/**
*
*/
@@ -87,4 +93,16 @@
public void setResponse(boolean isResponse) {
this.isResponse = isResponse;
}
+
+ public HashMap getHttpHeaders() {
+ return this.httpHeaders;
+ }
+
+ public void setHttpHeaders(HashMap headers) {
+ this.httpHeaders.putAll(headers);
+ }
+
+ public void setHttpHeader(String name, String value) {
+ this.httpHeaders.put(name, value);
+ }
}
Modified: public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java
===================================================================
--- public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java 2008-03-25 15:23:04 UTC (rev 34009)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java 2008-03-25 15:26:24 UTC (rev 34010)
@@ -90,7 +90,8 @@
viewID = DEFAULT_VIEW_ID;
}
try {
- ConfigurableViewDescriptor viewDescriptor = (ConfigurableViewDescriptor)getViewDescriptor(viewID);
+ ConfigurableViewDescriptor viewDescriptor = (ConfigurableViewDescriptor)getViewDescriptor(viewID);
+ View view = null;
if (viewDescriptor == null) {
throw new UsecaseException("Usecase " + getName() + " has no view with id: " + viewID);
@@ -98,17 +99,19 @@
if (viewDescriptor.getType().equals(ConfigurableViewDescriptor.TYPE_JELLY)) {
InputStream xmlInputStream = getJellyXML(viewDescriptor);
- return getXMLView(viewID, xmlInputStream);
+ view = getXMLView(viewID, xmlInputStream);
/*} else if (viewDescriptor.getType().equals(ViewDescriptor.TYPE_REDIRECT)) {
String redirectURL = getRedirectURL(viewDescriptor);
UsecaseView view = new UsecaseView(viewDescriptor.getId(), UsecaseView.TYPE_REDIRECT);
view.setRedirectURL(redirectURL);
return view;*/
} else if (viewDescriptor.getType().equals(ConfigurableViewDescriptor.TYPE_CUSTOM)) {
- return renderCustomView(viewDescriptor);
+ view = renderCustomView(viewDescriptor);
} else {
throw new UsecaseException("Usecase " + getName() + " has invalid view type: " + viewDescriptor.getType());
}
+ view.setHttpHeaders(viewDescriptor.getHttpHeaders());
+ return view;
} catch (Exception e) {
String errorMsg = "Error generating view of usecase: " + getName() + ": " + e;
log.error(errorMsg, e);
@@ -144,7 +147,9 @@
//String viewTemplate = view.getTemplate();
jellyContext.runScript(new InputSource(repo.getNode(viewTemplate).getInputStream()), jellyOutput);
jellyOutput.flush();
- return new ByteArrayInputStream(jellyResultStream.toByteArray());
+ byte[] result = jellyResultStream.toByteArray();
+ //System.out.println(new String(result, "utf-8"));
+ return new ByteArrayInputStream(result);
} catch (Exception e) {
String errorMsg = "Error creating jelly view of usecase: " + getName() + ": " + e;
log.error(errorMsg, e);
Modified: public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/xml/ConfigurableViewDescriptor.java
===================================================================
--- public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/xml/ConfigurableViewDescriptor.java 2008-03-25 15:23:04 UTC (rev 34009)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/xml/ConfigurableViewDescriptor.java 2008-03-25 15:26:24 UTC (rev 34010)
@@ -15,6 +15,7 @@
*/
package org.wyona.yanel.impl.resources.xml;
+import java.util.HashMap;
import java.util.Properties;
import org.apache.avalon.framework.configuration.Configuration;
@@ -34,6 +35,7 @@
protected String[] xsltPaths;
protected String serializerKey;
protected Properties serializerProperties;
+ protected HashMap httpHeaders;
public ConfigurableViewDescriptor(String id) {
super(id);
@@ -81,6 +83,17 @@
if (type.equals(TYPE_REDIRECT)) {
redirectURL = config.getChild("url").getValue();
}
+
+ httpHeaders = new HashMap();
+ Configuration headerParentConfig = config.getChild("http-headers", false);
+ if (headerParentConfig != null) {
+ Configuration[] headerConfigs = headerParentConfig.getChildren("header");
+ for (int i = 0; i < headerConfigs.length; i++) {
+ String name = headerConfigs[i].getAttribute("name");
+ String value = headerConfigs[i].getAttribute("value");
+ httpHeaders.put(name, value);
+ }
+ }
}
public String getRedirectURL() {
@@ -107,6 +120,14 @@
this.serializerProperties = serializerProperties;
}
+ public HashMap getHttpHeaders() {
+ return this.httpHeaders;
+ }
+
+ public void setHttpHeaders(HashMap httpHeaders) {
+ this.httpHeaders = httpHeaders;
+ }
+
public String getTemplate() {
return template;
}
Modified: public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java
===================================================================
--- public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java 2008-03-25 15:23:04 UTC (rev 34009)
+++ public/yanel/trunk/src/webapp/src/java/org/wyona/yanel/servlet/YanelServlet.java 2008-03-25 15:26:24 UTC (rev 34010)
@@ -15,6 +15,8 @@
import java.util.Calendar;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Properties;
import java.util.Vector;
import javax.servlet.ServletConfig;
@@ -1974,6 +1976,18 @@
}
}
+ // http headers:
+ HashMap headers = view.getHttpHeaders();
+ Iterator iter = headers.keySet().iterator();
+ while (iter.hasNext()) {
+ String name = (String)iter.next();
+ String value = (String)headers.get(name);
+ if (log.isDebugEnabled()) {
+ log.debug("set http header: " + name + ": " + value);
+ }
+ response.setHeader(name, value);
+ }
+
// Possibly embed toolbar:
// TODO: Check if user is authorized to actually see toolbar (Current flaw: Enabled Toolbar, Login, Toolbar is enabled, Logout, Toolbar is still visible!)
if (isToolbarEnabled(request)) {
More information about the Yanel-commits
mailing list