コード例 #1
0
  public void testExport() throws Exception {
    String[] headers = {"数据", "字符", "日期", "日历", "是否", "null"};
    String[] properties = {"INT", "CHAR", "DATE", "CALENDAR", "BOOL", "NULL"};

    DolphinObject obj;
    List data = new ArrayList(10);
    for (int i = 1; i < 10; i++) {
      obj = new DolphinObject();
      data.add(obj);

      obj.setProperty(properties[0], i);
      obj.setProperty(properties[1], "你好" + i);
      obj.setProperty(properties[2], new Date());
      obj.setProperty(properties[3], new GregorianCalendar());
      obj.setProperty(properties[4], true);
      obj.setProperty(properties[5], null);
    }

    IConvertor converter = (IConvertor) PureFactory.getBean("SimpleConvertor");
    DolphinExportGoods goods = new DolphinExportGoods();
    goods.setName("你好");
    goods.setHeaders(headers);
    goods.setData(data, properties, converter);

    BufferedOutputStream bos = null;
    try {
      IExporter exporter = new ExcelExporterImpl();
      bos = new BufferedOutputStream(new FileOutputStream("export.xls"));
      exporter.export(bos, goods);
      System.out.println("Excel file created: " + new File("export.xls").getAbsolutePath());
    } finally {
      goods.clear();
      if (bos != null) bos.close();
    }
  }
コード例 #2
0
 public static String getRemindNoticeText() throws PureException {
   INoticeMgr mgr = (INoticeMgr) PureFactory.getBean("INoticeMgr");
   Notice notice = mgr.getNotice("project$all");
   if (notice == null) return "";
   NoticeItem item = notice.getItem("hurry");
   return item == null ? "" : item.getText();
 }
コード例 #3
0
 public static void setRemindNoticeText(String _sText) throws PureException {
   INoticeMgr mgr = (INoticeMgr) PureFactory.getBean("INoticeMgr");
   Notice notice = mgr.getNotice("project$all");
   if (notice == null) notice = new Notice("project$all");
   NoticeItem item = notice.getItem("hurry");
   if (item == null) {
     item = new NoticeItem("hurry");
     notice.getItems().put("hurry", item);
   }
   item.setText(_sText);
   mgr.updateNotce(notice);
   mgr.store();
 }
コード例 #4
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();
    }
  }