Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李丛阳
education
Commits
9c84a878
Commit
9c84a878
authored
Jan 19, 2018
by
YangZhaoJun1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ppt转pdf java代码编译
parent
653cf840
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
168 additions
and
73 deletions
+168
-73
pom.xml
pom.xml
+14
-1
PptToPdf.java
...va/org/rcisoft/business/bchapter/controller/PptToPdf.java
+64
-0
BCodeFile.java
...main/java/org/rcisoft/business/bcode/model/BCodeFile.java
+0
-1
StudentFile.java
...in/java/org/rcisoft/business/bcode/model/StudentFile.java
+21
-0
BCodeService.java
...java/org/rcisoft/business/bcode/service/BCodeService.java
+2
-2
BCodeServiceImpl.java
...rcisoft/business/bcode/service/impl/BCodeServiceImpl.java
+23
-12
CompileUtil.java
src/main/java/org/rcisoft/core/util/CompileUtil.java
+44
-57
No files found.
pom.xml
View file @
9c84a878
...
...
@@ -341,7 +341,20 @@
<artifactId>
ganymed-ssh2-build
</artifactId>
<version>
210
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
19.0
</version>
</dependency>
<dependency>
<groupId>
com.github.livesense
</groupId>
<artifactId>
jodconverter-core
</artifactId>
<version>
1.0.5
</version>
</dependency>
</dependencies>
...
...
src/main/java/org/rcisoft/business/bchapter/controller/PptToPdf.java
0 → 100644
View file @
9c84a878
package
org
.
rcisoft
.
business
.
bchapter
.
controller
;
import
org.artofsolving.jodconverter.OfficeDocumentConverter
;
import
org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration
;
import
org.artofsolving.jodconverter.office.OfficeManager
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
/**
* Created by Administrator on 2018/1/19.
*/
public
class
PptToPdf
{
private
static
OfficeManager
officeManager
;
private
static
String
OFFICE_HOME
=
"D:/oppenOffice/openOffice"
;
private
static
int
port
[]
=
{
8100
};
public
void
convert2PDF
(
String
inputFile
,
String
outputFile
)
throws
FileNotFoundException
{
startService
();
System
.
out
.
println
(
"进行文档转换转换:"
+
inputFile
+
" --> "
+
outputFile
);
OfficeDocumentConverter
converter
=
new
OfficeDocumentConverter
(
officeManager
);
converter
.
convert
(
new
File
(
inputFile
),
new
File
(
outputFile
));
stopService
();
System
.
out
.
println
();
}
// 打开服务器
public
static
void
startService
()
{
DefaultOfficeManagerConfiguration
configuration
=
new
DefaultOfficeManagerConfiguration
();
try
{
System
.
out
.
println
(
"准备启动服务...."
);
configuration
.
setOfficeHome
(
OFFICE_HOME
);
// 设置OpenOffice.org安装目录
configuration
.
setPortNumbers
(
port
);
// 设置转换端口,默认为8100
configuration
.
setTaskExecutionTimeout
(
1000
*
60
*
5L
);
// 设置任务执行超时为5分钟
configuration
.
setTaskQueueTimeout
(
1000
*
60
*
60
*
24L
);
// 设置任务队列超时为24小时
officeManager
=
configuration
.
buildOfficeManager
();
officeManager
.
start
();
// 启动服务
System
.
out
.
println
(
"office转换服务启动成功!"
);
}
catch
(
Exception
ce
)
{
System
.
out
.
println
(
"office转换服务启动失败!详细信息:"
+
ce
);
}
}
// 关闭服务器
public
static
void
stopService
()
{
System
.
out
.
println
(
"关闭office转换服务...."
);
if
(
officeManager
!=
null
)
{
officeManager
.
stop
();
}
System
.
out
.
println
(
"关闭office转换成功!"
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
path
=
"C:/Users/Administrator/Desktop/"
;
PptToPdf
opc
=
new
PptToPdf
();
opc
.
convert2PDF
(
path
+
"abc.pptx"
,
path
+
"1.pdf"
);
}
}
src/main/java/org/rcisoft/business/bcode/model/BCodeFile.java
View file @
9c84a878
...
...
@@ -30,7 +30,6 @@ public class BCodeFile {
private
String
isFirstFile
;
private
String
studentName
;
/**
* 容器属性
*
...
...
src/main/java/org/rcisoft/business/bcode/model/StudentFile.java
0 → 100644
View file @
9c84a878
package
org
.
rcisoft
.
business
.
bcode
.
model
;
import
lombok.Data
;
import
java.util.List
;
/**
* Created by Administrator on 2018/1/19.
*/
@Data
public
class
StudentFile
{
private
String
studentName
;
/*0代表文件 1代表工程*/
private
String
projectOrFile
;
private
List
<
BCodeFile
>
project
;
private
BCodeFile
bCodeFile
;
}
src/main/java/org/rcisoft/business/bcode/service/BCodeService.java
View file @
9c84a878
package
org
.
rcisoft
.
business
.
bcode
.
service
;
import
org.rcisoft.business.bcode.model.BCodeFile
;
import
org.rcisoft.business.bcode.model.StudentFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
/**
...
...
@@ -33,5 +33,5 @@ public interface BCodeService {
String
exportFiles
(
String
slId
,
String
studentId
,
String
type
,
String
slCode
);
List
<
BCode
File
>
queryAllStudentCode
(
String
slId
,
String
chapterId
);
List
<
Student
File
>
queryAllStudentCode
(
String
slId
,
String
chapterId
);
}
src/main/java/org/rcisoft/business/bcode/service/impl/BCodeServiceImpl.java
View file @
9c84a878
...
...
@@ -7,6 +7,7 @@ import org.rcisoft.business.bchapter.entity.BChapter;
import
org.rcisoft.business.bcode.model.BCodeFile
;
import
org.rcisoft.business.bcode.model.BCodeLxc
;
import
org.rcisoft.business.bcode.model.CodeType
;
import
org.rcisoft.business.bcode.model.StudentFile
;
import
org.rcisoft.business.bcode.service.BCodeLxcService
;
import
org.rcisoft.business.bcode.service.BCodeService
;
import
org.rcisoft.business.brslstudent.dao.BRSlStudentRepository
;
...
...
@@ -165,7 +166,7 @@ public class BCodeServiceImpl implements BCodeService {
boolean
isFile
=
true
;
simpleCodeFile
=
new
BCodeFile
(
"0"
,
""
,
null
,
simplePath
.
getName
(),
IdGen
.
uuid
(),
"0"
,
""
);
//codeFile.add(simpleCodeFile);
getFileList
(
simplePath
,
codeFile
,
simpleCodeFile
,
isFile
,
""
);
getFileList
(
simplePath
,
codeFile
,
simpleCodeFile
,
isFile
);
}
/*容器是否已启动*/
byte
[]
results
=
rcRedisServiceImpl
.
getBytes
(
global
.
getLxcPrefix
()
+
lxc
.
getUserId
());
...
...
@@ -216,7 +217,7 @@ public class BCodeServiceImpl implements BCodeService {
* @param codeFile
* @throws IOException
*/
private
void
getFileList
(
File
files
,
List
<
BCodeFile
>
codeFile
,
BCodeFile
parentFile
,
boolean
isFile
,
String
studentName
)
throws
IOException
{
private
void
getFileList
(
File
files
,
List
<
BCodeFile
>
codeFile
,
BCodeFile
parentFile
,
boolean
isFile
)
throws
IOException
{
BCodeFile
bCodeFile
=
new
BCodeFile
();
bCodeFile
.
setContent
(
""
);
...
...
@@ -225,7 +226,6 @@ public class BCodeServiceImpl implements BCodeService {
bCodeFile
.
setName
(
files
.
getName
());
bCodeFile
.
setId
(
IdGen
.
uuid
());
bCodeFile
.
setPId
(
parentFile
.
getId
());
bCodeFile
.
setStudentName
(
studentName
);
codeFile
.
add
(
bCodeFile
);
if
(
files
.
isFile
()){
if
(
isFile
){
...
...
@@ -239,7 +239,7 @@ public class BCodeServiceImpl implements BCodeService {
bCodeFile
.
setFileType
(
"0"
);
File
[]
ffs
=
files
.
listFiles
();
for
(
File
ff
:
ffs
)
{
getFileList
(
ff
,
codeFile
,
bCodeFile
,
isFile
,
studentName
);
getFileList
(
ff
,
codeFile
,
bCodeFile
,
isFile
);
}
}
...
...
@@ -431,12 +431,14 @@ public class BCodeServiceImpl implements BCodeService {
@Override
public
List
<
BCodeFile
>
queryAllStudentCode
(
String
slId
,
String
chapterId
){
String
codePath
=
""
;
String
suffixName
=
""
;
public
List
<
StudentFile
>
queryAllStudentCode
(
String
slId
,
String
chapterId
){
List
<
StudentFile
>
studentFiles
=
new
ArrayList
<>();
BCodeFile
codeFile
=
null
;
List
<
BCodeFile
>
students
=
new
ArrayList
<>();
List
<
BChapter
>
bChapters
=
bChapterRepository
.
queryBchapterStudentById
(
chapterId
);
String
codePath
=
""
;
String
suffixName
=
""
;
for
(
BChapter
chapter
:
bChapters
)
{
if
(
chapter
.
getExperimentType
().
equals
(
"1"
))
{
//java单文件
codePath
=
global
.
getCOURSE_CODE_LOCATION
();
...
...
@@ -464,20 +466,29 @@ public class BCodeServiceImpl implements BCodeService {
if
(
file
.
exists
())
{
if
(
file
.
isFile
())
{
//单文件的处理
String
content
=
FileUtils
.
readFileToString
(
file
);
codeFile
=
new
BCodeFile
(
"0"
,
content
,
new
Date
(
file
.
lastModified
()),
file
.
getName
(),
IdGen
.
uuid
(),
"0"
,
""
,
studentName
,
null
);
students
.
add
(
codeFile
);
codeFile
=
new
BCodeFile
(
"0"
,
content
,
new
Date
(
file
.
lastModified
()),
file
.
getName
(),
IdGen
.
uuid
(),
"0"
,
""
,
null
);
StudentFile
studentFile
=
new
StudentFile
();
studentFile
.
setBCodeFile
(
codeFile
);
studentFile
.
setStudentName
(
studentName
);
studentFile
.
setProjectOrFile
(
"0"
);
studentFiles
.
add
(
studentFile
);
}
else
if
(
file
.
isDirectory
()){
//工程的处理
List
<
BCodeFile
>
codeFiles
=
new
ArrayList
<>();
BCodeFile
simpleCodeFile
=
null
;
boolean
isFile
=
true
;
simpleCodeFile
=
new
BCodeFile
(
"0"
,
""
,
null
,
file
.
getName
(),
IdGen
.
uuid
(),
"0"
,
""
);
getFileList
(
file
,
codeFiles
,
simpleCodeFile
,
isFile
,
studentName
);
getFileList
(
file
,
codeFiles
,
simpleCodeFile
,
isFile
);
StudentFile
studentFile
=
new
StudentFile
();
studentFile
.
setProject
(
codeFiles
);
studentFile
.
setStudentName
(
studentName
);
studentFile
.
setProjectOrFile
(
"1"
);
studentFiles
.
add
(
studentFile
);
}
}
}
catch
(
Exception
e
){
}
}
return
students
;
return
student
File
s
;
}
}
src/main/java/org/rcisoft/core/util/CompileUtil.java
View file @
9c84a878
...
...
@@ -10,21 +10,22 @@ public class CompileUtil {
* @return
*/
public
static
String
executeJavaCode
(
String
code
,
String
fileName
,
String
fileUrl
)
throws
Exception
{
writeCodeToFile
(
code
,
fileName
,
fileUrl
);
File
file
=
new
File
(
fileUrl
+
fileName
+
".java"
);
writeCodeToFile
(
code
,
fileName
,
fileUrl
);
//写文件
File
file
=
new
File
(
fileUrl
+
fileName
+
".java"
);
//java文件
//等待文件写完
while
(!
file
.
exists
())
{
Thread
.
sleep
(
10
);
}
File
dir
=
new
File
(
fileUrl
);
String
os
=
System
.
getProperty
(
"os.name"
);
String
command1
,
command2
;
String
java
,
java_class
;
//判断操作系统
if
(
os
.
toLowerCase
().
startsWith
(
"win"
))
{
command1
=
"c:\\Windows\\System32\\cmd.exe /c javac -encoding utf-8 "
+
fileName
+
".java"
;
command2
=
"c:\\Windows\\System32\\cmd.exe /c java "
+
fileName
;
java
=
"c:\\Windows\\System32\\cmd.exe /c javac -encoding utf-8 "
+
fileName
+
".java"
;
java_class
=
"c:\\Windows\\System32\\cmd.exe /c java "
+
fileName
;
}
else
{
command1
=
"javac -encoding utf-8 "
+
fileName
+
".java"
;
command2
=
"java "
+
fileName
;
java
=
"javac -encoding utf-8 "
+
fileName
+
".java"
;
java_class
=
"java "
+
fileName
;
}
Runtime
r1
=
Runtime
.
getRuntime
();
...
...
@@ -32,13 +33,14 @@ public class CompileUtil {
Boolean
comResult1
=
true
;
String
result
=
""
;
try
{
p1
=
r1
.
exec
(
command1
,
null
,
dir
);
//先编译java文件
p1
=
r1
.
exec
(
java
,
null
,
dir
);
InputStreamReader
ir
=
new
InputStreamReader
(
p1
.
getInputStream
(),
"GBK"
);
LineNumberReader
input
=
new
LineNumberReader
(
ir
);
StringBuilder
sb
=
new
StringBuilder
();
boolean
firstLine
=
true
;
String
line
;
//取出输出结果
while
((
line
=
input
.
readLine
())
!=
null
)
{
comResult1
=
false
;
if
(!
firstLine
){
...
...
@@ -50,65 +52,50 @@ public class CompileUtil {
}
input
.
close
();
ir
.
close
();
// result = new String(sb.toString().getBytes("iso8859-1"),"utf-8");
result
=
sb
.
toString
();
/*if(input.readLine()!=null) {
comResult1 = false;
}*/
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(!
comResult1
)
{
return
result
;
}
String
classUrl
=
fileUrl
+
fileName
+
".class"
;
File
classFile
=
new
File
(
classUrl
);
while
(!
classFile
.
exists
())
{
Thread
.
sleep
(
10
);
if
(!
comResult1
)
{
break
;
}
}
Runtime
r2
=
Runtime
.
getRuntime
();
Process
p2
=
null
;
try
{
p2
=
r2
.
exec
(
command2
,
null
,
dir
);
InputStreamReader
ir
=
new
InputStreamReader
(
p2
.
getInputStream
(),
"GBK"
);
LineNumberReader
input
=
new
LineNumberReader
(
ir
);
StringBuilder
sb
=
new
StringBuilder
();
boolean
firstLine
=
true
;
String
line
;
while
((
line
=
input
.
readLine
())
!=
null
)
{
if
(!
firstLine
){
sb
.
append
(
System
.
getProperty
(
"line.separator"
));
return
result
;
}
String
classUrl
=
fileUrl
+
fileName
+
".class"
;
File
classFile
=
new
File
(
classUrl
);
while
(!
classFile
.
exists
())
{
Thread
.
sleep
(
10
);
if
(!
comResult1
)
{
break
;
}
}
Runtime
r2
=
Runtime
.
getRuntime
();
Process
p2
=
null
;
p2
=
r2
.
exec
(
java_class
,
null
,
dir
);
InputStreamReader
isr
=
new
InputStreamReader
(
p2
.
getInputStream
(),
"GBK"
);
LineNumberReader
lnr
=
new
LineNumberReader
(
isr
);
StringBuilder
sbl
=
new
StringBuilder
();
boolean
firstLine2
=
true
;
String
line2
;
while
((
line2
=
lnr
.
readLine
())
!=
null
)
{
if
(!
firstLine2
){
sbl
.
append
(
System
.
getProperty
(
"line.separator"
));
}
else
{
firstLine
=
false
;
firstLine
2
=
false
;
}
sb
.
append
(
line
);
sb
l
.
append
(
line2
);
}
input
.
close
();
ir
.
close
();
// result = new String(sb.toString().getBytes("iso8859-1"),"utf-8");
result
=
sb
.
toString
();
//file.delete();
lnr
.
close
();
isr
.
close
();
result
=
sbl
.
toString
();
file
.
delete
();
classFile
.
delete
();
p2
.
waitFor
();
p2
.
destroy
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
result
=
"error"
;
}
p2
.
waitFor
();
p2
.
destroy
();
return
result
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment