예제 #1
0
  public static void renderJsResource(ImtWebContext imtWebContext) throws IOException {
    imtWebContext.setJavaScriptContentType();

    int pos = imtWebContext.getUrl().indexOf("/js");
    String path = imtWebContext.getUrl().substring(pos);

    InputStream is = null;
    BufferedReader in = null;
    try {
      is = ImtPageGen.class.getResourceAsStream(path);
      in = new BufferedReader(new InputStreamReader(is));

      String line = "";
      while ((line = in.readLine()) != null) {
        imtWebContext.render(line);
      }
    } finally {
      if (null != is) {
        try {
          is.close();
        } catch (IOException e) {
        }
      }
      if (null != in) {
        try {
          in.close();
        } catch (IOException e) {
        }
      }
    }
  }
예제 #2
0
  public static void renderCssResource(ImtWebContext context) throws IOException {
    context.setCssContentType();

    int pos = context.getUrl().indexOf("/css");
    String path = context.getUrl().substring(pos);
    context.put("url", context.getUrl().substring(0, pos));
    context.put("encoding", context.getEncoding());

    context.render(merge(context, path));
  }
예제 #3
0
  public static String merge(ImtWebContext context, String path) {
    try {
      VelocityEngine ve = new VelocityEngine();
      ve.setProperty("resource.loader", "imt");
      ve.setProperty("imt.resource.loader.class", ImtResourceLoader.class.getName());
      ve.setProperty("input.encoding", "UTF-8");
      ve.setProperty("output.encoding", context.getEncoding());

      ve.init();

      Template template = ve.getTemplate(path, context.getEncoding());

      StringWriter writer = new StringWriter();
      template.merge(context, writer);

      return writer.toString();
    } catch (Exception e) {
      throw new RuntimeException("渲染模版出错,", e);
    }
  }
예제 #4
0
  public static void renderImgResource(ImtWebContext imtWebContext) throws IOException {
    int pos = imtWebContext.getUrl().indexOf("/img");
    String path = imtWebContext.getUrl().substring(pos);

    InputStream is = null;
    try {
      is = ImtPageGen.class.getResourceAsStream(path);
      byte[] b = new byte[4000];
      is.read(b);

      imtWebContext.getResponse().getOutputStream().write(b);
    } finally {
      if (null != is) {
        try {
          is.close();
        } catch (IOException e) {
        }
      }
    }
  }
예제 #5
0
 public static void renderMethodInvoke(ImtWebContext imtWebContext) throws IOException {
   imtWebContext.setHtmlContentType();
   Object ret =
       imtWebContext
           .getInterfaceManagementTool()
           .invoke(
               imtWebContext.getKey(), imtWebContext.getAdditionalData(), imtWebContext.getArgs());
   imtWebContext.render(JSON.toJSONString(ret));
 }
예제 #6
0
 public static void renderPage(ImtWebContext imtWebContext) throws IOException {
   imtWebContext.setHtmlContentType();
   imtWebContext.render(merge(imtWebContext, "/vm/page.vm"));
 }
예제 #7
0
 public static boolean isImgResource(ImtWebContext imtWebContext) {
   return imtWebContext.getUrl().indexOf("/img") > 0;
 }
예제 #8
0
 public static boolean isCssResource(ImtWebContext imtWebContext) {
   return imtWebContext.getUrl().indexOf("/css") > 0;
 }
예제 #9
0
 public static boolean isMethodInvoke(ImtWebContext imtWebContext) {
   return null != imtWebContext.getKey();
 }
예제 #10
0
 public static boolean isContent(ImtWebContext imtWebContext) {
   return null != trimToNull(imtWebContext.getUuid());
 }
예제 #11
0
 public static boolean isInitPage(ImtWebContext imtWebContext) {
   return !isResource(imtWebContext)
       && !isContent(imtWebContext)
       && null == trimToNull(imtWebContext.getKey());
 }