cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation HTMLEventLinkTransformer.java AbstractCopletTransformer.java
Date Thu, 12 Feb 2004 09:32:38 GMT
cziegeler    2004/02/12 01:32:38

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/transformation
                        AbstractCopletTransformer.java
  Added:       src/blocks/portal/java/org/apache/cocoon/portal/transformation
                        HTMLEventLinkTransformer.java
  Log:
  New html->event transformer
  
  Revision  Changes    Path
  1.6       +5 -4      cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java
  
  Index: AbstractCopletTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/AbstractCopletTransformer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractCopletTransformer.java	11 Dec 2003 15:36:04 -0000	1.5
  +++ AbstractCopletTransformer.java	12 Feb 2004 09:32:37 -0000	1.6
  @@ -103,9 +103,9 @@
   
               portalService = (PortalService)this.manager.lookup(PortalService.ROLE);
   
  -            // determine coplet id
  -            Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
  -            if ( context == null ) {
  +            final Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT);
  +            
  +            if ( portalService.getPortalName() == null && context == null) {
                   // set portal name
                   try {
                       portalService.setPortalName(this.parameters.getParameter(PORTAL_NAME_PARAM));
  @@ -115,6 +115,7 @@
               }
               
               if ( copletId == null ) {
  +                // determine coplet id
                   if (context != null) {
                       copletId = (String)context.get(Constants.COPLET_ID_KEY);
                   } else {
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
  
  Index: HTMLEventLinkTransformer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 2004 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
  */
  package org.apache.cocoon.portal.transformation;
  
  import java.io.IOException;
  import java.util.Map;
  
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.portal.coplet.CopletInstanceData;
  import org.apache.cocoon.xml.AttributesImpl;
  import org.apache.excalibur.source.SourceUtil;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  
  /**
   * This transformer extends transforms html actions
   * into events.
   * The transformer listens for the element a and form.
   * Current we only support POSing of forms.
   * 
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: HTMLEventLinkTransformer.java,v 1.1 2004/02/12 09:32:37 cziegeler Exp
$
   */
  public class HTMLEventLinkTransformer 
  extends AbstractCopletTransformer 
  implements Serviceable {
      
      /** The temporary attribute used to store the uri */
      protected String attributeName;
      
      /** The jxpath for the attribute */
      protected String jxPath;
      
      /* (non-Javadoc)
       * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
       */
      public void setup(SourceResolver resolver,
                        Map objectModel,
                        String src,
                        Parameters par)
      throws ProcessingException, SAXException, IOException {
          super.setup(resolver, objectModel, src, par);
          this.attributeName = par.getParameter("attribute-name", "application-uri");
          this.jxPath = "temporaryAttributes/" + this.attributeName;
      }
  
      /* (non-Javadoc)
       * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String,
java.lang.String, org.xml.sax.Attributes)
       */
      public void startElement(String uri, String name, String raw, Attributes attr)
      throws SAXException {
          if ("a".equals(name) ) {
              this.createAnchorEvent(uri, name, raw, attr);
          } else if ("form".equals(name) ) {
              this.createFormEvent(uri, name, raw, attr);
          } else {
              super.startElement(uri, name, raw, attr);
          }
      }
  
      /* (non-Javadoc)
       * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
       */
      public void endElement(String uri, String name, String raw)
      throws SAXException {
          if ( "a".equals(name) || "form".equals("name") ) {
              this.xmlConsumer.endElement(CopletTransformer.NAMESPACE_URI,
                                          CopletTransformer.LINK_ELEM,
                                          "coplet:" + CopletTransformer.LINK_ELEM);
              this.xmlConsumer.endPrefixMapping("coplet");
          } else {
              super.endElement(uri, name, raw);
          }
      }
  
      protected void createAnchorEvent(String uri, String name, String raw, Attributes attributes)

      throws SAXException {
          AttributesImpl newAttributes = new AttributesImpl();
          String link = attributes.getValue("href");
          
          CopletInstanceData cid = this.getCopletInstanceData();
          link = this.getLink((String)cid.getTemporaryAttribute(this.attributeName), link);
  
          newAttributes.addCDATAAttribute("path", this.jxPath);
          newAttributes.addCDATAAttribute("value", link);
          newAttributes.addCDATAAttribute("coplet", cid.getId());
          newAttributes.addCDATAAttribute("format", "html-link");
          this.xmlConsumer.startPrefixMapping("coplet", CopletTransformer.NAMESPACE_URI);
          this.xmlConsumer.startElement(CopletTransformer.NAMESPACE_URI,
                                        CopletTransformer.LINK_ELEM,
                                        "coplet:" + CopletTransformer.LINK_ELEM,
                                        newAttributes);
      }
  
      protected void createFormEvent(String uri, String name, String raw, Attributes attributes)

      throws SAXException {
          AttributesImpl newAttributes = new AttributesImpl();
          String link = attributes.getValue("action");
          
          CopletInstanceData cid = this.getCopletInstanceData();
          link = this.getLink((String)cid.getTemporaryAttribute(this.attributeName), link);
          
          newAttributes.addCDATAAttribute("path", this.jxPath);
          newAttributes.addCDATAAttribute("value", link);
          newAttributes.addCDATAAttribute("coplet", cid.getId());
          newAttributes.addCDATAAttribute("format", "html-form");
          newAttributes.addCDATAAttribute("method", "POST");
          this.xmlConsumer.startPrefixMapping("coplet", CopletTransformer.NAMESPACE_URI);
          this.xmlConsumer.startElement(CopletTransformer.NAMESPACE_URI,
                  CopletTransformer.LINK_ELEM,
                  "coplet:" + CopletTransformer.LINK_ELEM,
                  newAttributes);
  
      }
      
      protected String getLink(String base, String link) {
          final String v = SourceUtil.absolutize(base, link);
          return v;
      }
  }
  
  
  

Mime
View raw message