Business Objects Java

时间:2014-01-14 19:00:46

标签: java business-objects-sdk

我需要帮助提取Business Objects中文件夹中的所有文件名。使用我现在的代码,我可以获得文件夹中单个文件的名称。我想获取该文件夹中的所有文件名。变量temp是我输入所需文件名的位置。变量doc是检索文件名的位置,变量reportname是我存储doc以写入外部电子表格的位置。

public class variable {

    private static String expressionEx;
    private static String nameEx;
    private static String nameXE[] = new String[11];
    private static String expressionXE[] = new String[11];
    private static String query;
    public static String reportName;
    private static String reportPath;



    /** This method writes data to new excel file * */
    public static void writeDataToExcelFile(String fileName) {
        String[][] excelData = preapreDataToWriteToExcel();// Creates first
                                                            // sheet in Excel
        String[][] excelData1 = preapreDataToWriteToExcel1();// Creates
                                                                // second
                                                                // sheet in
                                                                // Excel
        String[][] excelData2 = preapreDataToWriteToExcel2();// Creates third
                                                                // sheet in
                                                                // Excel
        HSSFWorkbook myReports = new HSSFWorkbook();

        HSSFSheet mySheet = myReports.createSheet("Variables");
        HSSFSheet mySheet1 = myReports.createSheet("SQL Statement");
        HSSFSheet mySheet2 = myReports.createSheet("File Info");
        // edits first sheet
        mySheet.setFitToPage(true);
        mySheet.setHorizontallyCenter(true);
        mySheet.setColumnWidth(0, 800 * 6);
        mySheet.setColumnWidth(1, 7000 * 6);
        // edits second sheet
        mySheet1.setFitToPage(true);
        mySheet1.setHorizontallyCenter(true);
        mySheet1.setColumnWidth(0, 800 * 6);
        mySheet1.setColumnWidth(1, 7000 * 6);
        // edits third sheet
        mySheet2.setFitToPage(true);
        mySheet2.setHorizontallyCenter(true);
        mySheet2.setColumnWidth(0, 800 * 6);
        mySheet2.setColumnWidth(1, 2000 * 6);

        HSSFRow myRow = null;
        HSSFCell myCell = null;
        // first sheet
        for (int rowNum = 0; rowNum < excelData[0].length; rowNum++) {
            myRow = mySheet.createRow(rowNum);
            for (int cellNum = 0; cellNum < 4; cellNum++) {
                myCell = myRow.createCell(cellNum);
                myCell.setCellValue(excelData[rowNum][cellNum]);
            }
        }
        try {
            FileOutputStream out = new FileOutputStream(fileName);
            myReports.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // second sheet
        for (int rowNum = 0; rowNum < excelData1[0].length; rowNum++) {
            myRow = mySheet1.createRow(rowNum);
            for (int cellNum = 0; cellNum < 4; cellNum++) {
                myCell = myRow.createCell(cellNum);
                myCell.setCellValue(excelData1[rowNum][cellNum]);
            }
        }
        try {
            FileOutputStream out = new FileOutputStream(fileName);
            myReports.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // third sheet
        for (int rowNum = 0; rowNum < excelData2[0].length; rowNum++) {
            myRow = mySheet2.createRow(rowNum);
            for (int cellNum = 0; cellNum < 4; cellNum++) {
                myCell = myRow.createCell(cellNum);
                myCell.setCellValue(excelData2[rowNum][cellNum]);
            }
        }
        try {
            FileOutputStream out = new FileOutputStream(fileName);
            myReports.write(out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param args
     */
    public static String password;
    public static String username;
    public static String temp;

    public variable() throws FileNotFoundException {
        // TODO Auto-generated method stub

        IEnterpriseSession oEnterpriseSession = null;

        ReportEngines reportEngines = null;
        try {

            // String cmsname = "det0190bpmsdev3";
            // String authenticationType = "secEnterprise";
            String cmsname = "";
            String authenticationType = "";

            // Log in.

            oEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(
                    username, password, cmsname, authenticationType);



            if (oEnterpriseSession == null) {

            } else {

                // Process Document
                reportEngines = (ReportEngines) oEnterpriseSession
                        .getService("ReportEngines");
                ReportEngine wiRepEngine = (ReportEngine) reportEngines
                        .getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE);

                IInfoStore infoStore = (IInfoStore) oEnterpriseSession
                        .getService("InfoStore");
                String query = "select SI_NAME, SI_ID from CI_INFOOBJECTS "
                        + "where SI_KIND = 'Webi' and SI_INSTANCE=0 and SI_NAME ='"
                        + temp + "'";
                IInfoObjects infoObjects = (IInfoObjects) infoStore
                        .query(query);
                for (Object object : infoObjects) {
                    IInfoObject infoObject = (IInfoObject) object;
                    String path = getInfoObjectPath(infoObject);
                    if (path.startsWith("/")) {
                        DocumentInstance widoc = wiRepEngine
                                .openDocument(infoObject.getID());
                        String doc = infoObject.getTitle();
                    reportPath = path;// this is the path of document
            $$$$$$$$$  reportName = doc;// this is the document name

                        printDocumentVariables(widoc);
                        purgeQueries(widoc);
                        widoc.closeDocument();
                    }
                }
                // End processing
            }
        } catch (SDKException sdkEx) {

        } finally {
            if (reportEngines != null)
                reportEngines.close();
            if (oEnterpriseSession != null)
                oEnterpriseSession.logoff();
        }

    }

    public static void printDocumentVariables(DocumentInstance widoc) {
        int i = 0;
        // this is the report documents variables
        ReportDictionary dic = widoc.getDictionary();
        VariableExpression[] variables = dic.getVariables();

        for (VariableExpression e : variables) {

            nameEx = e.getFormulaLanguageID();
            expressionEx = e.getFormula().getValue();
            // stores variables in array
            nameXE[i] = nameEx;
            expressionXE[i] = expressionEx;

            i++;
        }
    }

    public static String getInfoObjectPath(IInfoObject infoObject)
            throws SDKException {
        String path = "";
        while (infoObject.getParentID() != 0) {
            infoObject = infoObject.getParent();
            path = "/" + infoObject.getTitle() + path;
        }
        return path;
    }

    @SuppressWarnings("deprecation")
    public static void purgeQueries(DocumentInstance widoc) {
        DataProviders dps = widoc.getDataProviders();
        for (int i = 0; i < dps.getCount(); ++i) {
            DataProvider dp = (DataProvider) dps.getItem(i);
            if (dp instanceof SQLDataProvider) {

                SQLDataProvider sdp = (SQLDataProvider) dp;
                sdp.purge(true);
                query = sdp.getQuery().getSQL();
            }
        }

1 个答案:

答案 0 :(得分:1)

如果Temp将包含唯一文件夹的名称,则可以使用此代码。将String query =行替换为:

IInfoObjects oParents = infoStore.query("select si_id from ci_infoobjects where si_kind = 'folder' and si_name = '" + temp + "'");
if(oParents.size()==0)
    return; // folder name not found

IInfoObject oParent = (IInfoObject)oParents.get(0);

String query = "select SI_NAME, SI_ID from CI_INFOOBJECTS "
        + "where SI_KIND = 'Webi' and si_parentid = " + oParent.getID();

我在代码中没有看到您填充tempusernamepassword变量,但我认为您只是故意将其从列表中删除。显然他们需要定义。

我在你的代码中注意到的其他一些事情:

  • 您正在清除每个报告中的查询,但之后不保存报告。
  • 您将报表的SQL存储在名为query的实例变量中,但您在query构造函数中也有一个名为variable的局部变量。如果您需要SQL值,这很可能会导致冲突。
  • SDKException你有一个“空捕获”。 SDKExceptions可能由于各种原因而发生,因为您不知道程序失败的原因。你应该至少打印出异常,或者让它冒泡。