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*/ 019package org.apache.wiki.ui.admin.beans; 020 021import java.util.Collection; 022 023import javax.management.NotCompliantMBeanException; 024 025import org.apache.commons.lang.StringUtils; 026import org.apache.wiki.Release; 027import org.apache.wiki.WikiContext; 028import org.apache.wiki.WikiEngine; 029import org.apache.wiki.api.engine.PluginManager; 030import org.apache.wiki.plugin.DefaultPluginManager.WikiPluginInfo; 031import org.apache.wiki.ui.admin.SimpleAdminBean; 032import org.apache.wiki.util.XHTML; 033import org.apache.wiki.util.XhtmlUtil; 034import org.jdom2.Element; 035 036public class PluginBean extends SimpleAdminBean { 037 038 private WikiEngine m_engine; 039 040 private static final String VER_WARNING = "<span class='warning'>This module is not compatible with this version of JSPWiki.</span>"; 041 042 public PluginBean( WikiEngine engine ) throws NotCompliantMBeanException { 043 m_engine = engine; 044 } 045 046 public String[] getAttributeNames() { 047 return new String[0]; 048 } 049 050 public String[] getMethodNames() { 051 return new String[0]; 052 } 053 054 public String getTitle() { 055 return "Plugins"; 056 } 057 058 public int getType() { 059 return CORE; 060 } 061 062 @SuppressWarnings("unchecked") 063 public String doGet(WikiContext context) { 064 PluginManager pm = m_engine.getPluginManager(); 065 Collection< WikiPluginInfo > plugins = pm.modules(); 066 067 Element root = XhtmlUtil.element( XHTML.div ); 068 Element tb = XhtmlUtil.element( XHTML.table ).setAttribute( "border", "1" ); 069 070 root.addContent( XhtmlUtil.element( XHTML.h4 ).addContent( "Plugins") ) 071 .addContent( tb ); 072 073 Element trHead = XhtmlUtil.element( XHTML.tr ); 074 trHead.addContent( XhtmlUtil.element( XHTML.th ).addContent( "Name" ) ) 075 .addContent( XhtmlUtil.element( XHTML.th ).addContent( "Alias" ) ) 076 .addContent( XhtmlUtil.element( XHTML.th ).addContent( "Author" ) ) 077 .addContent( XhtmlUtil.element( XHTML.th ).addContent( "Notes" ) ); 078 079 tb.addContent( trHead ); 080 081 for( WikiPluginInfo info : plugins ) { 082 Element tr = XhtmlUtil.element( XHTML.tr ); 083 tr.addContent( XhtmlUtil.element( XHTML.td ).addContent( info.getName() ) ) 084 .addContent( XhtmlUtil.element( XHTML.td ).addContent( info.getAlias() ) ) 085 .addContent( XhtmlUtil.element( XHTML.td ).addContent( info.getAuthor() ) ) 086 .addContent( XhtmlUtil.element( XHTML.td ).addContent( validPluginVersion( info ) ) ); 087 088 tb.addContent( tr ); 089 } 090 091 return XhtmlUtil.serialize( root, XhtmlUtil.EXPAND_EMPTY_NODES ); 092 } 093 094 String validPluginVersion( WikiPluginInfo info ) { 095 return Release.isNewerOrEqual( info.getMinVersion() ) && Release.isOlderOrEqual( info.getMaxVersion() ) 096 ? StringUtils.EMPTY 097 : VER_WARNING; 098 } 099 100}