Changes between Version 1 and Version 2 of LocationContentDecorator

Show
Ignore:
Author:
jakob (IP: 88.90.163.216)
Timestamp:
08/17/07 08:04:03 (3 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LocationContentDecorator

    v1 v2  
    1 = How to combine two fields with an PresentationArticleDecorator 
    2  = 
    3  
     1= How to combine two fields with an PresentationArticleDecorator = 
    42 
    53This is the code example. 
    64 
    7  
    8  
    9  
    10  
    115{{{ 
    12  
    136/* 
    14  
    157 * $Header$ 
    16  
    178 * 
    18  
    199 * Created on Apr 5, 2006 
    20  
    2110 * 
    22  
    2311 * Copyright (C) 2005 Escenic. 
    24  
    2512 * All Rights Reserved. No use, copying or distribution of this work may be made 
    26  
    2713 * except in accordance with a valid license agreement from Escenic. This notice 
    28  
    2914 * must be ncluded on all copies, modifications and derivatives of this work. 
    30  
    3115 */ 
    32  
    3316package com.escenic.example; 
    3417 
    35  
    36  
    3718import neo.xredsys.presentation.PresentationArticle; 
    38  
    3919import neo.xredsys.presentation.PresentationArticleDecorator; 
    40  
    41  
    4220 
    4321public class LocationContentDecorator extends PresentationArticleDecorator { 
    4422 
    45  
    46  
    4723  private String locationContent; 
    48  
    4924  private String separator = "<p>"; 
    5025 
    51  
    52  
    5326  public LocationContentDecorator() { 
    54  
    5527    super(); 
    56  
    5728  } 
    5829 
    59  
    60  
    6130  public LocationContentDecorator(PresentationArticle pPresentationArticleToDecorate) { 
    62  
    6331    super(pPresentationArticleToDecorate); 
    64  
    6532  } 
    6633 
    67  
    68  
    6934  public String getFieldElement(String pFieldName) { 
    70  
    7135    if ("locationContent".equalsIgnoreCase(pFieldName)) { 
    72  
    7336      if (this.locationContent == null) { 
    74  
    7537        String content = super.getFieldElement("content"); 
    76  
    77  
    7838 
    7939        StringBuffer result = new StringBuffer(); 
    8040 
    81  
    82  
    8341        result.append(content.substring(0, this.separator.length())); 
    84  
    8542        result.append("<span class=\"location\">"); 
    86  
    8743        result.append(super.getFieldElement("location")); 
    88  
    8944        result.append("</span>"); 
    90  
    9145        result.append(content.substring(this.separator.length(), content.length())); 
    9246 
    93  
    94  
    9547        this.locationContent = result.toString(); 
    96  
    9748      } 
    9849 
    9950 
    100  
    101  
    102  
    10351      return this.locationContent; 
    104  
    10552    } 
    106  
    10753    return super.getFieldElement(pFieldName); 
    108  
    10954  } 
    110  
    11155} 
    11256 
    113  
    114  
    11557}}} 
    116  
    117  
    11858 
    11959We override the {{getFieldElement(String)}} method. This is the one that is called when you do a {{<ARTICLE:field field="hubba" />}}. So we have now in effect created a new field with the name of {{locationContent}}. When you now do a call with {{<ARTICLE:field field="locationContent" />}} you call upon our newly created method.