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