Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theoexec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Constantin Jucovschi
theoexec
Commits
db71a9b9
Commit
db71a9b9
authored
11 years ago
by
Constantin Jucovschi
Browse files
Options
Downloads
Patches
Plain Diff
multiline data works now
parent
ffd4ae98
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pom.xml
+6
-0
6 additions, 0 deletions
pom.xml
src/main/java/info/kwarc/theo/Browser.java
+0
-53
0 additions, 53 deletions
src/main/java/info/kwarc/theo/Browser.java
src/main/java/info/kwarc/theo/TheoExec.java
+56
-2
56 additions, 2 deletions
src/main/java/info/kwarc/theo/TheoExec.java
with
62 additions
and
55 deletions
pom.xml
+
6
−
0
View file @
db71a9b9
...
...
@@ -39,5 +39,11 @@
<artifactId>
jcommander
</artifactId>
<version>
1.30
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.2.1
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/java/info/kwarc/theo/Browser.java
deleted
100644 → 0
+
0
−
53
View file @
ffd4ae98
package
info.kwarc.theo
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.List
;
public
class
Browser
{
final
String
script
=
"<HTML><BODY><script>var myForm = document.createElement(\"form\");\r\nmyForm.method = \"post\";\r\nmyForm.action = \"%s\";\r\n%s\r\ndocument.body.appendChild(myForm);\r\nmyForm.submit();\r\ndocument.body.removeChild(myForm);</script></BODY></HTML>"
;
final
String
paramScript
=
"var myInput = document.createElement(\"input\");\r\nmyInput.setAttribute(\"name\", \"%s\");\r\nmyInput.setAttribute(\"value\", \"%s\");\r\nmyForm.appendChild(myInput);\n"
;
void
execFirefox
(
String
filePath
)
{
Process
p
;
try
{
p
=
Runtime
.
getRuntime
().
exec
(
"firefox -P theo --newinstance -new-window "
+
filePath
);
p
.
waitFor
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
public
Browser
(
String
url
,
List
<
String
>
data
)
{
if
(
data
.
size
()
==
0
)
{
execFirefox
(
url
);
}
else
{
StringBuilder
paramSettings
=
new
StringBuilder
();
for
(
String
param
:
data
)
{
int
eq
=
param
.
indexOf
(
'='
);
if
(
eq
==
-
1
)
{
continue
;
}
String
key
=
param
.
substring
(
0
,
eq
);
String
val
=
param
.
substring
(
eq
+
1
);
paramSettings
.
append
(
String
.
format
(
paramScript
,
key
,
val
));
}
final
String
allScript
=
String
.
format
(
script
,
url
,
paramSettings
.
toString
());
try
{
File
temp
=
File
.
createTempFile
(
"temp"
,
".html"
);
FileWriter
fileoutput
=
new
FileWriter
(
temp
);
BufferedWriter
buffout
=
new
BufferedWriter
(
fileoutput
);
buffout
.
write
(
allScript
);
buffout
.
close
();
execFirefox
(
temp
.
getAbsolutePath
());
temp
.
deleteOnExit
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/info/kwarc/theo/TheoExec.java
+
56
−
2
View file @
db71a9b9
package
info.kwarc.theo
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
com.beust.jcommander.JCommander
;
import
com.beust.jcommander.Parameter
;
import
com.beust.jcommander.ParameterException
;
...
...
@@ -24,6 +30,52 @@ public class TheoExec {
@Parameter
(
names
=
"--data"
,
required
=
false
,
description
=
"POST data to be sent"
,
variableArity
=
true
)
public
List
<
String
>
data
=
new
ArrayList
<
String
>();
final
String
script
=
"<HTML><BODY><script>var myForm = document.createElement(\"form\");\r\nmyForm.method = \"post\";\r\nmyForm.action = \"%s\";\r\n%s\r\ndocument.body.appendChild(myForm);\r\nmyForm.submit();\r\ndocument.body.removeChild(myForm);</script></BODY></HTML>"
;
final
String
paramScript
=
"var myInput = document.createElement(\"input\");\r\nmyInput.setAttribute(\"name\", \"%s\");\r\nmyInput.setAttribute(\"value\", \"%s\");\r\nmyForm.appendChild(myInput);\n"
;
void
execFirefox
(
String
filePath
)
{
Process
p
;
try
{
String
cmd
=
"firefox -P theo --newinstance -new-window "
+
filePath
+
" -width "
+
width
+
" -height "
+
height
;
System
.
out
.
println
(
cmd
);
p
=
Runtime
.
getRuntime
().
exec
(
cmd
);
p
.
waitFor
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
public
void
process
(
)
{
if
(
data
.
size
()
==
0
)
{
execFirefox
(
url
);
}
else
{
StringBuilder
paramSettings
=
new
StringBuilder
();
for
(
String
param
:
data
)
{
int
eq
=
param
.
indexOf
(
'='
);
if
(
eq
==
-
1
)
{
continue
;
}
String
key
=
param
.
substring
(
0
,
eq
);
String
val
=
param
.
substring
(
eq
+
1
);
val
=
StringEscapeUtils
.
escapeEcmaScript
(
val
);
paramSettings
.
append
(
String
.
format
(
paramScript
,
key
,
val
));
}
final
String
allScript
=
String
.
format
(
script
,
url
,
paramSettings
.
toString
());
try
{
File
temp
=
File
.
createTempFile
(
"temp"
,
".html"
);
FileWriter
fileoutput
=
new
FileWriter
(
temp
);
BufferedWriter
buffout
=
new
BufferedWriter
(
fileoutput
);
buffout
.
write
(
allScript
);
buffout
.
close
();
execFirefox
(
temp
.
getAbsolutePath
());
temp
.
deleteOnExit
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
public
void
run
(
String
[]
args
)
{
JCommander
cmd
=
new
JCommander
(
this
);
try
{
...
...
@@ -33,11 +85,13 @@ public class TheoExec {
return
;
}
new
Browser
(
url
,
data
);
process
(
);
}
public
static
void
main
(
String
[]
args
){
//new TheoExec().run(new String[] {"--title", "hello", "--url", "http://localhost:8080/sider-nnexus/app/link", "--data", "forward_destination=123", "forward_correlation=123", "body=function"});
//new TheoExec().run(new String[] {"--url" , "http://mathhub.info:8983/defindexer/app/search?forward_destination=/queue/sublime_client_f0ae6362-42c8-4faf-bd1b-83d53c2f8644&forward_correlation=69401.0"});
new
TheoExec
().
run
(
args
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment