com.microfocus.awm.utility

## Class AWMInternalUtility

- java.lang.Object
- - com.microfocus.awm.utility.AWMInternalUtility

-     public class AWMInternalUtility
      extends java.lang.Object

  AWM internal Utility intended only for internal use. Currently only used for saving of file caches.
  Author:
    Christelle Biahmou

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AWMInternalUtility()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `containsNullByte(java.lang.String pValue)` Checks if the given string contains NULL bytes (`(byte) 0)`).
    `static IMassProcessingSubContext` | `createMassProcessingSubcontext(IMassProcessingToolContext pParentToolContext)` This method is used to create a new `IMassProcessingSubContext`.
    `static <T extends IToolInputParameter> T` | `findInputParameter(RToolInParameter pInParameter, IToolContext pToolContext, java.lang.Class<T> pType)` Searches for a `IToolInputParameter` in the given `IToolContext` based on the given `RToolInParameter`.
    `static <T extends IModeledToolOutputParameter> T` | `findOutputParameter(RToolOutParameter pOutParm, IToolContext pToolContext, java.lang.Class<T> pType)` Searches for a `IModeledToolOutputParameter` in the given `IToolContext` based on the given `RToolOutParameter`.
    `static java.lang.String` | `getContributingHelpPlugin()` Gets contributing help plug-in of the the installed product.
    `static java.lang.String` | `getDataResponseToString(IGetDataResponse pResponse)` Converts an `IGetDataResponse` to a string by using a buffered reader and `IGetDataResponse.getLocalCodePage()` for encoding.
    `static <T extends IToolInputParameter> T` | `getFirstInputParameterWithFallBack(IToolContext pToolContext, java.lang.String pName, java.lang.Class<T> pType, int pFallBackIndex)` Calls `ToolUtility.getInputParameter(IToolContext, String, Class)` to get a parameter.
    `static <T extends IModeledToolOutputParameter> T` | `getFirstOutputParameterWithFallBack(IToolContext pToolContext, java.lang.String pName, java.lang.Class<T> pType, int pFallBackIndex)` Calls `ToolUtility.getOutputParameter(IToolContext, String, Class)` to get a parameter.
    `static <T extends IToolParameter> T` | `getFirstParameterFallback(java.lang.String pName, java.lang.Class<T> pType, int pFallBackIndex, TaurusToolException pNotFoundException, java.util.List<? extends IToolParameter> pAvailableParameters, java.lang.String pParameterLabel)`
    `static EToolResultSeverity` | `getSeverityFromReturnCode(TAURUSConfiguration pModel, int pReturnCode)` Gets the `EToolResultSeverity` from the given return code and AWM model.
    `static boolean` | `isCacheElement()` Gets whether AWM elements, element lists and column configurations will be cached.
    `static java.lang.String` | `replaceNullBytes(java.lang.String pValue)` Replaces `null` with an empty string and removes null bytes ( `(byte) 0`).
    `static java.lang.String` | `replaceResourceInvalidCharacter(java.lang.String pResourceName)` Replaces all invalid characters from the given resource name with theirs INTEGER values.
    `static void` | `saveCachedFile(org.w3c.dom.Document doc, org.eclipse.core.resources.IFile cacheFile)` Save the content of the given document in the given file (create the file if it doesn't exists)

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AWMInternalUtility

          public AWMInternalUtility()

  - ### Method Detail

    - #### saveCachedFile

          public static void saveCachedFile(org.w3c.dom.Document doc,
                                            org.eclipse.core.resources.IFile cacheFile)
                                     throws javax.xml.transform.TransformerException,
                                            javax.xml.transform.TransformerFactoryConfigurationError

      Save the content of the given document in the given file (create the file if it doesn't exists)
      Parameters:
        `doc` - The document whose content will be saved.
        `cacheFile` - The file in which the document content will be saved
      Throws:
        `javax.xml.transform.TransformerException` - If an unrecoverable error occurs during the course of the transformation what is needed for saving the file.
        `javax.xml.transform.TransformerFactoryConfigurationError` - When it is not possible to create a `Transformer` instance needed to save the file.

    - #### replaceNullBytes

          public static java.lang.String replaceNullBytes(java.lang.String pValue)

      Replaces `null` with an empty string and removes null bytes ( `(byte) 0`).
      Parameters:
        `pValue` - the value
      Returns:
        the value without null bytes or an empty string, if the given string was `null`

    - #### findInputParameter

          public static <T extends IToolInputParameter> T findInputParameter(RToolInParameter pInParameter,
                                                                             IToolContext pToolContext,
                                                                             java.lang.Class<T> pType)
                                                                      throws TaurusToolException

      Searches for a `IToolInputParameter` in the given `IToolContext` based on the given `RToolInParameter`.
      Parameters:
        `pInParameter` - the `RToolInParameter`
        `pToolContext` - the given `IToolContext`
        `pType` - the `Class` of the searched `IToolInputParameter`
      Returns:
        a `IToolInputParameter` of the `IToolContext` which `IToolInputParameter.getModelObject()` method returns an `RToolInParameter` which is equal to the given `RToolInParameter`.
      Throws:
        `TaurusToolException` - if no `IToolInputParameter` could be retrieved.

    - #### findOutputParameter

          public static <T extends IModeledToolOutputParameter> T findOutputParameter(RToolOutParameter pOutParm,
                                                                                      IToolContext pToolContext,
                                                                                      java.lang.Class<T> pType)
                                                                               throws TaurusToolException

      Searches for a `IModeledToolOutputParameter` in the given `IToolContext` based on the given `RToolOutParameter`.
      Parameters:
        `pOutParm` - the `RToolOutParameter`
        `pToolContext` - the given `IToolContext`
        `pType` - the `Class` of the searched `IModeledToolOutputParameter`
      Returns:
        a `IToolInputParameter` of the `IToolContext` which `IModeledToolOutputParameter.getModelObject()` method returns an `RToolOutParameter` which is equal to the given `RToolOutParameter`.
      Throws:
        `TaurusToolException` - if no `IToolInputParameter` could be retrieved.

    - #### containsNullByte

          public static boolean containsNullByte(java.lang.String pValue)

      Checks if the given string contains NULL bytes (`(byte) 0)`).
      Parameters:
        `pValue` - the string to check
      Returns:
        `true` if at least one NULL byte is detected

    - #### isCacheElement

          public static boolean isCacheElement()

      Gets whether AWM elements, element lists and column configurations will be cached.
      Returns:
        `true` only if AWM elements will be cached.

    - #### replaceResourceInvalidCharacter

          public static java.lang.String replaceResourceInvalidCharacter(java.lang.String pResourceName)

      Replaces all invalid characters from the given resource name with theirs INTEGER values.

    - Resource name invalid characters are "\, /, :, *, <, >, |".
    - Resource name "folder\\/:*?<>|" will be replaced to "folder_92_47_58_42_63_60_62_124".

Parameters:
  `pResourceName` - the resource name
Returns:
  A valid resource name.

- #### getContributingHelpPlugin

      public static java.lang.String getContributingHelpPlugin()

  Gets contributing help plug-in of the the installed product.
  Returns:
    the contributing help plug-in

- #### getDataResponseToString

      public static java.lang.String getDataResponseToString(IGetDataResponse pResponse)
                                                      throws java.io.IOException

  Converts an `IGetDataResponse` to a string by using a buffered reader and `IGetDataResponse.getLocalCodePage()` for encoding.
  Parameters:
    `pResponse` - the response to convert
  Returns:
    the converted response
  Throws:
    `java.io.IOException` - if reading the response fails

- #### getFirstInputParameterWithFallBack

      public static <T extends IToolInputParameter> T getFirstInputParameterWithFallBack(IToolContext pToolContext,
                                                                                         java.lang.String pName,
                                                                                         java.lang.Class<T> pType,
                                                                                         int pFallBackIndex)
                                                                                  throws TaurusToolException

  Calls `ToolUtility.getInputParameter(IToolContext, String, Class)` to get a parameter. If that fails, we attempt to get a matching parameter from the fall-back index.

  Any fall-back attempt will log a warning message with the original exception. If the attempt also fails, a more detailed exception will be thrown.

  Parameters:
    `pToolContext` - the tool context
    `pName` - expected parameter name
    `pType` - expected parameter type
    `pFallBackIndex` - index of the parameter that was used before all parameters had extension IDs
  Returns:
    the found parameter
  Throws:
    `TaurusToolException` - if the parameter cannot be found or its type does not match

- #### getFirstOutputParameterWithFallBack

      public static <T extends IModeledToolOutputParameter> T getFirstOutputParameterWithFallBack(IToolContext pToolContext,
                                                                                                  java.lang.String pName,
                                                                                                  java.lang.Class<T> pType,
                                                                                                  int pFallBackIndex)
                                                                                           throws TaurusToolException

  Calls `ToolUtility.getOutputParameter(IToolContext, String, Class)` to get a parameter. If that fails, we attempt to get a matching parameter from the fall-back index.
  Parameters:
    `pToolContext` - the tool context
    `pName` - expected parameter name
    `pType` - expected parameter type
    `pFallBackIndex` - index of the parameter that was used before all parameters had extension IDs
  Returns:
    the found parameter
  Throws:
    `TaurusToolException` - if the parameter cannot be found or its type does not match

- #### getFirstParameterFallback

      public static <T extends IToolParameter> T getFirstParameterFallback(java.lang.String pName,
                                                                           java.lang.Class<T> pType,
                                                                           int pFallBackIndex,
                                                                           TaurusToolException pNotFoundException,
                                                                           java.util.List<? extends IToolParameter> pAvailableParameters,
                                                                           java.lang.String pParameterLabel)
                                                                    throws TaurusToolException

  Parameters:
    `pName` - expected parameter name
    `pType` - expected parameter type
    `pFallBackIndex` - fall-back index
    `pNotFoundException` - the exception that has been thrown in the first place
    `pAvailableParameters` - the list of available parameters
    `pParameterLabel` - either `input parameter` or `output parameter` (translated)
  Returns:
    a matching parameter with no extension ID under the fall-back index
  Throws:
    `TaurusToolException` - if no matching parameter was found under the fall-back index

- #### createMassProcessingSubcontext

      public static IMassProcessingSubContext createMassProcessingSubcontext(IMassProcessingToolContext pParentToolContext)
                                                                      throws TaurusToolException

  This method is used to create a new `IMassProcessingSubContext`. This should only be required if a mass processing context should be overridden.

  This method creates a new `IExecutionContext` by using the `ISystemImage` (`IExecutionContext.getSystemImage()`) of the parent `IExecutionContext`.

  The newly created `IExecutionContext` will be initialized (`IExecutionContext.initContext(com.microfocus.awm.model.IResource)`) with the `IResource` of the parent context.

  `IExecutionContext` is used for the creation of the `IMassProcessingSubContext`.

  Parameters:
    `pParentToolContext` - the parent `IMassProcessingToolContext`
  Returns:
    a new `IMassProcessingSubContext` initiated with a newly created `IExecutionContext`.
  Throws:
    `TaurusToolException` - if an `Exception` occurs while creating the `IMassProcessingSubContext`

- #### getSeverityFromReturnCode

      public static EToolResultSeverity getSeverityFromReturnCode(TAURUSConfiguration pModel,
                                                                  int pReturnCode)

  Gets the `EToolResultSeverity` from the given return code and AWM model. The return code is compared to the model's maximum return code.
  Parameters:
    `pModel` - the used model
    `pReturnCode` - a numeric tool return code
  Returns:
    the severity relative to the model's maximum return code
  See Also:
    `ApplicationOptions.getMaxRC()`

Copyright © 2015 Micro Focus GmbH. All rights reserved.