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
0c5c7fe4
authored
2017-04-03 15:39:23 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Rewrote the csv output to use a library, instead of doing it manually.
Refs: #8187
1 parent
133fa70c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
31 deletions
src/com/brainfood/ofbiz/DirectControlServlet.java
src/com/brainfood/ofbiz/DirectControlServlet.java
View file @
0c5c7fe
...
...
@@ -81,6 +81,7 @@ import org.ofbiz.service.ServiceContainer;
import
org.apache.commons.csv.CSVFormat
;
import
org.apache.commons.csv.CSVRecord
;
import
org.apache.commons.csv.CSVPrinter
;
import
org.apache.commons.fileupload.MultipartStream
;
import
org.apache.commons.fileupload.ParameterParser
;
import
org.apache.http.HeaderElement
;
...
...
@@ -520,45 +521,28 @@ public class DirectControlServlet extends HttpServlet {
response
.
setContentType
(
"text/csv"
);
// Find the first list
List
<
Map
>
resList
=
null
;
List
<
Map
<
String
,
Object
>
>
resList
=
null
;
for
(
Object
o
:
result
.
values
())
{
if
(
o
instanceof
List
)
{
resList
=
(
List
<
Map
>)
o
;
resList
=
UtilGenerics
.
cast
(
o
)
;
break
;
}
}
}
if
(
resList
!=
null
)
{
if
(
UtilValidate
.
isNotEmpty
(
resList
)
)
{
PrintWriter
writer
=
response
.
getWriter
();
List
<
Map
>
data
=
null
;
if
(
resList
.
get
(
1
)
instanceof
List
)
{
data
=
(
List
<
Map
>)(
resList
.
get
(
1
));
}
else
{
data
=
resList
;
}
if
(
data
.
size
()
>
0
)
{
Set
keys
=
((
Map
)
data
.
get
(
0
)).
keySet
();
Iterator
hi
=
keys
.
iterator
();
StringBuffer
csvBuf
=
new
StringBuffer
();
while
(
hi
.
hasNext
())
{
csvBuf
.
append
(
hi
.
next
());
if
(
hi
.
hasNext
())
csvBuf
.
append
(
","
);
}
writer
.
println
(
csvBuf
);
for
(
Map
row
:
data
)
{
Iterator
i
=
keys
.
iterator
();
csvBuf
=
new
StringBuffer
();
while
(
i
.
hasNext
())
{
Object
val
=
row
.
get
(
i
.
next
());
if
(!
"null"
.
equals
(
""
+
val
))
csvBuf
.
append
(
val
);
if
(
i
.
hasNext
())
csvBuf
.
append
(
","
);
}
writer
.
println
(
csvBuf
);
Set
<
String
>
headerNameSet
=
resList
.
get
(
0
).
keySet
();
CSVFormat
csvFormat
=
CSVFormat
.
EXCEL
.
withHeader
(
headerNameSet
.
toArray
(
new
String
[
headerNameSet
.
size
()]));
CSVPrinter
csvPrinter
=
new
CSVPrinter
(
writer
,
csvFormat
);
for
(
Map
<
String
,
Object
>
csvLine:
resList
)
{
List
<
Object
>
csvData
=
new
ArrayList
<
Object
>(
headerNameSet
.
size
());
for
(
String
headerName:
headerNameSet
)
{
csvData
.
add
(
csvLine
.
get
(
headerName
));
}
csvPrinter
.
printRecord
(
csvData
.
toArray
(
new
Object
[
csvData
.
size
()]));
}
csvPrinter
.
flush
();
csvPrinter
.
close
();
writer
.
flush
();
writer
.
close
();
}
...
...
Please
register
or
sign in
to post a comment