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
cb76eeec
authored
2014-10-22 18:36:50 -0500
by
Ean Schuessler
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Handle CSV input #4378
1 parent
ef4b37ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
src/com/brainfood/ofbiz/DirectControlServlet.java
src/com/brainfood/ofbiz/DirectControlServlet.java
View file @
cb76eee
...
...
@@ -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,22 @@ public class DirectControlServlet extends HttpServlet {
for
(
String
key
:
items
.
keySet
())
{
context
.
put
(
key
,
items
.
get
(
key
));
}
}
else
if
(
"text/csv"
.
equals
(
contentType
))
{
Iterable
<
CSVRecord
>
records
=
CSVFormat
.
EXCEL
.
parse
(
request
.
getReader
());
List
data
=
new
ArrayList
();
for
(
CSVRecord
record
:
records
)
{
List
row
=
new
ArrayList
();
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 +268,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