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