001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/rwiki/tags/sakai_2-4-1/rwiki-impl/impl/src/java/uk/ac/cam/caret/sakai/rwiki/component/macros/SectionsMacro.java $
003: * $Id: SectionsMacro.java 29159 2007-04-19 01:46:15Z ajpoland@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package uk.ac.cam.caret.sakai.rwiki.component.macros;
021:
022: import java.io.IOException;
023: import java.io.Writer;
024: import java.util.Collection;
025: import java.util.Iterator;
026:
027: import org.radeox.api.macro.MacroParameter;
028: import org.radeox.macro.BaseMacro;
029: import org.sakaiproject.exception.IdUnusedException;
030: import org.sakaiproject.site.api.Group;
031: import org.sakaiproject.site.api.Site;
032: import org.sakaiproject.site.cover.SiteService;
033:
034: import uk.ac.cam.caret.sakai.rwiki.component.Messages;
035: import uk.ac.cam.caret.sakai.rwiki.component.radeox.service.impl.SpecializedRenderContext;
036:
037: /**
038: * This is a reimplementation of the LinkMacro but made aware of the sakai://
039: * and worksite:// url formats
040: *
041: * @author andrew
042: */
043: public class SectionsMacro extends BaseMacro {
044:
045: public String[] getParamDescription() {
046: return new String[] { Messages.getString("SectionsMacro.0"), //$NON-NLS-1$
047: Messages.getString("SectionsMacro.1") }; //$NON-NLS-1$
048: }
049:
050: /*
051: * (non-Javadoc)
052: *
053: * @see org.radeox.macro.Macro#getDescription()
054: */
055: public String getDescription() {
056: return Messages.getString("SectionsMacro.2"); //$NON-NLS-1$
057: }
058:
059: public String getName() {
060: return "sakai-sections"; //$NON-NLS-1$
061: }
062:
063: public void execute(Writer writer, MacroParameter params)
064: throws IllegalArgumentException, IOException {
065:
066: SpecializedRenderContext context = (SpecializedRenderContext) params
067: .getContext();
068:
069: String useids = params.get("useids", 0); //$NON-NLS-1$
070:
071: String siteId = context.getSiteId();
072:
073: Collection groups = null;
074: Site site;
075: try {
076: site = SiteService.getSite(siteId);
077: } catch (IdUnusedException e) {
078: throw new IllegalArgumentException(
079: Messages.getString("SectionsMacro.5") + siteId + " : " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
080: }
081: groups = site.getGroups();
082:
083: for (Iterator is = groups.iterator(); is.hasNext();) {
084: Group group = (Group) is.next();
085: String pageName = ""; //$NON-NLS-1$
086:
087: if ("true".equals(useids)) //$NON-NLS-1$
088: {
089: pageName = group.getId() + "/Home"; //$NON-NLS-1$
090: } else {
091: if (site != null) {
092: pageName = group.getReference() + "/"; //$NON-NLS-1$
093: }
094: pageName += "section/" + group.getTitle() + "/Home"; //$NON-NLS-1$ //$NON-NLS-2$
095: }
096: writer.write("\n"); //$NON-NLS-1$
097: writer.write("* [ Section: "); //$NON-NLS-1$
098: writer.write(group.getTitle());
099: writer.write("|"); //$NON-NLS-1$
100: writer.write(pageName);
101: writer.write("]"); //$NON-NLS-1$
102: }
103: writer.write("\n"); //$NON-NLS-1$
104: return;
105: }
106: }
|