use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.
the class GxImageUtil method writeImage.
private static void writeImage(BufferedImage croppedImage, String destinationFilePathOrUrl) throws IOException {
try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) {
ImageIO.write(croppedImage, CommonUtil.getFileType(destinationFilePathOrUrl), outStream);
try (ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray())) {
GXFile file = getGXFile(destinationFilePathOrUrl);
file.create(inStream, true);
file.close();
}
}
}
use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.
the class DocumentHandler method htmlPreview.
public static String htmlPreview(Object obj, String query, String textType, String preTag, String postTag, int fragmentSize, int maxNumFragments) {
String text;
try {
if (obj instanceof GxSilentTrnSdt) {
text = ((GxSilentTrnSdt) obj).getTransaction().toString();
} else if (obj instanceof GXFile) {
GXFile file = (GXFile) obj;
text = DocumentHandler.getText(file.getAbsoluteName(), file.getExt());
} else if (textType.toLowerCase().startsWith("htm")) {
text = new JTidyHTMLHandler().getTextFromString(obj.toString());
} else {
text = obj.toString();
}
if (!query.equals("") && !text.equals("")) {
QueryParser qp = new QueryParser(IndexRecord.CONTENTFIELD, Indexer.CreateAnalyzer());
qp.setDefaultOperator(QueryParser.Operator.AND);
Query unReWrittenQuery = qp.parse(query);
Query q = unReWrittenQuery;
try {
if (reader == null) {
reader = Indexer.getReader();
}
if (queries.get(query) != null) {
q = (Query) queries.get(query);
} else {
// required to expand search terms (for the usage of
q = unReWrittenQuery.rewrite(reader);
// highlighting with wildcards)
if (queries.size() == Integer.MAX_VALUE) {
queries.clear();
}
queries.put(query, q);
}
} catch (Exception ex) {
}
QueryScorer scorer = new QueryScorer(q);
SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(preTag, postTag);
Highlighter highlighter = new Highlighter(formatter, scorer);
Fragmenter fragmenter = new SimpleFragmenter(fragmentSize);
highlighter.setTextFragmenter(fragmenter);
TokenStream tokenStream = Indexer.CreateAnalyzer().tokenStream(IndexRecord.CONTENTFIELD, new StringReader(text));
String result = highlighter.getBestFragments(tokenStream, text, maxNumFragments, "...");
return result;
} else {
return text;
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
return "";
}
}
use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.
the class Indexer method getIndexRecord.
private IndexRecord getIndexRecord(Object obj, GXContentInfo contentInfo) {
if (contentInfo == null)
contentInfo = new GXContentInfo();
IndexRecord ir = new IndexRecord();
if (obj instanceof GXFile) {
GXFile file = (GXFile) obj;
ir.setUri(file.getAbsoluteName());
ir.setContent(DocumentHandler.getText(file.getAbsoluteName(), file.getExt()).toLowerCase());
ir.setEntity(contentInfo.getType() == null ? file.getClass().getName() : contentInfo.getType());
ir.setTitle(contentInfo.getTitle() == null ? file.getName() : contentInfo.getTitle());
ir.setViewer(contentInfo.getViewer() == null ? file.getName() : contentInfo.getViewer());
ir.setKeys(contentInfo.getKeys() == null || contentInfo.getKeys().size() == 0 ? new Vector<String>() : contentInfo.getKeys());
} else if (obj instanceof GxSilentTrnSdt) {
IGxSilentTrn bc = ((GxSilentTrnSdt) obj).getTransaction();
GXContentInfo info = bc.getContentInfo();
ir.setUri(info.getId());
ir.setContent(IndexRecord.processContent(bc.toString()));
ir.setEntity(contentInfo.getType() == null ? info.getType() : contentInfo.getType());
ir.setTitle(contentInfo.getTitle() == null ? info.getTitle() : contentInfo.getTitle());
ir.setViewer(contentInfo.getViewer() == null ? info.getViewer() : contentInfo.getViewer());
ir.setKeys(contentInfo.getKeys() == null || contentInfo.getKeys().size() == 0 ? info.getKeys() : contentInfo.getKeys());
} else if (obj instanceof String) {
ir.setUri(contentInfo.getId() == null ? "" : contentInfo.getId());
ir.setContent(IndexRecord.processContent((String) obj));
ir.setEntity(contentInfo.getType() == null ? "" : contentInfo.getType());
ir.setTitle(contentInfo.getTitle() == null ? "" : contentInfo.getTitle());
ir.setViewer(contentInfo.getViewer() == null ? "" : contentInfo.getViewer());
ir.setKeys(contentInfo.getKeys() == null || contentInfo.getKeys().size() == 0 ? new Vector<String>() : contentInfo.getKeys());
} else {
ir = null;
}
return ir;
}
use of com.genexus.util.GXFile in project JavaClasses by genexuslabs.
the class HttpContextWeb method getResourceRelative.
public String getResourceRelative(String path, boolean includeBasePath) {
if (Application.getExternalProvider() != null && !path.isEmpty()) {
if (CommonUtil.isAbsoluteURL(path))
return path;
GXFile gxFile = new GXFile(path);
String pathURL = gxFile.getAbsolutePath();
if (CommonUtil.isAbsoluteURL(pathURL))
return pathURL;
}
try {
java.io.File file = new java.io.File(path);
if (file.getPath().compareTo(file.getAbsolutePath()) != 0)
return path;
} catch (Exception e) {
return path;
}
if (path.length() == 0)
return "";
String ContextPath = null;
try {
ContextPath = request.getContextPath();
} catch (Exception e) {
// on submit (there is no http context) request.getContextPath throws a
// java.lang.NullPointerException
System.err.println(e.toString());
}
;
String Resource = path;
String basePath = getDefaultPath();
if (Resource.startsWith(basePath) && Resource.length() >= basePath.length())
Resource = Resource.substring(basePath.length());
if (ContextPath != null && !ContextPath.equals("") && Resource.startsWith(ContextPath))
return Resource.replace('\\', '/');
Resource = Resource.replace('\\', '/');
if (includeBasePath) {
if (Resource.startsWith("/"))
Resource = ContextPath + Resource;
else
Resource = ContextPath + "/" + Resource;
} else {
if (Resource.startsWith("/"))
Resource = Resource.substring(1);
}
String baseName = FilenameUtils.getBaseName(Resource);
Resource = CommonUtil.replaceLast(Resource, baseName, PrivateUtilities.encodeFileName(baseName));
return Resource;
}
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 SXSSFWorkbook(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 SXSSFWorkbook(new XSSFWorkbook(file.getStream()));
} else {
// System.out.println("Creating..");
workBook = new SXSSFWorkbook();
}
}
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;
}
Aggregations