From 73efd701fdff9ee8764f3f08e8bed1b18665e721 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 8 May 2009 15:18:09 +0000 Subject: [PATCH] Accept patch [2788801] MAttachementEntry.java patch Thanks to Muhammad Faisal Shahzad (ro2) --- .../org/compiere/report/ReportStarter.java | 2 +- .../process/PrepareMigrationScripts.java | 6 +- .../org/compiere/model/MAttachmentEntry.java | 593 +++++++++--------- .../posterita/struts/pos/GetReportAction.java | 2 +- .../servlet/org/compiere/www/WFilter.java | 8 +- 5 files changed, 307 insertions(+), 304 deletions(-) diff --git a/JasperReports/src/org/compiere/report/ReportStarter.java b/JasperReports/src/org/compiere/report/ReportStarter.java index 902f108de7..aea31d4e1d 100644 --- a/JasperReports/src/org/compiere/report/ReportStarter.java +++ b/JasperReports/src/org/compiere/report/ReportStarter.java @@ -603,7 +603,7 @@ public class ReportStarter implements ProcessCall, ClientProcess MAttachmentEntry[] entries = attachment.getEntries(); for(int i = 0; i < entries.length; i++) { if (!entries[i].getName().equals(name) && - (entries[i].getName().endsWith(".jrxml") || entries[i].getName().endsWith(".jasper"))) { + (entries[i].getName().toLowerCase().endsWith(".jrxml") || entries[i].getName().toLowerCase().endsWith(".jasper"))) { File reportFile = getAttachmentEntryFile(entries[i]); if (reportFile != null) subreports.add(reportFile); diff --git a/base/src/org/adempiere/process/PrepareMigrationScripts.java b/base/src/org/adempiere/process/PrepareMigrationScripts.java index 8c1c1d7651..5423b1350c 100644 --- a/base/src/org/adempiere/process/PrepareMigrationScripts.java +++ b/base/src/org/adempiere/process/PrepareMigrationScripts.java @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** * This file is part of Adempiere ERP Bazaar * * http://www.adempiere.org * * * @@ -25,7 +25,7 @@ * * * Sponsors: * * - Company (http://www.faire.com.br) * - ***********************************************************************/ + **********************************************************************/ package org.adempiere.process; @@ -67,7 +67,7 @@ public class PrepareMigrationScripts extends SvrProcess { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { - return name.endsWith(".sql"); + return name.toLowerCase().endsWith(".sql"); } }; dirList = dir.listFiles(filter); diff --git a/base/src/org/compiere/model/MAttachmentEntry.java b/base/src/org/compiere/model/MAttachmentEntry.java index 7a53b4121a..9965af5af2 100644 --- a/base/src/org/compiere/model/MAttachmentEntry.java +++ b/base/src/org/compiere/model/MAttachmentEntry.java @@ -1,296 +1,297 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.model; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Random; -import java.util.logging.Level; - -import org.compiere.util.CLogger; -import org.compiere.util.MimeType; - - -/** - * Individual Attachment Entry of MAttachment - * - * @author Jorg Janke - * @version $Id: MAttachmentEntry.java,v 1.2 2006/07/30 00:58:18 jjanke Exp $ - */ -public class MAttachmentEntry -{ - /** - * Attachment Entry - * @param name name - * @param data binary data - * @param index optional index - */ - public MAttachmentEntry (String name, byte[] data, int index) - { - super (); - setName (name); - setData (data); - if (index > 0) - m_index = index; - else - { - long now = System.currentTimeMillis(); - if (s_seed+3600000l < now) // older then 1 hour - { - s_seed = now; - s_random = new Random(s_seed); - } - m_index = s_random.nextInt(); - } - } // MAttachmentItem - - /** - * Attachment Entry - * @param name name - * @param data binary data - */ - public MAttachmentEntry (String name, byte[] data) - { - this (name, data, 0); - } // MAttachmentItem - - /** The Name */ - private String m_name = "?"; - /** The Data */ - private byte[] m_data = null; - - /** Random Seed */ - private static long s_seed = System.currentTimeMillis(); - /** Random Number */ - private static Random s_random = new Random(s_seed); - /** Index */ - private int m_index = 0; - - /** Logger */ - protected CLogger log = CLogger.getCLogger(getClass()); - - - /** - * @return Returns the data. - */ - public byte[] getData () - { - return m_data; - } - /** - * @param data The data to set. - */ - public void setData (byte[] data) - { - m_data = data; - } - /** - * @return Returns the name. - */ - public String getName () - { - return m_name; - } - - /** - * @param name The name to set. - */ - public void setName (String name) - { - if (name != null) - m_name = name; - if (m_name == null) - m_name = "?"; - } // setName - - /** - * Get Attachment Index - * @return timestamp - */ - public int getIndex() - { - return m_index; - } // getIndex - - /** - * To String - * @return name - */ - public String toString () - { - return m_name; - } // toString - - /** - * To String Extended - * @return name (length) - */ - public String toStringX () - { - StringBuffer sb = new StringBuffer (m_name); - if (m_data != null) - { - sb.append(" ("); - // - float size = m_data.length; - if (size <= 1024) - sb.append(m_data.length).append(" B"); - else - { - size /= 1024; - if (size > 1024) - { - size /= 1024; - sb.append(size).append(" MB"); - } - else - sb.append(size).append(" kB"); - } - // - sb.append(")"); - } - sb.append(" - ").append(getContentType()); - return sb.toString(); - } // toStringX - - - /** - * Dump Data - */ - public void dump () - { - String hdr = "----- " + getName() + " -----"; - System.out.println (hdr); - if (m_data == null) - { - System.out.println ("----- no data -----"); - return; - } - // raw data - for (int i = 0; i < m_data.length; i++) - { - char data = (char)m_data[i]; - System.out.print(data); - } - - System.out.println (); - System.out.println (hdr); - // Count nulls at end - int ii = m_data.length -1; - int nullCount = 0; - while (m_data[ii--] == 0) - nullCount++; - System.out.println("----- Length=" + m_data.length + ", EndNulls=" + nullCount - + ", RealLength=" + (m_data.length-nullCount)); - /** - // Dump w/o nulls - if (nullCount > 0) - { - for (int i = 0; i < m_data.length-nullCount; i++) - System.out.print((char)m_data[i]); - System.out.println (); - System.out.println (hdr); - } - /** **/ - } // dump - - /** - * Get File with default name - * @return File - */ - public File getFile () - { - return getFile (getName()); - } // getFile - - /** - * Get File with name - * @param fileName optional file name - * @return file - */ - public File getFile (String fileName) - { - if (fileName == null || fileName.length() == 0) - fileName = getName(); - return getFile (new File(fileName)); - } // getFile - - /** - * Get File - * @param file out file - * @return file - */ - public File getFile (File file) - { - if (m_data == null || m_data.length == 0) - return null; - try - { - FileOutputStream fos = new FileOutputStream(file); - fos.write(m_data); - fos.close(); - } - catch (IOException ioe) - { - log.log(Level.SEVERE, "getFile", ioe); - } - return file; - } // getFile - - /** - * Is attachment entry a PDF - * @return true if PDF - */ - public boolean isPDF() - { - return m_name.endsWith(".pdf"); - } // isPDF - - /** - * Isattachment entry a Graphic - * @return true if *.gif, *.jpg, *.png - */ - public boolean isGraphic() - { - return m_name.endsWith(".gif") || m_name.endsWith(".jpg") || m_name.endsWith(".png"); - } // isGraphic - - - /** - * Get Content (Mime) Type - * @return content type - */ - public String getContentType() - { - return MimeType.getMimeType(m_name); - } // getContentType - - /** - * Get Data as Input Stream - * @return input stream - */ - public InputStream getInputStream() - { - if (m_data == null) - return null; - return new ByteArrayInputStream(m_data); - } // getInputStream - -} // MAttachmentItem +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.model; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Random; +import java.util.logging.Level; + +import org.compiere.util.CLogger; +import org.compiere.util.MimeType; + + +/** + * Individual Attachment Entry of MAttachment + * + * @author Jorg Janke + * @version $Id: MAttachmentEntry.java,v 1.2 2006/07/30 00:58:18 jjanke Exp $ + */ +public class MAttachmentEntry +{ + /** + * Attachment Entry + * @param name name + * @param data binary data + * @param index optional index + */ + public MAttachmentEntry (String name, byte[] data, int index) + { + super (); + setName (name); + setData (data); + if (index > 0) + m_index = index; + else + { + long now = System.currentTimeMillis(); + if (s_seed+3600000l < now) // older then 1 hour + { + s_seed = now; + s_random = new Random(s_seed); + } + m_index = s_random.nextInt(); + } + } // MAttachmentItem + + /** + * Attachment Entry + * @param name name + * @param data binary data + */ + public MAttachmentEntry (String name, byte[] data) + { + this (name, data, 0); + } // MAttachmentItem + + /** The Name */ + private String m_name = "?"; + /** The Data */ + private byte[] m_data = null; + + /** Random Seed */ + private static long s_seed = System.currentTimeMillis(); + /** Random Number */ + private static Random s_random = new Random(s_seed); + /** Index */ + private int m_index = 0; + + /** Logger */ + protected CLogger log = CLogger.getCLogger(getClass()); + + + /** + * @return Returns the data. + */ + public byte[] getData () + { + return m_data; + } + /** + * @param data The data to set. + */ + public void setData (byte[] data) + { + m_data = data; + } + /** + * @return Returns the name. + */ + public String getName () + { + return m_name; + } + + /** + * @param name The name to set. + */ + public void setName (String name) + { + if (name != null) + m_name = name; + if (m_name == null) + m_name = "?"; + } // setName + + /** + * Get Attachment Index + * @return timestamp + */ + public int getIndex() + { + return m_index; + } // getIndex + + /** + * To String + * @return name + */ + public String toString () + { + return m_name; + } // toString + + /** + * To String Extended + * @return name (length) + */ + public String toStringX () + { + StringBuffer sb = new StringBuffer (m_name); + if (m_data != null) + { + sb.append(" ("); + // + float size = m_data.length; + if (size <= 1024) + sb.append(m_data.length).append(" B"); + else + { + size /= 1024; + if (size > 1024) + { + size /= 1024; + sb.append(size).append(" MB"); + } + else + sb.append(size).append(" kB"); + } + // + sb.append(")"); + } + sb.append(" - ").append(getContentType()); + return sb.toString(); + } // toStringX + + + /** + * Dump Data + */ + public void dump () + { + String hdr = "----- " + getName() + " -----"; + System.out.println (hdr); + if (m_data == null) + { + System.out.println ("----- no data -----"); + return; + } + // raw data + for (int i = 0; i < m_data.length; i++) + { + char data = (char)m_data[i]; + System.out.print(data); + } + + System.out.println (); + System.out.println (hdr); + // Count nulls at end + int ii = m_data.length -1; + int nullCount = 0; + while (m_data[ii--] == 0) + nullCount++; + System.out.println("----- Length=" + m_data.length + ", EndNulls=" + nullCount + + ", RealLength=" + (m_data.length-nullCount)); + /** + // Dump w/o nulls + if (nullCount > 0) + { + for (int i = 0; i < m_data.length-nullCount; i++) + System.out.print((char)m_data[i]); + System.out.println (); + System.out.println (hdr); + } + /** **/ + } // dump + + /** + * Get File with default name + * @return File + */ + public File getFile () + { + return getFile (getName()); + } // getFile + + /** + * Get File with name + * @param fileName optional file name + * @return file + */ + public File getFile (String fileName) + { + if (fileName == null || fileName.length() == 0) + fileName = getName(); + return getFile (new File(fileName)); + } // getFile + + /** + * Get File + * @param file out file + * @return file + */ + public File getFile (File file) + { + if (m_data == null || m_data.length == 0) + return null; + try + { + FileOutputStream fos = new FileOutputStream(file); + fos.write(m_data); + fos.close(); + } + catch (IOException ioe) + { + log.log(Level.SEVERE, "getFile", ioe); + } + return file; + } // getFile + + /** + * Is attachment entry a PDF + * @return true if PDF + */ + public boolean isPDF() + { + return m_name.toLowerCase().endsWith(".pdf"); + } // isPDF + + /** + * Is attachment entry a Graphic + * @return true if *.gif, *.jpg, *.png + */ + public boolean isGraphic() + { + String m_lowname = m_name.toLowerCase(); + return m_lowname.endsWith(".gif") || m_lowname.endsWith(".jpg") || m_lowname.endsWith(".png"); + } // isGraphic + + + /** + * Get Content (Mime) Type + * @return content type + */ + public String getContentType() + { + return MimeType.getMimeType(m_name); + } // getContentType + + /** + * Get Data as Input Stream + * @return input stream + */ + public InputStream getInputStream() + { + if (m_data == null) + return null; + return new ByteArrayInputStream(m_data); + } // getInputStream + +} // MAttachmentItem diff --git a/posterita/posterita/src/main/org/posterita/struts/pos/GetReportAction.java b/posterita/posterita/src/main/org/posterita/struts/pos/GetReportAction.java index 556cad2b30..039de6a62f 100644 --- a/posterita/posterita/src/main/org/posterita/struts/pos/GetReportAction.java +++ b/posterita/posterita/src/main/org/posterita/struts/pos/GetReportAction.java @@ -54,7 +54,7 @@ public class GetReportAction extends POSAction String mimeType = null; - if(reportName.endsWith(".csv")) + if(reportName.toLowerCase().endsWith(".csv")) { mimeType = "text/comma-separated-values"; } diff --git a/serverApps/src/main/servlet/org/compiere/www/WFilter.java b/serverApps/src/main/servlet/org/compiere/www/WFilter.java index e1a1a55dc6..56a803effd 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WFilter.java +++ b/serverApps/src/main/servlet/org/compiere/www/WFilter.java @@ -139,10 +139,12 @@ public final class WFilter implements javax.servlet.Filter // Get URI String uri = ""; + String urilow = ""; if (request instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest)request; uri = req.getRequestURI(); + urilow = uri.toLowerCase(); } @@ -171,9 +173,9 @@ public final class WFilter implements javax.servlet.Filter else pass = false; else if (!uri.startsWith(WebEnv.DIR_BASE) // not requesting /adempiere/... - || uri.endsWith(".gif") || uri.endsWith(".jpg") || uri.endsWith(".png") - || uri.endsWith(".html") || uri.endsWith(".css") - || uri.endsWith(".js")) + || urilow.endsWith(".gif") || urilow.endsWith(".jpg") || urilow.endsWith(".png") + || urilow.endsWith(".html") || urilow.endsWith(".css") + || urilow.endsWith(".js")) check = false; else ;