Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
ofbiz-directcontrolservlet
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
cd8ca01e
authored
2014-10-24 12:30:31 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'BF-4378' of /home/git/repositories/brainfood/ofbiz-directcontrolservlet
2 parents
ef4b37ae
8e6015ca
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
src/com/brainfood/ofbiz/DirectControlServlet.java
src/com/brainfood/ofbiz/DirectControlServlet.java
View file @
cd8ca01
...
...
@@ -55,6 +55,9 @@ import org.ofbiz.service.LocalDispatcher;
import
org.ofbiz.service.ModelService
;
import
org.ofbiz.service.ServiceContainer
;
import
org.apache.commons.csv.CSVFormat
;
import
org.apache.commons.csv.CSVRecord
;
import
groovy.lang.GroovyClassLoader
;
import
groovy.lang.Script
;
...
...
@@ -139,11 +142,31 @@ public class DirectControlServlet extends HttpServlet {
for
(
String
key
:
items
.
keySet
())
{
context
.
put
(
key
,
items
.
get
(
key
));
}
}
else
if
(
"text/csv"
.
equals
(
contentType
))
{
// Directly copy request parameters into context.
for
(
Enumeration
<
String
>
params
=
request
.
getParameterNames
();
params
.
hasMoreElements
();)
{
String
param
=
params
.
nextElement
();
Object
[]
values
=
request
.
getParameterValues
(
param
);
if
(!
"sessionId"
.
equals
(
param
)
&&
!
"_method"
.
equals
(
param
))
{
context
.
put
(
param
,
values
.
length
==
1
?
values
[
0
]
:
values
);
}
}
Iterable
<
CSVRecord
>
records
=
CSVFormat
.
EXCEL
.
parse
(
request
.
getReader
());
List
<
List
<
String
>>
data
=
new
ArrayList
<
List
<
String
>>();
for
(
CSVRecord
record
:
records
)
{
List
<
String
>
row
=
new
ArrayList
<
String
>();
String
cell
=
null
;
Iterator
<
String
>
i
=
record
.
iterator
();
while
(
i
.
hasNext
())
{
row
.
add
(
i
.
next
());
}
data
.
add
(
row
);
}
context
.
put
(
"data"
,
data
);
}
else
{
// Check if the request is a backbone style "emulateJSON" request
if
(
contentType
!=
null
&&
contentType
.
indexOf
(
"x-www-form-urlencoded"
)
!=
-
1
&&
request
.
getParameter
(
"model"
)
!=
null
)
{
if
(
contentType
!=
null
&&
contentType
.
indexOf
(
"x-www-form-urlencoded"
)
!=
-
1
&&
request
.
getParameter
(
"model"
)
!=
null
)
{
Debug
.
logInfo
(
"MODEL: "
+
request
.
getParameter
(
"model"
),
module
);
JSON
json
=
new
JSON
(
new
StringReader
(
request
.
getParameter
(
"model"
)));
Map
<
String
,
Object
>
items
=
json
.
JSONObject
();
...
...
@@ -254,7 +277,6 @@ public class DirectControlServlet extends HttpServlet {
String
jsonStr
=
json
.
toString
();
response
.
setContentLength
(
jsonStr
.
getBytes
(
"UTF8"
).
length
);
writer
.
write
(
jsonStr
);
writer
.
flush
();
writer
.
close
();
}
catch
(
Throwable
t
)
{
...
...
Please
register
or
sign in
to post a comment