1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.util.template;
1819// Jetspeed20import org.apache.jetspeed.om.profile.Entry;
21import org.apache.jetspeed.om.profile.Profile;
22import org.apache.jetspeed.om.profile.Portlets;
23import org.apache.jetspeed.om.profile.ProfileException;
24import org.apache.jetspeed.om.profile.ProfileLocator;
25import org.apache.jetspeed.portal.Portlet;
26import org.apache.jetspeed.services.Profiler;
27import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
28import org.apache.jetspeed.services.logging.JetspeedLogger;
29import org.apache.jetspeed.services.resources.JetspeedResources;
30import org.apache.jetspeed.services.rundata.JetspeedRunData;
31import org.apache.jetspeed.util.template.JetspeedLink;
3233// Turbine34import org.apache.turbine.util.RunData;
35import org.apache.turbine.util.DynamicURI;
36import org.apache.turbine.services.pull.ApplicationTool;
3738/***39 * <p>A customized version of the TemplateLink which can handle portlet40 * references.</p>41 *42 * <p>It is inserted into the template context by Turbine, via request tools.</p>43 *44 * <p>Each portlet must call setPortlet(this) on it before entering the template45 * rendering code. This is done currently in VelocityPortlet.</p>46 *47 * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>48 * @version $Id: BaseJetspeedLink.java,v 1.23 2004/02/23 03:20:45 jford Exp $49 */50publicclassBaseJetspeedLink implements ApplicationTool, JetspeedLink51 {
52/***53 * Static initialization of the logger for this class54 */55privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(BaseJetspeedLink.class.getName());
5657/***58 *<p>Request to which we refer.</p>59 */60privateJetspeedRunData rundata = null;
6162/***63 * Profile locator from <code>rundata</code>. This is here64 * for performance reasons.65 */66privateProfileLocator locator = null;
6768/***69 * Profile from <code>rundata</code>. This is here70 * for performance reasons.71 */72privateProfile profile = null;
7374/***75 * Has the initialization for the current rundata been performed?. This is76 * here for performance reasons.77 */78privateboolean initDone = false;
7980/***81 *<p>The portlet that will be used to build the reference.</p>82 */83protectedPortlet activePortlet = null;
8485/***86 * Empty constructor.for introspection87 */88publicBaseJetspeedLink()
89 {
90 }
9192/***93 * Constructor required by ApplicationTool interface94 *95 * @param data A Jetspeed RunData object.96 */97publicBaseJetspeedLink(RunData data)
98 {
99 init((Object) data);
100 }
101102/***103 * This will initialise a JetspeedLink object that was104 * constructed with the default constructor105 *106 * @param rundata to be a RunData object107 */108publicvoid init(RunData rundata)
109 {
110 init((Object) rundata);
111 }
112113/***114 * Adds a name=value pair to the query string.115 *116 * @param name A String with the name to add.117 * @param value An Object with the value to add.118 * @return DynamicURI that to the desired page119 */120public DynamicURI addQueryData(String name, Object value)
121 {
122try123 {
124return getRoot().addQueryData(name, value);
125 }
126catch (ProfileException e)
127 {
128 logger.error("Exception", e);
129returnnull;
130 }
131 }
132133/***134 * Adds a name=value pair to the path_info string.135 *136 * @param name A String with the name to add.137 * @param value An Object with the value to add.138 * @return DynamicURI that to the desired page139 */140public DynamicURI addPathInfo(String name, Object value)
141 {
142try143 {
144return getRoot().addPathInfo(name, value);
145 }
146catch (ProfileException e)
147 {
148 logger.error("Exception", e);
149returnnull;
150 }
151 }
152153/***154 * Return an link to a specific portal element155 *156 * @param peid of the portal element157 * @return DynamicURI to specific portal element158 *159 * @deprecated Use getPortletById() or getPaneById()160 */161public DynamicURI setPortalElement(String peid)
162 {
163if (initDone == false)
164 {
165 initLink();
166 }
167if (profile.getDocument().getEntryById(peid) != null)
168 {
169return getPortletById(peid);
170 }
171else172 {
173return setPaneById(peid);
174 }
175 }
176177/***178 * Return an link to a specific portlet using the portet's id179 *180 * @param peid of the portlet181 * @return DynamicURI to specific portlet182 *183 * @deprecated Use getPortletById()184 */185public DynamicURI setPortletById(String peid)
186 {
187return getPortletById(peid);
188 }
189190/***191 * Return link to the home page without user,192 * page, group, role, template, action, media type, language, or country193 * in link.194 *195 * @return DynamicURI to the home page196 */197public DynamicURI getHomePage()
198 {
199return getLink(JetspeedLink.DEFAULT, null, "", JetspeedLink.DEFAULT, null, "", "", "", "", "");
200 }
201202/***203 * Return a link that includes the template204 * from rundata205 *206 * @return DynamicURI to template207 */208public DynamicURI getTemplate()
209 {
210 String template = rundata.getRequestedTemplate();
211return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.DEFAULT, null, null, template, null, null, null);
212 }
213214/***215 * Return a link to the template.216 *217 * @param template to add to link218 * @return DynamicURI to specific portlet219 *220 * @deprecated Use getTemplate()221 */222public DynamicURI setTemplate(String template)
223 {
224return getTemplate(template);
225 }
226227/***228 * Return a link that includes an action229 *230 * @param action Desired action231 * @return DynamicURI that includes the desire action232 *233 * @deprecated Use getAction()234 */235public DynamicURI setAction(String action)
236 {
237return getAction(action);
238 }
239240/***241 * Return a link that includes an action to a specific portlet, as defined242 * by a portlets243 *244 * @param action Desired action245 * @param portlets to receive the action246 * @return DynamicURI that includes the desire action247 *248 * @deprecated Use getAction()249 */250public DynamicURI setAction(String action, Portlets portlets)
251 {
252return getAction(action, (Portlets) portlets);
253 }
254255/***256 * Return a link that includes an action to a specific portlet257 *258 * @param action Desired action259 * @param portlet to receive the action260 * @return DynamicURI that includes the desire action261 *262 * @deprecated Use getAction()263 */264public DynamicURI setAction(String action, Portlet portlet)
265 {
266return getAction(action, (Portlet) portlet);
267 }
268269/***270 * Return a link that includes an action to a specific portlet, as defined271 * by an entry272 *273 * @param action Desired action274 * @param entry to receive the action275 * @return DynamicURI that includes the desire action276 *277 * @deprecated Use getAction()278 */279public DynamicURI setAction(String action, Entry entry)
280 {
281return getAction(action, (Entry) entry);
282 }
283284/***285 * Return a link that includes an action to a specific portlet, as defined286 * by a PEID287 *288 * @param action Desired action289 * @param peid Id of portlet to receive the action290 * @return DynamicURI that includes the desire action291 * @deprecated Use getAction()292 */293public DynamicURI setAction(String action, String peid)
294 {
295return getAction(action, (String) peid);
296 }
297298/***299 * Return a link to a default page for the group300 *301 * @param group Desired group302 * @return DynamicURI that to the desired page303 *304 * @deprecated Use getGroup()305 */306public DynamicURI setGroup(String group)
307 {
308return getGroup(group);
309 }
310311/***312 * Return a link to a desired page for the group313 *314 * @param page Desired page315 * @param group Desired group316 * @return DynamicURI that to the desired page317 *318 * @deprecated Use getGroup()319 */320public DynamicURI setGroup(String group, String page)
321 {
322return getGroup(group, page);
323 }
324325/***326 * Return a link to a default page for the327 * current user, group, or role.328 *329 * @return DynamicURI that to the desired page330 *331 * @deprecated Use getPage()332 */333public DynamicURI setPage()
334 {
335return getPage();
336 }
337338/***339 * Return a link to a desired page for the340 * current user, group, or role.341 *342 * @param page Desired page343 * @return DynamicURI that to the desired page344 *345 * @deprecated Use getPage()346 */347public DynamicURI setPage(String page)
348 {
349return getPage(page);
350 }
351352/***353 * Return a link to a desired page and pane for the354 * current user, group, or role.355 *356 * @param page Desired page357 * @param paneName Desired pane name358 * @return DynamicURI that to the desired page359 * @deprecated Use getPage()360 */361public DynamicURI setPage(String page, String paneName)
362 {
363return getPage(page, paneName);
364 }
365366367/***368 * Return a link to a default page for the role369 *370 * @param role Desired role371 * @return DynamicURI that to the desired page372 *373 * @deprecated use getRole()374 */375public DynamicURI setRole(String role)
376 {
377return getRole(role);
378 }
379380/***381 * Return a link to a desired page for the role382 *383 * @param role Desired role384 * @param page Desired page385 * @return DynamicURI that to the desired page386 *387 * @deprecated use getRole()388 */389public DynamicURI setRole(String role, String page)
390 {
391return getRole(role, page);
392 }
393394/***395 * Return a link to a default page for the user396 *397 * @param user Desired user398 * @return DynamicURI that to the desired page399 *400 * @deprecated Use getUser()401 */402public DynamicURI setUser(String user)
403 {
404return getUser(user);
405 }
406407/***408 * Return a link to a desired page for the user409 *410 * @param page Desired page411 * @param user Desired user412 * @return DynamicURI that to the desired page413 *414 * @deprecated Use getUser()415 */416public DynamicURI setUser(String user, String page)
417 {
418return getUser(user, page);
419 }
420421/***422 * Return a link to a specific pane using the pane's id423 *424 * @param paneId of the Pane425 * @return URI to specific portlet426 *427 * @deprecated Use getPaneById()428 */429public DynamicURI setPaneById(String paneId)
430 {
431return getPaneById(paneId);
432 }
433434/***435 * Return a link to a specific pane using the pane's id436 *437 * @param paneName Name of the Pane438 * @return URI to specific portlet439 * @deprecated Use getPaneByName()440 */441public DynamicURI setPaneByName(String paneName)
442 {
443return getPaneByName(paneName);
444 }
445446/***447 * Return a link to a desired page. This is allows the inclusion of a Group/Role/User,448 * page, template, action, media type, language, and country.449 * 450 * @param rootType Type of root PSML docuument. The should be one of the following:451 * <dl>452 * <dt>JetspeedLink.CURRENT</dt><dd>The link will retain the current Group/Role/User referance. rootValue is not used</dd>453 * <dt>JetspeedLink.DEFAULT</dt><dd>Default Group, Role, or User. rootValue is not used</dd>454 * <dt>JetspeedLink.GROUP</dt><dd>Link will be to a Group PSML. rootValue is a Group Name</dd>455 * <dt>JetspeedLink.ROLE</dt><dd>Link will be to a Role PSML. rootValue is a Role Name</dd>456 * <dt>JetspeedLink.USER</dt><dd>Link will be to a User PSML. rootValue is a User Name</dd>457 * </dl>458 * @param rootValue See description of rootType459 * @param pageName Name of page. null = default page460 * @param elementType461 * <dl>462 * <dt>JetspeedLink.CURRENT</dt><dd>The link will retain the current Pane/Portlet referance. elementValue is not used</dd>463 * <dt>JetspeedLink.DEFAULT</dt><dd>The link will NOT referance a pane or portlet. elementValue is not used</dd>464 * <dt>JetspeedLink.PANE_ID</dt><dd>Link will be to a Pane using it's ID. elementValue is a Pane's ID</dd>465 * <dt>JetspeedLink.PANE_NAME</dt><dd>Link will be to a Pane using it's Name. elementValue is a Pane's Name</dd>466 * <dt>JetspeedLink.PORTLET_ID</dt><dd>Link will be to a Portlet using it's ID. elementValue is a Portlet's ID</dd>467 * <dt>JetspeedLink.PORTLET_NAME</dt><dd>Link will be to a Portlet using it's Name. elementValue is a Portlet's Name</dd>468 * <dt>JetspeedLink.PORTLET_ID_QUERY</dt><dd>Link will be to a Portlet using it's ID based on portlet name provided. elementValue is a Portlet's name. ID is for the first portlet with matching name</dd>469 * </dl>470 * @param elementValue471 * See description of elementType472 * @param actionName Name of action. If no action is desired use JetspeedLink.NO_ACTION.473 * @param templateName474 * Name of template. If no template is desired use JetspeedLink.NO_TEMPLATE.475 * @param mediaType Desired media type. null = default media type476 * @param language Desired language. null = default language477 * @param country Desired country. null = default language478 * @return URI to specific portlet479 */480public DynamicURI getLink(int rootType, String rootValue, String pageName, int elementType, String elementValue, String actionName, String templateName, String mediaType, String language, String country)
481 {
482 String uriPathType = null;
483 String uriPathElement = null;
484try485 {
486 DynamicURI uri = getRoot();
487488// Set Group/Role/User in path489switch (rootType)
490 {
491case JetspeedLink.DEFAULT:
492case JetspeedLink.CURRENT:
493break;
494case JetspeedLink.GROUP:
495 uriPathType = Profiler.PARAM_GROUP;
496break;
497case JetspeedLink.ROLE:
498 uriPathType = Profiler.PARAM_ROLE;
499break;
500case JetspeedLink.USER:
501 uriPathType = Profiler.PARAM_USER;
502break;
503 }
504505if (rootType != JetspeedLink.CURRENT)
506 {
507// Cleanup URI508 uri.removePathInfo(Profiler.PARAM_GROUP);
509 uri.removePathInfo(Profiler.PARAM_ROLE);
510 uri.removePathInfo(Profiler.PARAM_USER);
511512if ((rootType != JetspeedLink.DEFAULT) && (rootValue != null) && (rootValue.trim().length() > 0))
513 {
514 uri.addPathInfo(uriPathType, rootValue);
515 }
516 }
517518// Set Page in path519if (pageName != null)
520 {
521 uri.removePathInfo(Profiler.PARAM_PAGE);
522if (pageName.trim().length() > 0)
523 {
524 uri.addPathInfo(Profiler.PARAM_PAGE, pageName);
525 }
526 }
527528// Set Portlet/Pane in path529switch (elementType)
530 {
531case JetspeedLink.CURRENT:
532case JetspeedLink.DEFAULT:
533break;
534case JetspeedLink.PANE_ID:
535 uriPathElement = JetspeedResources.PATH_PANEID_KEY;
536break;
537case JetspeedLink.PANE_NAME:
538 uriPathElement = JetspeedResources.PATH_PANENAME_KEY;
539break;
540case JetspeedLink.PORTLET_ID:
541 uriPathElement = JetspeedResources.PATH_PORTLETID_KEY;
542break;
543case JetspeedLink.PORTLET_NAME:
544 uriPathElement = JetspeedResources.PATH_PORTLET_KEY;
545break;
546case JetspeedLink.PORTLET_ID_QUERY:
547if (logger.isDebugEnabled())
548 {
549 logger.debug("BaseJetspeedLink: elementValue = " + elementValue);
550 }
551 uriPathElement = JetspeedResources.PATH_PORTLETID_KEY;
552ProfileLocator baseLocator = Profiler.createLocator();
553Profile baseProfile = null;
554switch (rootType)
555 {
556case JetspeedLink.DEFAULT:
557break;
558case JetspeedLink.CURRENT:
559 baseProfile = rundata.getProfile();
560break;
561case JetspeedLink.GROUP:
562 baseLocator.setGroupByName(rootValue);
563break;
564case JetspeedLink.ROLE:
565 baseLocator.setRoleByName(rootValue);
566break;
567case JetspeedLink.USER:
568try569 {
570if (logger.isDebugEnabled())
571 {
572 logger.debug("BaseJetspeedLink: rootValue user = " + rootValue);
573 }
574 baseLocator.setUser(org.apache.jetspeed.services.JetspeedSecurity.getUser(rootValue));
575 }
576catch (Exception se)
577 {
578 logger.error("Exception", se);
579returnnull;
580 }
581break;
582 }
583584if ((rootType != JetspeedLink.CURRENT) && (rootType != JetspeedLink.DEFAULT))
585 {
586if (mediaType != null && mediaType.length() > 0)
587 {
588 baseLocator.setMediaType(mediaType);
589 }
590if (language != null && language.length() > 0)
591 {
592 baseLocator.setLanguage(language);
593 }
594if (country != null && country.length() > 0)
595 {
596 baseLocator.setCountry(country);
597 }
598if (pageName != null && pageName.length() > 0)
599 {
600 baseLocator.setName(pageName);
601 }
602 baseProfile = Profiler.getProfile(baseLocator);
603 }
604605if (logger.isDebugEnabled())
606 {
607 logger.debug("BaseJetspeedLink: baseLocator = " + baseLocator.getPath());
608 }
609610if ((baseProfile != null) && (elementValue != null))
611 {
612if (logger.isDebugEnabled())
613 {
614 logger.debug("BaseJetspeedLink: baseProfile = " + baseProfile.toString());
615 }
616if (baseProfile.getDocument() != null)
617 {
618if (logger.isDebugEnabled())
619 {
620 logger.debug("BaseJetspeedLink: baseProfile.getDocment() = " + baseProfile.getDocument());
621 }
622Entry entry = baseProfile.getDocument().getEntry(elementValue);
623if (entry != null)
624 {
625if (logger.isDebugEnabled())
626 {
627 logger.debug("BaseJetspeedLink: entry id = " + entry.getId());
628 }
629 elementValue = entry.getId();
630 }
631else632 {
633 elementValue = null;
634 }
635 }
636 }
637638break;
639 }
640641if (elementType != JetspeedLink.CURRENT)
642 {
643// Remove Group/Role/User in URI644 uri.removePathInfo(JetspeedResources.PATH_PANEID_KEY);
645 uri.removePathInfo(JetspeedResources.PATH_PANENAME_KEY);
646 uri.removePathInfo(JetspeedResources.PATH_PORTLETID_KEY);
647 uri.removePathInfo(JetspeedResources.PATH_PORTLET_KEY);
648649if ((elementType != JetspeedLink.DEFAULT) && (elementValue != null) && (elementValue.length() > 0))
650 {
651 uri.addPathInfo(uriPathElement, elementValue);
652 }
653 }
654655// Set Template in path656if (templateName != null)
657 {
658 uri.removePathInfo(JetspeedResources.PATH_TEMPLATE_KEY);
659if (templateName.length() > 0)
660 {
661 uri.addPathInfo(JetspeedResources.PATH_TEMPLATE_KEY, templateName);
662 }
663 }
664665// Set Action in path666if (actionName != null)
667 {
668 uri.removeQueryData(JetspeedResources.PATH_ACTION_KEY);
669if (actionName.length() > 0)
670 {
671 uri.addQueryData(JetspeedResources.PATH_ACTION_KEY, actionName);
672 }
673 }
674675// Set MediaType in path676if (mediaType != null)
677 {
678 uri.removePathInfo(Profiler.PARAM_MEDIA_TYPE);
679if (mediaType.length() > 0)
680 {
681 uri.addPathInfo(Profiler.PARAM_MEDIA_TYPE, mediaType);
682 }
683 }
684685// Set Language in path686if (language != null)
687 {
688 uri.removePathInfo(Profiler.PARAM_LANGUAGE);
689if (language.length() > 0)
690 {
691 uri.addPathInfo(Profiler.PARAM_LANGUAGE, language);
692 }
693 }
694695// Set Country in path696if (country != null)
697 {
698 uri.removePathInfo(Profiler.PARAM_COUNTRY);
699if (country.length() > 0)
700 {
701 uri.addPathInfo(Profiler.PARAM_COUNTRY, country);
702 }
703 }
704705return uri;
706 }
707catch (ProfileException e)
708 {
709 logger.error("Exception", e);
710returnnull;
711 }
712 }
713public DynamicURI getLink(int rootType, String rootValue, String pageName, int elementType, String elementValue, String actionName, String templateName, String mediaType, String language)
714 {
715return getLink(rootType, rootValue, pageName, elementType, elementValue, actionName, templateName, mediaType, language, null);
716 }
717718public DynamicURI getLink(int rootType, String rootValue, String pageName, int elementType, String elementValue, String actionName, String templateName, String mediaType)
719 {
720return getLink(rootType, rootValue, pageName, elementType, elementValue, actionName, templateName, mediaType, null, null);
721 }
722723public DynamicURI getLink(int rootType, String rootValue, String pageName, int elementType, String elementValue, String actionName, String templateName)
724 {
725return getLink(rootType, rootValue, pageName, elementType, elementValue, actionName, actionName, null, null, null);
726 }
727728public DynamicURI getLink(int rootType, String rootValue, String pageName, int elementType, String elementValue, String actionName)
729 {
730return getLink(rootType, rootValue, pageName, elementType, elementValue, actionName, null, null, null, null);
731 }
732733/***734 */735public DynamicURI getLink(int rootType, String rootValue, String pageName, int elementType, String elementValue)
736 {
737return getLink(rootType, rootValue, pageName, elementType, elementValue, null, null, null, null, null);
738 }
739740/***741 * Return a link that includes an action742 *743 * @param action action744 * @return DynamicURI that includes the desire action745 */746public DynamicURI getAction(String action)
747 {
748return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.CURRENT, null, action, null, null, null, null);
749 }
750751/***752 * Return a link that includes an action to a specific portlet, as defined753 * by an entry754 *755 * @param action Desired action756 * @param entry to receive the action757 * @return DynamicURI that includes the desire action758 */759public DynamicURI getAction(String action, Entry entry)
760 {
761if (entry != null)
762 {
763return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.PORTLET_ID, entry.getId(), null, action, null, null, null);
764 }
765else766 {
767return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.PORTLET_ID, null, null, action, null, null, null);
768 }
769 }
770771/***772 * Return a link that includes an action to a specific portlet773 *774 * @param action Desired action775 * @param portlet to receive the action776 * @return DynamicURI that includes the desire action777 */778public DynamicURI getAction(String action, Portlet portlet)
779 {
780if (portlet != null)
781 {
782return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.PORTLET_ID, portlet.getID(), action, null, null, null, null);
783 }
784else785 {
786return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.PORTLET_ID, null, action, null, null, null, null);
787 }
788 }
789790/***791 * Return a link that includes an action to a specific portlet, as defined792 * by a portlets793 *794 * @param action Desired action795 * @param portlets to receive the action796 * @return DynamicURI that includes the desire action797 */798public DynamicURI getAction(String action, Portlets portlets)
799 {
800if (portlets != null)
801 {
802return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.PORTLET_ID, portlets.getId(), action, null, null, null, null);
803 }
804else805 {
806return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.PORTLET_ID, null, action, null, null, null, null);
807 }
808 }
809810/***811 * Return a link that includes an action to a specific portlet, as defined812 * by a PEID813 *814 * @param action Desired action815 * @param peid Id of the portlet to receive the action816 * @return DynamicURI that includes the desire action817 */818public DynamicURI getAction(String action, String peid)
819 {
820return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.PORTLET_ID, peid, action, null, null, null, null);
821 }
822823/***824 * Return a link to a default page for the group825 *826 * @param group Desired group827 * @return DynamicURI that to the default page for the group828 */829public DynamicURI getGroup(String group)
830 {
831return getLink(JetspeedLink.GROUP, group, "", JetspeedLink.DEFAULT, null, null, null, null, null, null);
832 }
833834/***835 * Return a link to a desired page for the group836 *837 * @param page Desired page838 * @param group Desired group839 * @return DynamicURI that to the desired group and page840 */841public DynamicURI getGroup(String group, String page)
842 {
843return getLink(JetspeedLink.GROUP, group, page, JetspeedLink.DEFAULT, null, null, null, null, null, null);
844 }
845/***846 * Return a link to a default page for the847 * current user, group, or role.848 *849 * @return DynamicURI that to the default page850 */851public DynamicURI getPage()
852 {
853return getLink(JetspeedLink.CURRENT, null, "", JetspeedLink.DEFAULT, null, null, null, null, null, null);
854 }
855856/***857 * Return a link to a desired page for the858 * current user, group, or role.859 *860 * @param page Desired page861 * @return DynamicURI that to the desired page862 */863public DynamicURI getPage(String page)
864 {
865return getLink(JetspeedLink.CURRENT, null, page, JetspeedLink.DEFAULT, null, null, null, null, null, null);
866 }
867868/***869 * Return a link to a desired page and pane for the870 * current user, group, or role.871 *872 * @param page Desired page873 * @param paneName Name of the desired pane874 * @return DynamicURI that to the desired page875 */876public DynamicURI getPage(String page, String paneName)
877 {
878return getLink(JetspeedLink.CURRENT, null, page, JetspeedLink.PANE_NAME, paneName, null, null, null, null, null);
879 }
880/***881 * Return a link to a specific pane using the pane's id882 *883 * @param paneId of the Pane884 * @return URI to specific portlet885 */886public DynamicURI getPaneById(String paneId)
887 {
888return getLink(JetspeedLink.CURRENT, null, this.getPageName(), JetspeedLink.PANE_ID, paneId, null, null, null, null, null);
889 }
890891/***892 * Return a link to a specific pane using the pane's id893 *894 * @param paneName Name of the Pane895 * @return URI to specific portlet896 */897public DynamicURI getPaneByName(String paneName)
898 {
899return getLink(JetspeedLink.CURRENT, null, this.getPageName(), JetspeedLink.PANE_NAME, paneName, null, null, null, null, null);
900 }
901902/***903 * Return an link to a specific portlet using the portet's id904 *905 * @param peid of the portlet906 * @return DynamicURI to specific portlet907 */908public DynamicURI getPortletById(String peid)
909 {
910return getLink(JetspeedLink.CURRENT, null, this.getPageName(), JetspeedLink.PORTLET_ID, peid, null, null, null, null, null);
911 }
912/***913 * Add a portlet reference in the link.914 *915 * Note: This must be used with caution, since a portlet may exist may times916 * in a PSML. setPortletById() is the perfered method.917 *918 * @param portletName the name of the portlet to link to919 * @return a DynamicURI referencing the named portlet920 */921public DynamicURI getPortletByName(String portletName)
922 {
923return getLink(JetspeedLink.CURRENT, null, this.getPageName(), JetspeedLink.PORTLET_NAME, portletName, null, null, null, null, null);
924 }
925/***926 * Return a link to a default page for the role927 *928 * @param role Desired role929 * @return DynamicURI that to the desired page930 */931public DynamicURI getRole(String role)
932 {
933return getLink(JetspeedLink.ROLE, role, "", JetspeedLink.DEFAULT, null, null, null, null, null, null);
934 }
935936/***937 * Return a link to a desired page for the role938 *939 * @param role Desired role940 * @param page Desired page941 * @return DynamicURI that to the desired page942 */943public DynamicURI getRole(String role, String page)
944 {
945return getLink(JetspeedLink.ROLE, role, page, JetspeedLink.DEFAULT, null, null, null, null, null, null);
946 }
947948/***949 * Return a link to the template.950 *951 * @param template to add to link952 * @return DynamicURI to specific portlet953 */954public DynamicURI getTemplate(String template)
955 {
956return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.DEFAULT, null, null, template, null, null, null);
957 }
958959/***960 * Return a link to a default page for the user961 *962 * @param user Desired user963 * @return DynamicURI that to the desired page964 */965public DynamicURI getUser(String user)
966 {
967return getLink(JetspeedLink.USER, user, "", JetspeedLink.DEFAULT, null, null, null, null, null, null);
968 }
969970/***971 * Return a link to a desired page for the user972 *973 * @param page Desired page974 * @param user Desired user975 * @return DynamicURI that to the desired page976 */977public DynamicURI getUser(String user, String page)
978 {
979return getLink(JetspeedLink.USER, user, page, JetspeedLink.DEFAULT, null, null, null, null, null, null);
980 }
981982privatevoid initLink()
983 {
984if (initDone == true)
985 {
986return;
987 }
988989try990 {
991// get the profile that is set in the rundata992 profile = rundata.getProfile();
993994// if there was no profile, try making one from the rundata995if (profile == null)
996 {
997// this would only happen if the JetspeedAccessController didn't get a chance998// to setup the rundata...999 profile = Profiler.getProfile(rundata);
1000 rundata.setProfile(profile);
1001 logger.warn("BaseJetspeedLink: profile in rundata was null");
1002 }
1003 }
1004catch (ProfileException e)
1005 {
1006 logger.error("Exception", e);
1007 }
1008if (profile != null)
1009 {
1010// Get ProfileLocator for path info.1011if ((profile instanceof ProfileLocator) == true)
1012 {
1013 locator = (ProfileLocator) profile;
1014 }
1015 }
1016 initDone = true;
1017 }
10181019/***1020 * Return a link to the root portlet or pane1021 *1022 * @throws ProfileException if the profile detects an error1023 * @return URI to the root portlet/pane1024 */1025private DynamicURI getRoot() throws ProfileException
1026 {
1027 DynamicURI uri = null;
1028 initLink();
1029if (locator != null)
1030 {
1031 uri = Profiler.makeDynamicURI(rundata, locator);
1032 }
10331034if (uri == null)
1035 {
1036 uri = new DynamicURI(rundata);
1037 }
10381039// check if we need to force to a secure (https) link1040if (JetspeedResources.getBoolean("force.ssl", false))
1041 {
1042 uri.setSecure();
1043 }
10441045return uri;
1046 }
10471048/***1049 * Return a URL, as a string, the the root page or pane.1050 *1051 * @return a URL, as a string, the the root page or pane.1052 */1053public String toString()
1054 {
1055try1056 {
1057return getRoot().toString();
1058 }
1059catch (ProfileException e)
1060 {
1061 logger.error("Exception", e);
1062returnnull;
1063 }
1064 }
10651066/***1067 * Return the action key. Used by velocity templates, i.e. $jlink.ActionKey1068 *1069 * @return the action parameter name1070 */1071public String getActionKey()
1072 {
1073return JetspeedResources.PATH_ACTION_KEY;
1074 }
10751076/***1077 * Is the PSML for the anonymous user?1078 *1079 * @return True = PSML is for the anonymous user1080 */1081publicboolean getAnonymous()
1082 {
1083 initLink();
1084try1085 {
1086return locator.getAnonymous();
1087 }
1088catch (Exception e)
1089 {
1090 logger.error("Exception", e);
1091returntrue;
1092 }
1093 }
10941095/***1096 * Return country of the PSML file1097 *1098 * @return Country of PSML, or null if no country1099 */1100public String getCountry()
1101 {
1102 initLink();
1103try1104 {
1105return locator.getCountry();
1106 }
1107catch (Exception e)
1108 {
1109 logger.error("Exception", e);
1110returnnull;
1111 }
1112 }
11131114/***1115 * Return Group name of the PSML file1116 *1117 * @return Group name of PSML, or null if no Group name1118 */1119public String getGroupName()
1120 {
1121 initLink();
1122try1123 {
1124return locator.getGroupName();
1125 }
1126catch (Exception e)
1127 {
1128 logger.error("Exception", e);
1129returnnull;
1130 }
1131 }
11321133/***1134 * Return Language of the PSML file1135 *1136 * @return Language of PSML, or null if no Language1137 */1138public String getLanguage()
1139 {
1140 initLink();
1141try1142 {
1143return locator.getLanguage();
1144 }
1145catch (Exception e)
1146 {
1147 logger.error("Exception", e);
1148returnnull;
1149 }
1150 }
11511152/***1153 * Return Media Type of the PSML file1154 *1155 * @return Media Type of PSML, or null if no Media Type1156 */1157public String getMediaType()
1158 {
1159 initLink();
1160try1161 {
1162return locator.getMediaType();
1163 }
1164catch (Exception e)
1165 {
1166 logger.error("Exception", e);
1167returnnull;
1168 }
1169 }
11701171/***1172 * Return Page name of the PSML file1173 *1174 * @return Page name of PSML, or null if no Page name1175 */1176public String getPageName()
1177 {
1178 initLink();
1179try1180 {
1181return locator.getName();
1182 }
1183catch (Exception e)
1184 {
1185 logger.error("Exception", e);
1186returnnull;
1187 }
1188 }
11891190/***1191 * Return Role name of the PSML file1192 *1193 * @return Role name of PSML, or null if no Role name1194 */1195public String getRoleName()
1196 {
1197 initLink();
1198try1199 {
1200return locator.getRoleName();
1201 }
1202catch (Exception e)
1203 {
1204 logger.error("Exception", e);
1205returnnull;
1206 }
1207 }
12081209/***1210 * Return User name of the PSML file1211 *1212 * @return User name of PSML, or null if no User name1213 */1214public String getUserName()
1215 {
1216 initLink();
1217try1218 {
1219return locator.getUserName();
1220 }
1221catch (Exception e)
1222 {
1223 logger.error("Exception", e);
1224returnnull;
1225 }
1226 }
12271228/***1229 * The following methods used by Velocity to get value of constants1230 */1231publicstaticint getCURRENT()
1232 {
1233return JetspeedLink.CURRENT;
1234 }
1235publicstaticint getDEFAULT()
1236 {
1237return JetspeedLink.DEFAULT;
1238 }
1239publicstaticint getGROUP()
1240 {
1241return JetspeedLink.GROUP;
1242 }
1243publicstaticint getPANE_ID()
1244 {
1245return JetspeedLink.PANE_ID;
1246 }
1247publicstaticint getPANE_NAME()
1248 {
1249return JetspeedLink.PANE_NAME;
1250 }
1251publicstaticint getPORTLET_ID()
1252 {
1253return JetspeedLink.PORTLET_ID;
1254 }
1255publicstaticint getPORTLET_NAME()
1256 {
1257return JetspeedLink.PORTLET_NAME;
1258 }
1259publicstaticint getROLE()
1260 {
1261return JetspeedLink.ROLE;
1262 }
1263publicstaticint getUSER()
1264 {
1265return JetspeedLink.USER;
1266 }
1267publicstatic String getDEFAULT_PAGE()
1268 {
1269return"";
1270 }
12711272/***1273 * deprecated methods from JetspeedTemplateLink.1274 */12751276/***1277 * <p> Set the portlet giving context to this Link object.</p>1278 *1279 * This method is from JetspeedTemplateLink and is only here1280 * for backward compatibility. This it should not be used for1281 * any new development. Also any problems with this method will1282 * not be fixed1283 *1284 * @param portlet the name of the active portlet1285 * @deprecated the name is confusing. Use @see(#forPaneById()) instead.1286 */1287publicvoid setPortlet(Portlet portlet)
1288 {
1289this.activePortlet = portlet;
1290 }
129112921293/***1294 * Add a portlet reference in the link.1295 *1296 * Note: This must be used with caution, since a portlet may exist may times1297 * in a PSML. setPortletById() is the perfered method.1298 *1299 * @param portletName the name of the portlet to link to1300 * @return a DynamicURI referencing the named portlet for easy link construction in template1301 */1302public DynamicURI setPortletByName(String portletName)
1303 {
1304 DynamicURI uri = null;
1305try1306 {
1307 uri = getRoot();
1308 }
1309catch (Exception e)
1310 {
1311 logger.error("Exception", e);
1312returnnull;
1313 }
1314if ((portletName != null) && (portletName.length() > 0))
1315 {
1316 uri.addPathInfo(JetspeedResources.PATH_PORTLET_KEY, portletName);
1317 }
1318return uri;
1319 }
13201321/***1322 * Methods required by ApplictionTool interface1323 *1324 */13251326/***1327 * This will initialise a JetspeedLink object that was1328 * constructed with the default constructor (ApplicationTool1329 * method).1330 *1331 * @param data assumed to be a RunData object1332 */13331334publicvoid init(Object data)
1335 {
1336// Keeping init small and fast1337if (data instanceof JetspeedRunData)
1338 {
1339this.rundata = (JetspeedRunData) data;
1340 }
1341else1342 {
1343this.rundata = null;
1344 }
1345 profile = null;
1346 locator = null;
1347 initDone = false;
1348return;
1349 }
1350/***1351 * Refresh method - does nothing1352 */1353publicvoid refresh()
1354 {
1355// empty1356 }
13571358public DynamicURI setMediaType(String mediaType)
1359 {
1360return getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.DEFAULT, null, null, null, mediaType);
1361 }
13621363 }