コード例 #1
0
  public void testParent() throws Exception {
    String sText = "${#ifNull(@p:name, \"why\", @p:name)}";
    ScriptBlock script = ScriptReader.readBlock(sText);

    SimpleContext parent = new SimpleContext();
    parent.setVariable("p:name", "daniel");

    SimpleContext context = new SimpleContext(parent);
    String sResult = Executer.execute(script, context);
    assertEquals("daniel", sResult);
  }
コード例 #2
0
  public void testSimpleContext() throws PureException {
    String sText = "${#ifNull(@p:name, \"why\", @p:name)}";
    ScriptBlock script = ScriptReader.readBlock(sText);

    SimpleContext context = new SimpleContext();
    context.setVariable("p:name", null);

    String sResult = Executer.execute(script, context);
    assertEquals(sResult, "why");

    context.setVariable("p:name", "daniel");
    sResult = Executer.execute(script, context);
    assertEquals(sResult, "daniel");
  }
コード例 #3
0
  /** Exports object list. */
  protected ActionForward doExport() throws PureException {
    SearchForm thisform = (SearchForm) form;
    IObjects exObjs = null;
    try {
      // 1. to fetch the objects collection
      if (thisform.getExportMode() == SearchForm.EX_MODE_SELECTED
          && thisform.getExportIds() != null) {
        Class entityClass = thisform.getEntityMetadata().getEntityClass();
        IContentMgr mgr = ArkContentHelper.getContentMgrOf(entityClass);
        if (!isFromTemp()) {
          exObjs = mgr.lookupByIds(thisform.getExportIds());
        } else {
          String strSQL =
              "SELECT * FROM "
                  + thisform.getEntityMetadata().getTempTable()
                  + " WHERE {this.id} IN ("
                  + thisform.getExportIds()
                  + ")";
          ISession session = LocalContextHelper.currentSession();
          IStatement query = session.createQuery(strSQL, entityClass, 0);
          try {
            exObjs = query.executeQuery();
          } finally {
            query.clear();
          }
        }
      } else {
        exObjs = getIObjects();
      }

      // 2. to prepare the columns
      ListHelper lh = new ListHelper();
      lh.setSenery(getScenery());
      List baseCols = thisform.getColunms();
      String sClassName = exObjs.getElementClass().getName();
      if (baseCols == null || baseCols.size() < 1) {
        baseCols = lh.prepareBase(exObjs.getElementClass().getName());
      }

      lh.setSenery(getExportSenery());
      lh.setAct("content");

      List colInfos =
          lh.prepareColsInfo(baseCols, getInclude(), getExclude(), null, sClassName, false);
      String[] headers = new String[colInfos.size()];
      String[] properties = new String[colInfos.size()];
      SceneryContext sceneryContext = null;
      try {
        boolean bUsePropertyName = (thisform.getExportType() == ExportHelper.TYPE_XML);
        String sHeader;
        for (int i = 0; i < colInfos.size(); i++) {
          ColumnInfo colInfo = (ColumnInfo) colInfos.get(i);
          if (bUsePropertyName) {
            sHeader = colInfo.getOldName();
          } else {
            sHeader = colInfo.getTitle();
            if (sHeader.indexOf('$') >= 0) {
              if (sceneryContext == null) {
                IDVContextFactory factory =
                    (IDVContextFactory) PureFactory.getBean("IDVContextFactory");
                DolphinObject obj = (DolphinObject) exObjs.getElementClass().newInstance();
                sceneryContext =
                    factory.createSceneryContext(obj, getExportSenery(), "plain.default");
              }
              sHeader = Executer.execute(ScriptReader.readBlock(sHeader), sceneryContext);
            }
          }
          headers[i] = sHeader.replaceAll("[\\\\\\[\\]\\?/<>]+", "_");
          properties[i] = colInfo.getName();
        }
      } catch (Exception ex) {
        throw new PureException(ArkExceptionTypes.EXPORT_CONTENTS, "failed to get the headers", ex);
      } finally {
        if (sceneryContext != null) {
          sceneryContext.clear();
        }
        colInfos.clear();
      }

      // 3. to prepare the data
      IConvertor convertor = new ExportConvertor(getExportSenery(), "content");
      DolphinExportGoods goods = new DolphinExportGoods();
      goods.setType(thisform.getExportType());
      goods.setName(getTitle());
      goods.setHeaders(headers);
      goods.setData(exObjs, properties, convertor);

      // 4. to return
      request.setAttribute("export", goods);
      return mapping.findForward("guest-export");
    } finally {
      LocalContextHelper.closeSession();
    }
  }