Ejemplo n.º 1
0
  private void init(BuildSession session, ViewContext view_context) throws Exception {
    CompositeMap context = ServiceThreadLocal.getCurrentThreadContext();
    if (context == null)
      throw new IllegalStateException("No service context set in ThreadLocal yet");
    CompositeMap view = view_context.getView();
    CompositeMap base_model = view_context.getModel();
    HTMLIncludeConfig hic = HTMLIncludeConfig.getInstance(view);
    String path = TextParser.parse(hic.getPath(), base_model);
    version = TextParser.parse(hic.getVersion(), base_model);
    if (null != path && !path.isEmpty()) {
      int begin = path.indexOf("/release");
      if (begin < 0) return;
      path = path.substring(begin, path.length());
      articlePath = "../.." + path;
      sourcePath =
          session.getContextPath() + path.replaceAll("\\\\", "/").replaceAll("(.*/)[^/]*$", "$1");
      return;
    }
    String pathField = hic.getPathField();
    String model = hic.getModel();
    CompositeMap params = hic.getParams();
    Map map = new HashMap();
    if (null != params) {
      Iterator pit = params.getChildIterator();
      while (pit.hasNext()) {
        CompositeMap param = (CompositeMap) pit.next();
        map.put(
            param.get("name"),
            TextParser.parse((String) param.get("value"), view_context.getModel()));
      }
    }
    BusinessModelService service = factory.getModelService(model, context);

    CompositeMap resultMap = service.queryAsMap(map);
    if (null == resultMap || null == resultMap.getChilds()) {
      throw new ClassNotFoundException("文章未找到,输入的路径不正确。");
    }
    Iterator it = resultMap.getChildIterator();
    while (it.hasNext()) {
      path = ((CompositeMap) it.next()).getString(pathField);
      if (null != path) {
        articlePath = "../.." + path;
        sourcePath =
            session.getContextPath() + path.replaceAll("\\\\", "/").replaceAll("(.*/)[^/]*$", "$1");
        break;
      }
    }
  }
Ejemplo n.º 2
0
 public void buildView(BuildSession session, ViewContext view_context)
     throws IOException, ViewCreationException {
   Writer out = session.getWriter();
   try {
     init(session, view_context);
     if (null == articlePath) return;
     String source = getArticalSource(articlePath);
     if (null != source && !"".equals(source)) out.write(source);
   } catch (ClassNotFoundException e) {
     out.write(e.getMessage());
   } catch (Exception e) {
     throw new ViewCreationException(e);
   }
 }