WebContextOps.java

/*
** Module   : WebContextOps.java
** Abstract : Utility for working with WEB-CONTEXT system handle.
**
** Copyright (c) 2022-2025, Golden Code Development Corporation.
**
** -#- -I- --Date-- -------------------------------------- Description --------------------------------------
** 001 CA  20220428 Created initial version.
**     CA  20220505 Added missing methods from WrappedResource.
**     CA  20201003 CommonHandle.getResourceType() method renamed to resourceType() to prevent conflicts
**                  with namesakes in DMO. See #6694.
** 002 CA  20230221 Javadoc fixes.
** 003 CA  20250130 Added stubs for GET-BINARY-DATA(), GET-CONFIG-VALUE(), GET-CGI-LIST(), GET-CGI-VALUE(), 
**                  GET-CGI-LONG-VALUE(), INCREMENT-EXCLUSIVE-ID(), URL-DECODE(), CONFIG-NAME, 
**                  CURRENT-ENVIRONMENT, SESSION-END, UTC-OFFSET.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.util;

import com.goldencode.p2j.security.*;
import com.goldencode.proxy.*;

/**
 * Utility for working with WEB-CONTEXT system handle.
 */
public class WebContextOps
{
   /** Stores context-local state variables. */
   private static ContextLocal<WorkArea> local = new ContextLocal<WorkArea>()
   {
      /** Retrieve the initial value of this context local variable. */
      @Override
      protected WorkArea initialValue()
      {
         return new WorkArea();
      }
   };

   /**
    * Get the WEB-CONTEXT system handle.
    *
    * @return WEB-CONTEXT system handle.
    */
   public static handle asHandle()
   {
      WorkArea wa = local.get();
      
      Class[] classes = { WebContextOps.class };
      WebContextResource proxy = StaticProxy.obtain(WebContextResource.class, classes);
      
      if (wa.id == null)
      {
         wa.id = handle.resourceId(proxy);
      }
      
      return new handle(proxy);
   }
   
   /**
    * Get this resource's ID.
    * 
    * @return   The resource's ID.
    */
   public static Long id()
   {
      WorkArea wa = local.get();
      
      return wa.id;
   }
   
   /**
    * Set this resource's ID.
    * <p>
    * This is a no-op for system handles.
    *  
    * @param    id
    *           The resource's ID.
    */
   public static void id(long id)
   {
      // no-op
   }
   
   /**
    * Implementation for the {@link WrappedResource#valid()} API.
    * 
    * @return   Always true.
    */
   public static boolean valid()
   {
      return true;
   }
   
   /**
    * Implementation for the {@link WrappedResource#unknown()} API.
    * 
    * @return   Always false.
    */
   public static boolean unknown()
   {
      return false;
   }

   /**
    * Get the type of its associated handle.
    * 
    * @return   Always return the PSEUDO-WIDGET value.
    */
   public static character resourceType()
   {
      return new character(LegacyResource.PSEUDO_WIDGET);
   }

   /**
    * API needed to implement read-only attribute assignment (a 4GL "feature").
    * 
    * @param    attribute
    *           The attribute's name.
    *           
    * @see      handle#readOnlyError(handle, String)
    */
   public static void readOnlyError(String attribute)
   {
      handle.readOnlyError(asHandle(), attribute);
   }
   
   /**
    * API needed to implement read-only attribute assignment (a 4GL "feature").
    * 
    * @param    attribute
    *           The attribute's name.
    * @param    expr
    *           The value which is attempted to be assigned to the read-only attribute. 
    *
    * @see      handle#readOnlyError(handle, String, Object)
    */
   public static void readOnlyError(String attribute, Object expr)
   {
      handle.readOnlyError(asHandle(), attribute);
   }

