Changes between Version 1 and Version 2 of LocationContentDecorator
- Timestamp:
- 08/17/07 08:04:03 (3 years ago)
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 = 4 2 5 3 This is the code example. 6 4 7 8 9 10 11 5 {{{ 12 13 6 /* 14 15 7 * $Header$ 16 17 8 * 18 19 9 * Created on Apr 5, 2006 20 21 10 * 22 23 11 * Copyright (C) 2005 Escenic. 24 25 12 * All Rights Reserved. No use, copying or distribution of this work may be made 26 27 13 * except in accordance with a valid license agreement from Escenic. This notice 28 29 14 * must be ncluded on all copies, modifications and derivatives of this work. 30 31 15 */ 32 33 16 package com.escenic.example; 34 17 35 36 37 18 import neo.xredsys.presentation.PresentationArticle; 38 39 19 import neo.xredsys.presentation.PresentationArticleDecorator; 40 41 42 20 43 21 public class LocationContentDecorator extends PresentationArticleDecorator { 44 22 45 46 47 23 private String locationContent; 48 49 24 private String separator = "<p>"; 50 25 51 52 53 26 public LocationContentDecorator() { 54 55 27 super(); 56 57 28 } 58 29 59 60 61 30 public LocationContentDecorator(PresentationArticle pPresentationArticleToDecorate) { 62 63 31 super(pPresentationArticleToDecorate); 64 65 32 } 66 33 67 68 69 34 public String getFieldElement(String pFieldName) { 70 71 35 if ("locationContent".equalsIgnoreCase(pFieldName)) { 72 73 36 if (this.locationContent == null) { 74 75 37 String content = super.getFieldElement("content"); 76 77 78 38 79 39 StringBuffer result = new StringBuffer(); 80 40 81 82 83 41 result.append(content.substring(0, this.separator.length())); 84 85 42 result.append("<span class=\"location\">"); 86 87 43 result.append(super.getFieldElement("location")); 88 89 44 result.append("</span>"); 90 91 45 result.append(content.substring(this.separator.length(), content.length())); 92 46 93 94 95 47 this.locationContent = result.toString(); 96 97 48 } 98 49 99 50 100 101 102 103 51 return this.locationContent; 104 105 52 } 106 107 53 return super.getFieldElement(pFieldName); 108 109 54 } 110 111 55 } 112 56 113 114 115 57 }}} 116 117 118 58 119 59 We 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.
