/* 
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.  
 */
package org.apache.wiki.tags;

import org.apache.commons.lang3.StringUtils;
import org.apache.wiki.api.exceptions.ProviderException;

import java.io.IOException;

/**
 *  Includes body, if the request context matches.  To understand more about
 *  RequestContexts, please look at the WikiContext class.
 *
 *  @since 2.0
 *  @see org.apache.wiki.WikiContext
 */
public class CheckRequestContextTag
    extends WikiTagBase
{
    private static final long serialVersionUID = 0L;
    
    private String m_context;
    private String[] m_contextList = {};

    /**
     *  {@inheritDoc}
     */
    @Override
    public void initTag()
    {
        super.initTag();
        m_context = null;
        m_contextList = new String[0];
    }
    
    /**
     *  Returns the context.
     *  
     *  @return Return the context.
     */
    public String getContext()
    {
        return m_context;
    }

    /**
     *  Set the context to check for.
     *  
     *  @param arg One of the RequestsContexts.
     */
    public void setContext(final String arg )
    {
        m_context = arg;
        
        m_contextList = StringUtils.split(arg,'|');
    }

    /**
     *  {@inheritDoc}
     */
    @Override
    public final int doWikiStartTag()
        throws IOException,
               ProviderException
    {
        for(int i = 0; i < m_contextList.length; i++ )
        {
            final String ctx = m_wikiContext.getRequestContext();
            
            final String checkedCtx = m_contextList[i];

            if( !checkedCtx.isEmpty() )
            {
                if( checkedCtx.charAt(0) == '!' )
                {
                    if( !ctx.equalsIgnoreCase(checkedCtx.substring(1) ) )
                    {
                        return EVAL_BODY_INCLUDE;
                    }
                }
                else if( ctx.equalsIgnoreCase(m_contextList[i]) )
                {
                    return EVAL_BODY_INCLUDE;
                }
            }
        }

        return SKIP_BODY;
    }
}

@@ -1212,20 +1212,16 @@
 ntextTag
-%0A   
  extends
@@ -1236,10 +1236,11 @@
 Base
+ %7B
 %0A
-%7B
 %0A   
@@ -1443,20 +1443,16 @@
 nitTag()
-%0A   
  %7B%0A     
@@ -1845,16 +1845,17 @@
 Context(
+ 
 final St
@@ -1864,20 +1864,16 @@
 ng arg )
-%0A   
  %7B%0A     
@@ -1892,25 +1892,16 @@
  = arg;%0A
-        %0A
         
@@ -1938,15 +1938,17 @@
 lit(
+ 
 arg,'%7C'
+ 
 );%0A 
@@ -2042,24 +2042,16 @@
 artTag()
-%0A       
  throws 
@@ -2062,31 +2062,16 @@
 ception,
-%0A              
  Provide
@@ -2080,20 +2080,16 @@
 xception
-%0A   
  %7B%0A     
@@ -2098,59 +2098,52 @@
  for
-(int i = 0; i %3C m_contextList.length; i++ )%0A       
+ ( final String checkedCtx : m_contextList )
  %7B%0A 
@@ -2223,80 +2223,11 @@
     
-%0A            final String checkedCtx = m_contextList%5Bi%5D;%0A%0A            
 if
+ 
 ( !c
@@ -2247,28 +2247,16 @@
 mpty() )
-%0A           
  %7B%0A     
@@ -2268,16 +2268,17 @@
       if
+ 
 ( checke
@@ -2289,17 +2289,19 @@
 .charAt(
-0
+ 0 
 ) == '!'
@@ -2302,32 +2302,16 @@
 == '!' )
-%0A               
  %7B%0A     
@@ -2327,16 +2327,17 @@
       if
+ 
 ( !ctx.e
@@ -2352,16 +2352,17 @@
 oreCase(
+ 
 checkedC
@@ -2378,34 +2378,16 @@
 ing(
+ 
 1
-)
  ) )
-%0A                  
  
+)
  %7B%0A 
@@ -2478,32 +2478,16 @@
    %7D
-%0A               
  else if
 ( ct
@@ -2482,16 +2482,17 @@
  else if
+ 
 ( ctx.eq
@@ -2510,43 +2510,23 @@
 ase(
-m_contextList%5Bi%5D) )%0A               
+ checkedCtx ) )
  %7B%0A 
@@ -2608,25 +2608,24 @@
 %7D%0A        %7D%0A
-%0A
         retu
@@ -2644,10 +2644,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

apply format