001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.wiki.macros;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.kernel.KernelConstants;
038: import org.libresource.kernel.interfaces.KernelService;
039:
040: import org.libresource.membership.MembershipConstants;
041: import org.libresource.membership.ejb.model.ProfileResourceValue;
042: import org.libresource.membership.interfaces.MembershipService;
043:
044: import org.radeox.macro.BaseMacro;
045: import org.radeox.macro.parameter.MacroParameter;
046:
047: import java.io.IOException;
048: import java.io.Writer;
049:
050: public class UserLinkMacro extends BaseMacro {
051: private KernelService kernelService;
052: private MembershipService membershipService;
053:
054: public UserLinkMacro() throws Exception {
055: super ();
056: kernelService = (KernelService) Libresource
057: .getService(KernelConstants.SERVICE);
058: membershipService = (MembershipService) Libresource
059: .getService(MembershipConstants.SERVICE);
060: }
061:
062: public String getName() {
063: return "user";
064: }
065:
066: public void execute(Writer writer, MacroParameter params)
067: throws IllegalArgumentException, IOException {
068: try {
069: if (kernelService.isAuthentified()) {
070: ProfileResourceValue user = membershipService
071: .getProfile(kernelService
072: .getConnectedResource());
073: StringBuffer link = new StringBuffer();
074: link.append(kernelService.getServerUrl());
075: link.append(membershipService.getUsersRootURI()
076: .getPath()
077: + "/" + user.getId());
078:
079: // action
080: String action = (String) params.getParams().get(
081: "action");
082:
083: if (action != null) {
084: link.append("?action=" + action);
085: }
086:
087: // label
088: String label = (String) params.getParams().get("label");
089:
090: if (label == null) {
091: label = user.getFullName();
092: }
093:
094: writer.write("<a href=\"" + link + "\" title=\""
095: + label + "\">" + label + "</a>");
096: }
097: } catch (IOException e) {
098: throw e;
099: } catch (IllegalArgumentException e) {
100: throw e;
101: } catch (Exception e) {
102: throw new IllegalArgumentException("error in user : "
103: + e.getMessage());
104: }
105: }
106:
107: public String getDescription() {
108: return "Generate a link to the current user page, according 'action'.";
109: }
110:
111: public String[] getParamDescription() {
112: return new String[] { "1. the action (optional)",
113: "2. the link label (optional)" };
114: }
115: }
|