private boolean mediate(MessageContext synCtx, String format) {
   if (!isDoingXml(synCtx) && !isDoingJson(synCtx)) {
     log.error(
         "#mediate. Could not identify the payload format of the existing payload prior to mediate.");
     return false;
   }
   org.apache.axis2.context.MessageContext axis2MessageContext =
       ((Axis2MessageContext) synCtx).getAxis2MessageContext();
   StringBuffer result = new StringBuffer();
   StringBuffer resultCTX = new StringBuffer();
   regexTransformCTX(resultCTX, synCtx, format);
   replace(resultCTX.toString(), result, synCtx);
   String out = result.toString().trim();
   if (log.isDebugEnabled()) {
     log.debug("#mediate. Transformed payload format>>> " + out);
   }
   if (mediaType.equals(XML_TYPE)) {
     try {
       JsonUtil.removeJsonPayload(axis2MessageContext);
       OMElement omXML = AXIOMUtil.stringToOM(out);
       if (!checkAndReplaceEnvelope(
           omXML,
           synCtx)) { // check if the target of the PF 'format' is the entire SOAP envelop, not
                      // just the body.
         axis2MessageContext.getEnvelope().getBody().addChild(omXML.getFirstElement());
       }
     } catch (XMLStreamException e) {
       handleException("Error creating SOAP Envelope from source " + out, synCtx);
     }
   } else if (mediaType.equals(JSON_TYPE)) {
     JsonUtil.newJsonPayload(axis2MessageContext, out, true, true);
   } else if (mediaType.equals(TEXT_TYPE)) {
     JsonUtil.removeJsonPayload(axis2MessageContext);
     axis2MessageContext.getEnvelope().getBody().addChild(getTextElement(out));
   }
   // need to honour a content-type of the payload media-type as output from the payload
   // {re-merging patch https://wso2.org/jira/browse/ESBJAVA-3014}
   setContentType(synCtx);
   return true;
 }
예제 #2
0
 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());
 }