   /**
    * Get the EXCLUSIVE-ID attribute.
    * 
    * @return   See above.
    */
   public static character getExclusiveId()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:EXCLUSIVE-ID attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-END-OF-LINE attribute.
    * 
    * @return   See above.
    */
   public static character getHtmlEndOfLine()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-END-OF-LINE attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-END-OF-PAGE attribute.
    * 
    * @return   See above.
    */
   public static character getHtmlEndOfPage()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-END-OF-PAGE attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-FRAME-BEGIN attribute.
    * 
    * @return   See above.
    */
   public static character getHtmlFrameBegin()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-FRAME-BEGIN attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-FRAME-END attribute.
    * 
    * @return   See above.
    */
   public static character setHtmlFrameEnd()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-FRAME-END attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-TITLE-BEGIN attribute.
    * 
    * @return   See above.
    */
   public static character getHtmlHeaderBegin()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-HEADER-BEGIN attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-TITLE-END attribute.
    * 
    * @return   See above.
    */
   public static character getHtmlHeaderEnd()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-HEADER-END attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-TITLE-BEGIN attribute.
    * 
    * @return   See above.
    */
   public static character getHtmlTitleBegin()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-TITLE-BEGIN attribute is not implemented");
      return new character();
   }

   /**
    * Get the HTML-TITLE-END attribute.
    * 
    * @return   See above.
    */
   public static character getHtmlTitleEnd()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-TITLE-END attribute is not implemented");
      return new character();
   }

   /**
    * Set the HTML-END-OF-LINE attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlEndOfLine(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-END-OF-LINE attribute is not implemented");
   }

   /**
    * Set the HTML-END-OF-PAGE attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlEndOfPage(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-END-OF-PAGE attribute is not implemented");
   }

   /**
    * Set the HTML-FRAME-BEGIN attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlFrameBegin(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-FRAME-BEGIN attribute is not implemented");
   }

   /**
    * Set the HTML-FRAME-END attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlFrameEnd(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-FRAME-END attribute is not implemented");
   }

   /**
    * Set the HTML-HEADER-BEGIN attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlHeaderBegin(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-HEADER-BEGIN attribute is not implemented");
   }

   /**
    * Set the HTML-HEADER-END attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlHeaderEnd(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-HEADER-END attribute is not implemented");
   }

   /**
    * Set the HTML-TITLE-BEGIN attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlTitleBegin(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-TITLE-BEGIN attribute is not implemented");
   }

   /**
    * Set the HTML-TITLE-END attribute.
    * 
    * @param    val
    *           The attribute's value.
    */
   public static void setHtmlTitleEnd(character val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:HTML-TITLE-END attribute is not implemented");
   }

   /**
    * Gets the value of a form-field into a {@link memptr}.  The form-field must specify a file.
    * 
    * @param    fname
    *           The form-field name.
    *
    * @return   See above.
    */
   public static memptr getBinaryData(character fname)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-BINARY-DATA method is not implemented");
      return new memptr();
   }

   /**
    * Gets the value of a form-field into a {@link memptr}.  The form-field must specify a file.
    * 
    * @param    fname
    *           The form-field name.
    *
    * @return   See above.
    */
   public static memptr getBinaryData(String fname)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-BINARY-DATA method is not implemented");
      return new memptr();
   }

   /**
    * Get the value of parameters used to configured this webspeed agent.
    * 
    * @param    param
    *           The parameter name.
    *
    * @return   See above.
    */
   public static character getConfigValue(character param)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CONFIG-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the value of parameters used to configured this webspeed agent.
    * 
    * @param    param
    *           The parameter name.
    *
    * @return   See above.
    */
   public static character getConfigValue(String param)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CONFIG-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the list of CGI variables for the specified environment.
    * 
    * @param    env
    *           The environment name.
    *
    * @return   See above.
    */
   public static character getCgiList(character env)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-LIST method is not implemented");
      return new character();
   }
   
   /**
    * Get the list of CGI variables for the specified environment.
    * 
    * @param    env
    *           The environment name.
    *
    * @return   See above.
    */
   public static character getCgiList(String env)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-LIST method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static character getCgiValue(character env, character varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static character getCgiValue(String env, character varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static character getCgiValue(String env, String varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static character getCgiValue(character env, String varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static character getCgiValue(character env, character varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static character getCgiValue(String env, character varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static character getCgiValue(String env, String varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static character getCgiValue(character env, String varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-CGI-VALUE method is not implemented");
      return new character();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(character env, character varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(String env, character varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(String env, String varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(character env, String varName)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(character env, character varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(String env, character varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(String env, String varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Get the specified CGI variable for the specified environment.
    * 
    * @param    env
    *           The environment name.
    * @param    varName
    *           The variable name.
    * @param    delim
    *           The delimiter.
    *           
    * @return   See above.
    */
   public static longchar getCgiLongValue(character env, String varName, character delim)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:GET-GCI-LONG-VALUE method is not implemented");
      return new longchar();
   }
   
   /**
    * Increment the exclusive-id assigned to state-aware calls.
    * 
    * @param    i
    *           The step to increment.
    *           
    * @return   The new value.
    */
   public static integer incrementExclusiveId(integer i)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:INCREMENT-EXCLUSIVE-ID method is not implemented");
      return new integer();
   }
   
   /**
    * Increment the exclusive-id assigned to state-aware calls.
    * 
    * @param    i
    *           The step to increment.
    *           
    * @return   The new value.
    */
   public static integer incrementExclusiveId(long i)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:INCREMENT-EXCLUSIVE-ID method is not implemented");
      return new integer();
   }

   /**
    * Decode the specified string.
    * 
    * @param    str
    *           The string to decode.
    *           
    * @return   See above.
    */
   public static character urlDecode(character str)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:URL-DECODE method is not implemented");
      return new character();
   }

   /**
    * Decode the specified string.
    * 
    * @param    str
    *           The string to decode.
    *           
    * @return   See above.
    */
   public static character urlDecode(String str)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:URL-DECODE method is not implemented");
      return new character();
   }
   
   /**
    * Get the CONFIG-NAME attribute.
    * 
    * @return   See above.
    */
   public static character getConfigName()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:CONFIG-NAME attribute is not implemented");
      return new character();
   }

   /**
    * Get the CURRENT-ENVIRONMENT attribute.
    * 
    * @return   See above.
    */
   public static character getCurrentEnvironment()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:CURRENT-ENVIRONMENT attribute is not implemented");
      return new character();
   }

   /**
    * Get the SESSION-END attribute.
    * 
    * @return   See above.
    */
   public static logical getSessionEnd()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:SESSION-END attribute is not implemented");
      return logical.UNKNOWN;
   }

   /**
    * Set the SESSION-END attribute.
    * 
    * @param    val
    *           New value for the attribute.
    */
   public static void setSessionEnd(logical val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:SESSION-END attribute setter is not implemented");
   }

   /**
    * Set the SESSION-END attribute.
    * 
    * @param    val
    *           New value for the attribute.
    */
   public static void setSessionEnd(boolean val)
   {
      UnimplementedFeature.missing("WEB-CONTEXT:SESSION-END attribute setter is not implemented");
   }

   /**
    * Get the UTC-OFFSET attribute.
    * 
    * @return   See above.
    */
   public static integer getUtcOffset()
   {
      UnimplementedFeature.missing("WEB-CONTEXT:UTC-OFFSET attribute is not implemented");
      return new integer();
   }

   /** 
    * Stores global data relating to the state of the current context.
    */
   private static class WorkArea
   {  
      /** The resource's ID. */
      private Long id = null;
   }
}