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;
}
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;
}
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;
}
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);
}
}
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 "";
}
Aggregations