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.modules; 020 021import org.apache.wiki.api.Release; 022import org.apache.wiki.api.core.Engine; 023 024import java.util.Collection; 025import java.util.Iterator; 026import java.util.Set; 027import java.util.TreeSet; 028 029 030/** 031 * Superclass for all JSPWiki managers for modules (plugins, etc). 032 */ 033public abstract class BaseModuleManager implements ModuleManager { 034 035 protected Engine m_engine; 036 037 private boolean m_loadIncompatibleModules = false; 038 039 /** 040 * Constructs the ModuleManager. 041 * 042 * @param engine The Engine which owns this manager. 043 */ 044 public BaseModuleManager( final Engine engine ) { 045 m_engine = engine; 046 } 047 048 /** 049 * Returns true, if the given module is compatible with this version of JSPWiki. 050 * 051 * @param info The module to check 052 * @return True, if the module is compatible. 053 */ 054 @Override 055 public boolean checkCompatibility( final WikiModuleInfo info ) { 056 if( !m_loadIncompatibleModules ) { 057 final String minVersion = info.getMinVersion(); 058 final String maxVersion = info.getMaxVersion(); 059 060 return Release.isNewerOrEqual( minVersion ) && Release.isOlderOrEqual( maxVersion ); 061 } 062 063 return true; 064 } 065 066 protected < T extends WikiModuleInfo > Collection< WikiModuleInfo > modules( final Iterator< T > iterator ) { 067 final Set< WikiModuleInfo > ls = new TreeSet<>(); 068 for( final Iterator< T > i = iterator; i.hasNext(); ) { 069 final WikiModuleInfo wmi = i.next(); 070 ls.add( wmi ); 071 } 072 073 return ls; 074 } 075 076}