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.Collection;
022    import java.util.Map;
023    
024    import org.apache.wiki.ReferenceManager;
025    import org.apache.wiki.WikiContext;
026    import org.apache.wiki.api.exceptions.PluginException;
027    
028    /**
029     *  Plugin that enumerates the pages in the wiki that have not yet been defined.
030     *  
031     *  Parameters  (from AbstractReferralPlugin):
032     *  <ul>
033     *  <li><b>separator</b> - how to separate generated links; default is a wikitext line break,  producing a vertical list</li>
034     * <li><b> maxwidth</b> - maximum width, in chars, of generated links.</li>
035     * </ul>
036     *
037     */
038    public class UndefinedPagesPlugin
039        extends AbstractReferralPlugin
040    {
041        /**
042         *  {@inheritDoc}
043         */
044        public String execute( WikiContext context, Map<String, String> params )
045            throws PluginException
046        {
047            ReferenceManager refmgr = context.getEngine().getReferenceManager();
048            Collection links = refmgr.findUncreated();
049    
050            super.initialize( context, params );
051    
052            links = filterAndSortCollection( links );
053            
054            String wikitext = null;
055            
056            if (m_lastModified)
057            {
058                throw new PluginException("parameter " + PARAM_LASTMODIFIED + " is not valid for the UndefinedPagesPlugin");
059            }
060            
061            if (m_show.equals(PARAM_SHOW_VALUE_COUNT))
062            {
063                wikitext = "" + links.size();
064            }
065            else
066            {
067                wikitext = wikitizeCollection( links, m_separator, ALL_ITEMS );
068            }
069            
070            return makeHTML( context, wikitext );
071        }
072    }