Search in sources :

Example 1 with URLItem

use of lucee.commons.net.URLItem in project Lucee by lucee.

the class FormImpl method initializeUrlEncodedOrTextPlain.

/*
	 * private void initializeMultiPart(PageContext pc, boolean scriptProteced) {
	 * 
	 * File tempDir=FileWrapper.toFile(pc.getConfig().getTempDirectory());
	 * 
	 * // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(-1,tempDir);
	 * 
	 * // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory);
	 * 
	 * upload.setHeaderEncoding(getEncoding());
	 * 
	 * //FileUpload fileUpload=new FileUpload(new DiskFileItemFactory(0,tempDir)); java.util.List list; try { list =
	 * upload.parseRequest(pc.getHttpServletRequest()); raw=new ByteNameValuePair[list.size()];
	 * 
	 * for(int i=0;i<raw.length;i++) { DiskFileItem val=(DiskFileItem) list.get(i); if(val.isFormField()) { raw[i]=new
	 * ByteNameValuePair(getBytes(val.getFieldName()),val.get(),false); } else { print.out("-------------------------------");
	 * print.out("fieldname:"+val.getFieldName()); print.out("name:"+val.getName()); print.out("formfield:"+val.isFormField());
	 * print.out("memory:"+val.isInMemory()); print.out("exist:"+val.getStoreLocation().getCanonicalFile().exists());
	 * 
	 * fileItems.put(val.getFieldName().toLowerCase(),val);
	 * 
	 * raw[i]=new ByteNameValuePair(getBytes(val.getFieldName()),val.getStoreLocation().getCanonicalFile().toString().getBytes(),false);
	 * //raw.put(val.getFieldName(),val.getStoreLocation().getCanonicalFile().toString()); } } fillDecoded(raw,encoding,scriptProteced); } catch (Exception e) {
	 * 
	 * //throw new PageRuntimeException(Caster.toPageException(e)); fillDecodedEL(new ByteNameValuePair[0],encoding,scriptProteced); initException=e; } }
	 */
private void initializeUrlEncodedOrTextPlain(PageContext pc, char delimiter, boolean scriptProteced) {
    BufferedReader reader = null;
    try {
        reader = pc.getHttpServletRequest().getReader();
        raw = setFrom___(IOUtil.toString(reader, false), delimiter);
        fillDecoded(raw, encoding, scriptProteced, pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
    } catch (Exception e) {
        fillDecodedEL(new URLItem[0], encoding, scriptProteced, pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
        initException = e;
    } finally {
        IOUtil.closeEL(reader);
    }
}
Also used : URLItem(lucee.commons.net.URLItem) BufferedReader(java.io.BufferedReader) PageException(lucee.runtime.exp.PageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with URLItem

use of lucee.commons.net.URLItem in project Lucee by lucee.

the class FormImpl method initializeMultiPart.

private void initializeMultiPart(PageContext pc, boolean scriptProteced) {
    // get temp directory
    Resource tempDir = ((ConfigImpl) pc.getConfig()).getTempDirectory();
    Resource tempFile;
    // Create a new file upload handler
    final String encoding = getEncoding();
    FileItemFactory factory = tempDir instanceof File ? new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, (File) tempDir) : new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setHeaderEncoding(encoding);
    // ServletRequestContext c = new ServletRequestContext(pc.getHttpServletRequest());
    HttpServletRequest req = pc.getHttpServletRequest();
    ServletRequestContext context = new ServletRequestContext(req) {

        @Override
        public String getCharacterEncoding() {
            return encoding;
        }
    };
    // Parse the request
    try {
        FileItemIterator iter = upload.getItemIterator(context);
        // byte[] value;
        InputStream is;
        ArrayList<URLItem> list = new ArrayList<URLItem>();
        String fileName;
        while (iter.hasNext()) {
            FileItemStream item = iter.next();
            is = IOUtil.toBufferedInputStream(item.openStream());
            if (item.getContentType() == null || StringUtil.isEmpty(item.getName())) {
                list.add(new URLItem(item.getFieldName(), new String(IOUtil.toBytes(is), encoding), false));
            } else {
                fileName = getFileName();
                tempFile = tempDir.getRealResource(fileName);
                _fileItems.put(fileName, new Item(tempFile, item.getContentType(), item.getName(), item.getFieldName()));
                String value = tempFile.toString();
                IOUtil.copy(is, tempFile, true);
                list.add(new URLItem(item.getFieldName(), value, false));
            }
        }
        raw = list.toArray(new URLItem[list.size()]);
        fillDecoded(raw, encoding, scriptProteced, pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
    } catch (Exception e) {
        SystemOut.printDate(e);
        // throw new PageRuntimeException(Caster.toPageException(e));
        fillDecodedEL(new URLItem[0], encoding, scriptProteced, pc.getApplicationContext().getSameFieldAsArray(SCOPE_FORM));
        initException = e;
    }
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) ServletRequestContext(org.apache.commons.fileupload.servlet.ServletRequestContext) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileItemFactory(org.apache.commons.fileupload.FileItemFactory) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) PageException(lucee.runtime.exp.PageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpServletRequest(javax.servlet.http.HttpServletRequest) DiskFileItem(org.apache.commons.fileupload.disk.DiskFileItem) URLItem(lucee.commons.net.URLItem) URLItem(lucee.commons.net.URLItem) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileItemStream(org.apache.commons.fileupload.FileItemStream) File(java.io.File) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 3 with URLItem

use of lucee.commons.net.URLItem in project Lucee by lucee.

the class ScopeSupport method setFrom___.

protected static URLItem[] setFrom___(String tp, char delimiter) {
    if (tp == null)
        return new URLItem[0];
    Array arr = ListUtil.listToArrayRemoveEmpty(tp, delimiter);
    URLItem[] pairs = new URLItem[arr.size()];
    // Array item;
    int index;
    String name;
    for (int i = 1; i <= pairs.length; i++) {
        name = Caster.toString(arr.get(i, ""), "");
        // if(name.length()==0) continue;
        index = name.indexOf('=');
        if (index != -1)
            pairs[i - 1] = new URLItem(name.substring(0, index), name.substring(index + 1), true);
        else
            pairs[i - 1] = new URLItem(name, "", true);
    }
    return pairs;
}
Also used : Array(lucee.runtime.type.Array) URLItem(lucee.commons.net.URLItem)

Aggregations

URLItem (lucee.commons.net.URLItem)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 PageException (lucee.runtime.exp.PageException)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ServletInputStream (javax.servlet.ServletInputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Resource (lucee.commons.io.res.Resource)1 ConfigImpl (lucee.runtime.config.ConfigImpl)1 Array (lucee.runtime.type.Array)1 FileItemFactory (org.apache.commons.fileupload.FileItemFactory)1 FileItemIterator (org.apache.commons.fileupload.FileItemIterator)1 FileItemStream (org.apache.commons.fileupload.FileItemStream)1 DiskFileItem (org.apache.commons.fileupload.disk.DiskFileItem)1 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 ServletRequestContext (org.apache.commons.fileupload.servlet.ServletRequestContext)1