KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > util > CmsMacroResolver


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/util/CmsMacroResolver.java,v $
3  * Date : $Date: 2006/10/20 10:36:51 $
4  * Version: $Revision: 1.20 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.util;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsProperty;
36 import org.opencms.file.CmsResource;
37 import org.opencms.flex.CmsFlexController;
38 import org.opencms.i18n.CmsMessageContainer;
39 import org.opencms.i18n.CmsMessages;
40 import org.opencms.main.CmsException;
41 import org.opencms.main.CmsLog;
42 import org.opencms.main.OpenCms;
43
44 import java.util.Arrays JavaDoc;
45 import java.util.Collections JavaDoc;
46 import java.util.HashMap JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.Map JavaDoc;
49
50 import javax.servlet.jsp.PageContext JavaDoc;
51
52 import org.apache.commons.logging.Log;
53
54 /**
55  * Resolves macros in the form of <code>${key}</code> in an input String.<p>
56  *
57  * The macro names that can be resolved depend of the context objects provided to the resolver
58  * using the <code>set...</code> methods.<p>
59  *
60  * @author Alexander Kandzior
61  * @author Thomas Weckert
62  *
63  * @version $Revision: 1.20 $
64  *
65  * @since 6.0.0
66  */

67 public class CmsMacroResolver implements I_CmsMacroResolver {
68
69     /** Key used to specify the current time as macro value. */
70     public static final String JavaDoc KEY_CURRENT_TIME = "currenttime";
71
72     /** Key used to specify the city of the current user as macro value. */
73     public static final String JavaDoc KEY_CURRENT_USER_CITY = "currentuser.city";
74
75     /** Key used to specify the country of the current user as macro value. */
76     public static final String JavaDoc KEY_CURRENT_USER_COUNTRY = "currentuser.country";
77
78     /** Key used to specify the email address of the current user as macro value. */
79     public static final String JavaDoc KEY_CURRENT_USER_EMAIL = "currentuser.email";
80
81     /** Key used to specify the first name of the current user as macro value. */
82     public static final String JavaDoc KEY_CURRENT_USER_FIRSTNAME = "currentuser.firstname";
83
84     /** Key used to specify the full name of the current user as macro value. */
85     public static final String JavaDoc KEY_CURRENT_USER_FULLNAME = "currentuser.fullname";
86
87     /** Key used to specify the last name of the current user as macro value. */
88     public static final String JavaDoc KEY_CURRENT_USER_LASTNAME = "currentuser.lastname";
89
90     /** Key used to specify the username of the current user as macro value. */
91     public static final String JavaDoc KEY_CURRENT_USER_NAME = "currentuser.name";
92
93     /** Key used to specify the street of the current user as macro value. */
94     public static final String JavaDoc KEY_CURRENT_USER_STREET = "currentuser.street";
95
96     /** Key used to specify the zip code of the current user as macro value. */
97     public static final String JavaDoc KEY_CURRENT_USER_ZIP = "currentuser.zip";
98
99     /** Key prefix used to specify the value of a localized key as macro value. */
100     public static final String JavaDoc KEY_LOCALIZED_PREFIX = "key.";
101
102     /** Identifier for "magic" parameter names. */
103     public static final String JavaDoc KEY_OPENCMS = "opencms.";
104
105     /** The prefix indicating that the key represents a page context object. */
106     public static final String JavaDoc KEY_PAGE_CONTEXT = "pageContext.";
107
108     /** The prefix indicating that the key represents a Cms property to be read on the current request URI. */
109     public static final String JavaDoc KEY_PROPERTY = "property.";
110
111     /** The prefix indicating that the key represents a Cms property to be read on the current element. */
112     public static final String JavaDoc KEY_PROPERTY_ELEMENT = "elementProperty.";
113
114     /** Key used to specify the request encoding as macro value. */
115     public static final String JavaDoc KEY_REQUEST_ENCODING = "request.encoding";
116
117     /** Key used to specify the folder of the request uri as macro value. */
118     public static final String JavaDoc KEY_REQUEST_FOLDER = "request.folder";
119
120     /** Key user to specify the request locale as macro value. */
121     public static final String JavaDoc KEY_REQUEST_LOCALE = "request.locale";
122
123     /** The prefix indicating that the key represents a Http request parameter. */
124     public static final String JavaDoc KEY_REQUEST_PARAM = "param.";
125
126     /** Key used to specify the request uri as macro value. */
127     public static final String JavaDoc KEY_REQUEST_URI = "request.uri";
128
129     /** Key used to specify the validation path as macro value. */
130     public static final String JavaDoc KEY_VALIDATION_PATH = "validation.path";
131
132     /** Key used to specify the validation regex as macro value. */
133     public static final String JavaDoc KEY_VALIDATION_REGEX = "validation.regex";
134
135     /** Key used to specifiy the validation value as macro value. */
136     public static final String JavaDoc KEY_VALIDATION_VALUE = "validation.value";
137
138     /** Identified for "magic" parameter commands. */
139     public static final String JavaDoc[] VALUE_NAME_ARRAY = {"uri", "filename", "folder", "default.encoding"};
140
141     /** The "magic" commands wrapped in a List. */
142     public static final List JavaDoc VALUE_NAMES = Collections.unmodifiableList(Arrays.asList(VALUE_NAME_ARRAY));
143
144     /** The log object for this class. */
145     private static final Log LOG = CmsLog.getLog(CmsMacroResolver.class);
146
147     /** A map of additional values provided by the calling class. */
148     protected Map JavaDoc m_additionalMacros;
149
150     /** The OpenCms user context to use for resolving macros. */
151     protected CmsObject m_cms;
152
153     /** The JSP's page context to use for resolving macros. */
154     protected PageContext JavaDoc m_jspPageContext;
155
156     /** Indicates if unresolved macros should be kept "as is" or replaced by an empty String. */
157     protected boolean m_keepEmptyMacros;
158
159     /** The messages resource bundle to resolve localized keys with. */
160     protected CmsMessages m_messages;
161
162     /** The resource name to use for resolving macros. */
163     protected String JavaDoc m_resourceName;
164
165     /**
166      * Adds macro delimiters to the given input,
167      * for example <code>key</code> becomes <code>%(key)</code>.<p>
168      *
169      * @param input the input to format as a macro
170      *
171      * @return the input formatted as a macro
172      */

173     public static String JavaDoc formatMacro(String JavaDoc input) {
174
175         StringBuffer JavaDoc result = new StringBuffer JavaDoc(input.length() + 4);
176         result.append(I_CmsMacroResolver.MACRO_DELIMITER_NEW);
177         result.append(I_CmsMacroResolver.MACRO_START_NEW);
178         result.append(input);
179         result.append(I_CmsMacroResolver.MACRO_END_NEW);
180         return result.toString();
181     }
182
183     /**
184      * Returns <code>true</code> if the given input String if formatted like a macro,
185      * that is it starts with <code>{@link I_CmsMacroResolver#MACRO_DELIMITER} +
186      * {@link I_CmsMacroResolver#MACRO_START}</code> and ends with
187      * <code>{@link I_CmsMacroResolver#MACRO_END}</code>.<p>
188      *
189      * @param input the input to check for a macro
190      * @return <code>true</code> if the given input String if formatted like a macro
191      */

192     public static boolean isMacro(String JavaDoc input) {
193
194         if (CmsStringUtil.isEmpty(input) || (input.length() < 3)) {
195             return false;
196         }
197
198         return (((input.charAt(0) == I_CmsMacroResolver.MACRO_DELIMITER) && ((input.charAt(1) == I_CmsMacroResolver.MACRO_START) && (input.charAt(input.length() - 1) == I_CmsMacroResolver.MACRO_END))) || ((input.charAt(0) == I_CmsMacroResolver.MACRO_DELIMITER_NEW) && ((input.charAt(1) == I_CmsMacroResolver.MACRO_START_NEW) && (input.charAt(input.length() - 1) == I_CmsMacroResolver.MACRO_END_NEW))));
199     }
200
201     /**
202      * Returns <code>true</code> if the given input String is a macro equal to the given macro name.<p>
203      *
204      * @param input the input to check for a macro
205      * @param macroName the macro name to check for
206      *
207      * @return <code>true</code> if the given input String is a macro equal to the given macro name
208      */

209     public static boolean isMacro(String JavaDoc input, String JavaDoc macroName) {
210
211         if (isMacro(input)) {
212             return input.substring(2, input.length() - 1).equals(macroName);
213         }
214         return false;
215     }
216
217     /**
218      * Factory method to create a new {@link CmsMacroResolver} instance.<p>
219      *
220      * @return a new instance of a {@link CmsMacroResolver}
221      */

222     public static CmsMacroResolver newInstance() {
223
224         return new CmsMacroResolver();
225     }
226
227     /**
228      * Resolves the macros in the given input using the provided parameters.<p>
229      *
230      * A macro in the form <code>%(key)</code> or <code>${key}</code> in the content is replaced with it's assigned value
231      * returned by the <code>{@link I_CmsMacroResolver#getMacroValue(String)}</code> method of the given
232      * <code>{@link I_CmsMacroResolver}</code> instance.<p>
233      *
234      * If a macro is found that can not be mapped to a value by the given macro resolver,
235      * it is left untouched in the input.<p>
236      *
237      * @param input the input in which to resolve the macros
238      * @param cms the OpenCms user context to use when resolving macros
239      * @param messages the message resource bundle to use when resolving macros
240      *
241      * @return the input with the macros resolved
242      */

243     public static String JavaDoc resolveMacros(String JavaDoc input, CmsObject cms, CmsMessages messages) {
244
245         CmsMacroResolver resolver = new CmsMacroResolver();
246         resolver.m_cms = cms;
247         resolver.m_messages = messages;
248         resolver.m_keepEmptyMacros = true;
249         return resolver.resolveMacros(input);
250     }
251
252     /**
253      * Resolves macros in the provided input String using the given macro resolver.<p>
254      *
255      * A macro in the form <code>%(key)</code> or <code>${key}</code> in the content is replaced with it's assigned value
256      * returned by the <code>{@link I_CmsMacroResolver#getMacroValue(String)}</code> method of the given
257      * <code>{@link I_CmsMacroResolver}</code> instance.<p>
258      *
259      * If a macro is found that can not be mapped to a value by the given macro resolver,
260      * <code>{@link I_CmsMacroResolver#isKeepEmptyMacros()}</code> controls if the macro is replaced by
261      * an empty String, or is left untoched in the input.<p>
262      *
263      * @param input the input in which to resolve the macros
264      * @param resolver the macro resolver to use
265      *
266      * @return the input with all macros resolved
267      */

268     public static String JavaDoc resolveMacros(final String JavaDoc input, I_CmsMacroResolver resolver) {
269
270         if ((input == null) || (input.length() < 3)) {
271             // macro must have at last 3 chars "${}" or "%()"
272
return input;
273         }
274
275         int pn = input.indexOf(I_CmsMacroResolver.MACRO_DELIMITER_NEW);
276         int po = input.indexOf(I_CmsMacroResolver.MACRO_DELIMITER);
277
278         if ((po == -1) && (pn == -1)) {
279             // no macro delimiter found in input
280
return input;
281         }
282
283         int len = input.length();
284         StringBuffer JavaDoc result = new StringBuffer JavaDoc(len << 1);
285         int np, pp1, pp2, e;
286         String JavaDoc macro, value;
287         boolean keep = resolver.isKeepEmptyMacros();
288         boolean resolvedNone = true;
289         char ds, de;
290         int p;
291
292         if ((po == -1) || ((pn > -1) && (pn < po))) {
293             p = pn;
294             ds = I_CmsMacroResolver.MACRO_START_NEW;
295             de = I_CmsMacroResolver.MACRO_END_NEW;
296         } else {
297             p = po;
298             ds = I_CmsMacroResolver.MACRO_START;
299             de = I_CmsMacroResolver.MACRO_END;
300         }
301
302         // append chars before the first delimiter found
303
result.append(input.substring(0, p));
304         do {
305             pp1 = p + 1;
306             pp2 = pp1 + 1;
307             if (pp2 >= len) {
308                 // remaining chars can't be a macro (minumum size is 3)
309
result.append(input.substring(p, len));
310                 break;
311             }
312             // get the next macro delimiter
313
if ((pn > -1) && (pn < pp1)) {
314                 pn = input.indexOf(I_CmsMacroResolver.MACRO_DELIMITER_NEW, pp1);
315             }
316             if ((po > -1) && (po < pp1)) {
317                 po = input.indexOf(I_CmsMacroResolver.MACRO_DELIMITER, pp1);
318             }
319             if ((po == -1) && (pn == -1)) {
320                 // none found, make sure remaining chars in this segement are appended
321
np = len;
322             } else {
323                 // check if the next delimiter is old or new style
324
if ((po == -1) || ((pn > -1) && (pn < po))) {
325                     np = pn;
326                 } else {
327                     np = po;
328                 }
329             }
330             // check if the next char is a "macro start"
331
char st = input.charAt(pp1);
332             if (st == ds) {
333                 // we have a starting macro sequence "${" or "%(", now check if this segment contains a "}" or ")"
334
e = input.indexOf(de, p);
335                 if ((e > 0) && (e < np)) {
336                     // this segment contains a closing macro delimiter "}" or "]", so we may have found a macro
337
macro = input.substring(pp2, e);
338                     // resolve macro
339
value = resolver.getMacroValue(macro);
340                     e++;
341                     if (value != null) {
342                         // macro was successfully resolved
343
result.append(value);
344                         resolvedNone = false;
345                     } else if (keep) {
346                         // macro was unknown, but should be kept
347
result.append(input.substring(p, e));
348                     }
349                 } else {
350                     // no complete macro "${...}" or "%(...)" in this segment
351
e = p;
352                 }
353             } else {
354                 // no macro start char after the "$" or "%"
355
e = p;
356             }
357             // adpot macro style for next delimiter found
358
if (np == pn) {
359                 ds = I_CmsMacroResolver.MACRO_START_NEW;
360                 de = I_CmsMacroResolver.MACRO_END_NEW;
361             } else {
362                 ds = I_CmsMacroResolver.MACRO_START;
363                 de = I_CmsMacroResolver.MACRO_END;
364             }
365             // append the remaining chars after the macro to the start of the next macro
366
result.append(input.substring(e, np));
367             // this is a nerdy joke ;-)
368
p = np;
369         } while (p < len);
370
371         if (resolvedNone && keep) {
372             // nothing was resolved and macros should be kept, return original input
373
return input;
374         }
375
376         // input was changed during resolving of macros
377
return result.toString();
378     }
379
380     /**
381      * Strips the macro delimiters from the given input,
382      * for example <code>%(key)</code> or <code>${key}</code> becomes <code>key</code>.<p>
383      *
384      * In case the input is not a macro, <code>null</code> is returned.<p>
385      *
386      * @param input the input to strip
387      *
388      * @return the macro stripped from the input, or <code>null</code>
389      */

390     public static String JavaDoc stripMacro(String JavaDoc input) {
391
392         if (isMacro(input)) {
393             return input.substring(2, input.length() - 1);
394         }
395         return null;
396     }
397
398     /**
399      * Adds a customized macro to this macro resolver.<p>
400      *
401      * @param key the macro to add
402      * @param value the value to return if the macro is encountered
403      */

404     public void addMacro(String JavaDoc key, String JavaDoc value) {
405
406         if (m_additionalMacros == null) {
407             // use lazy initializing
408
m_additionalMacros = new HashMap JavaDoc();
409         }
410         m_additionalMacros.put(key, value);
411     }
412
413     /**
414      * @see org.opencms.util.I_CmsMacroResolver#getMacroValue(java.lang.String)
415      */

416     public String JavaDoc getMacroValue(String JavaDoc macro) {
417
418         if (m_messages != null) {
419             if (macro.startsWith(CmsMacroResolver.KEY_LOCALIZED_PREFIX)) {
420                 String JavaDoc keyName = macro.substring(CmsMacroResolver.KEY_LOCALIZED_PREFIX.length());
421                 return m_messages.keyWithParams(keyName);
422             }
423         }
424
425         if (m_jspPageContext != null) {
426
427             if (macro.startsWith(CmsMacroResolver.KEY_REQUEST_PARAM)) {
428                 // the key is a request parameter
429
macro = macro.substring(CmsMacroResolver.KEY_REQUEST_PARAM.length());
430                 return m_jspPageContext.getRequest().getParameter(macro);
431             }
432
433             if (macro.startsWith(CmsMacroResolver.KEY_PAGE_CONTEXT)) {
434                 // the key is a page context object
435
macro = macro.substring(CmsMacroResolver.KEY_PAGE_CONTEXT.length());
436                 int scope = m_jspPageContext.getAttributesScope(macro);
437                 return m_jspPageContext.getAttribute(macro, scope).toString();
438             }
439
440             if ((m_cms != null) && macro.startsWith(CmsMacroResolver.KEY_PROPERTY_ELEMENT)) {
441
442                 // the key is a cms property to be read on the current element
443

444                 macro = macro.substring(CmsMacroResolver.KEY_PROPERTY_ELEMENT.length());
445                 CmsFlexController controller = CmsFlexController.getController(m_jspPageContext.getRequest());
446                 try {
447                     CmsProperty property = m_cms.readPropertyObject(
448                         controller.getCurrentRequest().getElementUri(),
449                         macro,
450                         false);
451                     if (property != CmsProperty.getNullProperty()) {
452                         return property.getValue();
453                     }
454                 } catch (CmsException e) {
455                     if (LOG.isWarnEnabled()) {
456                         LOG.warn(Messages.get().getBundle().key(
457                             Messages.LOG_PROPERTY_READING_FAILED_2,
458                             macro,
459                             controller.getCurrentRequest().getElementUri()), e);
460                     }
461                 }
462             }
463         }
464
465         if (m_cms != null) {
466
467             if (macro.startsWith(CmsMacroResolver.KEY_PROPERTY)) {
468                 // the key is a cms property to be read on the current request URI
469
macro = macro.substring(CmsMacroResolver.KEY_PROPERTY.length());
470                 try {
471                     CmsProperty property = m_cms.readPropertyObject(m_cms.getRequestContext().getUri(), macro, true);
472                     if (property != CmsProperty.getNullProperty()) {
473                         return property.getValue();
474                     }
475                 } catch (CmsException e) {
476                     if (LOG.isWarnEnabled()) {
477                         CmsMessageContainer message = Messages.get().container(
478                             Messages.LOG_PROPERTY_READING_FAILED_2,
479                             macro,
480                             m_cms.getRequestContext().getUri());
481                         LOG.warn(message.key(), e);
482                     }
483                 }
484
485             }
486
487             if (macro.startsWith(CmsMacroResolver.KEY_OPENCMS)) {
488
489                 // the key is a shortcut for a cms runtime value
490

491                 String JavaDoc originalKey = macro;
492                 macro = macro.substring(CmsMacroResolver.KEY_OPENCMS.length());
493                 int index = VALUE_NAMES.indexOf(macro);
494                 String JavaDoc value = null;
495
496                 switch (index) {
497                     case 0:
498                         // "uri"
499
value = m_cms.getRequestContext().getUri();
500                         break;
501                     case 1:
502                         // "filename"
503
value = m_resourceName;
504                         break;
505                     case 2:
506                         // folder
507
value = m_cms.getRequestContext().getFolderUri();
508                         break;
509                     case 3:
510                         // default.encoding
511
value = OpenCms.getSystemInfo().getDefaultEncoding();
512                         break;
513                     default:
514                         // return the key "as is"
515
value = originalKey;
516                         break;
517                 }
518
519                 return value;
520             }
521
522             if (CmsMacroResolver.KEY_CURRENT_USER_NAME.equals(macro)) {
523                 // the key is the current users login name
524
return m_cms.getRequestContext().currentUser().getName();
525             }
526
527             if (CmsMacroResolver.KEY_CURRENT_USER_FIRSTNAME.equals(macro)) {
528                 // the key is the current users first name
529
return m_cms.getRequestContext().currentUser().getFirstname();
530             }
531
532             if (CmsMacroResolver.KEY_CURRENT_USER_LASTNAME.equals(macro)) {
533                 // the key is the current users last name
534
return m_cms.getRequestContext().currentUser().getLastname();
535             }
536
537             if (CmsMacroResolver.KEY_CURRENT_USER_FULLNAME.equals(macro)) {
538                 // the key is the current users full name
539
return m_cms.getRequestContext().currentUser().getFullName();
540             }
541
542             if (CmsMacroResolver.KEY_CURRENT_USER_EMAIL.equals(macro)) {
543                 // the key is the current users email address
544
return m_cms.getRequestContext().currentUser().getEmail();
545             }
546
547             if (CmsMacroResolver.KEY_CURRENT_USER_STREET.equals(macro)) {
548                 // the key is the current users address
549
return m_cms.getRequestContext().currentUser().getAddress();
550             }
551
552             if (CmsMacroResolver.KEY_CURRENT_USER_ZIP.equals(macro)) {
553                 // the key is the current users zip code
554
return m_cms.getRequestContext().currentUser().getZipcode();
555             }
556
557             if (CmsMacroResolver.KEY_CURRENT_USER_COUNTRY.equals(macro)) {
558                 // the key is the current users country
559
return m_cms.getRequestContext().currentUser().getCountry();
560             }
561
562             if (CmsMacroResolver.KEY_CURRENT_USER_CITY.equals(macro)) {
563                 // the key is the current users city
564
return m_cms.getRequestContext().currentUser().getCity();
565             }
566
567             if (CmsMacroResolver.KEY_REQUEST_URI.equals(macro)) {
568                 // the key is the currently requested uri
569
return m_cms.getRequestContext().getUri();
570             }
571
572             if (CmsMacroResolver.KEY_REQUEST_FOLDER.equals(macro)) {
573                 // the key is the currently requested folder
574
return CmsResource.getParentFolder(m_cms.getRequestContext().getUri());
575             }
576
577             if (CmsMacroResolver.KEY_REQUEST_ENCODING.equals(macro)) {
578                 // the key is the current encoding of the request
579
return m_cms.getRequestContext().getEncoding();
580             }
581
582             if (CmsMacroResolver.KEY_REQUEST_LOCALE.equals(macro)) {
583                 // the key is the current locale of the request
584
return m_cms.getRequestContext().getLocale().toString();
585             }
586
587         }
588
589         if (CmsMacroResolver.KEY_CURRENT_TIME.equals(macro)) {
590             // the key is the current system time
591
return String.valueOf(System.currentTimeMillis());
592         }
593
594         if (m_additionalMacros != null) {
595             return (String JavaDoc)m_additionalMacros.get(macro);
596         }
597
598         return null;
599     }
600
601     /**
602      * @see org.opencms.util.I_CmsMacroResolver#isKeepEmptyMacros()
603      */

604     public boolean isKeepEmptyMacros() {
605
606         return m_keepEmptyMacros;
607     }
608
609     /**
610      * Resolves the macros in the given input.<p>
611      *
612      * Calls <code>{@link #resolveMacros(String)}</code> until no more macros can
613      * be resolved in the input. This way "nested" macros in the input are resolved as well.<p>
614      *
615      * @see org.opencms.util.I_CmsMacroResolver#resolveMacros(java.lang.String)
616      */

617     public String JavaDoc resolveMacros(String JavaDoc input) {
618
619         String JavaDoc result = input;
620
621         if (input != null) {
622             String JavaDoc lastResult;
623             do {
624                 // save result for next comparison
625
lastResult = result;
626                 // resolve the macros
627
result = CmsMacroResolver.resolveMacros(result, this);
628                 // if nothing changes then the final result is found
629
} while (!result.equals(lastResult));
630         }
631
632         // return the result
633
return result;
634     }
635
636     /**
637      * Provides a set of additional macros to this macro resolver.<p>
638      *
639      * Macros added with {@link #addMacro(String, String)} are added to the same set
640      *
641      * @param additionalMacros the additional macros to add
642      *
643      * @return this instance of the macro resolver
644      */

645     public CmsMacroResolver setAdditionalMacros(Map JavaDoc additionalMacros) {
646
647         m_additionalMacros = additionalMacros;
648         return this;
649     }
650
651     /**
652      * Provides an OpenCms user context to this macro resolver, required to resolve certain macros.<p>
653      *
654      * @param cms the OpenCms user context
655      *
656      * @return this instance of the macro resolver
657      */

658     public CmsMacroResolver setCmsObject(CmsObject cms) {
659
660         m_cms = cms;
661         return this;
662     }
663
664     /**
665      * Provides a JSP page context to this macro resolver, required to resolve certain macros.<p>
666      *
667      * @param jspPageContext the JSP page context to use
668      *
669      * @return this instance of the macro resolver
670      */

671     public CmsMacroResolver setJspPageContext(PageContext JavaDoc jspPageContext) {
672
673         m_jspPageContext = jspPageContext;
674         return this;
675     }
676
677     /**
678      * Controls of macros that can't be resolved are left unchanged in the input,
679      * or are replaced with an empty String.<p>
680      *
681      * @param keepEmptyMacros the replacemanet flag to use
682      *
683      * @return this instance of the macro resolver
684      *
685      * @see #isKeepEmptyMacros()
686      */

687     public CmsMacroResolver setKeepEmptyMacros(boolean keepEmptyMacros) {
688
689         m_keepEmptyMacros = keepEmptyMacros;
690         return this;
691     }
692
693     /**
694      * Provides a set of <code>{@link CmsMessages}</code> to this macro resolver,
695      * required to resolve localized macros.<p>
696      *
697      * @param messages the message resource bundle to use
698      *
699      * @return this instance of the macro resolver
700      */

701     public CmsMacroResolver setMessages(CmsMessages messages) {
702
703         m_messages = messages;
704         return this;
705     }
706
707     /**
708      * Provides a resource name to this macro resolver, required to resolve certain macros.<p>
709      *
710      * @param resourceName the resource name to use
711      *
712      * @return this instance of the macro resolver
713      */

714     public CmsMacroResolver setResourceName(String JavaDoc resourceName) {
715
716         m_resourceName = resourceName;
717         return this;
718     }
719 }
Popular Tags