cziegeler    2004/05/06 04:03:45

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/transformation
                        HTMLEventLinkTransformer.java
  Log:
  Support for external links and mailto links
  
  Revision  Changes    Path
  1.12      +36 -5     
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
  
  Index: HTMLEventLinkTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- HTMLEventLinkTransformer.java     15 Apr 2004 07:51:41 -0000      1.11
  +++ HTMLEventLinkTransformer.java     6 May 2004 11:03:44 -0000       1.12
  @@ -32,7 +32,11 @@
    * into events.
    * The transformer listens for the element a and form. Links
    * that only contain an anchor are ignored.
  - *
  + * In addition if a link has the attribute "external" with the value
  + * "true", the link is also ignored.
  + * 
  + * TODO: Support target attribute
  + * 
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Id$
    */
  @@ -65,9 +69,13 @@
       throws SAXException {
           boolean processed = false;
           if ("a".equals(name) ) {
  +            boolean convert = false;
               final boolean isRemoteAnchor = this.isRemoteAnchor(attr);
  -            this.stack.push(isRemoteAnchor? Boolean.TRUE: Boolean.FALSE);
               if ( isRemoteAnchor ) {
  +                convert = this.isExternalLink(attr);
  +            }
  +            this.stack.push(convert ? Boolean.TRUE: Boolean.FALSE);
  +            if ( convert ) {
                   this.createAnchorEvent(attr);
                   processed = true;
               }
  @@ -87,8 +95,8 @@
       throws SAXException {
           boolean processed = false;
           if ( "a".equals(name) ) {
  -            final Boolean isRemoteAnchor = (Boolean)this.stack.pop();
  -            if ( isRemoteAnchor.booleanValue() ) {
  +            final Boolean converted = (Boolean)this.stack.pop();
  +            if ( converted.booleanValue() ) {
                   this.xmlConsumer.endElement(CopletTransformer.NAMESPACE_URI,
                                               CopletTransformer.LINK_ELEM,
                                               "coplet:" + 
CopletTransformer.LINK_ELEM);
  @@ -111,6 +119,7 @@
       throws SAXException {
           AttributesImpl newAttributes = new AttributesImpl(attributes);
           newAttributes.removeAttribute("href");
  +        newAttributes.removeAttribute("external");
           String link = attributes.getValue("href");
   
           CopletInstanceData cid = this.getCopletInstanceData();
  @@ -178,4 +187,26 @@
           return false;
       }
   
  +    /**
  +     * a link in an external application is not transformed
  +     * if there is an attribute external="true" in the link-element
  +     * or if the link starts with "mailto:";.
  +     * 
  +     * @param attributes attributes of the node
  +     * @return true if the attribute 'external' is 'true'
  +     */
  +    private boolean isExternalLink (Attributes attributes) {        
  +        final String external = attributes.getValue("external");
  +        // links to external documents will be not transformed to portal 
links
  +        if (external != null && external.trim().length() > 0 
  +            && external.trim().toLowerCase().equals ("true") ) {            
  +            return true;
  +        }
  +        final String link = attributes.getValue("href");
  +        if ( link != null && link.startsWith("mailto:";) ) {
  +            return true;
  +        }
  +        return false;
  +    }
  +    
   }
  
  
  

Reply via email to