001 /*
002 Licensed to the Apache Software Foundation (ASF) under one
003 or more contributor license agreements. See the NOTICE file
004 distributed with this work for additional information
005 regarding copyright ownership. The ASF licenses this file
006 to you under the Apache License, Version 2.0 (the
007 "License"); you may not use this file except in compliance
008 with the License. You may obtain a copy of the License at
009
010 http://www.apache.org/licenses/LICENSE-2.0
011
012 Unless required by applicable law or agreed to in writing,
013 software distributed under the License is distributed on an
014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 KIND, either express or implied. See the License for the
016 specific language governing permissions and limitations
017 under the License.
018 */
019 package org.apache.wiki.plugin;
020
021 import java.util.Iterator;
022 import java.util.List;
023 import java.util.Map;
024 import java.util.ResourceBundle;
025
026 import org.apache.wiki.PageLock;
027 import org.apache.wiki.PageManager;
028 import org.apache.wiki.WikiContext;
029 import org.apache.wiki.api.exceptions.PluginException;
030 import org.apache.wiki.api.plugin.WikiPlugin;
031 import org.apache.wiki.preferences.Preferences;
032
033 /**
034 * This is a plugin for the administrator: It allows him to see in a single
035 * glance who is editing what.
036 *
037 * <p>Parameters : </p>
038 * NONE
039 * @since 2.0.22.
040 */
041 public class ListLocksPlugin
042 implements WikiPlugin
043 {
044 /**
045 * {@inheritDoc}
046 */
047 public String execute( WikiContext context, Map<String, String> params )
048 throws PluginException
049 {
050 StringBuffer result = new StringBuffer();
051
052 PageManager mgr = context.getEngine().getPageManager();
053 List<PageLock> locks = mgr.getActiveLocks();
054 ResourceBundle rb = Preferences.getBundle( context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE );
055
056 result.append("<table class=\"wikitable\">\n");
057 result.append("<tr>\n");
058 result.append( "<th>" + rb.getString( "plugin.listlocks.page" ) + "</th><th>" + rb.getString( "plugin.listlocks.locked.by" )
059 + "</th><th>" + rb.getString( "plugin.listlocks.acquired" ) + "</th><th>"
060 + rb.getString( "plugin.listlocks.expires" ) + "</th>\n" );
061 result.append("</tr>");
062
063 if( locks.size() == 0 )
064 {
065 result.append( "<tr><td colspan=\"4\" class=\"odd\">" + rb.getString( "plugin.listlocks.no.locks.exist" )
066 + "</td></tr>\n" );
067 }
068 else
069 {
070 int rowNum = 1;
071 for( Iterator<PageLock> i = locks.iterator(); i.hasNext(); )
072 {
073 PageLock lock = i.next();
074
075 result.append( rowNum % 2 != 0 ? "<tr class=\"odd\">" : "<tr>" );
076 result.append("<td>"+lock.getPage()+"</td>");
077 result.append("<td>"+lock.getLocker()+"</td>");
078 result.append( "<td>"
079 + Preferences.renderDate( context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME )
080 + "</td>" );
081 result.append( "<td>" + Preferences.renderDate( context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME )
082 + "</td>" );
083 result.append("</tr>\n");
084 rowNum++;
085 }
086 }
087
088 result.append("</table>");
089
090 return result.toString();
091 }
092
093 }