use of org.compiere.model.MImage in project adempiere by adempiere.
the class SmjXlsReport method generate.
public HSSFWorkbook generate(LinkedList<ReportTO> data, String[] generalTitle, String clientName, String clientNIT, String periodName, String currencyName, MReportColumn[] m_columns, String city, Integer logoId) {
int fila = 0;
HSSFRow row;
cols = m_columns.length + 2;
endRegion = (short) (cols - 1);
try {
// create workbook
HSSFWorkbook book = new HSSFWorkbook();
// crea hoja - create sheet
// Goodwill BF: Invalid sheet name
HSSFSheet sheet = book.createSheet(StringUtils.makePrefix(generalTitle[0]));
// crea fuente - Create Font
HSSFFont font = book.createFont();
font.setFontHeightInPoints((short) 13);
font.setFontName(HSSFFont.FONT_ARIAL);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// estio celda - cell style
HSSFCellStyle cellStyle = book.createCellStyle();
cellStyle.setWrapText(true);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyle.setFont(font);
// add logo
if (logoId > 0) {
MImage mimage = MImage.get(Env.getCtx(), logoId);
byte[] imageData = mimage.getData();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFClientAnchor anchor;
anchor = new HSSFClientAnchor(100, 50, 200, 255, (short) 0, 0, (short) 1, 1);
anchor.setAnchorType(2);
int pictureIndex = book.addPicture(imageData, HSSFWorkbook.PICTURE_TYPE_PNG);
patriarch.createPicture(anchor, pictureIndex);
for (int i = 0; i < 5; i++) row = sheet.createRow(fila++);
}
//if Logo report
// Titulo General - general Title
row = sheet.createRow(fila++);
HSSFRichTextString text = new HSSFRichTextString(generalTitle[0]);
HSSFCell cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
Region region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// empresa - Company
row = sheet.createRow(fila++);
text = new HSSFRichTextString(clientName);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// Ciudad - City
row = sheet.createRow(fila++);
text = new HSSFRichTextString(city);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// NIT
row = sheet.createRow(fila++);
text = new HSSFRichTextString(clientNIT);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// periodo - Period
String pn = "";
if (generalTitle[1] != null && generalTitle[1].length() > 0) {
pn = generalTitle[1] + " " + periodName;
} else {
pn = periodName;
}
if (generalTitle[2] != null && generalTitle[2].length() > 0) {
pn = pn + " " + generalTitle[2];
}
row = sheet.createRow(fila++);
text = new HSSFRichTextString(pn);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// tipo moneda - currency
row = sheet.createRow(fila++);
text = new HSSFRichTextString(currencyName);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
row = sheet.createRow(fila++);
titleTable(book, sheet, fila++, m_columns);
// llena datos del reporte - fill data report
reportTable(book, data, sheet, fila);
return book;
} catch (Exception e) {
e.printStackTrace();
return null;
}
//try/catch
}
use of org.compiere.model.MImage in project adempiere by adempiere.
the class MediaBroadcast method doGet.
/**
* Process the HTTP Get request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Create New Session
HttpSession sess = request.getSession(true);
sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
if (configLoaded && !fatalError) {
String requestURL = request.getRequestURL().toString();
String serverName = request.getServerName();
String baseURL = requestURL.substring(0, requestURL.indexOf(serverName) + serverName.length() + 6) + request.getContextPath();
String relativeURL = requestURL.substring(baseURL.length());
// If the relativeURL still contains / we will simply strip them off...
if (relativeURL.indexOf('/') >= 0)
relativeURL = relativeURL.substring(relativeURL.lastIndexOf('/') + 1);
// We should have only an ID before the first dot.
Integer mediaID = null;
try {
if (relativeURL.indexOf('.') >= 0) {
mediaID = Integer.parseInt(relativeURL.substring(0, relativeURL.indexOf('.')));
} else {
mediaID = Integer.parseInt(relativeURL);
}
} catch (NumberFormatException ne) {
}
if (mediaID != null && mediaID.intValue() > 0) {
MMedia thisMedia = new org.compiere.model.MMedia(webProjectCache.getCtx(), mediaID, null);
if (thisMedia != null && thisMedia.get_ID() > 0) {
if (thisMedia.getMediaType().equals("CSS")) {
response.setContentType("text/css");
// Text Content will get handled via direct Stream
response.setContentLength(thisMedia.getContentText().length());
PrintWriter out;
out = response.getWriter();
out.print(thisMedia.getContentText());
out.close();
} else {
response.setContentType(thisMedia.getMediaType());
// Binary / Image content will get handled here
MImage thisImage = thisMedia.getImage();
if (thisImage != null) {
response.setContentLength(thisImage.getData().length);
// Open the file and output streams
byte[] buffer = thisImage.getData();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
OutputStream out = response.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}
}
} else {
response.sendError(404);
}
} else {
response.sendError(404);
}
} else if (fatalError) {
response.sendError(500, ErrorMessage);
}
}
Aggregations