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 final Engine m_engine;
036
037    /**
038     *  Constructs the ModuleManager.
039     *
040     *  @param engine The Engine which owns this manager.
041     */
042    public BaseModuleManager( final Engine engine ) {
043        m_engine = engine;
044    }
045
046    /**
047     *  Returns true, if the given module is compatible with this version of JSPWiki.
048     *
049     *  @param info The module to check
050     *  @return True, if the module is compatible.
051     */
052    @Override
053    public boolean checkCompatibility( final WikiModuleInfo info ) {
054        final String minVersion = info.getMinVersion();
055        final String maxVersion = info.getMaxVersion();
056
057        return Release.isNewerOrEqual( minVersion ) && Release.isOlderOrEqual( maxVersion );
058    }
059
060    protected < T extends WikiModuleInfo > Collection< WikiModuleInfo > modules( final Iterator< T > iterator ) {
061        final Set< WikiModuleInfo > ls = new TreeSet<>();
062        while( iterator.hasNext() ) {
063            final WikiModuleInfo wmi = iterator.next();
064            ls.add( wmi );
065        }
066
067        return ls;
068    }
069
070}