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