[Yanel-dev] Re: [Yanel-commits] rev 29163 - in public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources: . usecase usecase/thread

Michael Wechner michael.wechner at wyona.com
Fri Nov 23 16:36:37 CET 2007


simon litwan wrote:

> i think  we can safely remove following file, right?
>
> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseView.java 
>


I have just realized that this class was empty and I missed that fact 
within my review. Well, my bad.

But anyway we should never just delete a class from the core, but always 
set it to "deprecated".

If such a core class really is getting "obsolete" then we should 
introduce a policy such as for instance ask on the mailing list if it's 
ok to delete this class and then wait another 3 months and if nobody 
complains within the period, then delete it.

Cheers

Michi

>
>
> cheers
>
> simon
>
>
> michi at wyona.com schrieb:
>
>> Author: michi
>> Date: 2007-11-23 12:03:35 +0100 (Fri, 23 Nov 2007)
>> New Revision: 29163
>>
>> Modified:
>>    
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java 
>>
>>    
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/ExecutableUsecaseResource.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/usecase/UsecaseView.java 
>>
>>    
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java 
>>
>> Log:
>> configurable view descriptor added
>>
>> Modified: 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java 
>>
>> ===================================================================
>> --- 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java    
>> 2007-11-23 11:03:13 UTC (rev 29162)
>> +++ 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java    
>> 2007-11-23 11:03:35 UTC (rev 29163)
>> @@ -19,6 +19,9 @@
>>  import java.io.ByteArrayInputStream;
>>  import java.io.ByteArrayOutputStream;
>>  import java.io.InputStream;
>> +import java.util.Enumeration;
>> +import java.util.HashMap;
>> +import java.util.Properties;
>>  
>>  import javax.xml.transform.Transformer;
>>  import javax.xml.transform.TransformerFactory;
>> @@ -27,9 +30,13 @@
>>  import javax.xml.transform.sax.TransformerHandler;
>>  import javax.xml.transform.stream.StreamSource;
>>  
>> +import org.apache.avalon.framework.configuration.Configuration;
>> +import 
>> org.apache.avalon.framework.configuration.ConfigurationException;
>> +import org.apache.avalon.framework.configuration.ConfigurationUtil;
>>  import org.apache.log4j.Category;
>>  import org.apache.xml.resolver.tools.CatalogResolver;
>>  import org.apache.xml.serializer.Serializer;
>> +import org.w3c.dom.Document;
>>  import org.wyona.security.core.api.Identity;
>>  import org.wyona.yanel.core.Resource;
>>  import org.wyona.yanel.core.api.attributes.ViewableV2;
>> @@ -40,6 +47,8 @@
>>  import org.wyona.yanel.core.transformation.I18nTransformer2;
>>  import org.wyona.yanel.core.transformation.XIncludeTransformer;
>>  import org.wyona.yanel.core.util.PathUtil;
>> +import org.wyona.yanel.impl.resources.xml.ConfigurableViewDescriptor;
>> +import org.wyona.yanel.impl.resources.usecase.UsecaseException;
>>  import org.wyona.yarep.core.Repository;
>>  import org.xml.sax.InputSource;
>>  import org.xml.sax.XMLReader;
>> @@ -52,24 +61,68 @@
>>  
>>      private static Category log = 
>> Category.getInstance(BasicXMLResource.class);
>>  
>> +    protected static String DEFAULT_VIEW_ID = "default";
>>      protected static String SOURCE_VIEW_ID = "source";
>> +    +    protected static String SERIALIZER_OMIT_XML_DECLARATION = 
>> "serializer-omit-xml-declaration";
>> +    protected static String SERIALIZER_DOCTYPE_PUBLIC = 
>> "serializer-doctype-public";
>> +    protected static String SERIALIZER_DOCTYPE_SYSTEM = 
>> "serializer-doctype-system";
>>  
>> +    protected HashMap viewDescriptors;
>> +    +    public ViewDescriptor getViewDescriptor(String viewId) {
>> +        ViewDescriptor[] viewDescriptors = getViewDescriptors();
>> +        for (int i = 0; i < viewDescriptors.length; i++) {
>> +            if (viewDescriptors[i].getId().equals(viewId)) {
>> +                return viewDescriptors[i];
>> +            }
>> +        }
>> +        return null;
>> +    }
>> +         /**
>>       * @see 
>> org.wyona.yanel.core.api.attributes.ViewableV2#getViewDescriptors()
>>       */
>>      public ViewDescriptor[] getViewDescriptors() {
>> -        ViewDescriptor[] vd = new ViewDescriptor[2];
>> +        if (this.viewDescriptors != null) {
>> +            return 
>> (ViewDescriptor[])this.viewDescriptors.values().toArray(new 
>> ViewDescriptor[this.viewDescriptors.size()]); +        }
>>          try {
>> -            vd[0] = new ViewDescriptor("default");
>> -            vd[0].setMimeType(getMimeType(null));
>> -
>> -            vd[1] = new ViewDescriptor(SOURCE_VIEW_ID);
>> -            vd[1].setMimeType(getMimeType(SOURCE_VIEW_ID));
>> +            this.viewDescriptors = new HashMap();
>> +            // reads views from configuration:
>> +            Document customConfigDoc = 
>> getConfiguration().getCustomConfiguration();
>> +            if (customConfigDoc != null) {
>> +                Configuration config = 
>> ConfigurationUtil.toConfiguration(customConfigDoc.getDocumentElement());
>> +                Configuration viewsConfig = config.getChild("views");
>> +                Configuration[] viewConfigs = 
>> viewsConfig.getChildren("view");
>> +                for (int i = 0; i < viewConfigs.length; i++) {
>> +                    String id = viewConfigs[i].getAttribute("id");
>> +                    ConfigurableViewDescriptor viewDescriptor = new 
>> ConfigurableViewDescriptor(id);
>> +                    viewDescriptor.configure(viewConfigs[i]);
>> +                    this.viewDescriptors.put(id, viewDescriptor);
>> +                }
>> +            } else {
>> +                // no custom config
>> +                ConfigurableViewDescriptor[] vd = new 
>> ConfigurableViewDescriptor[2];
>> +                vd[0] = new 
>> ConfigurableViewDescriptor(DEFAULT_VIEW_ID);
>> +                String mimeType = 
>> getResourceConfigProperty("mime-type");
>> +                vd[0].setMimeType(mimeType);
>> +                this.viewDescriptors.put(DEFAULT_VIEW_ID, vd[0]);
>> +                +                vd[1] = new 
>> ConfigurableViewDescriptor(SOURCE_VIEW_ID);
>> +                mimeType = 
>> getResourceConfigProperty("source-view-mime-type");
>> +                vd[1].setMimeType(mimeType);
>> +                this.viewDescriptors.put(SOURCE_VIEW_ID, vd[1]);
>> +                return vd;
>> +            }
>>          } catch (Exception e) {
>> -            log.error(e.getMessage(), e);
>> +            String errorMsg = "Error configuring resource: " + 
>> getPath() + ": " + e.toString();
>> +            log.error(errorMsg, e);
>> +            // TODO: throw exception
>> +            return null;
>>          }
>> -
>> -        return vd;
>> +        +        return null;
>>      }
>>  
>>      /**
>> @@ -84,14 +137,18 @@
>>       * @see 
>> org.wyona.yanel.core.api.attributes.ViewableV2#getMimeType(java.lang.String) 
>>
>>       */
>>      public String getMimeType(String viewId) throws Exception {
>> -        if (viewId != null && viewId.equals(SOURCE_VIEW_ID)) {
>> -            String mimeType = 
>> getResourceConfigProperty("source-view-mime-type");
>> -            if (mimeType != null) return mimeType;
>> -        } else {
>> -            String mimeType = getResourceConfigProperty("mime-type");
>> -            if (mimeType != null) return mimeType;
>> +        String mimeType = null;
>> +        ViewDescriptor viewDescriptor = getViewDescriptor(viewId);
>> +        if (viewDescriptor != null) {
>> +            mimeType = viewDescriptor.getMimeType();
>>          }
>> -        return "application/xml";
>> +        if (mimeType == null) {
>> +            mimeType = this.getResourceConfigProperty("mime-type");
>> +        }
>> +        if (mimeType != null) {
>> +            return mimeType;
>> +        }
>> +        return "application/xhtml+xml";
>>      }
>>  
>>      /**
>> @@ -111,6 +168,10 @@
>>  
>>      public View getXMLView(String viewId, InputStream 
>> xmlInputStream) throws Exception {
>>          View view = new View();
>> +        if (viewId == null) {
>> +            viewId = DEFAULT_VIEW_ID;
>> +        }
>> +        ConfigurableViewDescriptor viewDescriptor = 
>> (ConfigurableViewDescriptor)getViewDescriptor(viewId);
>>          String mimeType = getMimeType(viewId);
>>          view.setMimeType(mimeType);
>>  
>> @@ -119,11 +180,9 @@
>>  
>>              if (viewId != null && viewId.equals(SOURCE_VIEW_ID)) {
>>                  view.setInputStream(xmlInputStream);
>> -                view.setMimeType(getMimeType(viewId));
>>                  return view;
>>              }
>>  
>> -
>>              // create reader:
>>              XMLReader xmlReader = XMLReaderFactory.createXMLReader();
>>              CatalogResolver catalogResolver = new CatalogResolver();
>> @@ -133,10 +192,13 @@
>>              // create xslt transformer:
>>              SAXTransformerFactory tf = 
>> (SAXTransformerFactory)TransformerFactory.newInstance();
>>  
>> -            String[] xsltPath = getXSLTPath(getPath());
>> -            TransformerHandler[] xsltHandlers = new 
>> TransformerHandler[xsltPath.length];
>> -            for (int i = 0; i < xsltPath.length; i++) {
>> -                xsltHandlers[i] = tf.newTransformerHandler(new 
>> StreamSource(repo.getNode(xsltPath[i]).getInputStream()));
>> +            String[] xsltPaths = viewDescriptor.getXSLTPaths();
>> +            if (xsltPaths == null || xsltPaths.length == 0) {
>> +                xsltPaths = getXSLTPath(getPath());
>> +            }
>> +            TransformerHandler[] xsltHandlers = new 
>> TransformerHandler[xsltPaths.length];
>> +            for (int i = 0; i < xsltPaths.length; i++) {
>> +                xsltHandlers[i] = tf.newTransformerHandler(new 
>> StreamSource(repo.getNode(xsltPaths[i]).getInputStream()));
>>                  
>> passTransformerParameters(xsltHandlers[i].getTransformer());
>>              }
>>  
>> @@ -150,14 +212,8 @@
>>              xIncludeTransformer.setResolver(resolver);
>>  
>>              // create serializer:
>> -            Serializer serializer = null;
>> -            if (getMimeType(viewId).equals("text/html")) {
>> -                serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.HTML_TRANSITIONAL);
>> -            } else if 
>> (getMimeType(viewId).equals("application/xhtml+xml")) {
>> -                    serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.XHTML_STRICT);
>> -            } else {
>> -                serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.XML);
>> -            }
>> +            Serializer serializer = createSerializer(viewDescriptor);
>> +                         ByteArrayOutputStream baos = new 
>> ByteArrayOutputStream();
>>  
>>              // chain everything together (create a pipeline):
>> @@ -188,6 +244,45 @@
>>      }
>>  
>>      /**
>> +     * Creates an html or xml serializer for the given view id.
>> +     * @param viewId
>> +     * @return serializer
>> +     * @throws Exception
>> +     */
>> +    protected Serializer createSerializer(ConfigurableViewDescriptor 
>> viewDescriptor) throws Exception {
>> +        Serializer serializer = null;
>> +        String serializerKey = viewDescriptor.getSerializerKey();
>> +        if (serializerKey != null) {
>> +            serializer = 
>> SerializerFactory.getSerializer(serializerKey);
>> +            if (serializer == null) {
>> +                throw new Exception("could not create serializer for 
>> key: " + serializerKey);
>> +            }
>> +        } else {
>> +            String mimeType = getMimeType(viewDescriptor.getId());
>> +
>> +            if (mimeType.equals("text/html")) {
>> +                serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.HTML_TRANSITIONAL);
>> +            } else if (mimeType.equals("application/xml")) {
>> +                serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.XML);
>> +            } else {
>> +                serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.XHTML_STRICT);
>> +            }
>> +        }
>> +        // allow to override xml declaration and doctype:
>> +        Properties properties = 
>> viewDescriptor.getSerializerProperties();
>> +        if (properties != null) {
>> +            Enumeration propNames = properties.propertyNames();
>> +            while (propNames.hasMoreElements()) {
>> +                String name = (String)propNames.nextElement();
>> +                String value = properties.getProperty(name);
>> +
>> +                serializer.getOutputFormat().setProperty(name, value);
>> +            }
>> +        }
>> +        return serializer;
>> +    }
>> +    +    /**
>>       * Gets the names of the i18n message catalogues used for the 
>> i18n transformation.
>>       * Looks for an rc config property named 'i18n-catalogue'. 
>> Defaults to 'global'.
>>       * @return i18n catalogue name
>> @@ -228,6 +323,7 @@
>>          // username
>>          String username = getUsername();
>>          if (username != null) transformer.setParameter("username", 
>> username);
>> +        transformer.setParameter("yanel.reservedPrefix", "yanel"); 
>> // TODO don't hardcode
>>      }
>>  
>>      /**
>>
>> Modified: 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/ExecutableUsecaseResource.java 
>>
>> ===================================================================
>> --- 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/ExecutableUsecaseResource.java    
>> 2007-11-23 11:03:13 UTC (rev 29162)
>> +++ 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/ExecutableUsecaseResource.java    
>> 2007-11-23 11:03:35 UTC (rev 29163)
>> @@ -21,6 +21,7 @@
>>  import java.util.List;
>>  
>>  import org.apache.log4j.Category;
>> +import org.wyona.yanel.core.attributes.viewable.View;
>>  
>>  /**
>>   * The standard executable usecase works as follows:
>> @@ -37,6 +38,7 @@
>>  
>>      private static Category log = 
>> Category.getInstance(ExecutableUsecaseResource.class);
>>      +    protected static final String VIEW_DEFAULT = "default";
>>      protected static final String VIEW_DONE = "done";
>>      protected static final String VIEW_CANCEL = "cancel";
>>      @@ -54,7 +56,7 @@
>>          this.errorMessages = new LinkedList();
>>      }
>>  
>> -    protected UsecaseView processUsecase(String viewID) throws 
>> UsecaseException {
>> +    protected View processUsecase(String viewID) throws 
>> UsecaseException {
>>          if (getParameter(PARAM_SUBMIT) != null) {
>>              if (!checkPreconditions() || hasErrors()) {
>>                  return generateView(VIEW_DEFAULT);
>>
>> 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    
>> 2007-11-23 11:03:13 UTC (rev 29162)
>> +++ 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseResource.java    
>> 2007-11-23 11:03:35 UTC (rev 29163)
>> @@ -19,6 +19,7 @@
>>  import java.io.ByteArrayInputStream;
>>  import java.io.ByteArrayOutputStream;
>>  import java.io.FileOutputStream;
>> +import java.io.InputStream;
>>  import java.io.UnsupportedEncodingException;
>>  import java.util.Enumeration;
>>  import java.util.HashMap;
>> @@ -51,6 +52,8 @@
>>  import org.wyona.yanel.core.transformation.I18nTransformer2;
>>  import org.wyona.yanel.core.transformation.XIncludeTransformer;
>>  import org.wyona.yanel.core.util.PathUtil;
>> +import org.wyona.yanel.impl.resources.xml.ConfigurableViewDescriptor;
>> +import org.wyona.yanel.impl.resources.BasicXMLResource;
>>  import org.wyona.yarep.core.Repository;
>>  import org.xml.sax.InputSource;
>>  import org.xml.sax.XMLReader;
>> @@ -59,14 +62,10 @@
>>  /**
>>   *
>>   */
>> -public class UsecaseResource extends Resource implements ViewableV2 {
>> +public class UsecaseResource extends BasicXMLResource {
>>  
>>      private static Category log = 
>> Category.getInstance(UsecaseResource.class);
>>  
>> -    protected static final String VIEW_DEFAULT = "default";
>> -
>> -    protected HashMap views;
>> -
>>      /**
>>       *
>>       */
>> @@ -77,70 +76,55 @@
>>          init();
>>          return processUsecase(viewID);
>>      }
>> -
>> +         protected void init() throws UsecaseException {
>> -        // reads views from configuration:
>> -        try {
>> -            this.views = new HashMap();
>> -            Document customConfigDoc = 
>> getConfiguration().getCustomConfiguration();
>> -            if (customConfigDoc != null) {
>> -                Configuration config = 
>> ConfigurationUtil.toConfiguration(customConfigDoc.getDocumentElement());
>> -                Configuration viewsConfig = config.getChild("views");
>> -                Configuration[] viewConfigs = 
>> viewsConfig.getChildren("view");
>> -                for (int i = 0; i < viewConfigs.length; i++) {
>> -                    String id = viewConfigs[i].getAttribute("id");
>> -                    String type = viewConfigs[i].getAttribute("type");
>> -                    UsecaseView view = new UsecaseView(id, type);
>> -                    view.configure(viewConfigs[i]);
>> -                    this.views.put(id, view);
>> -                }
>> -            }
>> -        } catch (ConfigurationException e) {
>> -            String errorMsg = "Error configuring usecase: " + 
>> getName() + ": " + e.toString();
>> -            log.error(errorMsg, e);
>> -            throw new UsecaseException(errorMsg, e);
>> -        }
>> +        // implement in subclass
>>      }
>> -
>> -    protected UsecaseView processUsecase(String viewID) throws 
>> UsecaseException {
>> +    +    protected View processUsecase(String viewID) throws 
>> UsecaseException {
>>          return generateView(viewID);
>>      }
>> -
>> -    protected UsecaseView generateView(String viewID) throws 
>> UsecaseException {
>> +    +    protected View generateView(String viewID) throws 
>> UsecaseException {
>>          if (viewID == null || viewID.length() == 0) {
>> -            viewID = VIEW_DEFAULT;
>> +            viewID = DEFAULT_VIEW_ID;
>>          }
>> -        UsecaseView view = (UsecaseView)this.views.get(viewID);
>> -
>> -        if (view == null) {
>> -            throw new UsecaseException("Usecase " + getName() + " 
>> has no view with id: " + viewID);
>> +        try {
>> +            ConfigurableViewDescriptor viewDescriptor = 
>> (ConfigurableViewDescriptor)getViewDescriptor(viewID); +           
>> +            if (viewDescriptor == null) {
>> +                throw new UsecaseException("Usecase " + getName() + 
>> " has no view with id: " + viewID);
>> +            }
>> +            +            if 
>> (viewDescriptor.getType().equals(ConfigurableViewDescriptor.TYPE_JELLY)) 
>> {
>> +                InputStream xmlInputStream = 
>> getJellyXML(viewDescriptor);
>> +                return 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);
>> +            } else {
>> +                throw new UsecaseException("Usecase " + getName() + 
>> " has invalid view type: " + viewDescriptor.getType());
>> +            }
>> +        } catch (Exception e) {
>> +            String errorMsg = "Error generating view of usecase: " + 
>> getName() + ": " + e;
>> +            log.error(errorMsg, e);
>> +            throw new UsecaseException(errorMsg, e);
>>          }
>> -
>> -        if (view.getType().equals(UsecaseView.TYPE_JELLY)) {
>> -            String viewTemplate = view.getTemplate();
>> -            renderJellyView(view, viewTemplate);
>> -            return view;
>> -        } else if (view.getType().equals(UsecaseView.TYPE_REDIRECT)) {
>> -            String redirectURL = getRedirectURL(view);
>> -            view.setRedirectURL(redirectURL);
>> -            return view;
>> -        } else if (view.getType().equals(UsecaseView.TYPE_CUSTOM)) {
>> -            renderCustomView(view);
>> -            return view;
>> -        } else {
>> -            throw new UsecaseException("Usecase " + getName() + " 
>> has invalid view type: " + view.getType());
>> -        }
>>      }
>> -
>> +         protected String getName() {
>>          return "name";
>>      }
>>  
>> -    protected void renderJellyView(UsecaseView view, String 
>> viewTemplate) throws UsecaseException {
>> +    protected InputStream getJellyXML(ConfigurableViewDescriptor 
>> viewDescriptor) throws UsecaseException {
>>          try {
>> -            String viewId = view.getID();
>> +            String viewTemplate = viewDescriptor.getTemplate();
>>              Repository repo = this.getRealm().getRepository();
>> -
>> +                         JellyContext jellyContext = new 
>> JellyContext();
>>              jellyContext.setVariable("resource", this);
>>              jellyContext.setVariable("yanel.back2context", 
>> PathUtil.backToContext(realm, getPath()));
>> @@ -150,127 +134,31 @@
>>              jellyContext.setVariable("yanel.reservedPrefix", 
>> this.getYanel().getReservedPrefix());
>>              //jellyContext.setVariable("request", request);
>>  
>> -            // at first we write the jelly output to a stream,
>> -            // instead of feeding it directly to the sax pipeline,
>> -            // because otherwise there is an error: EmptyStackException
>>              ByteArrayOutputStream jellyResultStream = new 
>> ByteArrayOutputStream();
>>              XMLOutput jellyOutput = 
>> XMLOutput.createXMLOutput(jellyResultStream);
>> -
>> +                         //String viewTemplate = view.getTemplate();
>>              jellyContext.runScript(new 
>> InputSource(repo.getNode(viewTemplate).getInputStream()), jellyOutput);
>>              jellyOutput.flush();
>> -
>> -            // create reader:
>> -            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
>> -            CatalogResolver catalogResolver = new CatalogResolver();
>> -            xmlReader.setEntityResolver(catalogResolver);
>> -
>> -            // create xslt transformer:
>> -            SAXTransformerFactory tf = 
>> (SAXTransformerFactory)TransformerFactory.newInstance();
>> -
>> -            String[] xsltPath = getResourceConfigProperties("xslt");
>> -
>> -            TransformerHandler[] xsltHandlers = new 
>> TransformerHandler[xsltPath.length];
>> -            for (int i = 0; i < xsltPath.length; i++) {
>> -                xsltHandlers[i] = tf.newTransformerHandler(new 
>> StreamSource(repo.getNode(xsltPath[i]).getInputStream()));
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yanel.path.name", 
>> PathUtil.getName(getPath()));
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yanel.path", getPath());
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yanel.back2context", 
>> PathUtil.backToContext(realm, getPath()));
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yanel.globalHtdocsPath", 
>> PathUtil.getGlobalHtdocsPath(this));
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yanel.resourcesHtdocsPath", 
>> PathUtil.getResourcesHtdocsPath(this));
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yanel.back2realm", 
>> PathUtil.backToRealm(getPath()));
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yarep.back2realm", 
>> PathUtil.backToRealm(getPath())); // for backwards compatibility
>> -                
>> xsltHandlers[i].getTransformer().setParameter("language", 
>> getRequestedLanguage());
>> -                
>> xsltHandlers[i].getTransformer().setParameter("yanel.reservedPrefix", 
>> this.getYanel().getReservedPrefix());
>> -            }
>> -
>> -            // create i18n transformer:
>> -            I18nTransformer2 i18nTransformer = new 
>> I18nTransformer2("global", getRequestedLanguage(), 
>> getRealm().getDefaultLanguage());
>> -            i18nTransformer.setEntityResolver(catalogResolver);
>> -
>> -            // create xinclude transformer:
>> -            XIncludeTransformer xIncludeTransformer = new 
>> XIncludeTransformer();
>> -            SourceResolver resolver = new SourceResolver(this);
>> -            xIncludeTransformer.setResolver(resolver);
>> -
>> -            // create serializer
>> -            Serializer serializer = null;
>> -            if (getMimeType(viewId).equals("text/html")) {
>> -                serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.HTML_TRANSITIONAL);
>> -            } else if 
>> (getMimeType(viewId).equals("application/xhtml+xml")) {
>> -                    serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.XHTML_STRICT);
>> -            } else {
>> -                serializer = 
>> SerializerFactory.getSerializer(SerializerFactory.XML);
>> -            }
>> -
>> -            ByteArrayOutputStream baos = new ByteArrayOutputStream();
>> -
>> -            // chain everything together (create a pipeline):
>> -            xmlReader.setContentHandler(xsltHandlers[0]);
>> -            for (int i = 0; i < xsltHandlers.length - 1; i++) {
>> -                xsltHandlers[i].setResult(new 
>> SAXResult(xsltHandlers[i+1]));
>> -            }
>> -            xsltHandlers[xsltHandlers.length - 1].setResult(new 
>> SAXResult(xIncludeTransformer));
>> -            xIncludeTransformer.setResult(new 
>> SAXResult(i18nTransformer));
>> -            i18nTransformer.setResult(new 
>> SAXResult(serializer.asContentHandler()));
>> -            serializer.setOutputStream(baos);
>> -
>> -            // execute pipeline:
>> -            xmlReader.parse(new InputSource(new 
>> ByteArrayInputStream(jellyResultStream.toByteArray())));
>> -
>> -            view.setInputStream(new 
>> ByteArrayInputStream(baos.toByteArray()));
>> -            view.setMimeType(getMimeType(viewId));
>> +            return new 
>> ByteArrayInputStream(jellyResultStream.toByteArray());
>>          } catch (Exception e) {
>>              String errorMsg = "Error creating jelly view of usecase: 
>> " + getName() + ": " + e;
>>              log.error(errorMsg, e);
>>              throw new UsecaseException(errorMsg, e);
>>          }
>>      }
>> -
>> -    protected String getRedirectURL(UsecaseView view) {
>> -        return view.getRedirectURL();
>> +        +    protected String 
>> getRedirectURL(ConfigurableViewDescriptor viewDescriptor) {
>> +        return viewDescriptor.getRedirectURL();
>>      }
>> -
>> -    protected void renderCustomView(UsecaseView view) throws 
>> UsecaseException {
>> +    +    protected View renderCustomView(ConfigurableViewDescriptor 
>> viewDescriptor) throws UsecaseException {
>>          // implement in subclass
>> +        return null;
>>      }
>> -
>> -
>> +         public boolean exists() throws Exception {
>>          return true;
>>      }
>>  
>> -    public String getMimeType(String viewId) throws Exception {
>> -        String mimeType = getResourceConfigProperty("mime-type");
>> -        if (mimeType != null) return mimeType;
>> -        return "application/xhtml+xml";
>> -    }
>> -
>> -    public long getSize() throws Exception {
>> -        // TODO Auto-generated method stub
>> -        return -1;
>> -    }
>> -
>> -    public ViewDescriptor[] getViewDescriptors() {
>> -        // TODO: call init() instead of return null
>> -        if (this.views != null) {
>> -            ViewDescriptor[] descriptors = new 
>> ViewDescriptor[this.views.size()];
>> -
>> -            Iterator iter = this.views.keySet().iterator();
>> -            int i = 0;
>> -            while (iter.hasNext()) {
>> -                UsecaseView view = (UsecaseView)iter.next();
>> -                descriptors[i] = new ViewDescriptor(view.getID());
>> -                String mimeType = view.getMimeType();
>> -                if (mimeType == null || mimeType.length() == 0) {
>> -                    mimeType = "application/xhtml+xml";
>> -                }
>> -                descriptors[i].setMimeType(mimeType);
>> -                i++;
>> -            }
>> -            return descriptors;
>> -        }
>> -        return null;
>> -    }
>> -
>>  }
>>
>> Modified: 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseView.java 
>>
>> ===================================================================
>> --- 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseView.java    
>> 2007-11-23 11:03:13 UTC (rev 29162)
>> +++ 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/UsecaseView.java    
>> 2007-11-23 11:03:35 UTC (rev 29163)
>> @@ -1,89 +0,0 @@
>> -/*
>> - * Copyright 2006 Wyona
>> - *
>> - *  Licensed under the Apache License, Version 2.0 (the "License");
>> - *  you may not use this file except in compliance with the License.
>> - *  You may obtain a copy of the License at
>> - *
>> - *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
>> - *
>> - *  Unless required by applicable law or agreed to in writing, software
>> - *  distributed under the License is distributed on an "AS IS" BASIS,
>> - *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
>> implied.
>> - *  See the License for the specific language governing permissions and
>> - *  limitations under the License.
>> - */
>> -
>> -package org.wyona.yanel.impl.resources.usecase;
>> -
>> -
>> -import org.wyona.yanel.core.attributes.viewable.View;
>> -import org.apache.avalon.framework.configuration.Configuration;
>> -import 
>> org.apache.avalon.framework.configuration.ConfigurationException;
>> -import org.apache.log4j.Category;
>> -
>> -/**
>> - *
>> - */
>> -public class UsecaseView extends View {
>> -
>> -    private static Category log = 
>> Category.getInstance(UsecaseView.class);
>> -    -    public static final String TYPE_JELLY = "jelly";
>> -    public static final String TYPE_REDIRECT = "redirect";
>> -    public static final String TYPE_CUSTOM = "custom";
>> -    -    protected String template;
>> -    protected String type;
>> -    protected String id;
>> -    protected String redirectURL;
>> -
>> -    /**
>> -     *
>> -     */
>> -    public UsecaseView(String id, String type) {
>> -        this.id = id;
>> -        this.type = type;
>> -    }
>> -    -    /**
>> -     * -     */
>> -    public void configure(Configuration config) throws 
>> ConfigurationException {
>> -        if (getType().equals(TYPE_JELLY)) {
>> -            setTemplate(config.getChild("template").getValue());
>> -        }
>> -        if (getType().equals(TYPE_REDIRECT)) {
>> -            setRedirectURL(config.getChild("url").getValue());
>> -        }
>> -    }
>> -
>> -    public String getRedirectURL() {
>> -        return redirectURL;
>> -    }
>> -
>> -    public void setRedirectURL(String redirectURL) {
>> -        this.redirectURL = redirectURL;
>> -    }
>> -
>> -    public String getTemplate() {
>> -        return template;
>> -    }
>> -
>> -    public void setTemplate(String template) {
>> -        this.template = template;
>> -    }
>> -
>> -    public String getType() {
>> -        return type;
>> -    }
>> -
>> -    public void setType(String type) {
>> -        this.type = type;
>> -    }
>> -    -    public String getID() {
>> -        return this.id;
>> -    }
>> -
>> -}
>>
>> Modified: 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java 
>>
>> ===================================================================
>> --- 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java    
>> 2007-11-23 11:03:13 UTC (rev 29162)
>> +++ 
>> public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java    
>> 2007-11-23 11:03:35 UTC (rev 29163)
>> @@ -7,9 +7,9 @@
>>  import javax.servlet.http.HttpSession;
>>  
>>  import org.apache.log4j.Category;
>> +import org.wyona.yanel.core.attributes.viewable.View;
>>  import 
>> org.wyona.yanel.impl.resources.usecase.ExecutableUsecaseResource;
>>  import org.wyona.yanel.impl.resources.usecase.UsecaseException;
>> -import org.wyona.yanel.impl.resources.usecase.UsecaseView;
>>  
>>  /**
>>   * A resource which executes a background thread and shows 
>> periodical status information.
>> @@ -26,8 +26,8 @@
>>      /**
>>       * @see 
>> org.wyona.yanel.impl.resources.usecase.UsecaseResource#processUsecase(java.lang.String) 
>>
>>       */
>> -    protected UsecaseView processUsecase(String viewID) throws 
>> UsecaseException {
>> -        UsecaseView view = null;
>> +    protected View processUsecase(String viewID) throws 
>> UsecaseException {
>> +        View view = null;
>>          try {
>>              HttpSession session = 
>> getEnvironment().getRequest().getSession();
>>            
>> _______________________________________________
>> Yanel-commits mailing list
>> Yanel-commits at wyona.com
>> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-commits
>>   
>
>
> _______________________________________________
> Yanel-development mailing list
> Yanel-development at wyona.com
> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development



-- 
Michael Wechner
Wyona      -   Open Source Content Management - Yanel, Yulup
http://www.wyona.com
michael.wechner at wyona.com, michi at apache.org
+41 44 272 91 61



More information about the Yanel-development mailing list