示例#1
0
 protected String resolveXMLResourceURI(String path) {
   MessageContext mc = getContext();
   if (mc != null) {
     String httpBasePath = (String) mc.get("http.base.path");
     UriBuilder builder = null;
     if (httpBasePath != null) {
       builder = UriBuilder.fromPath(httpBasePath);
     } else {
       builder = mc.getUriInfo().getBaseUriBuilder();
     }
     return builder.path(path).path(xmlResourceOffset).build().toString();
   } else {
     return path;
   }
 }
  protected Templates createTemplates(
      Templates templates, Map<String, Object> configuredParams, Map<String, String> outProps) {
    if (templates == null) {
      if (supportJaxbOnly) {
        return null;
      } else {
        LOG.severe("No template is available");
        throw ExceptionUtils.toInternalServerErrorException(null, null);
      }
    }

    TemplatesImpl templ = new TemplatesImpl(templates, uriResolver);
    MessageContext mc = getContext();
    if (mc != null) {
      UriInfo ui = mc.getUriInfo();
      MultivaluedMap<String, String> params = ui.getPathParameters();
      for (Map.Entry<String, List<String>> entry : params.entrySet()) {
        String value = entry.getValue().get(0);
        int ind = value.indexOf(";");
        if (ind > 0) {
          value = value.substring(0, ind);
        }
        templ.setTransformerParameter(entry.getKey(), value);
      }

      List<PathSegment> segments = ui.getPathSegments();
      if (segments.size() > 0) {
        setTransformParameters(templ, segments.get(segments.size() - 1).getMatrixParameters());
      }
      setTransformParameters(templ, ui.getQueryParameters());
      templ.setTransformerParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
      templ.setTransformerParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
      templ.setTransformerParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
      if (configuredParams != null) {
        for (Map.Entry<String, Object> entry : configuredParams.entrySet()) {
          templ.setTransformerParameter(entry.getKey(), entry.getValue());
        }
      }
    }
    if (outProps != null) {
      templ.setOutProperties(outProps);
    }

    return templ;
  }