Search in sources :

Example 16 with GXFile

use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.

the class ExcelDocument method Open.

public short Open(String fileName) {
    resetError();
    if (fileName.indexOf('.') == -1) {
        fileName += ".xls";
    }
    try {
        if (!template.equals("")) {
            GXFile templateFile = new GXFile(template);
            if (templateFile.exists()) {
                POIFSFileSystem poifs = new POIFSFileSystem(templateFile.getStream());
                workBook = new HSSFWorkbook(poifs);
            } else {
                // Invalid template
                errCod = 4;
                errDescription = "Invalid template.";
                return errCod;
            }
        } else {
            boolean isAbsolute = new java.io.File(fileName).isAbsolute();
            GXFile file = new GXFile(fileName, Constants.EXTERNAL_UPLOAD_ACL, isAbsolute);
            if (file.exists()) {
                // System.out.println("Opening..");
                POIFSFileSystem poifs = new POIFSFileSystem(file.getStream());
                workBook = new HSSFWorkbook(poifs);
            } else {
                // System.out.println("Creating..");
                workBook = new HSSFWorkbook();
            }
        }
        this.selectFirstSheet();
        xlsFileName = fileName.toString();
        stylesCache = new StylesCache(workBook);
    } catch (Exception e) {
        // error creando xls file
        errCod = 10;
        errDescription = "Could not open file.";
        System.err.println("GXOffice Error: " + e.toString());
        return errCod;
    }
    return 0;
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) GXFile(com.genexus.util.GXFile) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 17 with GXFile

use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.

the class ExcelDocument method Save.

public short Save() {
    resetError();
    if (isReadOnly()) {
        return -1;
    }
    autoFitColumns();
    recalculateFormulas();
    try {
        ByteArrayOutputStream fs = new ByteArrayOutputStream();
        workBook.write(fs);
        ByteArrayInputStream in = new ByteArrayInputStream(fs.toByteArray());
        fs.close();
        boolean isAbsolute = new java.io.File(xlsFileName).isAbsolute();
        GXFile file = new GXFile(xlsFileName, Constants.EXTERNAL_UPLOAD_ACL, isAbsolute);
        file.create(in, true);
    } catch (Exception e) {
        // error grabando xls file
        errCod = 12;
        errDescription = "Could not save file.";
        System.err.println("GXOffice Error: " + e.toString());
        return -1;
    }
    return 0;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GXFile(com.genexus.util.GXFile)

Example 18 with GXFile

use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.

the class ExcelDocument method Open.

public short Open(String fileName) {
    resetError();
    if (fileName.indexOf('.') == -1) {
        fileName += ".xlsx";
    }
    try {
        if (!template.equals("")) {
            GXFile templateFile = new GXFile(template);
            if (templateFile.exists()) {
                workBook = new XSSFWorkbook(templateFile.getStream());
            } else {
                // Invalid template
                errCod = 4;
                errDescription = "Invalid template.";
                return errCod;
            }
        } else {
            GXFile file = new GXFile("", fileName, Constants.EXTERNAL_UPLOAD_ACL, GxFileInfoSourceType.Unknown);
            if (file.exists()) {
                // System.out.println("Opening..");
                workBook = new XSSFWorkbook(file.getStream());
            } else {
                // System.out.println("Creating..");
                workBook = new XSSFWorkbook();
            }
        }
        this.selectFirstSheet();
        xlsFileName = fileName.toString();
        stylesCache = new StylesCache(workBook);
    } catch (Exception e) {
        // error creando xlsx file
        errCod = 10;
        errDescription = "Could not open file.";
        System.err.println("GXOffice Error: " + e.toString());
        return errCod;
    }
    return 0;
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) GXFile(com.genexus.util.GXFile)

Example 19 with GXFile

use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.

the class ExcelDoc method setTemplate.

public void setTemplate(String p1) {
    File path = new File(p1);
    if (com.genexus.ModelContext.getModelContext() != null) {
        com.genexus.internet.HttpContext webContext = (com.genexus.internet.HttpContext) com.genexus.ModelContext.getModelContext().getHttpContext();
        if ((webContext != null) && (webContext instanceof com.genexus.webpanels.HttpContextWeb)) {
            if (!path.isAbsolute()) {
                p1 = ((com.genexus.webpanels.HttpContextWeb) webContext).getRealPath(p1);
            }
        }
    }
    if (makeExternalUpload) {
        String localTemplate = p1;
        if (path.isAbsolute())
            p1 = path.getName().toString();
        GXFile template = new GXFile(p1);
        if (!template.exists()) {
            Application.getExternalProvider().upload(localTemplate, p1, ResourceAccessControlList.Default);
        }
    }
    template = p1;
    if (document != null) {
        document.setTemplate(p1);
    }
}
Also used : GXFile(com.genexus.util.GXFile) File(java.io.File) GXFile(com.genexus.util.GXFile)

Example 20 with GXFile

use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.

the class GXResultSet method getMultimediaFile.

public String getMultimediaFile(int columnIndex, String gxdbFileUri) throws SQLException {
    if (!GXDbFile.isFileExternal(gxdbFileUri)) {
        String fileName = GXDbFile.getFileNameFromUri(gxdbFileUri);
        if (fileName.trim().length() != 0) {
            String filePath = "";
            if (Application.getExternalProvider() == null) {
                String multimediaDir = com.genexus.Preferences.getDefaultPreferences().getMultimediaPath();
                filePath = GXutil.getNonTraversalPath(multimediaDir, fileName);
            } else {
                filePath = com.genexus.Preferences.getDefaultPreferences().getProperty("CS_BLOB_PATH", "").trim() + "/" + GXDbFile.getMultimediaDirectory() + "/" + fileName;
            }
            GXFile file = new GXFile(filePath);
            if (file.exists()) {
                return file.getAbsolutePath();
            } else {
                return getBLOBFile(columnIndex, CommonUtil.getFileType(gxdbFileUri), CommonUtil.getFileName(gxdbFileUri), filePath, false);
            }
        }
    }
    return "";
}
Also used : GXFile(com.genexus.util.GXFile)

Aggregations

GXFile (com.genexus.util.GXFile)20 ByteArrayInputStream (java.io.ByteArrayInputStream)6 File (java.io.File)5 IOException (java.io.IOException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 BufferedInputStream (java.io.BufferedInputStream)3 InputStream (java.io.InputStream)3 SQLException (java.sql.SQLException)3 GxSilentTrnSdt (com.genexus.GxSilentTrnSdt)2 HttpContext (com.genexus.internet.HttpContext)2 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 com.genexus (com.genexus)1 IGxSilentTrn (com.genexus.IGxSilentTrn)1 IExtensionGXExternalFileInfo (com.genexus.common.interfaces.IExtensionGXExternalFileInfo)1 ExternalProvider (com.genexus.db.driver.ExternalProvider)1 StylesCache (com.genexus.gxoffice.poi.xssf.StylesCache)1 ExcelException (com.genexus.msoffice.excel.exception.ExcelException)1 ExcelTemplateNotFoundException (com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException)1