java.lang.Object
org.eclipse.lemminx.customservice.synapse.utils.Utils

public class Utils extends Object
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • getInlineString

      public static String getInlineString(DOMNode node)
      Get the inline string of the given node
      Parameters:
      node - the node
      Returns:
      the inline string of the given node
    • getInlineString

      public static String getInlineString(DOMNode node, boolean requiresXmlUnescaping)
      Get the inline string of the given node
      Parameters:
      node - the node
      requiresXmlUnescaping - whether to unescape the xml content
      Returns:
      the inline string of the given node
    • parseInt

      public static int parseInt(String number)
    • getDOMDocumentFromPath

      public static DOMDocument getDOMDocumentFromPath(String path) throws IOException
      Returns the DOMDocument for the given file path.
      Parameters:
      path - the xml file path
      Returns:
      the DOMDocument for the given file path
      Throws:
      IOException - if an error occurs while reading the file
    • getDOMDocument

      public static DOMDocument getDOMDocument(File file) throws IOException
      Throws:
      IOException
    • getDOMDocument

      public static DOMDocument getDOMDocument(String content)
      Get the DOM document from the given xml content
      Parameters:
      content - the xml content
      Returns:
      the DOM document for the given xml content
    • getDOMDocument

      public static DOMDocument getDOMDocument(String content, URIResolverExtensionManager resolverExtensionManager)
    • getRootElementFromConfigXml

      public static DOMElement getRootElementFromConfigXml(DOMNode document)
    • containsIgnoreCase

      public static boolean containsIgnoreCase(List<String> list, String elementName)
    • isLegacyProject

      public static boolean isLegacyProject(String path)
    • findDescriptionNode

      public static DOMNode findDescriptionNode(DOMDocument projectDOM)
    • findNaturesNode

      public static DOMNode findNaturesNode(DOMNode descriptionNode)
    • isFileExists

      public static boolean isFileExists(String filePath)
    • isFileInRegistry

      public static boolean isFileInRegistry(File file)
    • getRegistryKey

      public static String getRegistryKey(File file)
    • getResourceKey

      public static String getResourceKey(File file)
    • isZipFile

      public static boolean isZipFile(File file)
    • isXml

      public static boolean isXml(File file)
    • extractZip

      public static void extractZip(File zip, File extractTo) throws IOException
      Throws:
      IOException
    • newFile

      public static File newFile(File destinationDir, String zipName) throws IOException
      Throws:
      IOException
    • removeHyphen

      public static String removeHyphen(String name)
    • pluralToSingular

      public static String pluralToSingular(String name)
    • getChildNodeByName

      public static DOMNode getChildNodeByName(DOMNode node, String name)
    • addUnderscoreBetweenWords

      public static String addUnderscoreBetweenWords(String input)
    • getHash

      public static String getHash(String input)
    • getFirstElement

      public static DOMElement getFirstElement(DOMElement element)
    • getRootElement

      public static DOMElement getRootElement(DOMDocument document)
      Get the root element of the given document
      Parameters:
      document - the document
      Returns:
      the root element of the given document
    • readFile

      public static String readFile(File file) throws IOException
      Read the content of the given file
      Parameters:
      file - the file
      Returns:
      the content of the given file
      Throws:
      IOException - if an error occurs while reading the file
    • getJsonObject

      public static com.google.gson.JsonObject getJsonObject(String content)
      Get the JSON object from the given content
      Parameters:
      content - the content
      Returns:
      the JSON object from the given content
    • getJsonArray

      public static com.google.gson.JsonArray getJsonArray(String content)
      Get the JSON array from the given content
      Parameters:
      content - the content
      Returns:
      the JSON object from the given content
    • getJsonElement

      public static com.google.gson.JsonElement getJsonElement(String content)
      Get the JSON element from the given content
      Parameters:
      content - the content
      Returns:
      the JSON element from the given content
    • isJson

      public static boolean isJson(String content)
      Check whether the given content is a JSON
      Parameters:
      content -
      Returns:
    • getEnumFromValue

      public static <T extends Enum<T>> T getEnumFromValue(String value, Class<T> enumClass)
    • getFileExtension

      public static String getFileExtension(File file)
      Get the extension of the given file
      Parameters:
      file -
      Returns:
    • getFileName

      public static String getFileName(File file)
      Get the file name without the extension
      Parameters:
      file -
      Returns:
    • unescapeXml

      public static String unescapeXml(String text)
      Unescape the given XML text
      Parameters:
      text -
      Returns:
    • escapeXML

      public static String escapeXML(String text)
    • getAbsolutePath

      public static String getAbsolutePath(String path)
      Returns the absolute path of the given file by sanitizing the file path.
      Parameters:
      path - the file path
      Returns:
      the absolute path of the given file
    • isRegistryPropertiesFile

      public static boolean isRegistryPropertiesFile(File file)
    • getUISchemaMap

      public static Map<String,com.google.gson.JsonObject> getUISchemaMap(String resourceFolderName)
    • getMediatorList

      public static com.google.gson.JsonObject getMediatorList(String version, ConnectorHolder connectorHolder) throws IOException
      Throws:
      IOException
    • getAgentToolList

      public static com.google.gson.JsonObject getAgentToolList(com.google.gson.JsonObject mediatorList, ConnectorHolder connectorHolder)
      Constructs the AI agent tool list by adding supported mediators and connector operations.
      Parameters:
      mediatorList - list of all the mediators
      connectorHolder - connector holder
      Returns:
      the AI agent tool list
    • getServerVersion

      public static String getServerVersion(String projectPath, String defaultVersion)
    • getTemplateMap

      public static Map<String,com.github.mustachejava.Mustache> getTemplateMap(String resourceFolderName)
    • copyXSDFiles

      public static Path copyXSDFiles(String projectUri) throws IOException, URISyntaxException
      Throws:
      IOException
      URISyntaxException
    • extractJarFolder

      public static void extractJarFolder(String resourceFolder, Path targetDirectory) throws IOException, URISyntaxException
      Throws:
      IOException
      URISyntaxException
    • updateSynapseCatalogSettings

      public static Path updateSynapseCatalogSettings(org.eclipse.lsp4j.InitializeParams params) throws IOException, URISyntaxException
      Throws:
      IOException
      URISyntaxException
    • updateSynapseCatalogSettings

      public static com.google.gson.JsonElement updateSynapseCatalogSettings(com.google.gson.JsonObject settings, Path schemaPath) throws IOException, URISyntaxException
      Throws:
      IOException
      URISyntaxException
    • deriveResourceKeyFromFilePath

      public static String deriveResourceKeyFromFilePath(String filePath)
    • copyFolder

      public static void copyFolder(Path source, Path target, List<String> copiedFiles) throws IOException
      Copy the content of the source folder to the target folder
      Parameters:
      source - the source folder
      target - the target folder
      copiedFiles - the list of copied files
      Throws:
      IOException - if an error occurs while copying the content
    • deleteDirectory

      public static void deleteDirectory(Path path) throws IOException
      Delete the given directory
      Parameters:
      path - the directory path
      Throws:
      IOException - if an error occurs while deleting the directory
    • writeToFile

      public static void writeToFile(String path, String content) throws IOException
      Write the given content to the file
      Parameters:
      path - the file path
      content - the content
      Throws:
      IOException - if an error occurs while writing the content to the file
    • isJSONObject

      public static boolean isJSONObject(String content)
      Check whether the given content is a JSON object
      Parameters:
      content - the content
      Returns:
      whether the given content is a JSON object
    • toCamelCase

      public static String toCamelCase(String input)
      Convert the given string to camel case
      Parameters:
      input - the input string
      Returns:
      the camel case string
    • copyFile

      public static void copyFile(String sourcePath, String targetPath) throws IOException
      Copy the file from the source path to the target path
      Parameters:
      sourcePath -
      targetPath -
      Throws:
      IOException
    • copyFile

      public static void copyFile(String sourcePath, String targetPath, String targetFileName) throws IOException
      Copy the file from the source path to the target path with the given target file name
      Parameters:
      sourcePath -
      targetPath -
      targetFileName -
      Throws:
      IOException
    • isExpression

      public static boolean isExpression(String value)
    • copySelectedContent

      public static void copySelectedContent(Path sourceFolder, Path targetFolder, List<String> includePaths) throws IOException
      Copies selected folders and files from source to destination based on include paths.
      Parameters:
      sourceFolder - Source directory path
      includePaths - List of relative paths to include in the copy
      Throws:
      IOException - If an I/O error occurs
    • nodeToString

      public static String nodeToString(Node node)
      Transform the org.w3c.dom.Node to a string
      Parameters:
      node -
      Returns:
    • isOlderCARPlugin

      public static boolean isOlderCARPlugin(String projectPath)
      Check whether the given project is using an older version of CAR plugin
      Parameters:
      projectPath -
      Returns:
    • compareVersions

      public static int compareVersions(String version1, String version2)
      Compares two version strings and determines their relative order.
      Parameters:
      version1 - The first version string to compare.
      version2 - The second version string to compare.
      Returns:
      a negative integer if version1 is less than version2, a positive integer if version1 is greater than version2, or 0 if they are equal
    • sanitizeTag

      public static String sanitizeTag(String tag)
    • downloadConnector

      public static void downloadConnector(String groupId, String artifactId, String version, File targetDirectory, String fileType) throws IOException
      Throws:
      IOException
    • getDependencyFromLocalRepo

      public static File getDependencyFromLocalRepo(String groupId, String artifactId, String version, String type)
      Retrieves a dependency file from the local Maven repository.
      Parameters:
      groupId - the group ID of the dependency
      artifactId - the artifact ID of the dependency
      version - the version of the dependency
      type - the file type (e.g., jar, zip)
      Returns:
      the dependency file if it exists, otherwise null
    • isValidProject

      public static boolean isValidProject(String projectRoot)
    • removeCDATATag

      public static String removeCDATATag(String value)
      Remove CDATA tags from the given xml string.

      * Example: <![CDATA[<xml/>]]> will be converted to <xml/>

      Parameters:
      value - the xml string
      Returns:
      the xml string without CDATA tags
    • pdfToImage

      public static List<String> pdfToImage(String base64Pdf)
      Converts a Base64 encoded PDF string into a List of Base64 encoded PNG image strings.
      Parameters:
      base64Pdf - Content of the PDF in Base64.
      Returns:
      A List of strings, where each string is a Base64 encoded PNG image of a page, or an empty list if any error occurs.