[Yanel-commits] rev 44171 - in
public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources:
usecase xml
guillaume at wyona.com
guillaume at wyona.com
Thu Aug 13 12:57:38 CEST 2009
Author: guillaume
Date: 2009-08-13 12:57:38 +0200 (Thu, 13 Aug 2009)
New Revision: 44171
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/xml/ConfigurableViewDescriptor.java
Log:
Added more explicit 'jelly-XML' and 'jelly-text' view-types,
please always use these instead of the "intentions-unclear" 'jelly'.
Also deprecated the 'jelly' view-type and refactored accordingly.
(See http://lists.wyona.org/pipermail/yanel-development/2009-May/003567.html for rationale.)
Issue: 5964
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 2009-08-13 08:52:29 UTC (rev 44170)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java 2009-08-13 10:57:38 UTC (rev 44171)
@@ -34,9 +34,6 @@
import org.wyona.yarep.core.Repository;
import org.xml.sax.InputSource;
-/**
- *
- */
public class UsecaseResource extends BasicXMLResource {
private static Logger log = Logger.getLogger(UsecaseResource.class);
@@ -68,8 +65,17 @@
}
if (viewDescriptor.getType().equals(ConfigurableViewDescriptor.TYPE_JELLY)) {
- InputStream xmlInputStream = getJellyXML(viewDescriptor);
+ String viewTemplateURI = viewDescriptor.getTemplate();
+ InputStream xmlInputStream = getJellyTextInputStream(viewID, viewTemplateURI);
view = getXMLView(viewID, xmlInputStream);
+ } else if (viewDescriptor.getType().equals(ConfigurableViewDescriptor.TYPE_JELLY_XML)) {
+ String viewTemplateURI = viewDescriptor.getTemplate();
+ InputStream xmlInputStream = getJellyXMLInputStream(viewID, viewTemplateURI);
+ view = getXMLView(viewID, xmlInputStream);
+ } else if (viewDescriptor.getType().equals(ConfigurableViewDescriptor.TYPE_JELLY_TEXT)) {
+ String viewTemplateURI = viewDescriptor.getTemplate();
+ InputStream xmlInputStream = getJellyTextInputStream(viewID, viewTemplateURI);
+ view = getXMLView(viewID, xmlInputStream);
// TODO: Why is this commented? It would be useful in some cases if one could redirect directly to the original referer instead sending a DONE screen.
/*} else if (viewDescriptor.getType().equals(ViewDescriptor.TYPE_REDIRECT)) {
String redirectURL = getRedirectURL(viewDescriptor);
@@ -103,10 +109,21 @@
/**
* Generate jelly view
+ * @deprecated Use {@link #getJelly(String, boolean)} instead.
*/
+ @Deprecated
protected InputStream getJellyXML(ConfigurableViewDescriptor viewDescriptor) throws UsecaseException {
+ String viewTemplateURI = viewDescriptor.getTemplate();
+ String viewID = viewDescriptor.getId();
+ return getJellyInputStream(viewID, viewTemplateURI, false);
+ }
+
+ /**
+ * Generate jelly view.
+ */
+ private InputStream getJellyInputStream(String viewID, String viewTemplate, boolean XMLoutput) throws UsecaseException {
try {
- String viewTemplate = viewDescriptor.getTemplate();
+
if (log.isDebugEnabled()) log.debug("viewTemplate: "+viewTemplate);
Repository repo = this.getRealm().getRepository();
@@ -120,11 +137,7 @@
//jellyContext.setVariable("request", request);
ByteArrayOutputStream jellyResultStream = new ByteArrayOutputStream();
- // TODO: should enable xml escaping, see bug:
- // http://bugzilla.wyona.com/cgi-bin/bugzilla/show_bug.cgi?id=5964
- // problem: it breaks backwards compatibility
- //XMLOutput jellyOutput = XMLOutput.createXMLOutput(jellyResultStream, true);
- XMLOutput jellyOutput = XMLOutput.createXMLOutput(jellyResultStream);
+ XMLOutput jellyOutput = XMLOutput.createXMLOutput(jellyResultStream, XMLoutput);
InputStream templateInputStream;
String templatePublicId;
String templateSystemId;
@@ -160,12 +173,20 @@
//System.out.println(new String(result, "utf-8"));
return new ByteArrayInputStream(result);
} catch (Exception e) {
- String errorMsg = "Error creating 'jelly' view '" + viewDescriptor.getId() + "' of usecase resource: " + getName() + ": " + e;
+ String errorMsg = "Error creating 'jelly' view '" + viewID + "' of usecase resource: " + getName() + ": " + e;
log.error(errorMsg, e);
throw new UsecaseException(errorMsg, e);
}
}
+ private InputStream getJellyTextInputStream(String viewID, String viewTemplateURI) throws UsecaseException {
+ return getJellyInputStream(viewID, viewTemplateURI, false);
+ }
+
+ private InputStream getJellyXMLInputStream(String viewID, String viewTemplateURI) throws UsecaseException {
+ return getJellyInputStream(viewID, viewTemplateURI, true);
+ }
+
protected String getRedirectURL(ConfigurableViewDescriptor viewDescriptor) {
return viewDescriptor.getRedirectURL();
}
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 2009-08-13 08:52:29 UTC (rev 44170)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/xml/ConfigurableViewDescriptor.java 2009-08-13 10:57:38 UTC (rev 44171)
@@ -20,12 +20,15 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.log4j.Logger;
import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
public class ConfigurableViewDescriptor extends ViewDescriptor {
public static final String TYPE_XML = "xml";
public static final String TYPE_JELLY = "jelly";
+ public static final String TYPE_JELLY_XML = "jelly-XML";
+ public static final String TYPE_JELLY_TEXT = "jelly-text";
public static final String TYPE_REDIRECT = "redirect";
public static final String TYPE_CUSTOM = "custom";
@@ -37,6 +40,8 @@
protected Properties serializerProperties;
protected HashMap httpHeaders;
+ private static final Logger log = Logger.getLogger(ConfigurableViewDescriptor.class);
+
public ConfigurableViewDescriptor(String id) {
super(id);
}
@@ -83,7 +88,12 @@
if (type.equals(TYPE_JELLY)) {
template = config.getChild("template").getValue();
+ /*TODO send a message to yanel-usage@ that we now will log what follows at the warn level and only then do it*/
+ log.info("'"+TYPE_JELLY+"' view-type is deprecated, please use '"+TYPE_JELLY_XML+"' or '"+TYPE_JELLY_TEXT+"' instead (see http://lists.wyona.org/pipermail/yanel-development/2009-May/003567.html for rationale).");
}
+ if (type.equals(TYPE_JELLY_XML) || type.equals(TYPE_JELLY_TEXT)) {
+ template = config.getChild("template").getValue();
+ }
if (type.equals(TYPE_REDIRECT)) {
redirectURL = config.getChild("url").getValue();
}
More information about the Yanel-commits
mailing list