private Map<String, Map<String, ServiceBean>> buildServiceVersionHierarchy(
     ServiceBean[] serviceBeans) {
   Map<String, Map<String, ServiceBean>> hierarchy =
       new LinkedHashMap<String, Map<String, ServiceBean>>();
   if (serviceBeans == null) {
     return hierarchy;
   }
   for (ServiceBean serviceBean : serviceBeans) {
     if (serviceBean != null) {
       String path = RegistryUtils.getParentPath(serviceBean.getPath());
       String version = RegistryUtils.getResourceName(path);
       if (!version.replace("-SNAPSHOT", "").matches("^\\d+[.]\\d+[.]\\d+$")) {
         version = "SNAPSHOT";
         serviceBean.setPath(serviceBean.getPath());
       } else {
         serviceBean.setPath(RegistryUtils.getParentPath(path));
       }
       Map<String, ServiceBean> versionMap;
       if (hierarchy.containsKey(serviceBean.getQName())) {
         versionMap = hierarchy.get(serviceBean.getQName());
       } else {
         versionMap = new LinkedHashMap<String, ServiceBean>();
         hierarchy.put(serviceBean.getQName(), versionMap);
       }
       versionMap.put(version, serviceBean);
     }
   }
   return hierarchy;
 }
  public void put(RequestContext requestContext) throws RegistryException {
    WSDLProcessor wsdl = null;

    if (!CommonUtil.isUpdateLockAvailable()) {
      return;
    }
    CommonUtil.acquireUpdateLock();
    try {
      Registry registry = requestContext.getRegistry();
      Resource resource = requestContext.getResource();
      if (resource == null) {
        throw new RegistryException("The resource is not available.");
      }
      String originalServicePath = requestContext.getResourcePath().getPath();
      String resourceName = RegistryUtils.getResourceName(originalServicePath);

      OMElement serviceInfoElement, previousServiceInfoElement = null;
      Object resourceContent = resource.getContent();
      String serviceInfo;
      if (resourceContent instanceof String) {
        serviceInfo = (String) resourceContent;
      } else {
        serviceInfo = RegistryUtils.decodeBytes((byte[]) resourceContent);
      }
      try {
        XMLStreamReader reader =
            XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(serviceInfo));
        StAXOMBuilder builder = new StAXOMBuilder(reader);
        serviceInfoElement = builder.getDocumentElement();
      } catch (Exception e) {
        String msg =
            "Error in parsing the service content of the service. "
                + "The requested path to store the service: "
                + originalServicePath
                + ".";
        log.error(msg);
        throw new RegistryException(msg, e);
      }
      // derive the service path that the service should be saved.
      String serviceName = CommonUtil.getServiceName(serviceInfoElement);
      String serviceNamespace = CommonUtil.getServiceNamespace(serviceInfoElement);

      String servicePath = "";
      if (serviceInfoElement.getChildrenWithLocalName("newServicePath").hasNext()) {
        Iterator OmElementIterator = serviceInfoElement.getChildrenWithLocalName("newServicePath");

        while (OmElementIterator.hasNext()) {
          OMElement next = (OMElement) OmElementIterator.next();
          servicePath = next.getText();
          break;
        }
      } else {
        if (registry.resourceExists(originalServicePath)) {
          // Fixing REGISTRY-1790. Save the Service to the given original
          // service path if there is a service already exists there
          servicePath = originalServicePath;
        } else {
          servicePath =
              RegistryUtils.getAbsolutePath(
                  registry.getRegistryContext(),
                  registry.getRegistryContext().getServicePath()
                      + (serviceNamespace == null
                          ? ""
                          : CommonUtil.derivePathFragmentFromNamespace(serviceNamespace))
                      + serviceName);
        }
      }
      String serviceVersion =
          org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion(serviceInfoElement);

      if (serviceVersion.length() == 0) {
        serviceVersion = defaultServiceVersion;
        CommonUtil.setServiceVersion(serviceInfoElement, serviceVersion);
        resource.setContent(serviceInfoElement.toString());
      }
      // saving the artifact id.
      String serviceId = resource.getUUID();
      if (serviceId == null) {
        // generate a service id
        serviceId = UUID.randomUUID().toString();
        resource.setUUID(serviceId);
      }

      if (registry.resourceExists(servicePath)) {
        Resource oldResource = registry.get(servicePath);
        String oldContent;
        Object content = oldResource.getContent();
        if (content instanceof String) {
          oldContent = (String) content;
        } else {
          oldContent = RegistryUtils.decodeBytes((byte[]) content);
        }
        OMElement oldServiceInfoElement = null;
        if (serviceInfo.equals(oldContent)) {
          // TODO: This needs a better solution. This fix was put in place to avoid
          // duplication of services under /_system/governance, when no changes were made.
          // However, the fix is not perfect and needs to be rethought. Perhaps the logic
          // below can be reshaped a bit, or may be we don't need to compare the
          // difference over here with a little fix to the Governance API end. - Janaka.

          // We have fixed this assuming that the temp path where services are stored is under
          // /_system/governance/[serviceName]
          // Hence if we are to change that location, then we need to change the following code
          // segment as well
          String tempPath =
              RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH
                  + RegistryConstants.PATH_SEPARATOR
                  + resourceName;

          if (!originalServicePath.equals(tempPath)) {
            String path =
                RegistryUtils.getRelativePathToOriginal(
                    servicePath, RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH);
            ArtifactManager.getArtifactManager().getTenantArtifactRepository().addArtifact(path);
            return;
          }
          requestContext.setProcessingComplete(true);
          return;
        }
        if ("true".equals(resource.getProperty("registry.DefinitionImport"))) {
          resource.removeProperty("registry.DefinitionImport");
          try {
            XMLStreamReader reader =
                XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(oldContent));
            StAXOMBuilder builder = new StAXOMBuilder(reader);
            oldServiceInfoElement = builder.getDocumentElement();
            CommonUtil.setServiceName(
                oldServiceInfoElement, CommonUtil.getServiceName(serviceInfoElement));
            CommonUtil.setServiceNamespace(
                oldServiceInfoElement, CommonUtil.getServiceNamespace(serviceInfoElement));
            CommonUtil.setDefinitionURL(
                oldServiceInfoElement, CommonUtil.getDefinitionURL(serviceInfoElement));
            CommonUtil.setEndpointEntries(
                oldServiceInfoElement, CommonUtil.getEndpointEntries(serviceInfoElement));
            CommonUtil.setServiceVersion(
                oldServiceInfoElement,
                org.wso2.carbon.registry.common.utils.CommonUtil.getServiceVersion(
                    serviceInfoElement));
            serviceInfoElement = oldServiceInfoElement;
            resource.setContent(serviceInfoElement.toString());
            resource.setDescription(oldResource.getDescription());
          } catch (Exception e) {
            String msg =
                "Error in parsing the service content of the service. "
                    + "The requested path to store the service: "
                    + originalServicePath
                    + ".";
            log.error(msg);
            throw new RegistryException(msg, e);
          }
        }

        try {
          previousServiceInfoElement = AXIOMUtil.stringToOM(oldContent);
        } catch (XMLStreamException e) {
          String msg =
              "Error in parsing the service content of the service. "
                  + "The requested path to store the service: "
                  + originalServicePath
                  + ".";
          log.error(msg);
          throw new RegistryException(msg, e);
        }
      } else if ("true".equals(resource.getProperty("registry.DefinitionImport"))) {
        resource.removeProperty("registry.DefinitionImport");
      }
      //            CommonUtil.addGovernanceArtifactEntryWithAbsoluteValues(
      //                    CommonUtil.getUnchrootedSystemRegistry(requestContext),
      //                    serviceId, servicePath);

      String definitionURL = CommonUtil.getDefinitionURL(serviceInfoElement);
      if (previousServiceInfoElement != null) {
        String oldDefinition = CommonUtil.getDefinitionURL(previousServiceInfoElement);
        if ((!"".equals(oldDefinition) && "".equals(definitionURL))
            || (!"".endsWith(oldDefinition) && !oldDefinition.equals(definitionURL))) {
          try {
            registry.removeAssociation(servicePath, oldDefinition, CommonConstants.DEPENDS);
            registry.removeAssociation(oldDefinition, servicePath, CommonConstants.USED_BY);
            EndpointUtils.removeEndpointEntry(oldDefinition, serviceInfoElement, registry);
            resource.setContent(
                RegistryUtils.decodeBytes((serviceInfoElement.toString()).getBytes()));
          } catch (RegistryException e) {
            throw new RegistryException(
                "Failed to remove endpoints from Service UI : " + serviceName, e);
          }
        }
      }

      boolean alreadyAdded = false;
      if (definitionURL != null
          && (definitionURL.startsWith("http://") || definitionURL.startsWith("https://"))) {
        String definitionPath;
        if (definitionURL.toLowerCase().endsWith("wsdl")) {
          wsdl = buildWSDLProcessor(requestContext);
          RequestContext context =
              new RequestContext(
                  registry, requestContext.getRepository(), requestContext.getVersionRepository());
          context.setResourcePath(
              new ResourcePath(RegistryConstants.PATH_SEPARATOR + serviceName + ".wsdl"));
          context.setSourceURL(definitionURL);
          context.setResource(new ResourceImpl());
          definitionPath =
              wsdl.addWSDLToRegistry(
                  context,
                  definitionURL,
                  null,
                  false,
                  false,
                  disableWSDLValidation,
                  disableSymlinkCreation);

        } else if (definitionURL.toLowerCase().endsWith("wadl")) {
          WADLProcessor wadlProcessor = buildWADLProcessor(requestContext);
          wadlProcessor.setCreateService(false);
          RequestContext context =
              new RequestContext(
                  registry, requestContext.getRepository(), requestContext.getVersionRepository());
          context.setResourcePath(
              new ResourcePath(RegistryConstants.PATH_SEPARATOR + serviceName + ".wadl"));
          context.setSourceURL(definitionURL);
          context.setResource(new ResourceImpl());
          definitionPath = wadlProcessor.importWADLToRegistry(context, null, disableWADLValidation);
        } else {
          throw new RegistryException(
              "Invalid service definition found. " + "Please enter a valid WSDL/WADL URL");
        }

        if (definitionPath == null) {
          return;
        }
        definitionURL =
            RegistryUtils.getRelativePath(requestContext.getRegistryContext(), definitionPath);
        CommonUtil.setDefinitionURL(serviceInfoElement, definitionURL);
        resource.setContent(RegistryUtils.decodeBytes((serviceInfoElement.toString()).getBytes()));
        // updating the wsdl/wadl url
        ((ResourceImpl) resource).prepareContentForPut();
        persistServiceResource(registry, resource, servicePath);
        alreadyAdded = true;
        // and make the associations
        registry.addAssociation(servicePath, definitionPath, CommonConstants.DEPENDS);
        registry.addAssociation(definitionPath, servicePath, CommonConstants.USED_BY);

      } else if (definitionURL != null && definitionURL.startsWith(RegistryConstants.ROOT_PATH)) {
        // it seems definitionUrl is a registry path..
        String definitionPath =
            RegistryUtils.getAbsolutePath(requestContext.getRegistryContext(), definitionURL);
        if (!definitionPath.startsWith(
            RegistryUtils.getAbsolutePath(
                requestContext.getRegistryContext(),
                RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH))) {

          definitionPath = RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + definitionPath;
        }
        boolean addItHere = false;
        if (!registry.resourceExists(definitionPath)) {
          String msg =
              "Associating service to a non-existing WSDL. wsdl url: "
                  + definitionPath
                  + ", "
                  + "service path: "
                  + servicePath
                  + ".";
          log.error(msg);
          throw new RegistryException(msg);
        }
        if (!registry.resourceExists(servicePath)) {
          addItHere = true;
        } else {
          Association[] dependencies =
              registry.getAssociations(servicePath, CommonConstants.DEPENDS);
          boolean dependencyFound = false;
          if (dependencies != null) {
            for (Association dependency : dependencies) {
              if (definitionPath.equals(dependency.getDestinationPath())) {
                dependencyFound = true;
              }
            }
          }
          if (!dependencyFound) {
            addItHere = true;
          }
        }
        if (addItHere) { // add the service right here..
          ((ResourceImpl) resource).prepareContentForPut();
          persistServiceResource(registry, resource, servicePath);
          alreadyAdded = true;
          // and make the associations

          registry.addAssociation(servicePath, definitionPath, CommonConstants.DEPENDS);
          registry.addAssociation(definitionPath, servicePath, CommonConstants.USED_BY);
        }
      }

      if (!alreadyAdded) {
        // we are adding the resource anyway.
        ((ResourceImpl) resource).prepareContentForPut();
        persistServiceResource(registry, resource, servicePath);
      }

      /*
                  if (!servicePath.contains(registry.getRegistryContext().getServicePath())) {
                      if (defaultEnvironment == null) {
                          String serviceDefaultEnvironment = registry.getRegistryContext().getServicePath();
                          String relativePath = serviceDefaultEnvironment.replace(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH, "");
                          relativePath = relativePath.replace(CommonUtil.derivePathFragmentFromNamespace(serviceNamespace),"");
                          defaultEnvironment = relativePath;
                      }

                      String currentRelativePath = servicePath.substring(0, servicePath.indexOf(CommonUtil.derivePathFragmentFromNamespace(serviceNamespace)));
                      currentRelativePath = currentRelativePath.replace(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH,"");

                      String endpointEnv = EndpointUtils.getEndpointLocation();

                      String[] pathSegments = defaultEnvironment.split(RegistryConstants.PATH_SEPARATOR);

                      for (String pathSegment : pathSegments) {
                          endpointEnv = endpointEnv.replace(pathSegment,"");
                          currentRelativePath = currentRelativePath.replace(pathSegment,"");
                      }

                      while(endpointEnv.startsWith(RegistryConstants.PATH_SEPARATOR)){
                          endpointEnv = endpointEnv.replaceFirst(RegistryConstants.PATH_SEPARATOR,"");
                      }

                      environment = currentRelativePath + endpointEnv;
                  }
      */

      EndpointUtils.saveEndpointsFromServices(
          servicePath,
          serviceInfoElement,
          registry,
          CommonUtil.getUnchrootedSystemRegistry(requestContext));

      String symlinkLocation =
          RegistryUtils.getAbsolutePath(
              requestContext.getRegistryContext(),
              requestContext.getResource().getProperty(RegistryConstants.SYMLINK_PROPERTY_NAME));
      if (!servicePath.equals(originalServicePath)) {
        // we are creating a sym link from service path to original service path.
        Resource serviceResource =
            requestContext.getRegistry().get(RegistryUtils.getParentPath(originalServicePath));
        String isLink = serviceResource.getProperty("registry.link");
        String mountPoint = serviceResource.getProperty("registry.mountpoint");
        String targetPoint = serviceResource.getProperty("registry.targetpoint");
        String actualPath = serviceResource.getProperty("registry.actualpath");
        if (isLink != null && mountPoint != null && targetPoint != null) {
          symlinkLocation = actualPath + RegistryConstants.PATH_SEPARATOR;
        }
        if (symlinkLocation != null) {
          requestContext
              .getSystemRegistry()
              .createLink(symlinkLocation + resourceName, servicePath);
        }
      }
      // in this flow the resource is already added. marking the process completed..
      requestContext.setProcessingComplete(true);

      if (wsdl != null
          && CommonConstants.ENABLE.equals(
              System.getProperty(CommonConstants.UDDI_SYSTEM_PROPERTY))) {
        AuthToken authToken = UDDIUtil.getPublisherAuthToken();
        if (authToken == null) {
          return;
        }

        // creating the business service info bean
        BusinessServiceInfo businessServiceInfo = new BusinessServiceInfo();
        // Following lines removed  for fixing REGISTRY-1898.
        //              businessServiceInfo.setServiceName(serviceName.trim());
        //              businessServiceInfo.setServiceNamespace(serviceNamespace.trim());
        //
        // businessServiceInfo.setServiceEndpoints(CommonUtil.getEndpointEntries(serviceInfoElement));
        //
        // businessServiceInfo.setDocuments(CommonUtil.getDocLinks(serviceInfoElement));

        businessServiceInfo.setServiceDescription(
            CommonUtil.getServiceDescription(serviceInfoElement));
        WSDLInfo wsdlInfo = wsdl.getMasterWSDLInfo();
        businessServiceInfo.setServiceWSDLInfo(wsdlInfo);
        UDDIPublisher publisher = new UDDIPublisher();
        publisher.publishBusinessService(authToken, businessServiceInfo);
      }

      String path =
          RegistryUtils.getRelativePathToOriginal(
              servicePath, RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH);
      ArtifactManager.getArtifactManager().getTenantArtifactRepository().addArtifact(path);
    } finally {
      CommonUtil.releaseUpdateLock();
    }
  }
 public static String decorateVersionElement(
     String version,
     String basicVersionElement,
     String path,
     String type,
     String append,
     String screenWidth,
     ServletConfig config,
     HttpSession session,
     HttpServletRequest request) {
   String hrefPrefix = "../resources/resource.jsp?region=region3&item=resource_browser_menu&path=";
   String hrefPostfix = (screenWidth != null) ? "&screenWidth=" + screenWidth : "";
   String patchPath = RegistryUtils.getParentPath(path);
   String minorPath = RegistryUtils.getParentPath(patchPath);
   String majorPath = RegistryUtils.getParentPath(minorPath);
   String servicePath = RegistryUtils.getParentPath(majorPath);
   String versions[] = version.split("[.]");
   StringBuffer sb = new StringBuffer("$1type=\"hidden\"$2");
   if (type.equals("collection")) {
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(majorPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[0])
         .append("</a>");
     sb.append(".");
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(minorPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[1])
         .append("</a>");
     sb.append(".");
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(patchPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[2])
         .append("</a>");
     sb.append(append);
   } else if (type.equals("patch")) {
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(majorPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[0])
         .append("</a>");
     sb.append(".");
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(minorPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[1])
         .append("</a>");
     sb.append(".");
     sb.append("<a href=\"javascript:void(0)\">").append(versions[2]).append("</a>");
     sb.append(append);
     try {
       int[] adjacentVersions =
           getAdjacentVersions(config, session, minorPath, Integer.parseInt(versions[2]));
       sb.append("&nbsp;");
       if (adjacentVersions[0] > -1) {
         sb.append("<a class=\"icon-link\" style=\"background-image: ")
             .append("url(../resources/images/arrow-up.gif);float:none !important;")
             .append("margin-bottom:0px !important;margin-top:0px !important;")
             .append("margin-left:0px !important\" href=\"")
             .append(hrefPrefix)
             .append(minorPath.replaceAll("&", "%26"))
             .append(hrefPostfix)
             .append("/")
             .append(adjacentVersions[0])
             .append("\" title=\"")
             .append(
                 CarbonUIUtil.geti18nString(
                     "previous.version",
                     "org.wso2.carbon.governance.generic.ui.i18n.Resources",
                     request.getLocale()))
             .append(": ")
             .append(versions[0])
             .append(".")
             .append(versions[1])
             .append(".")
             .append(adjacentVersions[0])
             .append("\"/>");
       }
       if (adjacentVersions[1] > -1) {
         sb.append("<a class=\"icon-link\" style=\"background-image: ")
             .append("url(../resources/images/arrow-right.gif);float:none !important;")
             .append("margin-bottom:0px !important;margin-top:0px !important;")
             .append("margin-left:0px !important\" href=\"")
             .append(hrefPrefix)
             .append(minorPath.replaceAll("&", "%26"))
             .append(hrefPostfix)
             .append("/")
             .append(adjacentVersions[1])
             .append("\" title=\"")
             .append(
                 CarbonUIUtil.geti18nString(
                     "next.version",
                     "org.wso2.carbon.governance.generic.ui.i18n.Resources",
                     request.getLocale()))
             .append(": ")
             .append(versions[0])
             .append(".")
             .append(versions[1])
             .append(".")
             .append(adjacentVersions[1])
             .append("\"/>");
       }
     } catch (Exception ignore) {
     }
   } else if (type.equals("minor")) {
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(majorPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[0])
         .append("</a>");
     sb.append(".");
     sb.append("<a href=\"javascript:void(0)\">").append(versions[1]).append("</a>");
     sb.append(".");
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(patchPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[2])
         .append("</a>");
     sb.append(append);
     try {
       int[] adjacentVersions =
           getAdjacentVersions(config, session, majorPath, Integer.parseInt(versions[1]));
       sb.append("&nbsp;");
       if (adjacentVersions[0] > -1) {
         String latestPatch =
             getGreatestChildVersion(config, session, majorPath + "/" + adjacentVersions[0]);
         sb.append("<a class=\"icon-link\" style=\"background-image: ")
             .append("url(../resources/images/arrow-up.gif);float:none !important;")
             .append("margin-bottom:0px !important;margin-top:0px !important;")
             .append("margin-left:0px !important\" href=\"")
             .append(hrefPrefix)
             .append(majorPath.replaceAll("&", "%26"))
             .append(hrefPostfix)
             .append("/")
             .append(adjacentVersions[0])
             .append("\" title=\"")
             .append(
                 CarbonUIUtil.geti18nString(
                     "previous.version",
                     "org.wso2.carbon.governance.generic.ui.i18n.Resources",
                     request.getLocale()))
             .append(": ")
             .append(versions[0])
             .append(".")
             .append(adjacentVersions[0])
             .append(".")
             .append(latestPatch)
             .append("\"/>");
       }
       if (adjacentVersions[1] > -1) {
         String latestPatch =
             getGreatestChildVersion(config, session, majorPath + "/" + adjacentVersions[1]);
         sb.append("<a class=\"icon-link\" style=\"background-image: ")
             .append("url(../resources/images/arrow-right.gif);float:none !important;")
             .append("margin-bottom:0px !important;margin-top:0px !important;")
             .append("margin-left:0px !important\" href=\"")
             .append(hrefPrefix)
             .append(majorPath.replaceAll("&", "%26"))
             .append(hrefPostfix)
             .append("/")
             .append(adjacentVersions[1])
             .append("\" title=\"")
             .append(
                 CarbonUIUtil.geti18nString(
                     "next.version",
                     "org.wso2.carbon.governance.generic.ui.i18n.Resources",
                     request.getLocale()))
             .append(": ")
             .append(versions[0])
             .append(".")
             .append(adjacentVersions[1])
             .append(".")
             .append(latestPatch)
             .append("\"/>");
       }
     } catch (Exception ignore) {
     }
   } else if (type.equals("major")) {
     sb.append("<a href=\"javascript:void(0)\">").append(versions[0]).append("</a>");
     sb.append(".");
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(minorPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[1])
         .append("</a>");
     sb.append(".");
     sb.append("<a href=\"")
         .append(hrefPrefix)
         .append(patchPath.replaceAll("&", "%26"))
         .append(hrefPostfix)
         .append("\">")
         .append(versions[2])
         .append("</a>");
     sb.append(append);
     try {
       int[] adjacentVersions =
           getAdjacentVersions(config, session, servicePath, Integer.parseInt(versions[0]));
       sb.append("&nbsp;");
       if (adjacentVersions[0] > -1) {
         String latestMinor =
             getGreatestChildVersion(config, session, servicePath + "/" + adjacentVersions[0]);
         String latestPatch =
             getGreatestChildVersion(
                 config, session, servicePath + "/" + adjacentVersions[0] + "/" + latestMinor);
         sb.append("<a class=\"icon-link\" style=\"background-image: ")
             .append("url(../resources/images/arrow-up.gif);float:none !important;")
             .append("margin-bottom:0px !important;margin-top:0px !important;")
             .append("margin-left:0px !important\" href=\"")
             .append(hrefPrefix)
             .append(servicePath.replaceAll("&", "%26"))
             .append(hrefPostfix)
             .append("/")
             .append(adjacentVersions[0])
             .append("\" title=\"")
             .append(
                 CarbonUIUtil.geti18nString(
                     "previous.version",
                     "org.wso2.carbon.governance.generic.ui.i18n.Resources",
                     request.getLocale()))
             .append(": ")
             .append(adjacentVersions[0])
             .append(".")
             .append(latestMinor)
             .append(".")
             .append(latestPatch)
             .append("\"/>");
       }
       if (adjacentVersions[1] > -1) {
         String latestMinor =
             getGreatestChildVersion(config, session, servicePath + "/" + adjacentVersions[1]);
         String latestPatch =
             getGreatestChildVersion(
                 config, session, servicePath + "/" + adjacentVersions[1] + "/" + latestMinor);
         sb.append("<a class=\"icon-link\" style=\"background-image: ")
             .append("url(../resources/images/arrow-right.gif);float:none !important;")
             .append("margin-bottom:0px !important;margin-top:0px !important;")
             .append("margin-left:0px !important\" href=\"")
             .append(hrefPrefix)
             .append(servicePath.replaceAll("&", "%26"))
             .append(hrefPostfix)
             .append("/")
             .append(adjacentVersions[1])
             .append("\" title=\"")
             .append(
                 CarbonUIUtil.geti18nString(
                     "next.version",
                     "org.wso2.carbon.governance.generic.ui.i18n.Resources",
                     request.getLocale()))
             .append(": ")
             .append(adjacentVersions[1])
             .append(".")
             .append(latestMinor)
             .append(".")
             .append(latestPatch)
             .append("\"/>");
       }
     } catch (Exception ignore) {
     }
   }
   return basicVersionElement.replaceAll(
       "(<input[^>]*)type=\"text\"([^>]*id=\"id_Overview_Version\"[^>]*>)", sb.toString());
 }