Compare commits
108 commits
Author | SHA1 | Date | |
---|---|---|---|
72f2892d30 | |||
0bb7490ac2 | |||
ff556c19dd | |||
a6e85d367a | |||
19b17c5b58 | |||
7d03b2a02d | |||
56a44ea1fd | |||
f5bf88532d | |||
1454d68b4a | |||
f0c43c83e3 | |||
8247b4f976 | |||
9fae696122 | |||
63de83dad1 | |||
a5a311136f | |||
4e1ca75a4a | |||
2b1c69e85e | |||
2ff537d384 | |||
2324e6815b | |||
639fea75e1 | |||
7cc2ba2d4d | |||
9a4f2eda97 | |||
c44b41ad8a | |||
7be5e479dc | |||
334c569332 | |||
8b676491fe | |||
f88a4a17a4 | |||
c417b4fcd0 | |||
0f9bce9037 | |||
1de23921d5 | |||
237416dc43 | |||
5566e5ff43 | |||
80b7005066 | |||
8e81b3511c | |||
401bfc67ec | |||
3191be6e53 | |||
1820a88c80 | |||
9bca9103d3 | |||
d3c1ecbed7 | |||
86bbdab7c5 | |||
027106e1b7 | |||
c5631e06b1 | |||
9d007c9188 | |||
8621834a5b | |||
1d4ce4e100 | |||
505fbd23cd | |||
d6c36e1012 | |||
b400d98380 | |||
c79fc809f2 | |||
56a262caee | |||
253007416e | |||
5f1b0bd3d8 | |||
a43e8803cb | |||
34fc3f506c | |||
e7e7139251 | |||
5a561d987b | |||
085735e509 | |||
7db145b987 | |||
eaa1078cd3 | |||
23f7544948 | |||
6cc9ffcfa6 | |||
8424511e9b | |||
b7aced55ab | |||
a4d510caa7 | |||
0babf899ee | |||
c79b2a9f9e | |||
568865ab42 | |||
48f8902bc7 | |||
d2cfbb40b7 | |||
710e89cc5d | |||
2a03ae2c2a | |||
be88aec977 | |||
450b76470c | |||
20f7e21595 | |||
37699b8b5a | |||
be7047683d | |||
187f3d1eb4 | |||
0680742212 | |||
f223b2ef9b | |||
29d275e26d | |||
6ad91477cc | |||
9a66e68dca | |||
c2953f7f68 | |||
93592950dd | |||
fc43ce34e4 | |||
e6fbee9f67 | |||
22ba9e1077 | |||
6aeeed4b54 | |||
d7d4b4083e | |||
e2d03d7f93 | |||
9898cbc5ed | |||
44ffd9f3ed | |||
17bf5a9259 | |||
89f2807f4e | |||
4ecae8efcb | |||
b05df6b2a6 | |||
84bfd16d02 | |||
50313e5f64 | |||
8b4103a8f5 | |||
6eeaebecf4 | |||
d96897d5ae | |||
3f7fbe076a | |||
f4027a339c | |||
da9326a19e | |||
80441c4ad9 | |||
642500a4ba | |||
b6a3aec8d7 | |||
b60088711e | |||
63e5d5936c |
291 changed files with 4589 additions and 15612 deletions
|
@ -1,11 +1,11 @@
|
|||
image: gradle:alpine
|
||||
image: gradle:jdk11-alpine
|
||||
|
||||
stages:
|
||||
- build
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script: gradle jar && gradle oxt
|
||||
script: ./gradlew regressionTests && ./gradlew jar && ./gradlew oxt
|
||||
artifacts:
|
||||
paths:
|
||||
- build/distributions/w2phtml.oxt
|
||||
|
|
27
.project
27
.project
|
@ -2,22 +2,21 @@
|
|||
<projectDescription>
|
||||
<name>w2phtml</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<projects/>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<linkedResources/>
|
||||
<filteredResources/>
|
||||
</projectDescription>
|
||||
|
|
124
build.gradle
124
build.gradle
|
@ -1,4 +1,5 @@
|
|||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
repositories{
|
||||
mavenCentral()
|
||||
}
|
||||
|
@ -11,27 +12,41 @@ properties.setProperty('releaseVersion', project.version )
|
|||
mkdir "src/main/tmp/w2phtml"
|
||||
propertyDestFile.withWriter { properties.store(it, null) }
|
||||
|
||||
sourceSets {
|
||||
regressionTests {
|
||||
java {
|
||||
compileClasspath += main.output + test.output
|
||||
runtimeClasspath += main.output + test.output + files('src/main/java')
|
||||
srcDir file('src/r_tests/java')
|
||||
}
|
||||
}
|
||||
}
|
||||
sourceCompatibility = 1.8
|
||||
configurations{
|
||||
bundledLibs
|
||||
regressionTestsCompile.extendsFrom mainCompile
|
||||
regressionTestsRuntime.extendsFrom mainRuntime
|
||||
regressionTestsRuntime.extendsFrom compileClasspath
|
||||
regressionTestsImplementation.extendsFrom compileClasspath
|
||||
}
|
||||
dependencies{
|
||||
bundledLibs 'org.libreoffice:jurt:5.3.2'
|
||||
bundledLibs 'org.libreoffice:juh:5.3.2'
|
||||
bundledLibs 'org.libreoffice:ridl:5.3.2'
|
||||
bundledLibs 'org.libreoffice:unoil:5.3.2'
|
||||
bundledLibs 'org.json:json:20190722'
|
||||
bundledLibs group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
|
||||
bundledLibs group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
|
||||
compile 'junit:junit:4.12'
|
||||
bundledLibs group: 'com.miglayout', name: 'miglayout-swing', version: '5.2'
|
||||
bundledLibs group: 'org.apache.jena', name: 'jena-core', version: '3.15.0'
|
||||
bundledLibs group: 'org.apache.jena', name: 'jena-arq', version: '3.15.0'
|
||||
bundledLibs group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
|
||||
bundledLibs group: 'com.opencsv', name: 'opencsv', version: '5.1'
|
||||
bundledLibs group: 'org.apache.commons', name: 'commons-imaging', version: '1.0-alpha2'
|
||||
regressionTestsImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.1'
|
||||
regressionTestsImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.7.1'
|
||||
regressionTestsImplementation 'org.junit.jupiter:junit-jupiter-engine'
|
||||
|
||||
compileClasspath 'org.libreoffice:jurt:5.3.2'
|
||||
compileClasspath 'org.libreoffice:juh:5.3.2'
|
||||
compileClasspath 'org.libreoffice:ridl:5.3.2'
|
||||
compileClasspath 'org.libreoffice:unoil:5.3.2'
|
||||
compileClasspath 'org.json:json:20190722'
|
||||
compileClasspath group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
|
||||
compileClasspath group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
|
||||
compileClasspath group: 'com.miglayout', name: 'miglayout-swing', version: '5.2'
|
||||
compileClasspath group: 'org.apache.jena', name: 'jena-core', version: '3.15.0'
|
||||
compileClasspath group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
|
||||
compileClasspath group: 'com.opencsv', name: 'opencsv', version: '5.1'
|
||||
compileClasspath group: 'org.imgscalr', name: 'imgscalr-lib', version: '4.2'
|
||||
compileClasspath group: 'org.apache.commons', name: 'commons-imaging', version: '1.0-alpha2'
|
||||
|
||||
configurations.compile.extendsFrom(configurations.bundledLibs)
|
||||
}
|
||||
jar {
|
||||
archiveName 'w2phtml.jar'
|
||||
|
@ -42,8 +57,9 @@ jar {
|
|||
"Class-Path" : "jasp.jar parser.jar")
|
||||
}
|
||||
|
||||
duplicatesStrategy = 'exclude'
|
||||
from {
|
||||
configurations.bundledLibs.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
from('src/main/java') {
|
||||
include '**/*.properties'
|
||||
|
@ -60,45 +76,6 @@ jar {
|
|||
}
|
||||
}
|
||||
task xhtml(type: Jar) {
|
||||
manifest {
|
||||
attributes("Implementation-Title": rootProject.name,
|
||||
"Implementation-Version": project.version,
|
||||
"RegistrationClassName" : "org.openoffice.da.comp.writer2xhtml.W2XRegistration",
|
||||
"Class-Path" : "jasp.jar parser.jar")
|
||||
}
|
||||
baseName = "writer2xhtml-filter"
|
||||
from {
|
||||
configurations.bundledLibs.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
}
|
||||
}
|
||||
from sourceSets.main.output
|
||||
exclude '.gradle'
|
||||
exclude '**/*Test.class'
|
||||
exclude '**/AllTests.class'
|
||||
exclude '**/*.java'
|
||||
include 'w2phtml/pageSplitters/**/*.class'
|
||||
include 'pro/litvinovg/**/*.class'
|
||||
include 'org/openoffice/da/comp/wl2common/**/*.class'
|
||||
include 'org/openoffice/da/comp/writer2xhtml/**/*.class'
|
||||
include 'org/openoffice/da/comp/wl2common/**/*.properties'
|
||||
include 'w2phtml/api/**/*.class'
|
||||
include 'w2phtml/base/**/*.class'
|
||||
include 'w2phtml/epub/**/*.class'
|
||||
include 'w2phtml/office/**/*.class'
|
||||
include 'w2phtml/util/**/*.class'
|
||||
include 'w2phtml/xhtml/**/*.class'
|
||||
include 'w2phtml/xhtml/**/*.xml'
|
||||
include 'w2phtml/xmerge/**/*.class'
|
||||
from 'src/main/java'
|
||||
include 'w2phtml/xhtml/**/*.properties'
|
||||
include 'w2phtml/xhtml/**/**/*.properties'
|
||||
from sourceSets.main.output
|
||||
include 'org/**/*'
|
||||
include 'net/**/*'
|
||||
}
|
||||
|
||||
task xhtml2(type: Jar) {
|
||||
archiveName 'writer2phtml.jar'
|
||||
manifest {
|
||||
attributes("Implementation-Title": rootProject.name,
|
||||
|
@ -106,9 +83,10 @@ task xhtml2(type: Jar) {
|
|||
"RegistrationClassName" : "pro.litvinovg.w2phtml.RegistrationHandler",
|
||||
"Class-Path" : "jasp.jar parser.jar")
|
||||
}
|
||||
duplicatesStrategy = 'exclude'
|
||||
baseName = "writer2phtml"
|
||||
from {
|
||||
configurations.bundledLibs.collect {
|
||||
configurations.compileClasspath.collect {
|
||||
exclude 'module-info.class'
|
||||
exclude '.gradle'
|
||||
exclude '**/LICENSE*'
|
||||
|
@ -129,6 +107,7 @@ task xhtml2(type: Jar) {
|
|||
include 'etc/*'
|
||||
include 'com/**'
|
||||
include 'com/**/*'
|
||||
exclude '**/DEPENDENCIES'
|
||||
include 'w2phtml/pageSplitters/**/*.class'
|
||||
include 'pro/litvinovg/**/*.class'
|
||||
include 'pro/litvinovg/**/*.png'
|
||||
|
@ -151,12 +130,14 @@ task xhtml2(type: Jar) {
|
|||
exclude '.gradle'
|
||||
}
|
||||
from ('src/main/java'){
|
||||
exclude '**/DEPENDENCIES'
|
||||
exclude '.gradle'
|
||||
include 'w2phtml/xhtml/**/*.properties'
|
||||
include 'w2phtml/xhtml/**/**/*.properties'
|
||||
include 'pro/litvinovg/**/*.classes'
|
||||
include 'logback.xml'
|
||||
include '**/*.png'
|
||||
include 'pro/litvinovg/w2phtml/gui/localizations/*.properties'
|
||||
exclude 'w2phtml/project.properties'
|
||||
}
|
||||
from('src/main/tmp') {
|
||||
|
@ -169,21 +150,7 @@ task xhtml2(type: Jar) {
|
|||
task oxt(type: Zip){
|
||||
dependsOn = [ 'xhtml', 'setVersion' ]
|
||||
archiveName 'w2phtml.oxt'
|
||||
from 'src/main/oxt'
|
||||
include '*'
|
||||
include '**'
|
||||
from 'build/libs/writer2xhtml-filter.jar'
|
||||
include '*'
|
||||
from 'src/main/idl/writer2xhtml'
|
||||
include 'writer2xhtml.rdb'
|
||||
from 'releasenotes.txt'
|
||||
include '*'
|
||||
}
|
||||
|
||||
task oxtNew(type: Zip){
|
||||
dependsOn = [ 'xhtml2', 'setVersion' ]
|
||||
archiveName 'w2phtml-new.oxt'
|
||||
from ('src/main/oxt2'){
|
||||
from ('src/main/oxt'){
|
||||
include '*'
|
||||
include '**'
|
||||
exclude '.gradle'
|
||||
|
@ -195,14 +162,23 @@ task oxtNew(type: Zip){
|
|||
from ('build/libs/writer2phtml.jar'){
|
||||
include '*'
|
||||
}
|
||||
from 'idl/writer2paginatedhtml.rdb'
|
||||
from 'releasenotes.txt'
|
||||
include '*'
|
||||
}
|
||||
|
||||
task regressionTests(type: Test) {
|
||||
testClassesDirs = sourceSets.regressionTests.output.classesDirs
|
||||
classpath = sourceSets.regressionTests.runtimeClasspath
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed", "standardOut", "standardError"
|
||||
}
|
||||
mustRunAfter jar
|
||||
}
|
||||
|
||||
task setVersion(){
|
||||
ant.taskdef(name: 'xmltask', classpath: 'buildPlugins/xmltask.jar', classname: 'com.oopsconsultancy.xmltask.ant.XmlTask')
|
||||
ant.xmltask(source: 'src/main/oxt2/description.xml', dest: 'src/main/tmp/description.xml', report:'true') {
|
||||
ant.xmltask(source: 'src/main/oxt/description.xml', dest: 'src/main/tmp/description.xml', report:'true') {
|
||||
replace(path: "//*[local-name()='version']/@value", withText: "${project.version}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
version=0.9.11
|
||||
version=0.9.29
|
||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#Wed Feb 24 17:29:34 CET 2021
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
|
172
gradlew
vendored
Executable file
172
gradlew
vendored
Executable file
|
@ -0,0 +1,172 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
gradlew.bat
vendored
Normal file
84
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -1,52 +0,0 @@
|
|||
#ifndef __org_openoffice_da_writer2xhtml_XBatchConverter_idl__
|
||||
#define __org_openoffice_da_writer2xhtml_XBatchConverter_idl__
|
||||
#include <com/sun/star/uno/XInterface.idl>
|
||||
#include <com/sun/star/beans/PropertyValue.idl>
|
||||
|
||||
module org { module openoffice { module da { module writer2xhtml {
|
||||
|
||||
// This interface is an IDL version of the java interface (writer2latex.api.BatchHandler)
|
||||
interface XBatchHandler : com::sun::star::uno::XInterface
|
||||
{
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::startConversion
|
||||
void startConversion ();
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::endConversion
|
||||
void endConversion ();
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::startDirectory
|
||||
void startDirectory ( [in] string sName );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::endDirectory
|
||||
void endDirectory ( [in] string sName, [in] boolean bSuccess );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::startFile
|
||||
void startFile ( [in] string sName );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::endFile
|
||||
void endFile ( [in] string sName, [in] boolean bSuccess );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::cancel
|
||||
boolean cancel ();
|
||||
|
||||
};
|
||||
|
||||
// This interface is an IDL version of the java interface (writer2latex.api.BatchConverter)
|
||||
interface XBatchConverter : com::sun::star::uno::XInterface
|
||||
{
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchConverter::convert
|
||||
void convert ( [in] string sSourceURL,
|
||||
[in] string sTargetURL,
|
||||
[in] sequence< com::sun::star::beans::PropertyValue > lArguments,
|
||||
[in] XBatchHandler handler );
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
}; }; }; };
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#ifndef __org_libreoffice_example_writer2latex_idl__
|
||||
#define __org_libreoffice_example_writer2latex_idl__
|
||||
|
||||
#include <org/libreoffice/example/XWriter2latex.idl>
|
||||
module org { module libreoffice { module example {
|
||||
|
||||
service Writer2latex : org::libreoffice::example::XWriter2latex {
|
||||
|
||||
};
|
||||
|
||||
}; }; };
|
||||
#endif
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef __org_libreoffice_example_xwriter2latex_idl__
|
||||
#define __org_libreoffice_example_xwriter2latex_idl__
|
||||
|
||||
module org { module libreoffice { module example {
|
||||
|
||||
interface XWriter2latex {
|
||||
|
||||
};
|
||||
|
||||
}; }; };
|
||||
#endif
|
|
@ -1,13 +0,0 @@
|
|||
package org.libreoffice.example;
|
||||
|
||||
|
||||
/**
|
||||
* org/libreoffice/example/XWriter2latex.java .
|
||||
* Generated by the IDL-to-Java compiler (portable), version "3.2"
|
||||
* from XWriter2latex.idl
|
||||
* Friday, 7 July 2017 12:51:34 o'clock MSK
|
||||
*/
|
||||
|
||||
public interface XWriter2latex extends XWriter2latexOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity
|
||||
{
|
||||
} // interface XWriter2latex
|
|
@ -1,85 +0,0 @@
|
|||
package org.libreoffice.example;
|
||||
|
||||
|
||||
/**
|
||||
* org/libreoffice/example/XWriter2latexHelper.java .
|
||||
* Generated by the IDL-to-Java compiler (portable), version "3.2"
|
||||
* from XWriter2latex.idl
|
||||
* Friday, 7 July 2017 12:51:34 o'clock MSK
|
||||
*/
|
||||
|
||||
abstract public class XWriter2latexHelper
|
||||
{
|
||||
private static String _id = "IDL:org/libreoffice/example/XWriter2latex:1.0";
|
||||
|
||||
public static void insert (org.omg.CORBA.Any a, org.libreoffice.example.XWriter2latex that)
|
||||
{
|
||||
org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();
|
||||
a.type (type ());
|
||||
write (out, that);
|
||||
a.read_value (out.create_input_stream (), type ());
|
||||
}
|
||||
|
||||
public static org.libreoffice.example.XWriter2latex extract (org.omg.CORBA.Any a)
|
||||
{
|
||||
return read (a.create_input_stream ());
|
||||
}
|
||||
|
||||
private static org.omg.CORBA.TypeCode __typeCode = null;
|
||||
synchronized public static org.omg.CORBA.TypeCode type ()
|
||||
{
|
||||
if (__typeCode == null)
|
||||
{
|
||||
__typeCode = org.omg.CORBA.ORB.init ().create_interface_tc (org.libreoffice.example.XWriter2latexHelper.id (), "XWriter2latex");
|
||||
}
|
||||
return __typeCode;
|
||||
}
|
||||
|
||||
public static String id ()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public static org.libreoffice.example.XWriter2latex read (org.omg.CORBA.portable.InputStream istream)
|
||||
{
|
||||
return narrow (istream.read_Object (_XWriter2latexStub.class));
|
||||
}
|
||||
|
||||
public static void write (org.omg.CORBA.portable.OutputStream ostream, org.libreoffice.example.XWriter2latex value)
|
||||
{
|
||||
ostream.write_Object ((org.omg.CORBA.Object) value);
|
||||
}
|
||||
|
||||
public static org.libreoffice.example.XWriter2latex narrow (org.omg.CORBA.Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
else if (obj instanceof org.libreoffice.example.XWriter2latex)
|
||||
return (org.libreoffice.example.XWriter2latex)obj;
|
||||
else if (!obj._is_a (id ()))
|
||||
throw new org.omg.CORBA.BAD_PARAM ();
|
||||
else
|
||||
{
|
||||
org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
|
||||
org.libreoffice.example._XWriter2latexStub stub = new org.libreoffice.example._XWriter2latexStub ();
|
||||
stub._set_delegate(delegate);
|
||||
return stub;
|
||||
}
|
||||
}
|
||||
|
||||
public static org.libreoffice.example.XWriter2latex unchecked_narrow (org.omg.CORBA.Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
else if (obj instanceof org.libreoffice.example.XWriter2latex)
|
||||
return (org.libreoffice.example.XWriter2latex)obj;
|
||||
else
|
||||
{
|
||||
org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
|
||||
org.libreoffice.example._XWriter2latexStub stub = new org.libreoffice.example._XWriter2latexStub ();
|
||||
stub._set_delegate(delegate);
|
||||
return stub;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package org.libreoffice.example;
|
||||
|
||||
/**
|
||||
* org/libreoffice/example/XWriter2latexHolder.java .
|
||||
* Generated by the IDL-to-Java compiler (portable), version "3.2"
|
||||
* from XWriter2latex.idl
|
||||
* Friday, 7 July 2017 12:51:34 o'clock MSK
|
||||
*/
|
||||
|
||||
public final class XWriter2latexHolder implements org.omg.CORBA.portable.Streamable
|
||||
{
|
||||
public org.libreoffice.example.XWriter2latex value = null;
|
||||
|
||||
public XWriter2latexHolder ()
|
||||
{
|
||||
}
|
||||
|
||||
public XWriter2latexHolder (org.libreoffice.example.XWriter2latex initialValue)
|
||||
{
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
public void _read (org.omg.CORBA.portable.InputStream i)
|
||||
{
|
||||
value = org.libreoffice.example.XWriter2latexHelper.read (i);
|
||||
}
|
||||
|
||||
public void _write (org.omg.CORBA.portable.OutputStream o)
|
||||
{
|
||||
org.libreoffice.example.XWriter2latexHelper.write (o, value);
|
||||
}
|
||||
|
||||
public org.omg.CORBA.TypeCode _type ()
|
||||
{
|
||||
return org.libreoffice.example.XWriter2latexHelper.type ();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package org.libreoffice.example;
|
||||
|
||||
|
||||
/**
|
||||
* org/libreoffice/example/XWriter2latexOperations.java .
|
||||
* Generated by the IDL-to-Java compiler (portable), version "3.2"
|
||||
* from XWriter2latex.idl
|
||||
* Friday, 7 July 2017 12:51:34 o'clock MSK
|
||||
*/
|
||||
|
||||
public interface XWriter2latexOperations
|
||||
{
|
||||
} // interface XWriter2latexOperations
|
|
@ -1,50 +0,0 @@
|
|||
package org.libreoffice.example;
|
||||
|
||||
|
||||
/**
|
||||
* org/libreoffice/example/_XWriter2latexStub.java .
|
||||
* Generated by the IDL-to-Java compiler (portable), version "3.2"
|
||||
* from XWriter2latex.idl
|
||||
* Friday, 7 July 2017 12:51:34 o'clock MSK
|
||||
*/
|
||||
|
||||
public class _XWriter2latexStub extends org.omg.CORBA.portable.ObjectImpl implements org.libreoffice.example.XWriter2latex
|
||||
{
|
||||
|
||||
// Type-specific CORBA::Object operations
|
||||
private static String[] __ids = {
|
||||
"IDL:org/libreoffice/example/XWriter2latex:1.0"};
|
||||
|
||||
public String[] _ids ()
|
||||
{
|
||||
return (String[])__ids.clone ();
|
||||
}
|
||||
|
||||
private void readObject (java.io.ObjectInputStream s) throws java.io.IOException
|
||||
{
|
||||
String str = s.readUTF ();
|
||||
String[] args = null;
|
||||
java.util.Properties props = null;
|
||||
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, props);
|
||||
try {
|
||||
org.omg.CORBA.Object obj = orb.string_to_object (str);
|
||||
org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl) obj)._get_delegate ();
|
||||
_set_delegate (delegate);
|
||||
} finally {
|
||||
orb.destroy() ;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeObject (java.io.ObjectOutputStream s) throws java.io.IOException
|
||||
{
|
||||
String[] args = null;
|
||||
java.util.Properties props = null;
|
||||
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, props);
|
||||
try {
|
||||
String str = orb.object_to_string (this);
|
||||
s.writeUTF (str);
|
||||
} finally {
|
||||
orb.destroy() ;
|
||||
}
|
||||
}
|
||||
} // class _XWriter2latexStub
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,30 +0,0 @@
|
|||
This directory contains idl specifications for the custom uno interfaces
|
||||
defined by the Writer2LaTeX and Writer2xhtml extensions
|
||||
|
||||
To avoid dependencies on the OOo SDK in the build process, compiled versions
|
||||
are included here.
|
||||
|
||||
If you need to rebuild it, the complete SDK is required. These are the steps:
|
||||
|
||||
To create the registry database for Writer2LaTeX:
|
||||
|
||||
idlc -I<path to SDK>\idl XW2LStarMathConverter.idl
|
||||
regmerge writer2latex.rdb /UCR XW2LStarMathConverter.urd
|
||||
|
||||
To create the java interface
|
||||
|
||||
javamaker -BUCR -Torg.openoffice.da.writer2latex.XW2LStarMathConverter -nD <path to the OOo installation>\program\types.rdb writer2latex.rdb
|
||||
|
||||
and likewise for Writer2xhtml:
|
||||
|
||||
idlc -I<path to SDK>\idl XBatchConverter.idl
|
||||
regmerge writer2xhtml.rdb /UCR XBatchConverter.urd
|
||||
|
||||
To create the java interfaces
|
||||
|
||||
javamaker -BUCR -Torg.openoffice.da.writer2xhtml.XBatchConverter -nD <path to the OOo installation>\program\types.rdb writer2xhtml.rdb
|
||||
javamaker -BUCR -Torg.openoffice.da.writer2xhtml.XBatchHandler -nD <path to the OOo installation>\program\types.rdb writer2xhtml.rdb
|
||||
|
||||
|
||||
If you need to use the interfaces from C++ you will also need to run cppumaker
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef __org_openoffice_da_writer2latex_XW2LStarMathConverter_idl__
|
||||
#define __org_openoffice_da_writer2latex_XW2LStarMathConverter_idl__
|
||||
#include <com/sun/star/uno/XInterface.idl>
|
||||
|
||||
module org { module openoffice { module da { module writer2latex {
|
||||
|
||||
interface XW2LStarMathConverter : com::sun::star::uno::XInterface
|
||||
{
|
||||
|
||||
// method org::openoffice::da::writer2latex::XW2LStarMathConverter::convertFormula
|
||||
string convertFormula ( [in] string sStarMathFormula );
|
||||
|
||||
// method org::openoffice::da::writer2latex::XW2LStarMathConverter::getPreamble
|
||||
string getPreamble ( );
|
||||
|
||||
};
|
||||
|
||||
}; }; }; };
|
||||
|
||||
#endif
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
|
@ -1,52 +0,0 @@
|
|||
#ifndef __org_openoffice_da_writer2xhtml_XBatchConverter_idl__
|
||||
#define __org_openoffice_da_writer2xhtml_XBatchConverter_idl__
|
||||
#include <com/sun/star/uno/XInterface.idl>
|
||||
#include <com/sun/star/beans/PropertyValue.idl>
|
||||
|
||||
module org { module openoffice { module da { module writer2xhtml {
|
||||
|
||||
// This interface is an IDL version of the java interface (writer2latex.api.BatchHandler)
|
||||
interface XBatchHandler : com::sun::star::uno::XInterface
|
||||
{
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::startConversion
|
||||
void startConversion ();
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::endConversion
|
||||
void endConversion ();
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::startDirectory
|
||||
void startDirectory ( [in] string sName );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::endDirectory
|
||||
void endDirectory ( [in] string sName, [in] boolean bSuccess );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::startFile
|
||||
void startFile ( [in] string sName );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::endFile
|
||||
void endFile ( [in] string sName, [in] boolean bSuccess );
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchHandler::cancel
|
||||
boolean cancel ();
|
||||
|
||||
};
|
||||
|
||||
// This interface is an IDL version of the java interface (writer2latex.api.BatchConverter)
|
||||
interface XBatchConverter : com::sun::star::uno::XInterface
|
||||
{
|
||||
|
||||
// method org::openoffice::da::writer2xhtml::XBatchConverter::convert
|
||||
void convert ( [in] string sSourceURL,
|
||||
[in] string sTargetURL,
|
||||
[in] sequence< com::sun::star::beans::PropertyValue > lArguments,
|
||||
[in] XBatchHandler handler );
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
}; }; }; };
|
||||
|
||||
#endif
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,187 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* ByteArrayXStream.java
|
||||
*
|
||||
* Copyright: 2002-2008 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.0 (2008-07-22)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
// This class is based on these java uno adapter classes:
|
||||
// com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter;
|
||||
// com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter;
|
||||
// See http://go-oo.org/lxr/source/udk/javaunohelper/com/sun/star/lib/uno/adapter/XOutputStreamToByteArrayAdapter.java
|
||||
// and http://go-oo.org/lxr/source/udk/javaunohelper/com/sun/star/lib/uno/adapter/ByteArrayToXInputStreamAdapter.java
|
||||
// for original source
|
||||
|
||||
import com.sun.star.io.XInputStream;
|
||||
import com.sun.star.io.XOutputStream;
|
||||
import com.sun.star.io.XSeekable;
|
||||
import com.sun.star.io.XStream;
|
||||
|
||||
/** <p>This is a java-uno adapter class which implements XStream using a
|
||||
* byte array. (We need this because XGraphicProvider demans read/write access
|
||||
* when storing a graphic to a stream.)</p>
|
||||
*/
|
||||
public class ByteArrayXStream implements XInputStream, XOutputStream, XSeekable, XStream {
|
||||
|
||||
// Keep data about our byte array (we read and write to the same byte array)
|
||||
|
||||
private int initialSize = 100240; // 10 kb
|
||||
private int size = 0; // The current buffer size
|
||||
private int position = 0; // The current write position, always<=size
|
||||
private int readPosition = 0; // The current read position, always<=position
|
||||
private boolean closed = false; // The XStream is closed
|
||||
private byte[] buffer; // The buffer
|
||||
|
||||
// Constructor: Initialize the byte array
|
||||
|
||||
public ByteArrayXStream() {
|
||||
size = initialSize;
|
||||
buffer = new byte[size];
|
||||
}
|
||||
|
||||
// Implementation of XOutputStream
|
||||
|
||||
public void closeOutput()
|
||||
throws com.sun.star.io.NotConnectedException,
|
||||
com.sun.star.io.BufferSizeExceededException,
|
||||
com.sun.star.io.IOException {
|
||||
|
||||
// trim buffer
|
||||
if ( buffer.length > position) {
|
||||
byte[] newBuffer = new byte[position];
|
||||
System.arraycopy(buffer, 0, newBuffer, 0, position);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
|
||||
public void flush()
|
||||
throws com.sun.star.io.NotConnectedException,
|
||||
com.sun.star.io.BufferSizeExceededException,
|
||||
com.sun.star.io.IOException {
|
||||
}
|
||||
|
||||
public void writeBytes(byte[] values)
|
||||
throws com.sun.star.io.NotConnectedException,
|
||||
com.sun.star.io.BufferSizeExceededException,
|
||||
com.sun.star.io.IOException {
|
||||
if ( values.length > size-position ) {
|
||||
byte[] newBuffer = null;
|
||||
while ( values.length > size-position )
|
||||
size *= 2;
|
||||
newBuffer = new byte[size];
|
||||
System.arraycopy(buffer, 0, newBuffer, 0, position);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
System.arraycopy(values, 0, buffer, position, values.length);
|
||||
position += values.length;
|
||||
}
|
||||
|
||||
// Implementation of XInputStream
|
||||
|
||||
private void _check() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
|
||||
if(closed) {
|
||||
throw new com.sun.star.io.IOException("input closed");
|
||||
}
|
||||
}
|
||||
|
||||
public int available() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
|
||||
_check();
|
||||
return position - readPosition;
|
||||
}
|
||||
|
||||
public void closeInput() throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException {
|
||||
closed = true;
|
||||
}
|
||||
|
||||
public int readBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
|
||||
_check();
|
||||
try {
|
||||
int remain = (int)(position - readPosition);
|
||||
if (param > remain) param = remain;
|
||||
/* ARGH!!! */
|
||||
if (values[0] == null){
|
||||
values[0] = new byte[param];
|
||||
// System.err.println("allocated new buffer of "+param+" bytes");
|
||||
}
|
||||
System.arraycopy(buffer, readPosition, values[0], 0, param);
|
||||
// System.err.println("readbytes() -> "+param);
|
||||
readPosition += param;
|
||||
return param;
|
||||
} catch (ArrayIndexOutOfBoundsException ae) {
|
||||
// System.err.println("readbytes() -> ArrayIndexOutOfBounds");
|
||||
ae.printStackTrace();
|
||||
throw new com.sun.star.io.BufferSizeExceededException("buffer overflow");
|
||||
} catch (Exception e) {
|
||||
// System.err.println("readbytes() -> Exception: "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
throw new com.sun.star.io.IOException("error accessing buffer");
|
||||
}
|
||||
}
|
||||
|
||||
public int readSomeBytes(byte[][] values, int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
|
||||
// System.err.println("readSomebytes()");
|
||||
return readBytes(values, param);
|
||||
}
|
||||
|
||||
public void skipBytes(int param) throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException {
|
||||
// System.err.println("skipBytes("+param+")");
|
||||
_check();
|
||||
if (param > (position - readPosition))
|
||||
throw new com.sun.star.io.BufferSizeExceededException("buffer overflow");
|
||||
readPosition += param;
|
||||
}
|
||||
|
||||
|
||||
// Implementation of XSeekable
|
||||
|
||||
public long getLength() throws com.sun.star.io.IOException {
|
||||
// System.err.println("getLength() -> "+m_length);
|
||||
if (buffer != null) return position;
|
||||
else throw new com.sun.star.io.IOException("no bytes");
|
||||
}
|
||||
|
||||
public long getPosition() throws com.sun.star.io.IOException {
|
||||
// System.err.println("getPosition() -> "+m_pos);
|
||||
if (buffer != null) return readPosition;
|
||||
else throw new com.sun.star.io.IOException("no bytes");
|
||||
}
|
||||
|
||||
public void seek(long param) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException {
|
||||
// System.err.println("seek("+param+")");
|
||||
if (buffer != null) {
|
||||
if (param < 0 || param > position) throw new com.sun.star.lang.IllegalArgumentException("invalid seek position");
|
||||
else readPosition = (int)param;
|
||||
} else throw new com.sun.star.io.IOException("no bytes");
|
||||
}
|
||||
|
||||
// Implementation of XStream
|
||||
public XInputStream getInputStream() { return this; }
|
||||
|
||||
public XOutputStream getOutputStream() { return this; }
|
||||
|
||||
// Get the buffer
|
||||
public byte[] getBuffer() { return buffer; }
|
||||
|
||||
}
|
||||
|
|
@ -1,870 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* ConfigurationDialogBase.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-09)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.star.awt.XContainerWindowEventHandler;
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.awt.XDialogProvider2;
|
||||
import com.sun.star.awt.XWindow;
|
||||
import com.sun.star.container.NoSuchElementException;
|
||||
import com.sun.star.io.NotConnectedException;
|
||||
import com.sun.star.io.XInputStream;
|
||||
import com.sun.star.io.XOutputStream;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.ucb.CommandAbortedException;
|
||||
import com.sun.star.ucb.XSimpleFileAccess2;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.XStringSubstitution;
|
||||
|
||||
import w2phtml.api.ComplexOption;
|
||||
import w2phtml.api.Config;
|
||||
import w2phtml.api.ConverterFactory;
|
||||
import w2phtml.util.Misc;
|
||||
|
||||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
import com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter;
|
||||
import com.sun.star.lib.uno.adapter.XOutputStreamToOutputStreamAdapter;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.DialogAccess;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.FilePicker;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.StyleNameProvider;
|
||||
|
||||
/** This is a base implementation of a uno component which supports several option pages
|
||||
* with a single <code>XContainerWindowEventHandler</code>. The title of the dialogs
|
||||
* are used to differentiate between the individual pages
|
||||
*/
|
||||
public abstract class ConfigurationDialogBase extends WeakBase implements XContainerWindowEventHandler {
|
||||
|
||||
// The full path to the configuration file we handle
|
||||
private String sConfigFileName = null;
|
||||
|
||||
// The component context
|
||||
protected XComponentContext xContext;
|
||||
|
||||
// File picker wrapper
|
||||
protected FilePicker filePicker = null;
|
||||
|
||||
// UNO simple file access service
|
||||
protected XSimpleFileAccess2 sfa2 = null;
|
||||
|
||||
// UNO path substitution
|
||||
protected XStringSubstitution xPathSub = null;
|
||||
|
||||
// The configuration implementation
|
||||
protected Config config;
|
||||
|
||||
// The individual page handlers (the subclass must populate this)
|
||||
protected Map<String,PageHandler> pageHandlers = new HashMap<String,PageHandler>();
|
||||
|
||||
// The subclass must provide these:
|
||||
|
||||
// MIME type of the document type we configure
|
||||
protected abstract String getMIMEType();
|
||||
|
||||
// The dialog library containing the "new" and "delete" dialogs
|
||||
protected abstract String getDialogLibraryName();
|
||||
|
||||
// The file name used for persistent storage of the edited configuration
|
||||
protected abstract String getConfigFileName();
|
||||
|
||||
/** Create a new <code>ConfigurationDialogBase</code> */
|
||||
public ConfigurationDialogBase(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
|
||||
// Get the file picker
|
||||
filePicker = new FilePicker(xContext);
|
||||
|
||||
// Get the SimpleFileAccess service
|
||||
try {
|
||||
Object sfaObject = xContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess", xContext);
|
||||
sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// failed to get SimpleFileAccess service (should not happen)
|
||||
}
|
||||
|
||||
// Create the config file name
|
||||
try {
|
||||
Object psObject = xContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.util.PathSubstitution", xContext);
|
||||
xPathSub = (XStringSubstitution) UnoRuntime.queryInterface(XStringSubstitution.class, psObject);
|
||||
sConfigFileName = xPathSub.substituteVariables("$(user)/"+getConfigFileName(), false);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// failed to get PathSubstitution service (should not happen)
|
||||
}
|
||||
|
||||
// Create the configuration
|
||||
config = ConverterFactory.createConverter(getMIMEType()).getConfig();
|
||||
|
||||
}
|
||||
|
||||
// Implement XContainerWindowEventHandler
|
||||
public boolean callHandlerMethod(XWindow xWindow, Object event, String sMethod)
|
||||
throws com.sun.star.lang.WrappedTargetException {
|
||||
XDialog xDialog = (XDialog)UnoRuntime.queryInterface(XDialog.class, xWindow);
|
||||
String sTitle = xDialog.getTitle();
|
||||
|
||||
if (!pageHandlers.containsKey(sTitle)) {
|
||||
throw new com.sun.star.lang.WrappedTargetException("Unknown dialog "+sTitle);
|
||||
}
|
||||
|
||||
DialogAccess dlg = new DialogAccess(xDialog);
|
||||
|
||||
try {
|
||||
if (sMethod.equals("external_event") ) {
|
||||
return handleExternalEvent(dlg, sTitle, event);
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.RuntimeException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
throw new com.sun.star.lang.WrappedTargetException(sMethod, this, e);
|
||||
}
|
||||
|
||||
return pageHandlers.get(sTitle).handleEvent(dlg, sMethod);
|
||||
}
|
||||
|
||||
private boolean handleExternalEvent(DialogAccess dlg, String sTitle, Object aEventObject) throws com.sun.star.uno.Exception {
|
||||
try {
|
||||
String sMethod = AnyConverter.toString(aEventObject);
|
||||
if (sMethod.equals("ok")) {
|
||||
loadConfig(); // The file may have been changed by other pages, thus we reload
|
||||
pageHandlers.get(sTitle).getControls(dlg);
|
||||
saveConfig();
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("back") || sMethod.equals("initialize")) {
|
||||
loadConfig();
|
||||
pageHandlers.get(sTitle).setControls(dlg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
throw new com.sun.star.lang.IllegalArgumentException(
|
||||
"Method external_event requires a string in the event object argument.", this,(short) -1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the user configuration from file
|
||||
private void loadConfig() {
|
||||
if (sfa2!=null && sConfigFileName!=null) {
|
||||
try {
|
||||
XInputStream xIs = sfa2.openFileRead(sConfigFileName);
|
||||
if (xIs!=null) {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
config.read(is);
|
||||
is.close();
|
||||
xIs.closeInput();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the user configuration
|
||||
private void saveConfig() {
|
||||
if (sfa2!=null && sConfigFileName!=null) {
|
||||
try {
|
||||
//Remove the file if it exists
|
||||
if (sfa2.exists(sConfigFileName)) {
|
||||
sfa2.kill(sConfigFileName);
|
||||
}
|
||||
// Then write the new contents
|
||||
XOutputStream xOs = sfa2.openFileWrite(sConfigFileName);
|
||||
if (xOs!=null) {
|
||||
OutputStream os = new XOutputStreamToOutputStreamAdapter(xOs);
|
||||
config.write(os);
|
||||
os.close();
|
||||
xOs.closeOutput();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Inner class to handle the individual option pages
|
||||
protected abstract class PageHandler {
|
||||
protected abstract void getControls(DialogAccess dlg);
|
||||
|
||||
protected abstract void setControls(DialogAccess dlg);
|
||||
|
||||
protected abstract boolean handleEvent(DialogAccess dlg, String sMethodName);
|
||||
|
||||
|
||||
// Methods to set and get controls based on config
|
||||
protected void checkBoxFromConfig(DialogAccess dlg, String sCheckBoxName, String sConfigName) {
|
||||
dlg.setCheckBoxStateAsBoolean(sCheckBoxName, "true".equals(config.getOption(sConfigName)));
|
||||
}
|
||||
|
||||
protected void checkBoxToConfig(DialogAccess dlg, String sCheckBoxName, String sConfigName) {
|
||||
config.setOption(sConfigName, Boolean.toString(dlg.getCheckBoxStateAsBoolean(sCheckBoxName)));
|
||||
}
|
||||
|
||||
protected void textFieldFromConfig(DialogAccess dlg, String sTextBoxName, String sConfigName) {
|
||||
dlg.setTextFieldText(sTextBoxName, config.getOption(sConfigName));
|
||||
}
|
||||
|
||||
protected void textFieldToConfig(DialogAccess dlg, String sTextBoxName, String sConfigName) {
|
||||
config.setOption(sConfigName, dlg.getTextFieldText(sTextBoxName));
|
||||
}
|
||||
|
||||
protected void listBoxFromConfig(DialogAccess dlg, String sListBoxName, String sConfigName, String[] sConfigValues, short nDefault) {
|
||||
String sCurrentValue = config.getOption(sConfigName);
|
||||
int nCount = sConfigValues.length;
|
||||
for (short i=0; i<nCount; i++) {
|
||||
if (sConfigValues[i].equals(sCurrentValue)) {
|
||||
dlg.setListBoxSelectedItem(sListBoxName, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
dlg.setListBoxSelectedItem(sListBoxName, nDefault);
|
||||
}
|
||||
|
||||
protected void listBoxToConfig(DialogAccess dlg, String sListBoxName, String sConfigName, String[] sConfigValues) {
|
||||
config.setOption(sConfigName, sConfigValues[dlg.getListBoxSelectedItem(sListBoxName)]);
|
||||
}
|
||||
|
||||
// Method to get a named dialog
|
||||
protected XDialog getDialog(String sDialogName) {
|
||||
XMultiComponentFactory xMCF = xContext.getServiceManager();
|
||||
try {
|
||||
Object provider = xMCF.createInstanceWithContext(
|
||||
"com.sun.star.awt.DialogProvider2", xContext);
|
||||
XDialogProvider2 xDialogProvider = (XDialogProvider2)
|
||||
UnoRuntime.queryInterface(XDialogProvider2.class, provider);
|
||||
String sDialogUrl = "vnd.sun.star.script:"+sDialogName+"?location=application";
|
||||
return xDialogProvider.createDialog(sDialogUrl);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to display delete dialog
|
||||
protected boolean deleteItem(String sName) {
|
||||
XDialog xDialog=getDialog(getDialogLibraryName()+".DeleteDialog");
|
||||
if (xDialog!=null) {
|
||||
DialogAccess ddlg = new DialogAccess(xDialog);
|
||||
String sLabel = ddlg.getLabelText("DeleteLabel");
|
||||
sLabel = sLabel.replaceAll("%s", sName);
|
||||
ddlg.setLabelText("DeleteLabel", sLabel);
|
||||
boolean bDelete = xDialog.execute()==ExecutableDialogResults.OK;
|
||||
xDialog.endExecute();
|
||||
return bDelete;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected abstract class CustomFileHandler extends PageHandler {
|
||||
|
||||
// The file name
|
||||
private String sCustomFileName;
|
||||
|
||||
public CustomFileHandler() {
|
||||
super();
|
||||
try {
|
||||
sCustomFileName = xPathSub.substituteVariables("$(user)/"+getFileName(), false);
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
sCustomFileName = getFileName();
|
||||
}
|
||||
}
|
||||
|
||||
// The subclass must provide these
|
||||
protected abstract String getSuffix();
|
||||
|
||||
protected abstract String getFileName();
|
||||
|
||||
protected abstract void useCustomInner(DialogAccess dlg, boolean bUseCustom);
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
String sText = "";
|
||||
boolean bUseCustom = false;
|
||||
if (fileExists(sCustomFileName)) {
|
||||
sText = loadFile(sCustomFileName);
|
||||
bUseCustom = true;
|
||||
}
|
||||
else if (fileExists(sCustomFileName+".bak")) {
|
||||
sText = loadFile(sCustomFileName+".bak");
|
||||
}
|
||||
// Currently ignore failure to load the file
|
||||
if (sText==null) { sText=""; }
|
||||
|
||||
dlg.setCheckBoxStateAsBoolean("UseCustom"+getSuffix(), bUseCustom);
|
||||
dlg.setTextFieldText("Custom"+getSuffix(), sText);
|
||||
|
||||
useCustomChange(dlg);
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
if (dlg.getCheckBoxStateAsBoolean("UseCustom"+getSuffix())) {
|
||||
saveFile(sCustomFileName,dlg.getTextFieldText("Custom"+getSuffix()));
|
||||
killFile(sCustomFileName+".bak");
|
||||
}
|
||||
else {
|
||||
saveFile(sCustomFileName+".bak",dlg.getTextFieldText("Custom"+getSuffix()));
|
||||
killFile(sCustomFileName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("UseCustom"+getSuffix()+"Change")) {
|
||||
useCustomChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("Load"+getSuffix()+"Click")) {
|
||||
loadCustomClick(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void useCustomChange(DialogAccess dlg) {
|
||||
boolean bUseCustom = dlg.getCheckBoxStateAsBoolean("UseCustom"+getSuffix());
|
||||
dlg.setControlEnabled("Custom"+getSuffix(), bUseCustom);
|
||||
dlg.setControlEnabled("Load"+getSuffix()+"Button", bUseCustom);
|
||||
useCustomInner(dlg,bUseCustom);
|
||||
}
|
||||
|
||||
protected void loadCustomClick(DialogAccess dlg) {
|
||||
String sFileName=filePicker.getPath();
|
||||
if (sFileName!=null) {
|
||||
String sText = loadFile(sFileName);
|
||||
if (sText!=null) {
|
||||
dlg.setTextFieldText("Custom"+getSuffix(), sText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers for sfa2
|
||||
|
||||
// Checks that the file exists
|
||||
protected boolean fileExists(String sFileName) {
|
||||
try {
|
||||
return sfa2!=null && sfa2.exists(sFileName);
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete a file if it exists, return true on success
|
||||
protected boolean killFile(String sFileName) {
|
||||
try {
|
||||
if (sfa2!=null && sfa2.exists(sFileName)) {
|
||||
sfa2.kill(sFileName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load a text file, returns null on failure
|
||||
private String loadFile(String sFileName) {
|
||||
if (sfa2!=null) {
|
||||
try {
|
||||
XInputStream xIs = sfa2.openFileRead(sFileName);
|
||||
if (xIs!=null) {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder buf = new StringBuilder();
|
||||
String sLine;
|
||||
try {
|
||||
while ((sLine = reader.readLine())!=null) {
|
||||
buf.append(sLine).append('\n');
|
||||
}
|
||||
reader.close();
|
||||
is.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
xIs.closeInput();
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Save a text file, return true on success
|
||||
protected boolean saveFile(String sFileName, String sText) {
|
||||
killFile(sFileName);
|
||||
try {
|
||||
XOutputStream xOs = sfa2.openFileWrite(sFileName);
|
||||
if (xOs!=null) {
|
||||
OutputStream os = new XOutputStreamToOutputStreamAdapter(xOs);
|
||||
try {
|
||||
OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
|
||||
osw.write(sText);
|
||||
osw.flush();
|
||||
os.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
xOs.closeOutput();
|
||||
return false;
|
||||
}
|
||||
xOs.closeOutput();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class UserListPageHandler extends PageHandler {
|
||||
|
||||
// Methods to handle user controlled lists
|
||||
protected boolean deleteCurrentItem(DialogAccess dlg, String sListName) {
|
||||
String[] sItems = dlg.getListBoxStringItemList(sListName);
|
||||
short nSelected = dlg.getListBoxSelectedItem(sListName);
|
||||
if (nSelected>=0 && deleteItem(sItems[nSelected])) {
|
||||
int nOldLen = sItems.length;
|
||||
String[] sNewItems = new String[nOldLen-1];
|
||||
if (nSelected>0) {
|
||||
System.arraycopy(sItems, 0, sNewItems, 0, nSelected);
|
||||
}
|
||||
if (nSelected<nOldLen-1) {
|
||||
System.arraycopy(sItems, nSelected+1, sNewItems, nSelected, nOldLen-1-nSelected);
|
||||
}
|
||||
dlg.setListBoxStringItemList(sListName, sNewItems);
|
||||
short nNewSelected = nSelected<nOldLen-1 ? nSelected : (short)(nSelected-1);
|
||||
dlg.setListBoxSelectedItem(sListName, nNewSelected);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String newItem(Set<String> suggestions) {
|
||||
XDialog xDialog=getDialog(getDialogLibraryName()+".NewDialog");
|
||||
if (xDialog!=null) {
|
||||
String[] sItems = Misc.sortStringSet(suggestions);
|
||||
DialogAccess ndlg = new DialogAccess(xDialog);
|
||||
ndlg.setListBoxStringItemList("Name", sItems);
|
||||
String sResult = null;
|
||||
if (xDialog.execute()==ExecutableDialogResults.OK) {
|
||||
DialogAccess dlg = new DialogAccess(xDialog);
|
||||
sResult = dlg.getTextFieldText("Name");
|
||||
}
|
||||
xDialog.endExecute();
|
||||
return sResult;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String appendItem(DialogAccess dlg, String sListName, Set<String> suggestions) {
|
||||
String[] sItems = dlg.getListBoxStringItemList(sListName);
|
||||
String sNewItem = newItem(suggestions);
|
||||
if (sNewItem!=null) {
|
||||
int nOldLen = sItems.length;
|
||||
for (short i=0; i<nOldLen; i++) {
|
||||
if (sNewItem.equals(sItems[i])) {
|
||||
// Item already exists, select the existing one
|
||||
dlg.setListBoxSelectedItem(sListName, i);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
String[] sNewItems = new String[nOldLen+1];
|
||||
System.arraycopy(sItems, 0, sNewItems, 0, nOldLen);
|
||||
sNewItems[nOldLen]=sNewItem;
|
||||
dlg.setListBoxStringItemList(sListName, sNewItems);
|
||||
dlg.setListBoxSelectedItem(sListName, (short)nOldLen);
|
||||
}
|
||||
return sNewItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract class StylesPageHandler extends UserListPageHandler {
|
||||
// The subclass must define these
|
||||
protected String[] sFamilyNames;
|
||||
protected String[] sOOoFamilyNames;
|
||||
|
||||
// Our data
|
||||
private ComplexOption[] styleMap;
|
||||
protected short nCurrentFamily = -1;
|
||||
private String sCurrentStyleName = null;
|
||||
|
||||
// Access to display names of the styles in the current document
|
||||
protected StyleNameProvider styleNameProvider = null;
|
||||
|
||||
// Some methods to be implemented by the subclass
|
||||
protected abstract String getDefaultConfigName();
|
||||
|
||||
protected abstract void getControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void setControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void clearControls(DialogAccess dlg);
|
||||
|
||||
protected abstract void prepareControls(DialogAccess dlg, boolean bHasDefinitions);
|
||||
|
||||
// Constructor
|
||||
protected StylesPageHandler(int nCount) {
|
||||
// Get the style name provider
|
||||
styleNameProvider = new StyleNameProvider(xContext);
|
||||
|
||||
// Reset the options
|
||||
styleMap = new ComplexOption[nCount];
|
||||
for (int i=0; i<nCount; i++) {
|
||||
styleMap[i] = new ComplexOption();
|
||||
}
|
||||
}
|
||||
|
||||
// Implement abstract methods from super
|
||||
protected void setControls(DialogAccess dlg) {
|
||||
// Load style maps from config (translating keys to display names)
|
||||
int nCount = sFamilyNames.length;
|
||||
for (int i=0; i<nCount; i++) {
|
||||
ComplexOption configMap = config.getComplexOption(sFamilyNames[i]+"-map");
|
||||
styleMap[i].clear();
|
||||
Map<String,String> displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]);
|
||||
copyStyles(configMap, styleMap[i], displayNames);
|
||||
}
|
||||
|
||||
// Display paragraph maps first
|
||||
nCurrentFamily = -1;
|
||||
sCurrentStyleName = null;
|
||||
dlg.setListBoxSelectedItem("StyleFamily", (short)1);
|
||||
styleFamilyChange(dlg);
|
||||
}
|
||||
|
||||
protected void getControls(DialogAccess dlg) {
|
||||
updateStyleMaps(dlg);
|
||||
|
||||
// Save style maps to config (translating keys back to internal names)
|
||||
int nCount = sFamilyNames.length;
|
||||
for (int i=0; i<nCount; i++) {
|
||||
ComplexOption configMap = config.getComplexOption(sFamilyNames[i]+"-map");
|
||||
configMap.clear();
|
||||
Map<String,String> internalNames = styleNameProvider.getInternalNames(sOOoFamilyNames[i]);
|
||||
copyStyles(styleMap[i], configMap, internalNames);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("StyleFamilyChange")) {
|
||||
styleFamilyChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("StyleNameChange")) {
|
||||
styleNameChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("NewStyleClick")) {
|
||||
newStyleClick(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("DeleteStyleClick")) {
|
||||
deleteStyleClick(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("LoadDefaultsClick")) {
|
||||
loadDefaultsClick(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Internal methods
|
||||
private void updateStyleMaps(DialogAccess dlg) {
|
||||
// Save the current style map, if any
|
||||
if (nCurrentFamily>-1 && sCurrentStyleName!=null) {
|
||||
getControls(dlg,styleMap[nCurrentFamily].get(sCurrentStyleName));
|
||||
}
|
||||
}
|
||||
|
||||
private void styleFamilyChange(DialogAccess dlg) {
|
||||
short nNewFamily = dlg.getListBoxSelectedItem("StyleFamily");
|
||||
if (nNewFamily>-1 && nNewFamily!=nCurrentFamily) {
|
||||
// The user has changed the family; load and display the corresponding style names
|
||||
updateStyleMaps(dlg);
|
||||
nCurrentFamily = nNewFamily;
|
||||
sCurrentStyleName = null;
|
||||
|
||||
String[] sStyleNames = Misc.sortStringSet(styleMap[nNewFamily].keySet());
|
||||
dlg.setListBoxStringItemList("StyleName", sStyleNames);
|
||||
if (sStyleNames.length>0) {
|
||||
dlg.setListBoxSelectedItem("StyleName", (short)0);
|
||||
}
|
||||
else {
|
||||
dlg.setListBoxSelectedItem("StyleName", (short)-1);
|
||||
}
|
||||
|
||||
updateStyleControls(dlg);
|
||||
styleNameChange(dlg);
|
||||
}
|
||||
}
|
||||
|
||||
private void styleNameChange(DialogAccess dlg) {
|
||||
if (nCurrentFamily>-1) {
|
||||
updateStyleMaps(dlg);
|
||||
short nStyleNameItem = dlg.getListBoxSelectedItem("StyleName");
|
||||
if (nStyleNameItem>=0) {
|
||||
sCurrentStyleName = dlg.getListBoxStringItemList("StyleName")[nStyleNameItem];
|
||||
setControls(dlg,styleMap[nCurrentFamily].get(sCurrentStyleName));
|
||||
}
|
||||
else {
|
||||
sCurrentStyleName = null;
|
||||
clearControls(dlg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void newStyleClick(DialogAccess dlg) {
|
||||
if (nCurrentFamily>-1) {
|
||||
updateStyleMaps(dlg);
|
||||
// Invalidate current style name in any case (appendItem returns null if the user
|
||||
// selects an existing style, but it still changes the current item)
|
||||
sCurrentStyleName = null;
|
||||
String sNewName = appendItem(dlg, "StyleName",styleNameProvider.getInternalNames(sOOoFamilyNames[nCurrentFamily]).keySet());
|
||||
if (sNewName!=null) {
|
||||
styleMap[nCurrentFamily].put(sNewName, new HashMap<String,String>());
|
||||
clearControls(dlg);
|
||||
}
|
||||
styleNameChange(dlg);
|
||||
updateStyleControls(dlg);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteStyleClick(DialogAccess dlg) {
|
||||
if (nCurrentFamily>-1 && sCurrentStyleName!=null) {
|
||||
String sStyleName = sCurrentStyleName;
|
||||
if (deleteCurrentItem(dlg,"StyleName")) {
|
||||
styleMap[nCurrentFamily].remove(sStyleName);
|
||||
sCurrentStyleName=null;
|
||||
styleNameChange(dlg);
|
||||
}
|
||||
updateStyleControls(dlg);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDefaultsClick(DialogAccess dlg) {
|
||||
updateStyleMaps(dlg);
|
||||
|
||||
// Count styles that we will overwrite
|
||||
Config clean = ConverterFactory.createConverter(getMIMEType()).getConfig();
|
||||
clean.readDefaultConfig(getDefaultConfigName());
|
||||
|
||||
int nCount = 0;
|
||||
int nFamilyCount = sFamilyNames.length;
|
||||
for (int i=0; i<nFamilyCount; i++) {
|
||||
ComplexOption cleanMap = clean.getComplexOption(sFamilyNames[i]+"-map");
|
||||
Map<String,String> displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]);
|
||||
for (String sName : cleanMap.keySet()) {
|
||||
String sDisplayName = (displayNames!=null && displayNames.containsKey(sName)) ? displayNames.get(sName) : "";
|
||||
if (styleMap[i].containsKey(sDisplayName)) { nCount++; }
|
||||
}
|
||||
}
|
||||
|
||||
// Display confirmation dialog
|
||||
boolean bConfirm = false;
|
||||
XDialog xDialog=getDialog(getDialogLibraryName()+".LoadDefaults");
|
||||
if (xDialog!=null) {
|
||||
DialogAccess ldlg = new DialogAccess(xDialog);
|
||||
if (nCount>0) {
|
||||
String sLabel = ldlg.getLabelText("OverwriteLabel");
|
||||
sLabel = sLabel.replaceAll("%s", Integer.toString(nCount));
|
||||
ldlg.setLabelText("OverwriteLabel", sLabel);
|
||||
}
|
||||
else {
|
||||
ldlg.setLabelText("OverwriteLabel", "");
|
||||
}
|
||||
bConfirm = xDialog.execute()==ExecutableDialogResults.OK;
|
||||
xDialog.endExecute();
|
||||
}
|
||||
|
||||
// Do the replacement
|
||||
if (bConfirm) {
|
||||
for (int i=0; i<nFamilyCount; i++) {
|
||||
ComplexOption cleanMap = clean.getComplexOption(sFamilyNames[i]+"-map");
|
||||
Map<String,String> displayNames = styleNameProvider.getDisplayNames(sOOoFamilyNames[i]);
|
||||
copyStyles(cleanMap, styleMap[i], displayNames);
|
||||
}
|
||||
}
|
||||
|
||||
// Force update of the user interface
|
||||
nCurrentFamily = -1;
|
||||
sCurrentStyleName = null;
|
||||
styleFamilyChange(dlg);
|
||||
}
|
||||
|
||||
private void updateStyleControls(DialogAccess dlg) {
|
||||
boolean bHasMappings = dlg.getListBoxStringItemList("StyleName").length>0;
|
||||
dlg.setControlEnabled("DeleteStyleButton", bHasMappings);
|
||||
prepareControls(dlg,bHasMappings);
|
||||
}
|
||||
|
||||
private void copyStyles(ComplexOption source, ComplexOption target, Map<String,String> nameTranslation) {
|
||||
for (String sName : source.keySet()) {
|
||||
String sNewName = sName;
|
||||
if (nameTranslation!=null && nameTranslation.containsKey(sName)) {
|
||||
sNewName = nameTranslation.get(sName);
|
||||
}
|
||||
target.copy(sNewName, source.get(sName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class AttributePageHandler extends PageHandler {
|
||||
// The subclass must define this
|
||||
protected String[] sAttributeNames;
|
||||
|
||||
// Our data
|
||||
private ComplexOption attributeMap = new ComplexOption();
|
||||
private int nCurrentAttribute = -1;
|
||||
|
||||
// Some methods to be implemented by subclass
|
||||
protected abstract void getControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void setControls(DialogAccess dlg, Map<String,String> attr);
|
||||
|
||||
protected abstract void prepareControls(DialogAccess dlg, boolean bEnable);
|
||||
|
||||
// Implement abstract methods from our super
|
||||
protected void setControls(DialogAccess dlg) {
|
||||
// Load attribute maps from config
|
||||
attributeMap.clear();
|
||||
attributeMap.copyAll(config.getComplexOption("text-attribute-map"));
|
||||
|
||||
// Update the dialog
|
||||
nCurrentAttribute = -1;
|
||||
dlg.setListBoxSelectedItem("FormattingAttribute", (short)0);
|
||||
formattingAttributeChange(dlg);
|
||||
}
|
||||
|
||||
protected void getControls(DialogAccess dlg) {
|
||||
updateAttributeMaps(dlg);
|
||||
|
||||
// Save attribute maps to config
|
||||
ComplexOption configMap = config.getComplexOption("text-attribute-map");
|
||||
configMap.clear();
|
||||
for (String s: attributeMap.keySet()) {
|
||||
Map<String,String> attr = attributeMap.get(s);
|
||||
if (!attr.containsKey("deleted") || attr.get("deleted").equals("false")) {
|
||||
configMap.copy(s, attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("FormattingAttributeChange")) {
|
||||
formattingAttributeChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("CustomAttributeChange")) {
|
||||
customAttributeChange(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Internal methods
|
||||
private void updateAttributeMaps(DialogAccess dlg) {
|
||||
// Save the current attribute map, if any
|
||||
if (nCurrentAttribute>-1) {
|
||||
String sName = sAttributeNames[nCurrentAttribute];
|
||||
if (!attributeMap.containsKey(sName)) {
|
||||
attributeMap.put(sName, new HashMap<String,String>());
|
||||
}
|
||||
Map<String,String> attr = attributeMap.get(sName);
|
||||
attr.put("deleted", Boolean.toString(!dlg.getCheckBoxStateAsBoolean("CustomAttribute")));
|
||||
getControls(dlg,attr);
|
||||
attributeMap.put(sName, attr);
|
||||
}
|
||||
}
|
||||
|
||||
private void formattingAttributeChange(DialogAccess dlg) {
|
||||
updateAttributeMaps(dlg);
|
||||
short nNewAttribute = dlg.getListBoxSelectedItem("FormattingAttribute");
|
||||
if (nNewAttribute>-1 && nNewAttribute!=nCurrentAttribute) {
|
||||
nCurrentAttribute = nNewAttribute;
|
||||
String sName = sAttributeNames[nCurrentAttribute];
|
||||
if (!attributeMap.containsKey(sName)) {
|
||||
attributeMap.put(sName, new HashMap<String,String>());
|
||||
attributeMap.get(sName).put("deleted", "true");
|
||||
}
|
||||
Map<String,String> attr = attributeMap.get(sName);
|
||||
dlg.setCheckBoxStateAsBoolean("CustomAttribute", !attr.containsKey("deleted") || attr.get("deleted").equals("false"));
|
||||
customAttributeChange(dlg);
|
||||
setControls(dlg,attr);
|
||||
}
|
||||
}
|
||||
|
||||
private void customAttributeChange(DialogAccess dlg) {
|
||||
prepareControls(dlg,dlg.getCheckBoxStateAsBoolean("CustomAttribute"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* EPSCleaner.java
|
||||
*
|
||||
* Copyright: 2002-2009 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.0 (2009-03-09)
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
/** This class removes redundant binary information from EPS files created by OOo.
|
||||
* See the issue http://qa.openoffice.org/issues/show_bug.cgi?id=25256
|
||||
* According to this message http://markmail.org/message/dc6rprmtktxuq35v
|
||||
* on dev@openoffice.org the binary data is an EPSI preview in TIFF format
|
||||
* TODO: Is it possible to avoid this export?
|
||||
*/
|
||||
public class EPSCleaner {
|
||||
|
||||
// Signatures for start and end in eps
|
||||
private byte[] psStart;
|
||||
private byte[] psEnd;
|
||||
|
||||
public EPSCleaner() {
|
||||
try {
|
||||
psStart = "%!PS-Adobe".getBytes("US-ASCII");
|
||||
psEnd = "%%EOF".getBytes("US-ASCII");
|
||||
}
|
||||
catch (java.io.UnsupportedEncodingException ex) {
|
||||
// US-ASCII *is* supported :-)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
public byte[] cleanEps(byte[] blob) {
|
||||
int n = blob.length;
|
||||
|
||||
int nStart = 0;
|
||||
for (int i=0; i<n; i++) {
|
||||
if (match(blob,psStart,i)) {
|
||||
nStart=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int nEnd = n;
|
||||
for (int i=nStart; i<n; i++) {
|
||||
if (match(blob,psEnd,i)) {
|
||||
nEnd=i+psEnd.length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] newBlob = new byte[nEnd-nStart];
|
||||
System.arraycopy(blob,nStart,newBlob,0,nEnd-nStart);
|
||||
return newBlob;
|
||||
}
|
||||
|
||||
private boolean match(byte[] blob, byte[] sig, int nStart) {
|
||||
int n = sig.length;
|
||||
if (nStart+n>=blob.length) { return false; }
|
||||
for (int i=0; i<n; i++) {
|
||||
if (blob[nStart+i]!=sig[i]) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* ExportFilterBase.java
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2014-10-06)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import com.sun.star.lang.XServiceInfo;
|
||||
import com.sun.star.lang.XServiceName;
|
||||
import com.sun.star.lang.XTypeProvider;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.xml.sax.XDocumentHandler;
|
||||
|
||||
import w2phtml.util.SimpleDOMBuilder;
|
||||
|
||||
import com.sun.star.xml.XExportFilter;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/** This class provides an abstract UNO component which implements an XExportFilter.
|
||||
* The filter is actually generic and only the constructor and 3 strings needs
|
||||
* to be changed by the subclass.
|
||||
*/
|
||||
public abstract class ExportFilterBase implements
|
||||
XExportFilter,
|
||||
XServiceName,
|
||||
XServiceInfo,
|
||||
XDocumentHandler,
|
||||
XTypeProvider {
|
||||
|
||||
/** Service name for the component */
|
||||
public static final String __serviceName = "";
|
||||
|
||||
/** Implementation name for the component */
|
||||
public static final String __implementationName = "";
|
||||
|
||||
/** Filter name to include in error messages */
|
||||
public String __displayName = "";
|
||||
|
||||
private XComponentContext xComponentContext = null;
|
||||
private SimpleDOMBuilder domBuilder = new SimpleDOMBuilder();
|
||||
private UNOConverter converter = null;
|
||||
|
||||
/** Construct a new ExportFilterBase from a given component context
|
||||
*
|
||||
* @param xComponentContext the component context used to instantiate new UNO services
|
||||
*/
|
||||
public ExportFilterBase(XComponentContext xComponentContext) {
|
||||
this.xComponentContext = xComponentContext;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Implementation of XExportFilter:
|
||||
|
||||
public boolean exporter(com.sun.star.beans.PropertyValue[] aSourceData,
|
||||
java.lang.String[] msUserData) {
|
||||
// Create a suitable converter
|
||||
converter = new UNOConverter(aSourceData, xComponentContext);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Implementation of XDocumentHandler:
|
||||
// A flat XML DOM tree is created by the SAX events and finally converted
|
||||
|
||||
public void startDocument () {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
public void endDocument()throws com.sun.star.uno.RuntimeException {
|
||||
try{
|
||||
converter.convert(domBuilder.getDOM());
|
||||
}
|
||||
catch (IOException e){
|
||||
MessageBox msgBox = new MessageBox(xComponentContext);
|
||||
msgBox.showMessage(__displayName+": IO error in conversion",
|
||||
e.toString()+" at "+e.getStackTrace()[0].toString());
|
||||
throw new com.sun.star.uno.RuntimeException(e.getMessage());
|
||||
}
|
||||
catch (Exception e){
|
||||
MessageBox msgBox = new MessageBox(xComponentContext);
|
||||
msgBox.showMessage(__displayName+": Internal error in conversion",
|
||||
e.toString()+" at "+e.getStackTrace()[0].toString());
|
||||
throw new com.sun.star.uno.RuntimeException(__displayName+" Exception");
|
||||
}
|
||||
}
|
||||
|
||||
public void startElement (String sTagName, com.sun.star.xml.sax.XAttributeList xAttribs) {
|
||||
domBuilder.startElement(sTagName);
|
||||
int nLen = xAttribs.getLength();
|
||||
for (short i=0;i<nLen;i++) {
|
||||
domBuilder.setAttribute(xAttribs.getNameByIndex(i), xAttribs.getValueByIndex(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String sTagName){
|
||||
domBuilder.endElement();
|
||||
}
|
||||
|
||||
public void characters(String sText){
|
||||
domBuilder.characters(sText);
|
||||
}
|
||||
|
||||
public void ignorableWhitespace(String str){
|
||||
}
|
||||
|
||||
public void processingInstruction(String aTarget, String aData){
|
||||
}
|
||||
|
||||
public void setDocumentLocator(com.sun.star.xml.sax.XLocator xLocator){
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Implement methods from interface XTypeProvider
|
||||
|
||||
public com.sun.star.uno.Type[] getTypes() {
|
||||
Type[] typeReturn = {};
|
||||
|
||||
try {
|
||||
typeReturn = new Type[] {
|
||||
new Type( XTypeProvider.class ),
|
||||
new Type( XExportFilter.class ),
|
||||
new Type( XServiceName.class ),
|
||||
new Type( XServiceInfo.class ) };
|
||||
}
|
||||
catch( Exception exception ) {
|
||||
|
||||
}
|
||||
|
||||
return( typeReturn );
|
||||
}
|
||||
|
||||
|
||||
public byte[] getImplementationId() {
|
||||
byte[] byteReturn = {};
|
||||
|
||||
byteReturn = new String( "" + this.hashCode() ).getBytes();
|
||||
|
||||
return( byteReturn );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Implement method from interface XServiceName
|
||||
public String getServiceName() {
|
||||
return( __serviceName );
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Implement methods from interface XServiceInfo
|
||||
public boolean supportsService(String stringServiceName) {
|
||||
return( stringServiceName.equals( __serviceName ) );
|
||||
}
|
||||
|
||||
public String getImplementationName() {
|
||||
return __implementationName;
|
||||
}
|
||||
|
||||
public String[] getSupportedServiceNames() {
|
||||
String[] stringSupportedServiceNames = { __serviceName };
|
||||
return( stringSupportedServiceNames );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,433 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* FilterDataParser.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-05-06)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.io.NotConnectedException;
|
||||
import com.sun.star.io.XInputStream;
|
||||
import com.sun.star.io.XOutputStream;
|
||||
import com.sun.star.ucb.CommandAbortedException;
|
||||
import com.sun.star.ucb.XSimpleFileAccess2;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.XStringSubstitution;
|
||||
|
||||
import w2phtml.api.Converter;
|
||||
|
||||
import com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter;
|
||||
import com.sun.star.lib.uno.adapter.XOutputStreamToOutputStreamAdapter;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
|
||||
|
||||
|
||||
/** This class parses the FilterData property passed to the filter and
|
||||
* applies it to a <code>Converter</code>
|
||||
* All errors are silently ignored
|
||||
*/
|
||||
public class FilterDataParser {
|
||||
// TODO: Use JSON format
|
||||
|
||||
//private static XComponentContext xComponentContext = null;
|
||||
|
||||
private XSimpleFileAccess2 sfa2;
|
||||
private XStringSubstitution xPathSub;
|
||||
|
||||
public FilterDataParser(XComponentContext xComponentContext) {
|
||||
//this.xComponentContext = xComponentContext;
|
||||
|
||||
// Get the SimpleFileAccess service
|
||||
sfa2 = null;
|
||||
try {
|
||||
Object sfaObject = xComponentContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess", xComponentContext);
|
||||
sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// failed to get SimpleFileAccess service (should not happen)
|
||||
}
|
||||
|
||||
// Get the PathSubstitution service
|
||||
xPathSub = null;
|
||||
try {
|
||||
Object psObject = xComponentContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.util.PathSubstitution", xComponentContext);
|
||||
xPathSub = (XStringSubstitution) UnoRuntime.queryInterface(XStringSubstitution.class, psObject);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// failed to get PathSubstitution service (should not happen)
|
||||
}
|
||||
}
|
||||
|
||||
/** Apply the given FilterOptions property to the given converter.
|
||||
* The property must be a comma separated list of name=value items.
|
||||
* @param options an <code>Any</code> containing the FilterOptions property
|
||||
* @param converter a <code>writer2latex.api.Converter</code> implementation
|
||||
*/
|
||||
public void applyFilterOptions(Object options, Converter converter) {
|
||||
// Get the string from the data, if possible
|
||||
if (AnyConverter.isString(options)) {
|
||||
String sOptions = AnyConverter.toString(options);
|
||||
if (sOptions!=null) {
|
||||
// Convert to array
|
||||
String[] sItems = sOptions.split(",");
|
||||
int nItemCount = sItems.length;
|
||||
PropertyValue[] filterData = new PropertyValue[nItemCount];
|
||||
for (int i=0; i<nItemCount; i++) {
|
||||
String[] sItem = sItems[i].split("=");
|
||||
filterData[i] = new PropertyValue();
|
||||
filterData[i].Name = sItem[0];
|
||||
filterData[i].Value = sItem.length>1 ? sItem[1] : "";
|
||||
System.out.println(filterData[i].Name+" "+filterData[i].Value);
|
||||
}
|
||||
applyParsedFilterData(filterData,converter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Apply the given FilterData property to the given converter.
|
||||
* The property must be an array of PropertyValue objects.
|
||||
* @param data an <code>Any</code> containing the FilterData property
|
||||
* @param converter a <code>writer2latex.api.Converter</code> implementation
|
||||
*/
|
||||
public void applyFilterData(Object data, Converter converter) {
|
||||
// Get the array from the data, if possible
|
||||
PropertyValue[] filterData = null;
|
||||
if (AnyConverter.isArray(data)) {
|
||||
try {
|
||||
Object[] arrayData = (Object[]) AnyConverter.toArray(data);
|
||||
if (arrayData instanceof PropertyValue[]) {
|
||||
filterData = (PropertyValue[]) arrayData;
|
||||
if (filterData!=null) {
|
||||
applyParsedFilterData(filterData,converter);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to array; should not happen - ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyParsedFilterData(PropertyValue[] filterData, Converter converter) {
|
||||
PropertyHelper props = new PropertyHelper(filterData);
|
||||
|
||||
// Get the special properties TemplateURL, StyleSheetURL, ResourceURL, Resources, ConfigURL and AutoCreate
|
||||
Object tpl = props.get("TemplateURL");
|
||||
String sTemplate = null;
|
||||
if (tpl!=null && AnyConverter.isString(tpl)) {
|
||||
try {
|
||||
sTemplate = substituteVariables(AnyConverter.toString(tpl));
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to String; should not happen - ignore
|
||||
}
|
||||
}
|
||||
|
||||
Object styles = props.get("StyleSheetURL");
|
||||
String sStyleSheet = null;
|
||||
if (styles!=null && AnyConverter.isString(styles)) {
|
||||
try {
|
||||
sStyleSheet = substituteVariables(AnyConverter.toString(styles));
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to String; should not happen - ignore
|
||||
}
|
||||
}
|
||||
|
||||
// This property accepts an URL pointing to a folder containing the resources to include
|
||||
Object resourcedir = props.get("ResourceURL");
|
||||
String sResourceURL = null;
|
||||
if (resourcedir!=null && AnyConverter.isString(resourcedir)) {
|
||||
try {
|
||||
sResourceURL = substituteVariables(AnyConverter.toString(resourcedir));
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to String; should not happen - ignore
|
||||
}
|
||||
}
|
||||
|
||||
// This property accepts a semicolon separated list of <URL>[[::<file name>]::<mime type>]
|
||||
Object resources = props.get("Resources");
|
||||
String[] sResources = null;
|
||||
if (resources!=null && AnyConverter.isString(resources)) {
|
||||
try {
|
||||
sResources = substituteVariables(AnyConverter.toString(resources)).split(";");
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to String; should not happen - ignore
|
||||
}
|
||||
}
|
||||
|
||||
Object auto = props.get("AutoCreate");
|
||||
boolean bAutoCreate = false;
|
||||
if (auto!=null && AnyConverter.isString(auto)) {
|
||||
try {
|
||||
if ("true".equals(AnyConverter.toString(auto))) {
|
||||
bAutoCreate = true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to String; should not happen - ignore
|
||||
}
|
||||
}
|
||||
|
||||
Object cfg = props.get("ConfigURL");
|
||||
String sConfig = null;
|
||||
if (cfg!=null && AnyConverter.isString(cfg)) {
|
||||
try {
|
||||
sConfig = substituteVariables(AnyConverter.toString(cfg));
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to String; should not happen - ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Load the template from the specified URL, if any
|
||||
if (sfa2!=null && sTemplate!=null && sTemplate.length()>0) {
|
||||
try {
|
||||
XInputStream xIs = sfa2.openFileRead(sTemplate);
|
||||
if (xIs!=null) {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
converter.readTemplate(is);
|
||||
is.close();
|
||||
xIs.closeInput();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Load the style sheet from the specified URL, if any
|
||||
if (sfa2!=null && sStyleSheet!=null && sStyleSheet.length()>0) {
|
||||
try {
|
||||
XInputStream xIs = sfa2.openFileRead(sStyleSheet);
|
||||
if (xIs!=null) {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
converter.readStyleSheet(is);
|
||||
is.close();
|
||||
xIs.closeInput();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Load the resource from the specified folder URL, if any
|
||||
if (sfa2!=null && sResourceURL!=null && sResourceURL.length()>0) {
|
||||
String[] sURLs;
|
||||
try {
|
||||
sURLs = sfa2.getFolderContents(sResourceURL, false); // do not include folders
|
||||
for (String sURL : sURLs) {
|
||||
XInputStream xIs = sfa2.openFileRead(sURL);
|
||||
if (xIs!=null) {
|
||||
String sFileName = sURL.substring(sURL.lastIndexOf('/')+1);
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
converter.readResource(is,sFileName,null);
|
||||
is.close();
|
||||
xIs.closeInput();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
} catch (CommandAbortedException e1) {
|
||||
// ignore
|
||||
} catch (Exception e1) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Load the resources from the specified URLs, if any
|
||||
if (sfa2!=null && sResources!=null) {
|
||||
for (String sResource : sResources) {
|
||||
// Format is <URL>[[::<file name>]::<mime type>]
|
||||
String[] sParts = sResource.split("::");
|
||||
if (sParts.length>0) {
|
||||
String sURL=sParts[0];
|
||||
String sFileName;
|
||||
String sMediaType=null;
|
||||
if (sParts.length==3) {
|
||||
sFileName = sParts[1];
|
||||
sMediaType = sParts[2];
|
||||
}
|
||||
else {
|
||||
sFileName = sURL.substring(sURL.lastIndexOf('/')+1);
|
||||
if (sParts.length==2) {
|
||||
sMediaType = sParts[1];
|
||||
}
|
||||
}
|
||||
try {
|
||||
XInputStream xIs = sfa2.openFileRead(sURL);
|
||||
if (xIs!=null) {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
converter.readResource(is, sFileName, sMediaType);
|
||||
is.close();
|
||||
xIs.closeInput();
|
||||
} // otherwise wrong format, ignore
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create config if required
|
||||
try {
|
||||
if (bAutoCreate && sfa2!=null && sConfig!=null && !sConfig.startsWith("*") && !sfa2.exists(sConfig)) {
|
||||
// Note: Requires random access, ie. must be a file URL:
|
||||
XOutputStream xOs = sfa2.openFileWrite(sConfig);
|
||||
if (xOs!=null) {
|
||||
OutputStream os = new XOutputStreamToOutputStreamAdapter(xOs);
|
||||
converter.getConfig().write(os);
|
||||
os.flush();
|
||||
os.close();
|
||||
xOs.closeOutput();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
// Ignore
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
// Load the configuration from the specified URL, if any
|
||||
if (sConfig!=null) {
|
||||
if (sConfig.startsWith("*")) { // internal configuration
|
||||
try {
|
||||
converter.getConfig().readDefaultConfig(sConfig.substring(1));
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
else if (sfa2!=null) { // real URL
|
||||
try {
|
||||
XInputStream xIs = sfa2.openFileRead(sConfig);;
|
||||
if (xIs!=null) {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xIs);
|
||||
converter.getConfig().read(is);
|
||||
is.close();
|
||||
xIs.closeInput();
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
// Ignore
|
||||
}
|
||||
catch (CommandAbortedException e) {
|
||||
// Ignore
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read further configuration properties
|
||||
Enumeration<String> keys = props.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String sKey = keys.nextElement();
|
||||
if (!"ConfigURL".equals(sKey) && !"TemplateURL".equals(sKey) && !"StyleSheetURL".equals(sKey)
|
||||
&& !"Resources".equals(sKey) && !"AutoCreate".equals(sKey)) {
|
||||
Object value = props.get(sKey);
|
||||
if (AnyConverter.isString(value)) {
|
||||
try {
|
||||
converter.getConfig().setOption(sKey,AnyConverter.toString(value));
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
// Failed to convert to String; should not happen - ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String substituteVariables(String sUrl) {
|
||||
if (xPathSub!=null) {
|
||||
try {
|
||||
return xPathSub.substituteVariables(sUrl, false);
|
||||
}
|
||||
catch (com.sun.star.container.NoSuchElementException e) {
|
||||
// Found an unknown variable, no substitution
|
||||
// (This will only happen if false is replaced by true above)
|
||||
return sUrl;
|
||||
}
|
||||
}
|
||||
else { // Not path substitution available
|
||||
return sUrl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* GraphicConverterImpl.java
|
||||
*
|
||||
* Copyright: 2002-2008 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.0 (2008-07-21)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import w2phtml.api.GraphicConverter;
|
||||
|
||||
public class GraphicConverterImpl implements GraphicConverter {
|
||||
|
||||
private GraphicConverter graphicConverter1;
|
||||
private GraphicConverter graphicConverter2;
|
||||
|
||||
public GraphicConverterImpl(XComponentContext xComponentContext) {
|
||||
graphicConverter1 = new GraphicConverterImpl1(xComponentContext);
|
||||
graphicConverter2 = new GraphicConverterImpl2(xComponentContext);
|
||||
}
|
||||
|
||||
public boolean supportsConversion(String sSourceMime, String sTargetMime, boolean bCrop, boolean bResize) {
|
||||
return graphicConverter1.supportsConversion(sSourceMime, sTargetMime, bCrop, bResize) ||
|
||||
graphicConverter2.supportsConversion(sSourceMime, sTargetMime, bCrop, bResize);
|
||||
}
|
||||
|
||||
public byte[] convert(byte[] source, String sSourceMime, String sTargetMime) {
|
||||
byte[] result = null;
|
||||
|
||||
// Prefer the simple implementation (GraphicProvider)
|
||||
if (graphicConverter1.supportsConversion(sSourceMime, sTargetMime, false, false)) {
|
||||
result = graphicConverter1.convert(source, sSourceMime, sTargetMime);
|
||||
}
|
||||
|
||||
// If this is not possible or fails, try the complex implementation
|
||||
if (result==null) {
|
||||
result = graphicConverter2.convert(source, sSourceMime, sTargetMime);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* GraphicConverterImpl1.java
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.4 (2014-09-05)
|
||||
*/
|
||||
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
// Java uno helper class
|
||||
import com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter;
|
||||
|
||||
// UNO classes
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.graphic.XGraphic;
|
||||
import com.sun.star.graphic.XGraphicProvider;
|
||||
//import com.sun.star.io.XInputStream;
|
||||
//import com.sun.star.io.XOutputStream;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import w2phtml.api.GraphicConverter;
|
||||
import w2phtml.api.MIMETypes;
|
||||
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
|
||||
/** A GraphicConverter implementation which uses the GraphicProvider service
|
||||
* to convert the graphic. This service does only support simple format
|
||||
* conversion using the "internal" graphics filters in Draw. Advanced features
|
||||
* like pdf, crop and resize thus cannot be handled.
|
||||
*/
|
||||
public class GraphicConverterImpl1 implements GraphicConverter {
|
||||
|
||||
private XGraphicProvider xGraphicProvider;
|
||||
|
||||
private EPSCleaner epsCleaner;
|
||||
|
||||
public GraphicConverterImpl1(XComponentContext xComponentContext) {
|
||||
try {
|
||||
// Get the XGraphicProvider interface of the GraphicProvider service
|
||||
XMultiComponentFactory xMCF = xComponentContext.getServiceManager();
|
||||
Object graphicProviderObject = xMCF.createInstanceWithContext("com.sun.star.graphic.GraphicProvider", xComponentContext);
|
||||
xGraphicProvider = (XGraphicProvider) UnoRuntime.queryInterface(XGraphicProvider.class, graphicProviderObject);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception ex) {
|
||||
System.err.println("Failed to get XGraphicProvider object");
|
||||
xGraphicProvider = null;
|
||||
}
|
||||
|
||||
epsCleaner = new EPSCleaner();
|
||||
|
||||
}
|
||||
|
||||
public boolean supportsConversion(String sSourceMime, String sTargetMime, boolean bCrop, boolean bResize) {
|
||||
// We don't support cropping and resizing
|
||||
if (bCrop || bResize) { return false; }
|
||||
|
||||
// We can convert vector formats to EPS and SVG
|
||||
if ((MIMETypes.EPS.equals(sTargetMime) || MIMETypes.SVG.equals(sTargetMime)) &&
|
||||
(MIMETypes.EMF.equals(sSourceMime) || MIMETypes.WMF.equals(sSourceMime) || MIMETypes.SVM.equals(sSourceMime))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// And we can convert all formats to bitmaps
|
||||
boolean bSupportsSource =
|
||||
MIMETypes.PNG.equals(sSourceMime) || MIMETypes.JPEG.equals(sSourceMime) ||
|
||||
MIMETypes.GIF.equals(sSourceMime) || MIMETypes.TIFF.equals(sSourceMime) ||
|
||||
MIMETypes.BMP.equals(sSourceMime) || MIMETypes.EMF.equals(sSourceMime) ||
|
||||
MIMETypes.WMF.equals(sSourceMime) || MIMETypes.SVM.equals(sSourceMime);
|
||||
boolean bSupportsTarget =
|
||||
MIMETypes.PNG.equals(sTargetMime) || MIMETypes.JPEG.equals(sTargetMime) ||
|
||||
MIMETypes.GIF.equals(sTargetMime) || MIMETypes.TIFF.equals(sTargetMime) ||
|
||||
MIMETypes.BMP.equals(sTargetMime);
|
||||
return bSupportsSource && bSupportsTarget;
|
||||
}
|
||||
|
||||
public byte[] convert(byte[] source, String sSourceMime, String sTargetMime) {
|
||||
// It seems that the GraphicProvider can only create proper eps if
|
||||
// the source is a vector format, hence
|
||||
if (MIMETypes.EPS.equals(sTargetMime)) {
|
||||
if (!MIMETypes.EMF.equals(sSourceMime) && !MIMETypes.WMF.equals(sSourceMime) && !MIMETypes.SVM.equals(sSourceMime)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayToXInputStreamAdapter xSource = new ByteArrayToXInputStreamAdapter(source);
|
||||
ByteArrayXStream xTarget = new ByteArrayXStream();
|
||||
try {
|
||||
// Read the source
|
||||
PropertyValue[] sourceProps = new PropertyValue[1];
|
||||
sourceProps[0] = new PropertyValue();
|
||||
sourceProps[0].Name = "InputStream";
|
||||
sourceProps[0].Value = xSource;
|
||||
XGraphic result = xGraphicProvider.queryGraphic(sourceProps);
|
||||
|
||||
// Store as new type
|
||||
PropertyValue[] targetProps = new PropertyValue[2];
|
||||
targetProps[0] = new PropertyValue();
|
||||
targetProps[0].Name = "MimeType";
|
||||
targetProps[0].Value = sTargetMime;
|
||||
targetProps[1] = new PropertyValue();
|
||||
targetProps[1].Name = "OutputStream";
|
||||
targetProps[1].Value = xTarget;
|
||||
xGraphicProvider.storeGraphic(result,targetProps);
|
||||
|
||||
// Close the output and return the result
|
||||
xTarget.flush();
|
||||
xTarget.closeOutput();
|
||||
if (MIMETypes.EPS.equals(sTargetMime)) {
|
||||
return epsCleaner.cleanEps(xTarget.getBuffer());
|
||||
}
|
||||
else {
|
||||
byte[] converted = xTarget.getBuffer();
|
||||
if (converted.length>0) { // Older versions of AOO/LO fails to convert to SVG (empty result)
|
||||
return converted;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.io.IOException e) {
|
||||
return null;
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
catch (com.sun.star.lang.WrappedTargetException e) {
|
||||
return null;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,267 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* GraphicConverterImpl2.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-07-30)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.sun.star.awt.Point;
|
||||
import com.sun.star.awt.Size;
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.drawing.XDrawPage;
|
||||
import com.sun.star.drawing.XDrawPages;
|
||||
import com.sun.star.drawing.XDrawPagesSupplier;
|
||||
import com.sun.star.drawing.XShape;
|
||||
import com.sun.star.frame.XComponentLoader;
|
||||
import com.sun.star.frame.XStorable;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.util.XRefreshable;
|
||||
|
||||
import w2phtml.api.GraphicConverter;
|
||||
import w2phtml.api.MIMETypes;
|
||||
|
||||
import com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter;
|
||||
import com.sun.star.lib.uno.adapter.XOutputStreamToByteArrayAdapter;
|
||||
|
||||
/** A GraphicConverter implementation which uses a hidden Draw document to
|
||||
* store the graphic, providing more control over the image than the
|
||||
* simple GraphicProvider implementation.
|
||||
*/
|
||||
public class GraphicConverterImpl2 implements GraphicConverter {
|
||||
|
||||
private XComponentContext xComponentContext;
|
||||
private Hashtable<String,String> importFilter;
|
||||
private Hashtable<String,String> exportFilter;
|
||||
private EPSCleaner epsCleaner;
|
||||
|
||||
public GraphicConverterImpl2(XComponentContext xComponentContext) {
|
||||
this.xComponentContext = xComponentContext;
|
||||
|
||||
importFilter = new Hashtable<String,String>();
|
||||
importFilter.put(MIMETypes.BMP, "BMP - MS Windows");
|
||||
importFilter.put(MIMETypes.EMF, "EMF - MS Windows Metafile");
|
||||
importFilter.put(MIMETypes.EPS, "EPS - Encapsulated PostScript");
|
||||
importFilter.put(MIMETypes.GIF, "GIF - Graphics Interchange Format");
|
||||
importFilter.put(MIMETypes.JPEG, "JPG - JPEG");
|
||||
importFilter.put(MIMETypes.PNG, "PNG - Portable Network Graphic");
|
||||
importFilter.put(MIMETypes.SVM, "SVM - StarView Metafile");
|
||||
importFilter.put(MIMETypes.TIFF, "TIF - Tag Image File");
|
||||
importFilter.put(MIMETypes.WMF, "WMF - MS Windows Metafile");
|
||||
|
||||
exportFilter = new Hashtable<String,String>();
|
||||
exportFilter.put(MIMETypes.BMP,"draw_bmp_Export");
|
||||
exportFilter.put(MIMETypes.EMF,"draw_emf_Export");
|
||||
exportFilter.put(MIMETypes.EPS,"draw_eps_Export");
|
||||
exportFilter.put(MIMETypes.GIF,"draw_gif_Export");
|
||||
exportFilter.put(MIMETypes.JPEG,"draw_jpg_Export");
|
||||
exportFilter.put(MIMETypes.PNG,"draw_png_Export");
|
||||
exportFilter.put(MIMETypes.SVG,"draw_svg_Export");
|
||||
exportFilter.put(MIMETypes.SVM,"draw_svm_Export");
|
||||
exportFilter.put(MIMETypes.TIFF,"draw_tif_Export");
|
||||
exportFilter.put(MIMETypes.WMF,"draw_wmf_Export");
|
||||
exportFilter.put(MIMETypes.PDF,"draw_pdf_Export");
|
||||
|
||||
epsCleaner = new EPSCleaner();
|
||||
}
|
||||
|
||||
public boolean supportsConversion(String sSourceMime, String sTargetMime, boolean bCrop, boolean bResize) {
|
||||
// We don't support cropping and resizing
|
||||
if (bCrop || bResize) { return false; }
|
||||
|
||||
// We currently support conversion of bitmaps and SVM into PDF, EPS and SVG
|
||||
// TODO: SVG does not seem to work in all versions of OOo/LO?
|
||||
// Trying WMF/EMF causes an IllegalArgumentException "URL seems to be an unsupported one"
|
||||
// Seems to be an OOo bug; workaround: Use temporary files..??
|
||||
boolean bSupportsSource = MIMETypes.SVM.equals(sSourceMime) ||
|
||||
MIMETypes.PNG.equals(sSourceMime) || MIMETypes.JPEG.equals(sSourceMime) ||
|
||||
MIMETypes.GIF.equals(sSourceMime) || MIMETypes.TIFF.equals(sSourceMime) ||
|
||||
MIMETypes.BMP.equals(sSourceMime)
|
||||
|| MIMETypes.WMF.equals(sSourceMime) || MIMETypes.EMF.equals(sSourceMime);
|
||||
boolean bSupportsTarget = MIMETypes.PDF.equals(sTargetMime) || MIMETypes.EPS.equals(sTargetMime) ||
|
||||
MIMETypes.SVG.equals(sTargetMime);
|
||||
return bSupportsSource && bSupportsTarget;
|
||||
}
|
||||
|
||||
public byte[] convert(byte[] source, String sSourceMime, String sTargetMime) {
|
||||
// Open a hidden sdraw document
|
||||
XMultiComponentFactory xMCF = xComponentContext.getServiceManager();
|
||||
try {
|
||||
// Load the graphic into a new draw document as xDocument
|
||||
// using a named filter
|
||||
Object desktop = xMCF.createInstanceWithContext(
|
||||
"com.sun.star.frame.Desktop", xComponentContext);
|
||||
|
||||
XComponentLoader xComponentLoader = (XComponentLoader)
|
||||
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
|
||||
|
||||
PropertyValue[] fileProps = new PropertyValue[3];
|
||||
fileProps[0] = new PropertyValue();
|
||||
fileProps[0].Name = "FilterName";
|
||||
fileProps[0].Value = importFilter.get(sSourceMime);
|
||||
fileProps[1] = new PropertyValue();
|
||||
fileProps[1].Name = "InputStream";
|
||||
fileProps[1].Value = new ByteArrayToXInputStreamAdapter(source);
|
||||
fileProps[2] = new PropertyValue();
|
||||
fileProps[2].Name = "Hidden";
|
||||
fileProps[2].Value = new Boolean(true);
|
||||
|
||||
XComponent xDocument = xComponentLoader.loadComponentFromURL(
|
||||
"private:stream", "_blank", 0, fileProps);
|
||||
|
||||
// Get the first draw page as xDrawPage
|
||||
XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier)
|
||||
UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDocument);
|
||||
XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
|
||||
|
||||
Object drawPage = xDrawPages.getByIndex(0);
|
||||
XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(
|
||||
XDrawPage.class, drawPage);
|
||||
|
||||
// Get the shape as xShape
|
||||
Object shape = xDrawPage.getByIndex(0);
|
||||
XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, shape);
|
||||
|
||||
// Move the shape to upper left corner of the page
|
||||
Point position = new Point();
|
||||
position.X = 0;
|
||||
position.Y = 0;
|
||||
xShape.setPosition(position);
|
||||
|
||||
// Adjust the page size and margin to the size of the graphic
|
||||
XPropertySet xPageProps = (XPropertySet) UnoRuntime.queryInterface(
|
||||
XPropertySet.class, xDrawPage);
|
||||
Size size = xShape.getSize();
|
||||
xPageProps.setPropertyValue("Width", new Integer(size.Width));
|
||||
xPageProps.setPropertyValue("Height", new Integer(size.Height));
|
||||
xPageProps.setPropertyValue("BorderTop", new Integer(0));
|
||||
xPageProps.setPropertyValue("BorderBottom", new Integer(0));
|
||||
xPageProps.setPropertyValue("BorderLeft", new Integer(0));
|
||||
xPageProps.setPropertyValue("BorderRight", new Integer(0));
|
||||
|
||||
// Export the draw document (xDocument)
|
||||
refreshDocument(xDocument);
|
||||
|
||||
XOutputStreamToByteArrayAdapter outputStream = new XOutputStreamToByteArrayAdapter();
|
||||
|
||||
PropertyValue[] exportProps = new PropertyValue[3];
|
||||
exportProps[0] = new PropertyValue();
|
||||
exportProps[0].Name = "FilterName";
|
||||
exportProps[0].Value = exportFilter.get(sTargetMime);
|
||||
exportProps[1] = new PropertyValue();
|
||||
exportProps[1].Name = "OutputStream";
|
||||
exportProps[1].Value = outputStream;
|
||||
exportProps[2] = new PropertyValue();
|
||||
exportProps[2].Name = "Overwrite";
|
||||
exportProps[2].Value = new Boolean(true);
|
||||
|
||||
XStorable xStore = (XStorable) UnoRuntime.queryInterface (
|
||||
XStorable.class, xDocument);
|
||||
xStore.storeToURL ("private:stream", exportProps);
|
||||
outputStream.closeOutput();
|
||||
|
||||
byte[] result = outputStream.getBuffer();
|
||||
|
||||
xDocument.dispose();
|
||||
|
||||
if (MIMETypes.EPS.equals(sTargetMime)) {
|
||||
return epsCleaner.cleanEps(result);
|
||||
}
|
||||
else {
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
catch (com.sun.star.beans.PropertyVetoException e) {
|
||||
}
|
||||
catch (com.sun.star.beans.UnknownPropertyException e) {
|
||||
}
|
||||
catch (com.sun.star.io.IOException e) {
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
}
|
||||
catch (com.sun.star.lang.IndexOutOfBoundsException e) {
|
||||
}
|
||||
catch (com.sun.star.lang.WrappedTargetException e) {
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
}
|
||||
|
||||
// Conversion failed, for whatever reason
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void refreshDocument(XComponent document) {
|
||||
XRefreshable refreshable = (XRefreshable) UnoRuntime.queryInterface(XRefreshable.class, document);
|
||||
if (refreshable != null) {
|
||||
refreshable.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Dim SelSize As New com.sun.star.awt.Size
|
||||
SelSize = oGraphic.Size
|
||||
oDrawGraphic.GraphicURL = oGraphic.GraphicURL
|
||||
oDrawGraphic.Size = SelSize
|
||||
oDrawPage.add(oDrawGraphic)
|
||||
oDrawGraphic.GraphicCrop = oGraphic.GraphicCrop
|
||||
oDrawPage.Width = oGraphic.Size.Width
|
||||
oDrawPage.Height = oGraphic.Size.Height
|
||||
Dim aFilterData (1) As new com.sun.star.beans.PropertyValue
|
||||
aFilterData(0).Name = "PixelWidth" '
|
||||
aFilterData(0).Value = oDrawPage.Width/100 * iPixels / 25.40
|
||||
aFilterData(1).Name = "PixelHeight"
|
||||
aFilterData(1).Value = oDrawPage.Height/100 * iPixels / 25.40
|
||||
Export( oDrawPage, sURLImageResized , aFilterData() )
|
||||
On error resume Next
|
||||
oDrawDoc.Close(True)
|
||||
On error goto 0
|
||||
|
||||
SUB Export( xObject, sFileUrl As String, aFilterData )
|
||||
Dim xExporter As Object
|
||||
xExporter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
|
||||
xExporter.SetSourceDocument( xObject )
|
||||
Dim aArgs (2) As new com.sun.star.beans.PropertyValue
|
||||
'sFileURL = ConvertToURL(sFileURL)
|
||||
aArgs(0).Name = "FilterName"
|
||||
aArgs(0).Value = "jpg"
|
||||
aArgs(1).Name = "URL"
|
||||
aArgs(1).Value = sFileURL
|
||||
'print sFileURL
|
||||
aArgs(2).Name = "FilterData"
|
||||
aArgs(2).Value = aFilterData
|
||||
xExporter.filter( aArgs() )
|
||||
END SUB*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* Messages.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-05-28)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Messages {
|
||||
private static final String BUNDLE_NAME = "org.openoffice.da.comp.w2lcommon.filter.messages"; //$NON-NLS-1$
|
||||
|
||||
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
|
||||
.getBundle(BUNDLE_NAME);
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return RESOURCE_BUNDLE.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,542 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* OptionsDialogBase.java
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.4 (2014-11-01)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.sun.star.awt.XDialogEventHandler;
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.beans.XPropertyAccess;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.container.XNameAccess;
|
||||
import com.sun.star.document.XDocumentPropertiesSupplier;
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiServiceFactory;
|
||||
import com.sun.star.lang.XServiceInfo;
|
||||
import com.sun.star.lang.XServiceName;
|
||||
import com.sun.star.lang.XTypeProvider;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.XChangesBatch;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.DialogBase;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MacroExpander;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
|
||||
|
||||
/** This class provides an abstract uno component which implements a filter ui
|
||||
*/
|
||||
public abstract class OptionsDialogBase extends DialogBase implements
|
||||
XPropertyAccess { // Filter ui requires XExecutableDialog + XPropertyAccess
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// The subclass must override the following; and override the
|
||||
// implementation of XDialogEventHandler if needed
|
||||
|
||||
/** Load settings from the registry to the dialog
|
||||
* The subclass must implement this
|
||||
*/
|
||||
protected abstract void loadSettings(XPropertySet xRegistryProps);
|
||||
|
||||
/** Save settings from the dialog to the registry and create FilterData
|
||||
* The subclass must implement this
|
||||
*/
|
||||
protected abstract void saveSettings(XPropertySet xRegistryProps, PropertyHelper filterData);
|
||||
|
||||
/** Return the name of the library containing the dialog
|
||||
*/
|
||||
public abstract String getDialogLibraryName();
|
||||
|
||||
/** Return the name of the dialog within the library
|
||||
*/
|
||||
public abstract String getDialogName();
|
||||
|
||||
/** Return the path to the options in the registry */
|
||||
public abstract String getRegistryPath();
|
||||
|
||||
/** Create a new OptionsDialogBase */
|
||||
public OptionsDialogBase(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
this.xMSF = null; // must be set properly by subclass
|
||||
mediaProps = null;
|
||||
sConfigNames = null;
|
||||
lockedOptions = new HashSet<String>();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Implement some methods required by DialogBase
|
||||
|
||||
/** Initialize the dialog (eg. with settings from the registry)
|
||||
*/
|
||||
public void initialize() {
|
||||
try {
|
||||
// Prepare registry view
|
||||
Object view = getRegistryView(false);
|
||||
XPropertySet xProps = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
|
||||
// Load settings using method from subclass
|
||||
loadSettings(xProps);
|
||||
|
||||
// Dispose the registry view
|
||||
disposeRegistryView(view);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
}
|
||||
|
||||
/** Finalize the dialog after execution (eg. save settings to the registry)
|
||||
*/
|
||||
public void endDialog() {
|
||||
try {
|
||||
// Prepare registry view
|
||||
Object rwview = getRegistryView(true);
|
||||
XPropertySet xProps = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class,rwview);
|
||||
|
||||
// Save settings and create FilterData using method from subclass
|
||||
PropertyHelper filterData = new PropertyHelper();
|
||||
saveSettings(xProps, filterData);
|
||||
|
||||
// Commit registry changes
|
||||
XChangesBatch xUpdateContext = (XChangesBatch)
|
||||
UnoRuntime.queryInterface(XChangesBatch.class,rwview);
|
||||
try {
|
||||
xUpdateContext.commitChanges();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// Dispose the registry view
|
||||
disposeRegistryView(rwview);
|
||||
|
||||
// Update the media properties with the FilterData
|
||||
PropertyHelper helper = new PropertyHelper(mediaProps);
|
||||
helper.put("FilterData",filterData.toArray());
|
||||
mediaProps = helper.toArray();
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Some private global variables
|
||||
|
||||
// The service factory
|
||||
protected XMultiServiceFactory xMSF;
|
||||
|
||||
// The media properties (set/get via XPropertyAccess implementation)
|
||||
private PropertyValue[] mediaProps;
|
||||
|
||||
// Configuration names (stored during execution of dialog)
|
||||
private String[] sConfigNames;
|
||||
|
||||
// Set of locked controls
|
||||
private HashSet<String> lockedOptions;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Some private utility methods
|
||||
|
||||
// Get the template name from the document with ui focus
|
||||
private String getTemplateName() {
|
||||
try {
|
||||
// Get current component
|
||||
Object desktop = xContext.getServiceManager()
|
||||
.createInstanceWithContext("com.sun.star.frame.Desktop",xContext);
|
||||
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,desktop);
|
||||
XComponent xComponent = xDesktop.getCurrentComponent();
|
||||
|
||||
// Get the document info property set
|
||||
XDocumentPropertiesSupplier xDocPropsSuppl =
|
||||
UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xComponent);
|
||||
return xDocPropsSuppl.getDocumentProperties().getTemplateName();
|
||||
}
|
||||
catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Get a view of the options root in the registry
|
||||
private Object getRegistryView(boolean bUpdate)
|
||||
throws com.sun.star.uno.Exception {
|
||||
Object provider = xMSF.createInstance(
|
||||
"com.sun.star.configuration.ConfigurationProvider");
|
||||
XMultiServiceFactory xProvider = (XMultiServiceFactory)
|
||||
UnoRuntime.queryInterface(XMultiServiceFactory.class,provider);
|
||||
PropertyValue[] args = new PropertyValue[1];
|
||||
args[0] = new PropertyValue();
|
||||
args[0].Name = "nodepath";
|
||||
args[0].Value = getRegistryPath();
|
||||
String sServiceName = bUpdate ?
|
||||
"com.sun.star.configuration.ConfigurationUpdateAccess" :
|
||||
"com.sun.star.configuration.ConfigurationAccess";
|
||||
Object view = xProvider.createInstanceWithArguments(sServiceName,args);
|
||||
return view;
|
||||
}
|
||||
|
||||
// Dispose a previously obtained registry view
|
||||
private void disposeRegistryView(Object view) {
|
||||
XComponent xComponent = (XComponent)
|
||||
UnoRuntime.queryInterface(XComponent.class,view);
|
||||
xComponent.dispose();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Implement uno interfaces
|
||||
|
||||
// Override getTypes() from the interface XTypeProvider
|
||||
public Type[] getTypes() {
|
||||
Type[] typeReturn = {};
|
||||
try {
|
||||
typeReturn = new Type[] {
|
||||
new Type( XServiceName.class ),
|
||||
new Type( XServiceInfo.class ),
|
||||
new Type( XTypeProvider.class ),
|
||||
new Type( XExecutableDialog.class ),
|
||||
new Type( XPropertyAccess.class ),
|
||||
new Type( XDialogEventHandler.class ) };
|
||||
} catch(Exception exception) {
|
||||
}
|
||||
return typeReturn;
|
||||
}
|
||||
|
||||
|
||||
// Implement the interface XPropertyAccess
|
||||
public PropertyValue[] getPropertyValues() {
|
||||
return mediaProps;
|
||||
}
|
||||
|
||||
public void setPropertyValues(PropertyValue[] props) {
|
||||
mediaProps = props;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Various utility methods to be used by the sublasses
|
||||
|
||||
// Helpers to load and save settings
|
||||
|
||||
protected void updateLockedOptions() {
|
||||
lockedOptions.clear();
|
||||
short nItem = getListBoxSelectedItem("Config");
|
||||
int nStdConfigs = getListBoxStringItemList("Config").length - sConfigNames.length;
|
||||
if (nItem>=nStdConfigs) {
|
||||
// Get current configuration name
|
||||
String sName = sConfigNames[nItem-nStdConfigs];
|
||||
|
||||
try {
|
||||
// Prepare registry view
|
||||
Object view = getRegistryView(false);
|
||||
XPropertySet xProps = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
|
||||
// Get the available configurations
|
||||
Object configurations = XPropertySetHelper.getPropertyValue(xProps,"Configurations");
|
||||
XNameAccess xConfigurations = (XNameAccess)
|
||||
UnoRuntime.queryInterface(XNameAccess.class,configurations);
|
||||
|
||||
// Get the LockedOptions node from the desired configuration
|
||||
String sLockedOptions = "";
|
||||
Object config = xConfigurations.getByName(sName);
|
||||
XPropertySet xCfgProps = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class,config);
|
||||
sLockedOptions = XPropertySetHelper.getPropertyValueAsString(xCfgProps,"LockedOptions");
|
||||
|
||||
// Dispose the registry view
|
||||
disposeRegistryView(view);
|
||||
|
||||
// Feed lockedOptions with the comma separated list of options
|
||||
int nStart = 0;
|
||||
for (int i=0; i<sLockedOptions.length(); i++) {
|
||||
if (sLockedOptions.charAt(i)==',') {
|
||||
lockedOptions.add(sLockedOptions.substring(nStart,i).trim());
|
||||
nStart = i+1;
|
||||
}
|
||||
}
|
||||
if (nStart<sLockedOptions.length()) {
|
||||
lockedOptions.add(sLockedOptions.substring(nStart).trim());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// no options will be locked...
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected boolean isLocked(String sOptionName) {
|
||||
return lockedOptions.contains(sOptionName);
|
||||
}
|
||||
|
||||
// Configuration
|
||||
protected void loadConfig(XPropertySet xProps) {
|
||||
// The list box is extended with configurations from the registry
|
||||
String[] sStdConfigs = getListBoxStringItemList("Config");
|
||||
int nStdConfigs = sStdConfigs.length;
|
||||
|
||||
Object configurations = XPropertySetHelper.getPropertyValue(xProps,"Configurations");
|
||||
XNameAccess xConfigurations = (XNameAccess)
|
||||
UnoRuntime.queryInterface(XNameAccess.class,configurations);
|
||||
sConfigNames = xConfigurations.getElementNames();
|
||||
int nRegConfigs = sConfigNames.length;
|
||||
|
||||
String[] sAllConfigs = new String[nStdConfigs+nRegConfigs];
|
||||
for (short i=0; i<nStdConfigs; i++) {
|
||||
sAllConfigs[i] = sStdConfigs[i];
|
||||
}
|
||||
|
||||
for (short i=0; i<nRegConfigs; i++) {
|
||||
try {
|
||||
Object config = xConfigurations.getByName(sConfigNames[i]);
|
||||
XPropertySet xCfgProps = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class,config);
|
||||
sAllConfigs[nStdConfigs+i] = XPropertySetHelper.getPropertyValueAsString(xCfgProps,"DisplayName");
|
||||
}
|
||||
catch (Exception e) {
|
||||
sAllConfigs[nStdConfigs+i] = "";
|
||||
}
|
||||
}
|
||||
|
||||
setListBoxStringItemList("Config",sAllConfigs);
|
||||
if (nStdConfigs+nRegConfigs<=12) {
|
||||
setListBoxLineCount("Config",(short) (nStdConfigs+nRegConfigs));
|
||||
}
|
||||
else {
|
||||
setListBoxLineCount("Config",(short) 12);
|
||||
}
|
||||
|
||||
// Select item based on template name
|
||||
String sTheTemplateName = getTemplateName();
|
||||
Object templates = XPropertySetHelper.getPropertyValue(xProps,"Templates");
|
||||
XNameAccess xTemplates = (XNameAccess)
|
||||
UnoRuntime.queryInterface(XNameAccess.class,templates);
|
||||
String[] sTemplateNames = xTemplates.getElementNames();
|
||||
for (int i=0; i<sTemplateNames.length; i++) {
|
||||
try {
|
||||
Object template = xTemplates.getByName(sTemplateNames[i]);
|
||||
XPropertySet xTplProps = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class,template);
|
||||
String sTemplateName = XPropertySetHelper.getPropertyValueAsString(xTplProps,"TemplateName");
|
||||
if (sTemplateName.equals(sTheTemplateName)) {
|
||||
String sConfigName = XPropertySetHelper.getPropertyValueAsString(xTplProps,"ConfigName");
|
||||
for (short j=0; j<nRegConfigs; j++) {
|
||||
if (sConfigNames[j].equals(sConfigName)) {
|
||||
setListBoxSelectedItem("Config",(short) (nStdConfigs+j));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Select item based on value stored in registry
|
||||
short nConfig = XPropertySetHelper.getPropertyValueAsShort(xProps,"Config");
|
||||
if (nConfig<nStdConfigs) {
|
||||
setListBoxSelectedItem("Config",nConfig);
|
||||
}
|
||||
else { // Registry configurations are stored by name
|
||||
String sConfigName = XPropertySetHelper.getPropertyValueAsString(xProps,"ConfigName");
|
||||
for (short i=0; i<nRegConfigs; i++) {
|
||||
if (sConfigNames[i].equals(sConfigName)) {
|
||||
setListBoxSelectedItem("Config",(short) (nStdConfigs+i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected short saveConfig(XPropertySet xProps, PropertyHelper filterData) {
|
||||
// The Config list box is common for all dialogs
|
||||
Object configurations = XPropertySetHelper.getPropertyValue(xProps,"Configurations");
|
||||
XNameAccess xNameAccess = (XNameAccess)
|
||||
UnoRuntime.queryInterface(XNameAccess.class,configurations);
|
||||
|
||||
short nConfig = getListBoxSelectedItem("Config");
|
||||
int nStdConfigs = getListBoxStringItemList("Config").length - sConfigNames.length;
|
||||
if (nConfig>=nStdConfigs) { // only handle registry configurations
|
||||
int i = nConfig-nStdConfigs;
|
||||
XPropertySetHelper.setPropertyValue(xProps,"ConfigName",sConfigNames[i]);
|
||||
try {
|
||||
Object config = xNameAccess.getByName(sConfigNames[i]);
|
||||
XPropertySet xCfgProps = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class,config);
|
||||
MacroExpander expander = new MacroExpander(xContext);
|
||||
filterData.put("ConfigURL",expander.expandMacros(XPropertySetHelper.getPropertyValueAsString(xCfgProps,"ConfigURL")));
|
||||
filterData.put("TemplateURL",expander.expandMacros(XPropertySetHelper.getPropertyValueAsString(xCfgProps,"TargetTemplateURL")));
|
||||
filterData.put("StyleSheetURL",expander.expandMacros(XPropertySetHelper.getPropertyValueAsString(xCfgProps,"StyleSheetURL")));
|
||||
|
||||
// The resources are provided as a set
|
||||
Object resources = XPropertySetHelper.getPropertyValue(xCfgProps,"Resources");
|
||||
XNameAccess xResourceNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,resources);
|
||||
if (xResourceNameAccess!=null) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
String[] sResourceNames = xResourceNameAccess.getElementNames();
|
||||
for (String sName : sResourceNames) {
|
||||
Object resource = xResourceNameAccess.getByName(sName);
|
||||
XPropertySet xResourceProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,resource);
|
||||
String sURL = expander.expandMacros(XPropertySetHelper.getPropertyValueAsString(xResourceProps,"URL"));
|
||||
String sFileName = expander.expandMacros(XPropertySetHelper.getPropertyValueAsString(xResourceProps,"FileName"));
|
||||
String sMediaType = expander.expandMacros(XPropertySetHelper.getPropertyValueAsString(xResourceProps,"MediaType"));
|
||||
if (buf.length()>0) { buf.append(';'); }
|
||||
buf.append(sURL).append("::").append(sFileName).append("::").append(sMediaType);
|
||||
}
|
||||
filterData.put("Resources",buf.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
else { // Standard configurations have no name
|
||||
XPropertySetHelper.setPropertyValue(xProps,"ConfigName","");
|
||||
}
|
||||
XPropertySetHelper.setPropertyValue(xProps,"Config",nConfig);
|
||||
return nConfig;
|
||||
}
|
||||
|
||||
// Check box option (boolean)
|
||||
protected boolean loadCheckBoxOption(XPropertySet xProps, String sName) {
|
||||
boolean bValue = XPropertySetHelper.getPropertyValueAsBoolean(xProps,sName);
|
||||
setCheckBoxStateAsBoolean(sName, bValue);
|
||||
return bValue;
|
||||
}
|
||||
|
||||
protected boolean saveCheckBoxOption(XPropertySet xProps, String sName) {
|
||||
boolean bValue = getCheckBoxStateAsBoolean(sName);
|
||||
XPropertySetHelper.setPropertyValue(xProps, sName, bValue);
|
||||
return bValue;
|
||||
}
|
||||
|
||||
protected boolean saveCheckBoxOption(XPropertySet xProps, PropertyHelper filterData,
|
||||
String sName, String sOptionName) {
|
||||
boolean bValue = saveCheckBoxOption(xProps, sName);
|
||||
if (!isLocked(sOptionName)) {
|
||||
filterData.put(sOptionName, Boolean.toString(bValue));
|
||||
}
|
||||
return bValue;
|
||||
}
|
||||
|
||||
// List box option
|
||||
protected short loadListBoxOption(XPropertySet xProps, String sName) {
|
||||
short nValue = XPropertySetHelper.getPropertyValueAsShort(xProps, sName);
|
||||
setListBoxSelectedItem(sName ,nValue);
|
||||
return nValue;
|
||||
}
|
||||
|
||||
protected short saveListBoxOption(XPropertySet xProps, String sName) {
|
||||
short nValue = getListBoxSelectedItem(sName);
|
||||
XPropertySetHelper.setPropertyValue(xProps, sName, nValue);
|
||||
return nValue;
|
||||
}
|
||||
|
||||
protected short saveListBoxOption(XPropertySet xProps, PropertyHelper filterData,
|
||||
String sName, String sOptionName, String[] sValues) {
|
||||
short nValue = saveListBoxOption(xProps, sName);
|
||||
if (!isLocked(sOptionName) && (nValue>=0) && (nValue<sValues.length)) {
|
||||
filterData.put(sOptionName, sValues[nValue]);
|
||||
}
|
||||
return nValue;
|
||||
}
|
||||
|
||||
// Combo box option
|
||||
protected String loadComboBoxOption(XPropertySet xProps, String sName) {
|
||||
String sValue = XPropertySetHelper.getPropertyValueAsString(xProps, sName);
|
||||
setComboBoxText(sName ,sValue);
|
||||
return sValue;
|
||||
}
|
||||
|
||||
protected String saveComboBoxOption(XPropertySet xProps, String sName) {
|
||||
String sValue = getComboBoxText(sName);
|
||||
XPropertySetHelper.setPropertyValue(xProps, sName, sValue);
|
||||
return sValue;
|
||||
}
|
||||
|
||||
protected String saveComboBoxOption(XPropertySet xProps, PropertyHelper filterData,
|
||||
String sName, String sOptionName) {
|
||||
String sValue = saveComboBoxOption(xProps, sName);
|
||||
if (!isLocked(sOptionName)) {
|
||||
filterData.put(sOptionName, sValue);
|
||||
}
|
||||
return sValue;
|
||||
}
|
||||
|
||||
// Text Field option
|
||||
protected String loadTextFieldOption(XPropertySet xProps, String sName) {
|
||||
String sValue = XPropertySetHelper.getPropertyValueAsString(xProps, sName);
|
||||
setTextFieldText(sName ,sValue);
|
||||
return sValue;
|
||||
}
|
||||
|
||||
protected String saveTextFieldOption(XPropertySet xProps, String sName) {
|
||||
String sValue = getTextFieldText(sName);
|
||||
XPropertySetHelper.setPropertyValue(xProps, sName, sValue);
|
||||
return sValue;
|
||||
}
|
||||
|
||||
protected String saveTextFieldOption(XPropertySet xProps, PropertyHelper filterData,
|
||||
String sName, String sOptionName) {
|
||||
String sValue = saveTextFieldOption(xProps, sName);
|
||||
if (!isLocked(sOptionName)) {
|
||||
filterData.put(sOptionName, sValue);
|
||||
}
|
||||
return sValue;
|
||||
}
|
||||
|
||||
// Numeric option
|
||||
protected int loadNumericOption(XPropertySet xProps, String sName) {
|
||||
int nValue = XPropertySetHelper.getPropertyValueAsInteger(xProps, sName);
|
||||
setNumericFieldValue(sName, nValue);
|
||||
return nValue;
|
||||
}
|
||||
|
||||
protected int saveNumericOption(XPropertySet xProps, String sName) {
|
||||
int nValue = getNumericFieldValue(sName);
|
||||
XPropertySetHelper.setPropertyValue(xProps, sName, nValue);
|
||||
return nValue;
|
||||
}
|
||||
|
||||
protected int saveNumericOptionAsPercentage(XPropertySet xProps,
|
||||
PropertyHelper filterData, String sName, String sOptionName) {
|
||||
int nValue = saveNumericOption(xProps, sName);
|
||||
if (!isLocked(sOptionName)) {
|
||||
filterData.put(sOptionName,Integer.toString(nValue)+"%");
|
||||
}
|
||||
return nValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,264 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* UNOConverter.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-05-06)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.io.XInputStream;
|
||||
import com.sun.star.io.XOutputStream;
|
||||
import com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter;
|
||||
import com.sun.star.lib.uno.adapter.XOutputStreamToOutputStreamAdapter;
|
||||
import com.sun.star.ucb.XSimpleFileAccess2;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import w2phtml.api.Converter;
|
||||
import w2phtml.api.ConverterFactory;
|
||||
import w2phtml.api.ConverterResult;
|
||||
import w2phtml.api.OutputFile;
|
||||
import w2phtml.util.Misc;
|
||||
|
||||
/** This class provides conversion using UNO:
|
||||
* Graphics conversion is done using appropriate UNO services.
|
||||
* Files are written to an URL using UCB.
|
||||
* The document source document can be provided as an <code>XInputStream</code> or as a DOM tree
|
||||
*/
|
||||
public class UNOConverter {
|
||||
private XComponentContext xComponentContext;
|
||||
private Converter converter;
|
||||
private String sTargetFormat = null;
|
||||
private XOutputStream xos = null;
|
||||
private String sURL = null;
|
||||
|
||||
/** Construct a new UNODocumentConverter from an array of arguments
|
||||
*
|
||||
* @param xComponentContext the component context used to instantiate new UNO services
|
||||
* @param lArguments arguments providing FilterName, URL, OutputStream (optional), FilterData (optional)
|
||||
* and FilterOptions (optional, alternative to FilterData)
|
||||
*/
|
||||
public UNOConverter(PropertyValue[] lArguments, XComponentContext xComponentContext) {
|
||||
this.xComponentContext = xComponentContext;
|
||||
|
||||
// Create mapping from filter names to target media types
|
||||
HashMap<String,String> filterNames = new HashMap<String,String>();
|
||||
//filterNames.put("org.openoffice.da.writer2latex","application/x-latex");
|
||||
//filterNames.put("org.openoffice.da.writer2bibtex","application/x-bibtex");
|
||||
filterNames.put("org.openoffice.da.writer2xhtml","text/html");
|
||||
filterNames.put("org.openoffice.da.writer2xhtml11","application/xhtml11");
|
||||
filterNames.put("org.openoffice.da.writer2xhtml5","text/html5");
|
||||
filterNames.put("org.openoffice.da.writer2xhtml.mathml","application/xhtml+xml");
|
||||
filterNames.put("org.openoffice.da.writer2xhtml.epub","application/epub+zip");
|
||||
filterNames.put("org.openoffice.da.writer2xhtml.epub3","epub3");
|
||||
filterNames.put("org.openoffice.da.calc2xhtml","text/html");
|
||||
filterNames.put("org.openoffice.da.calc2xhtml11","application/xhtml11");
|
||||
filterNames.put("org.openoffice.da.calc2xhtml5","text/html5");
|
||||
|
||||
// Get the arguments
|
||||
Object filterData = null;
|
||||
Object filterOptions = null;
|
||||
PropertyValue[] pValue = lArguments;
|
||||
for (int i = 0 ; i < pValue.length; i++) {
|
||||
try {
|
||||
if (pValue[i].Name.compareTo("FilterName")==0) {
|
||||
String sFilterName = (String)AnyConverter.toObject(new Type(String.class), pValue[i].Value);
|
||||
if (filterNames.containsKey(sFilterName)) {
|
||||
sTargetFormat = filterNames.get(sFilterName);
|
||||
}
|
||||
else {
|
||||
sTargetFormat = sFilterName;
|
||||
}
|
||||
}
|
||||
if (pValue[i].Name.compareTo("OutputStream")==0){
|
||||
xos = (XOutputStream)AnyConverter.toObject(new Type(XOutputStream.class), pValue[i].Value);
|
||||
}
|
||||
if (pValue[i].Name.compareTo("URL")==0){
|
||||
sURL = (String)AnyConverter.toObject(new Type(String.class), pValue[i].Value);
|
||||
}
|
||||
if (pValue[i].Name.compareTo("FilterData")==0) {
|
||||
filterData = pValue[i].Value;
|
||||
}
|
||||
if (pValue[i].Name.compareTo("FilterOptions")==0) {
|
||||
filterOptions = pValue[i].Value;
|
||||
}
|
||||
}
|
||||
catch(com.sun.star.lang.IllegalArgumentException AnyExec){
|
||||
System.err.println("\nIllegalArgumentException "+AnyExec);
|
||||
}
|
||||
}
|
||||
if (sURL==null){
|
||||
sURL="";
|
||||
}
|
||||
|
||||
// Create converter and supply it with filter data and a suitable graphic converter
|
||||
converter = ConverterFactory.createConverter(sTargetFormat);
|
||||
if (converter==null) {
|
||||
throw new com.sun.star.uno.RuntimeException("Failed to create converter to "+sTargetFormat);
|
||||
}
|
||||
if (filterData!=null) {
|
||||
FilterDataParser fdp = new FilterDataParser(xComponentContext);
|
||||
fdp.applyFilterData(filterData,converter);
|
||||
}
|
||||
else if (filterOptions!=null) {
|
||||
FilterDataParser fdp = new FilterDataParser(xComponentContext);
|
||||
fdp.applyFilterOptions(filterOptions,converter);
|
||||
}
|
||||
converter.setGraphicConverter(new GraphicConverterImpl(xComponentContext));
|
||||
|
||||
}
|
||||
|
||||
/** Convert a document given by a DOM tree
|
||||
*
|
||||
* @param dom the DOMsource
|
||||
* @throws IOException
|
||||
*/
|
||||
public void convert(Document dom) throws IOException {
|
||||
writeFiles(converter.convert(dom, Misc.makeFileName(getFileName(sURL)),true));
|
||||
}
|
||||
|
||||
/** Convert a document given by an XInputStream
|
||||
*
|
||||
* @param xis the input stream
|
||||
* @throws IOException
|
||||
*/
|
||||
public void convert(XInputStream xis) throws IOException {
|
||||
InputStream is = new XInputStreamToInputStreamAdapter(xis);
|
||||
writeFiles(converter.convert(is, Misc.makeFileName(getFileName(sURL))));
|
||||
}
|
||||
|
||||
private void writeFiles(ConverterResult result) throws IOException {
|
||||
Iterator<OutputFile> docEnum = result.iterator();
|
||||
if (docEnum.hasNext()) {
|
||||
// The master document is written to the supplied XOutputStream, if any
|
||||
if (xos!=null) {
|
||||
XOutputStreamToOutputStreamAdapter newxos =new XOutputStreamToOutputStreamAdapter(xos);
|
||||
docEnum.next().write(newxos);
|
||||
newxos.flush();
|
||||
newxos.close();
|
||||
}
|
||||
// Additional files are written directly using UCB
|
||||
if (docEnum.hasNext() && sURL.startsWith("file:")) {
|
||||
// Initialize the file access (used to write all additional output files)
|
||||
XSimpleFileAccess2 sfa2 = null;
|
||||
try {
|
||||
Object sfaObject = xComponentContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess", xComponentContext);
|
||||
sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// failed to get SimpleFileAccess service (should not happen)
|
||||
}
|
||||
|
||||
if (sfa2!=null) {
|
||||
// Remove the file name part of the URL
|
||||
String sNewURL = null;
|
||||
if (sURL.lastIndexOf("/")>-1) {
|
||||
// Take the URL up to and including the last slash
|
||||
sNewURL = sURL.substring(0,sURL.lastIndexOf("/")+1);
|
||||
}
|
||||
else {
|
||||
// The URL does not include a path; this should not really happen,
|
||||
// but in this case we will write to the current default directory
|
||||
sNewURL = "";
|
||||
}
|
||||
|
||||
while (docEnum.hasNext()) {
|
||||
OutputFile docOut = docEnum.next();
|
||||
// Get the file name and the (optional) directory name
|
||||
String sFullFileName = Misc.makeHref(docOut.getFileName());
|
||||
String sDirName = "";
|
||||
String sFileName = sFullFileName;
|
||||
int nSlash = sFileName.indexOf("/");
|
||||
if (nSlash>-1) {
|
||||
sDirName = sFileName.substring(0,nSlash);
|
||||
sFileName = sFileName.substring(nSlash+1);
|
||||
}
|
||||
|
||||
try {
|
||||
// Create subdirectory if required
|
||||
if (sDirName.length()>0 && !sfa2.exists(sNewURL+sDirName)) {
|
||||
sfa2.createFolder(sNewURL+sDirName);
|
||||
}
|
||||
|
||||
// writeFile demands an InputStream, so we use a Pipe for the transport
|
||||
Object xPipeObj = xComponentContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.io.Pipe", xComponentContext);
|
||||
XInputStream xInStream = (XInputStream) UnoRuntime.queryInterface(XInputStream.class, xPipeObj);
|
||||
XOutputStream xOutStream = (XOutputStream) UnoRuntime.queryInterface(XOutputStream.class, xPipeObj);
|
||||
OutputStream outStream = new XOutputStreamToOutputStreamAdapter(xOutStream);
|
||||
// Feed the pipe with content...
|
||||
docOut.write(outStream);
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
xOutStream.closeOutput();
|
||||
// ...and then write the content to the URL
|
||||
sfa2.writeFile(sNewURL+sFullFileName,xInStream);
|
||||
}
|
||||
catch (Throwable e){
|
||||
throw new IOException("Error writing file "+sFileName+" "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The converter did not produce any files (should not happen)
|
||||
throw new IOException("Conversion failed: Internal error");
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileName(String origName) {
|
||||
String name=null;
|
||||
if (origName !=null) {
|
||||
if(origName.equalsIgnoreCase(""))
|
||||
name = "OutFile";
|
||||
else {
|
||||
if (origName.lastIndexOf("/")>=0) {
|
||||
origName=origName.substring(origName.lastIndexOf("/")+1,origName.length());
|
||||
}
|
||||
if (origName.lastIndexOf(".")>=0) {
|
||||
name = origName.substring(0,(origName.lastIndexOf(".")));
|
||||
}
|
||||
else {
|
||||
name=origName;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
name = "OutFile";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,326 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* UNOPublisher.java
|
||||
*
|
||||
* Copyright: 2002-2018 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2018-03-06)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.w2lcommon.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.beans.XPropertyAccess;
|
||||
import com.sun.star.frame.XController;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.frame.XStorable;
|
||||
import com.sun.star.io.XInputStream;
|
||||
import com.sun.star.task.XStatusIndicator;
|
||||
import com.sun.star.task.XStatusIndicatorFactory;
|
||||
import com.sun.star.ucb.XSimpleFileAccess2;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.XModifiable;
|
||||
|
||||
import w2phtml.util.Misc;
|
||||
|
||||
/** This class converts an open office document to another format
|
||||
*/
|
||||
public class UNOPublisher {
|
||||
|
||||
public enum TargetFormat { xhtml, xhtml11, xhtml_mathml, html5, epub, epub3 };
|
||||
|
||||
private String sAppName;
|
||||
|
||||
protected XComponentContext xContext;
|
||||
protected XFrame xFrame;
|
||||
private XModel xModel = null;
|
||||
private PropertyValue[] mediaProps = null;
|
||||
|
||||
/** Create a new <code>UNOPublisher</code> based on a loaded office document
|
||||
*
|
||||
* @param xContext the component context from which new UNO services are instantiated
|
||||
* @param xFrame the current frame
|
||||
* @param sAppName the name of the application using the <code>UNOPublisher</code>
|
||||
*/
|
||||
public UNOPublisher(XComponentContext xContext, XFrame xFrame, String sAppName) {
|
||||
this.xContext = xContext;
|
||||
this.xFrame = xFrame;
|
||||
this.sAppName = sAppName;
|
||||
// Get the model for the document from the frame
|
||||
XController xController = xFrame.getController();
|
||||
if (xController!=null) {
|
||||
xModel = xController.getModel();
|
||||
}
|
||||
}
|
||||
|
||||
/** Publish the document associated with this <code>UNOPublisher</code>. This involves five steps:
|
||||
* (1) Check that the document is saved in the local file system.
|
||||
* (2) Display the options dialog.
|
||||
* (3) Save the document (if the modified flag is true).
|
||||
* (4) Convert the document.
|
||||
* (5) Post process the document, e.g. displaying the result
|
||||
*
|
||||
* @param format the target format
|
||||
* @return true if the publishing was successful
|
||||
*/
|
||||
public boolean publish(TargetFormat format) {
|
||||
if (documentSaved() && updateMediaProperties(format)) {
|
||||
// Create a (somewhat coarse grained) status indicator/progress bar
|
||||
XStatusIndicatorFactory xFactory = (com.sun.star.task.XStatusIndicatorFactory)
|
||||
UnoRuntime.queryInterface(com.sun.star.task.XStatusIndicatorFactory.class, xFrame);
|
||||
XStatusIndicator xStatus = xFactory.createStatusIndicator();
|
||||
xStatus.start(sAppName,10);
|
||||
xStatus.setValue(1); // At least we have started, that's 10% :-)
|
||||
|
||||
try {
|
||||
// Save document if required
|
||||
saveDocument();
|
||||
xStatus.setValue(4); // Document saved, that's 40%
|
||||
|
||||
// Convert to desired format
|
||||
UNOConverter converter = new UNOConverter(mediaProps, xContext);
|
||||
// Initialize the file access (to read the office document)
|
||||
XSimpleFileAccess2 sfa2 = null;
|
||||
try {
|
||||
Object sfaObject = xContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess", xContext); //$NON-NLS-1$
|
||||
sfa2 = (XSimpleFileAccess2) UnoRuntime.queryInterface(XSimpleFileAccess2.class, sfaObject);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// failed to get SimpleFileAccess service (should not happen)
|
||||
}
|
||||
XInputStream xis = sfa2.openFileRead(xModel.getURL());
|
||||
converter.convert(xis);
|
||||
xis.closeInput();
|
||||
}
|
||||
catch (IOException e) {
|
||||
xStatus.end();
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage(sAppName,Messages.getString("UNOPublisher.failexport")); //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
xStatus.end();
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage(sAppName,Messages.getString("UNOPublisher.failexport")); //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
xStatus.setValue(7); // Document is converted, that's 70%
|
||||
|
||||
postProcess(getTargetURL(format),format);
|
||||
|
||||
xStatus.setValue(10); // Export is finished (The user will usually not see this...)
|
||||
xStatus.end();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Filter the file name to avoid unwanted characters
|
||||
*
|
||||
* @param sFileName the original file name
|
||||
* @return the filtered file name
|
||||
*/
|
||||
protected String filterFileName(String sFileName) {
|
||||
return sFileName;
|
||||
}
|
||||
|
||||
/** Post process the media properties after displaying the dialog
|
||||
*
|
||||
* @param mediaProps the media properties as set by the dialog
|
||||
* @return the updated media properties
|
||||
*/
|
||||
protected PropertyValue[] postProcessMediaProps(PropertyValue[] mediaProps) {
|
||||
return mediaProps;
|
||||
}
|
||||
|
||||
/** Post process the document after conversion.
|
||||
*
|
||||
* @param sTargetURL URL of the converted document
|
||||
* @param format the target format
|
||||
*/
|
||||
protected void postProcess(String sTargetURL, TargetFormat format) {
|
||||
}
|
||||
|
||||
/** Check that the document is saved in a location, we can use
|
||||
*
|
||||
* @return true if everthing is o.k.
|
||||
*/
|
||||
public boolean documentSaved() {
|
||||
String sDocumentUrl = xModel.getURL();
|
||||
if (sDocumentUrl.length()==0) { // The document has no location
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage(sAppName,Messages.getString("UNOPublisher.savedocument")); //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
else if (!".odt".equals(Misc.getFileExtension(sDocumentUrl)) && !".fodt".equals(Misc.getFileExtension(sDocumentUrl)) && !".ods".equals(Misc.getFileExtension(sDocumentUrl)) && !".fods".equals(Misc.getFileExtension(sDocumentUrl))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage(sAppName,Messages.getString("UNOPublisher.saveodt")); //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
else if (!sDocumentUrl.startsWith("file:")) { //$NON-NLS-1$
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage(sAppName,Messages.getString("UNOPublisher.savefilesystem")); //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
else if (System.getProperty("os.name").startsWith("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// Avoid UNC paths (LaTeX does not like them)
|
||||
Pattern windowsPattern = Pattern.compile("^file:///[A-Za-z][|:].*"); //$NON-NLS-1$
|
||||
if (!windowsPattern.matcher(sDocumentUrl).matches()) {
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage(sAppName,
|
||||
Messages.getString("UNOPublisher.savedrivename")); //$NON-NLS-1$
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean saveDocument() {
|
||||
XModifiable xModifiable = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, xModel);
|
||||
if (xModifiable.isModified()) { // The document is modified and need to be saved
|
||||
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xModel);
|
||||
try {
|
||||
xStorable.store();
|
||||
} catch (com.sun.star.io.IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Some utility methods
|
||||
|
||||
/** Get the target path (or null if the document is not saved)
|
||||
*
|
||||
* @return the path
|
||||
*/
|
||||
public String getTargetPath() {
|
||||
if (xModel.getURL().length()>0) {
|
||||
String sBaseURL = Misc.removeExtension(xModel.getURL());
|
||||
return Misc.getPath(sBaseURL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Get the target file name (or null if the document is not saved)
|
||||
*
|
||||
* @return the file name
|
||||
*/
|
||||
public String getTargetFileName() {
|
||||
if (xModel.getURL().length()>0) {
|
||||
String sBaseURL = Misc.removeExtension(xModel.getURL());
|
||||
return filterFileName(Misc.getFileName(sBaseURL));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getTargetURL(TargetFormat format) {
|
||||
return getTargetPath()+getTargetFileName()+getTargetExtension(format);
|
||||
}
|
||||
|
||||
private void prepareMediaProperties(TargetFormat format) {
|
||||
// Create inital media properties
|
||||
mediaProps = new PropertyValue[2];
|
||||
mediaProps[0] = new PropertyValue();
|
||||
mediaProps[0].Name = "FilterName"; //$NON-NLS-1$
|
||||
mediaProps[0].Value = getFilterName(format);
|
||||
mediaProps[1] = new PropertyValue();
|
||||
mediaProps[1].Name = "URL"; //$NON-NLS-1$
|
||||
mediaProps[1].Value = getTargetURL(format);
|
||||
}
|
||||
|
||||
private boolean updateMediaProperties(TargetFormat format) {
|
||||
prepareMediaProperties(format);
|
||||
|
||||
String sDialogName = getDialogName(format);
|
||||
if (sDialogName!=null) {
|
||||
try {
|
||||
// Display options dialog
|
||||
Object dialog = xContext.getServiceManager()
|
||||
.createInstanceWithContext(sDialogName, xContext);
|
||||
|
||||
XPropertyAccess xPropertyAccess = (XPropertyAccess)
|
||||
UnoRuntime.queryInterface(XPropertyAccess.class, dialog);
|
||||
xPropertyAccess.setPropertyValues(mediaProps);
|
||||
|
||||
XExecutableDialog xDialog = (XExecutableDialog)
|
||||
UnoRuntime.queryInterface(XExecutableDialog.class, dialog);
|
||||
if (xDialog.execute()==ExecutableDialogResults.OK) {
|
||||
mediaProps = postProcessMediaProps(xPropertyAccess.getPropertyValues());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.beans.UnknownPropertyException e) {
|
||||
// setPropertyValues will not fail..
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
// getServiceManager will not fail..
|
||||
}
|
||||
}
|
||||
// No dialog exists, or the dialog was cancelled
|
||||
mediaProps = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String getTargetExtension(TargetFormat format) {
|
||||
switch (format) {
|
||||
case xhtml: return ".html"; //$NON-NLS-1$
|
||||
case xhtml11: return ".xhtml"; //$NON-NLS-1$
|
||||
case xhtml_mathml: return ".xhtml"; //$NON-NLS-1$
|
||||
case html5: return ".html"; //$NON-NLS-1$
|
||||
case epub: return ".epub"; //$NON-NLS-1$
|
||||
case epub3: return ".epub"; //$NON-NLS-1$
|
||||
default: return ""; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private static String getDialogName(TargetFormat format) {
|
||||
switch (format) {
|
||||
case xhtml:
|
||||
case xhtml11: return "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialog"; //$NON-NLS-1$
|
||||
case xhtml_mathml:
|
||||
case html5: return "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialogMath"; //$NON-NLS-1$
|
||||
case epub: return "org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog"; //$NON-NLS-1$
|
||||
case epub3: return "org.openoffice.da.comp.writer2xhtml.Epub3OptionsDialog"; //$NON-NLS-1$
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getFilterName(TargetFormat format) {
|
||||
switch (format) {
|
||||
case xhtml: return "org.openoffice.da.writer2xhtml"; //$NON-NLS-1$
|
||||
case xhtml11: return "org.openoffice.da.writer2xhtml11"; //$NON-NLS-1$
|
||||
case xhtml_mathml: return "org.openoffice.da.writer2xhtml.mathml"; //$NON-NLS-1$
|
||||
case html5: return "org.openoffice.da.writer2xhtml5"; //$NON-NLS-1$
|
||||
case epub: return "org.openoffice.da.writer2xhtml.epub"; //$NON-NLS-1$
|
||||
case epub3: return "org.openoffice.da.writer2xhtml.epub3"; //$NON-NLS-1$
|
||||
default: return ""; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
UNOPublisher.failexport=Error: Failed to export document
|
||||
UNOPublisher.savedocument=Please save the document first
|
||||
UNOPublisher.saveodt=Please save the document in OpenDocument format (.odt)
|
||||
UNOPublisher.savefilesystem=Please save the document in the local file system
|
||||
UNOPublisher.savedrivename=Please save the document on a location with a drive name
|
|
@ -1,5 +0,0 @@
|
|||
UNOPublisher.failexport=Fejl: Kunne ikke eksportere dokumentet
|
||||
UNOPublisher.savedocument=Gem dokumentet først
|
||||
UNOPublisher.saveodt=Gem dokumentet i OpenDocument-format (.odt)
|
||||
UNOPublisher.savefilesystem=Gem dokumentet i det lokale filsystem
|
||||
UNOPublisher.savedrivename=Gem dokumentet et sted med et drevbogstav
|
|
@ -1,355 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* DialogAccess.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-15)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.awt.XControl;
|
||||
import com.sun.star.awt.XControlContainer;
|
||||
import com.sun.star.awt.XControlModel;
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.util.Date;
|
||||
|
||||
|
||||
/** This class provides some convenient methods to access a uno dialog
|
||||
*/
|
||||
public class DialogAccess {
|
||||
|
||||
/** The XDialog containing the controls. */
|
||||
private XDialog xDialog = null;
|
||||
|
||||
// State of a checkbox
|
||||
|
||||
public static final short CHECKBOX_NOT_CHECKED = 0;
|
||||
public static final short CHECKBOX_CHECKED = 1;
|
||||
public static final short CHECKBOX_DONT_KNOW = 2;
|
||||
|
||||
public DialogAccess(XDialog xDialog) {
|
||||
this.xDialog = xDialog;
|
||||
}
|
||||
|
||||
protected void setDialog(XDialog xDialog) {
|
||||
this.xDialog = xDialog;
|
||||
}
|
||||
|
||||
protected XDialog getDialog() {
|
||||
return this.xDialog;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Helpers to access controls in the dialog (to be used by the subclass)
|
||||
// Note: The helpers fail silently if an exception occurs. Could query the
|
||||
// the ClassId property for the control type and check that the property
|
||||
// exists to ensure a correct behaviour in all cases, but as long as the
|
||||
// helpers are used correctly, this doesn't really matter.
|
||||
|
||||
// Get the properties of a named control in the dialog
|
||||
public XPropertySet getControlProperties(String sControlName) {
|
||||
XControlContainer xContainer = (XControlContainer)
|
||||
UnoRuntime.queryInterface(XControlContainer.class, xDialog);
|
||||
XControl xControl = xContainer.getControl(sControlName);
|
||||
XControlModel xModel = xControl.getModel();
|
||||
XPropertySet xPropertySet = (XPropertySet)
|
||||
UnoRuntime.queryInterface(XPropertySet.class, xModel);
|
||||
return xPropertySet;
|
||||
}
|
||||
|
||||
|
||||
public boolean getControlEnabled(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Boolean) xPropertySet.getPropertyValue("Enabled")).booleanValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setControlEnabled(String sControlName, boolean bEnabled) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Enabled", new Boolean(bEnabled));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public short getCheckBoxState(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Short) xPropertySet.getPropertyValue("State")).shortValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e);
|
||||
|
||||
// Will fail if the control does not exist or is not a checkbox
|
||||
return CHECKBOX_DONT_KNOW;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getCheckBoxStateAsBoolean(String sControlName) {
|
||||
return getCheckBoxState(sControlName)==CHECKBOX_CHECKED;
|
||||
}
|
||||
|
||||
public void setCheckBoxState(String sControlName, short nState) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("State",new Short(nState));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// will fail if the control does not exist or is not a checkbox or
|
||||
// nState has an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
public void setCheckBoxStateAsBoolean(String sControlName, boolean bChecked) {
|
||||
setCheckBoxState(sControlName,bChecked ? CHECKBOX_CHECKED : CHECKBOX_NOT_CHECKED);
|
||||
}
|
||||
|
||||
public String[] getListBoxStringItemList(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String[]) xPropertySet.getPropertyValue("StringItemList");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void setListBoxStringItemList(String sControlName, String[] items) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("StringItemList",items);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
}
|
||||
}
|
||||
|
||||
public short getListBoxSelectedItem(String sControlName) {
|
||||
// Returns the first selected element in case of a multiselection
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
short[] selection = (short[]) xPropertySet.getPropertyValue("SelectedItems");
|
||||
return selection[0];
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void setListBoxSelectedItem(String sControlName, short nIndex) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
short[] selection = new short[1];
|
||||
selection[0] = nIndex;
|
||||
xPropertySet.setPropertyValue("SelectedItems",selection);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box or
|
||||
// nIndex is an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
public short getListBoxLineCount(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Short) xPropertySet.getPropertyValue("LineCount")).shortValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setListBoxLineCount(String sControlName, short nLineCount) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("LineCount",new Short(nLineCount));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a list box or
|
||||
// nLineCount is an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
public String getComboBoxText(String sControlName) {
|
||||
// Returns the text of a combobox
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Text");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a combo
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setComboBoxText(String sControlName, String sText) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Text", sText);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a combo box or
|
||||
// nText is an illegal value
|
||||
}
|
||||
}
|
||||
|
||||
public String getLabelText(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Label");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a label
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setLabelText(String sControlName, String sLabel) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Label",sLabel);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a label
|
||||
}
|
||||
}
|
||||
|
||||
public String getTextFieldText(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Text");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a text field
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextFieldText(String sControlName, String sText) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Text",sText);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a text field
|
||||
}
|
||||
}
|
||||
|
||||
public String getFormattedFieldText(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return (String) xPropertySet.getPropertyValue("Text");
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a formatted field
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setFormattedFieldText(String sControlName, String sText) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Text",sText);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a formatted field
|
||||
}
|
||||
}
|
||||
|
||||
public int getDateFieldValue(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
Object dateObject = xPropertySet.getPropertyValue("Date");
|
||||
if (dateObject instanceof Date) {
|
||||
// Since LO 4.1
|
||||
Date date = (Date) dateObject;
|
||||
return 10000*date.Year+100*date.Month+date.Day;
|
||||
}
|
||||
else if (dateObject instanceof Integer) {
|
||||
// AOO and older versions of LO
|
||||
return ((Integer) dateObject).intValue();
|
||||
}
|
||||
else {
|
||||
// The date field does not have a value
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a date field
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDateFieldValue(String sControlName, int nValue) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
Date date = new Date();
|
||||
date.Year = (short) (nValue/10000);
|
||||
date.Month = (short) ((nValue%10000)/100);
|
||||
date.Day = (short) (nValue%100);
|
||||
|
||||
// TODO: Use reflection to identify the correct type of the property
|
||||
try {
|
||||
// Since LO 4.1
|
||||
xPropertySet.setPropertyValue("Date", date);
|
||||
} catch (Exception e) {
|
||||
// AOO and older versions of LO
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Date", nValue);
|
||||
} catch (Exception e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getNumericFieldValue(String sControlName) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
return ((Double) xPropertySet.getPropertyValue("Value")).intValue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a numeric field
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setNumericFieldValue(String sControlName, int nValue) {
|
||||
XPropertySet xPropertySet = getControlProperties(sControlName);
|
||||
try {
|
||||
xPropertySet.setPropertyValue("Value",new Double(nValue));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Will fail if the control does not exist or is not a numeric field
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,203 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* DialogBase.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-15)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.awt.XDialogEventHandler;
|
||||
import com.sun.star.awt.XDialogProvider2;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.lang.XServiceInfo;
|
||||
import com.sun.star.lang.XServiceName;
|
||||
import com.sun.star.lang.XTypeProvider;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
|
||||
/** This class provides an abstract uno component which implements a dialog
|
||||
* from an xml description (using the DialogProvider2 service)
|
||||
*/
|
||||
public abstract class DialogBase extends DialogAccess implements
|
||||
XTypeProvider, XServiceInfo, XServiceName, // Uno component
|
||||
XExecutableDialog, // Execute the dialog
|
||||
XDialogEventHandler { // Event handling for dialog
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// The subclass must override the following; and override the
|
||||
// implementation of XDialogEventHandler if needed
|
||||
|
||||
/** The component will be registered under this name.
|
||||
* The subclass must override this with a suitable name
|
||||
*/
|
||||
public static String __serviceName = "";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
* The subclass must override this with a suitable name
|
||||
*/
|
||||
public static String __implementationName = "";
|
||||
|
||||
/** Return the name of the library containing the dialog
|
||||
* The subclass must override this to provide the name of the library
|
||||
*/
|
||||
public abstract String getDialogLibraryName();
|
||||
|
||||
/** Return the name of the dialog within the library
|
||||
* The subclass must override this to provide the name of the dialog
|
||||
*/
|
||||
public abstract String getDialogName();
|
||||
|
||||
/** Initialize the dialog (eg. with settings from the registry)
|
||||
* The subclass must implement this
|
||||
*/
|
||||
protected abstract void initialize();
|
||||
|
||||
/** End the dialog after execution (eg. save settings to the registry)
|
||||
* The subclass must implement this
|
||||
*/
|
||||
protected abstract void endDialog();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Some private global variables
|
||||
|
||||
// The component context (from constructor)
|
||||
protected XComponentContext xContext;
|
||||
|
||||
// The dialog title (created by XExecutableDialog implementation)
|
||||
private String sTitle;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// The constructor
|
||||
|
||||
/** Create a new OptionsDialogBase */
|
||||
public DialogBase(XComponentContext xContext) {
|
||||
super(null);
|
||||
this.xContext = xContext;
|
||||
sTitle = null;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Implement uno interfaces
|
||||
|
||||
// Implement the interface XTypeProvider
|
||||
public Type[] getTypes() {
|
||||
Type[] typeReturn = {};
|
||||
try {
|
||||
typeReturn = new Type[] {
|
||||
new Type( XServiceName.class ),
|
||||
new Type( XServiceInfo.class ),
|
||||
new Type( XTypeProvider.class ),
|
||||
new Type( XExecutableDialog.class ),
|
||||
new Type( XDialogEventHandler.class ) };
|
||||
} catch(Exception exception) {
|
||||
}
|
||||
return typeReturn;
|
||||
}
|
||||
|
||||
public byte[] getImplementationId() {
|
||||
byte[] byteReturn = {};
|
||||
byteReturn = new String( "" + this.hashCode() ).getBytes();
|
||||
return( byteReturn );
|
||||
}
|
||||
|
||||
|
||||
// Implement the interface XServiceName
|
||||
public String getServiceName() {
|
||||
return __serviceName;
|
||||
}
|
||||
|
||||
|
||||
// Implement the interface XServiceInfo
|
||||
public boolean supportsService(String sServiceName) {
|
||||
return sServiceName.equals(__serviceName);
|
||||
}
|
||||
|
||||
public String getImplementationName() {
|
||||
return __implementationName;
|
||||
}
|
||||
|
||||
public String[] getSupportedServiceNames() {
|
||||
String[] sSupportedServiceNames = { __serviceName };
|
||||
return sSupportedServiceNames;
|
||||
}
|
||||
|
||||
|
||||
// Implement the interface XExecutableDialog
|
||||
public void setTitle(String sTitle) {
|
||||
this.sTitle = sTitle;
|
||||
}
|
||||
|
||||
public short execute() {
|
||||
try {
|
||||
// Create the dialog
|
||||
XMultiComponentFactory xMCF = xContext.getServiceManager();
|
||||
Object provider = xMCF.createInstanceWithContext(
|
||||
"com.sun.star.awt.DialogProvider2", xContext);
|
||||
XDialogProvider2 xDialogProvider = (XDialogProvider2)
|
||||
UnoRuntime.queryInterface(XDialogProvider2.class, provider);
|
||||
String sDialogUrl = "vnd.sun.star.script:"+getDialogLibraryName()+"."
|
||||
+getDialogName()+"?location=application";
|
||||
setDialog(xDialogProvider.createDialogWithHandler(sDialogUrl, this));
|
||||
if (sTitle!=null) { getDialog().setTitle(sTitle); }
|
||||
|
||||
// Do initialization using method from subclass
|
||||
initialize();
|
||||
|
||||
// Execute the dialog
|
||||
short nResult = getDialog().execute();
|
||||
|
||||
if (nResult == ExecutableDialogResults.OK) {
|
||||
// Finalize after execution of dialog using method from subclass
|
||||
endDialog();
|
||||
}
|
||||
getDialog().endExecute();
|
||||
return nResult;
|
||||
}
|
||||
catch (Exception e) {
|
||||
// continue as if the dialog was executed OK
|
||||
return ExecutableDialogResults.OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Implement the interface XDialogEventHandler
|
||||
public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) {
|
||||
// Do nothing, leaving the responsibility to the subclass
|
||||
return true;
|
||||
}
|
||||
|
||||
public String[] getSupportedMethodNames() {
|
||||
// We do not support any method names, subclass should take care of this
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* FiledMasterNameProvider.java
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.2 (2010-12-09)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.star.container.XNameAccess;
|
||||
import com.sun.star.frame.XController;
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.text.XTextFieldsSupplier;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
/** This class provides access to the names of all field masters in the current document
|
||||
*/
|
||||
public class FieldMasterNameProvider {
|
||||
private String[] fieldMasterNames;
|
||||
|
||||
/** Construct a new <code>FieldMasterNameProvider</code>
|
||||
*
|
||||
* @param xContext the component context to get the desktop from
|
||||
*/
|
||||
public FieldMasterNameProvider(XComponentContext xContext) {
|
||||
fieldMasterNames = new String[0];
|
||||
|
||||
// TODO: This code should be shared (identical with StyleNameProvider...)
|
||||
// Get the model for the current frame
|
||||
XModel xModel = null;
|
||||
try {
|
||||
Object desktop = xContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
|
||||
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop);
|
||||
XController xController = xDesktop.getCurrentFrame().getController();
|
||||
if (xController!=null) {
|
||||
xModel = xController.getModel();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// Get the field masters from the model
|
||||
if (xModel!=null) {
|
||||
XTextFieldsSupplier xSupplier = (XTextFieldsSupplier) UnoRuntime.queryInterface(
|
||||
XTextFieldsSupplier.class, xModel);
|
||||
if (xSupplier!=null) {
|
||||
XNameAccess xFieldMasters = xSupplier.getTextFieldMasters();
|
||||
fieldMasterNames = xFieldMasters.getElementNames();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the names of all field masters relative to a given prefix
|
||||
*
|
||||
* @param sPrefix the prefix to look for, e.g. "com.sun.star.text.fieldmaster.SetExpression."
|
||||
* @return a read only <code>Set</code> containing all known names with the given prefix, stripped for the prefix
|
||||
*/
|
||||
public Set<String> getFieldMasterNames(String sPrefix) {
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (String sName : fieldMasterNames) {
|
||||
if (sName.startsWith(sPrefix)) {
|
||||
names.add(sName.substring(sPrefix.length()));
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* FilePicker.java
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.4 (2014-09-24)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.lang.IllegalArgumentException;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.ui.dialogs.XFilePicker;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class FilePicker {
|
||||
|
||||
private XComponentContext xContext;
|
||||
|
||||
// The default directory for the dialog
|
||||
private String sDirectoryURL;
|
||||
|
||||
/** Convenience wrapper class for the UNO file picker service
|
||||
*
|
||||
* @param xContext the UNO component context from which the file picker can be created
|
||||
*/
|
||||
public FilePicker(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
sDirectoryURL = null;
|
||||
}
|
||||
|
||||
/** Get one or more user selected paths with a file picker
|
||||
*
|
||||
* Warning: This does not work on all platforms when using native file pickers
|
||||
* (but always when using Office file pickers)
|
||||
*
|
||||
* @return array containing the path URLs or null if the dialog is canceled
|
||||
*/
|
||||
public String[] getPaths() {
|
||||
return getPaths(true);
|
||||
}
|
||||
|
||||
/** Get a user selected path with a file picker
|
||||
*
|
||||
* @return the path URL or null if the dialog is canceled
|
||||
*/
|
||||
public String getPath() {
|
||||
String[] sPaths = getPaths(false);
|
||||
if (sPaths!=null && sPaths.length>0) {
|
||||
return sPaths[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String[] getPaths(boolean bAllowMultiSelection) {
|
||||
// Create FilePicker
|
||||
Object filePicker = null;
|
||||
try {
|
||||
// Note: Could be changed for OfficeFilePicker to always use internal file pickers
|
||||
filePicker = xContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FilePicker", xContext);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the required interfaces
|
||||
XFilePicker xFilePicker = (XFilePicker) UnoRuntime.queryInterface(XFilePicker.class, filePicker);
|
||||
XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, xFilePicker);
|
||||
|
||||
// Configure the file picker
|
||||
xFilePicker.setMultiSelectionMode(bAllowMultiSelection);
|
||||
if (sDirectoryURL!=null) {
|
||||
try {
|
||||
xFilePicker.setDisplayDirectory(sDirectoryURL);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Get the paths
|
||||
String[] sPaths = null;
|
||||
if (xExecutable.execute() == ExecutableDialogResults.OK) {
|
||||
sDirectoryURL = xFilePicker.getDisplayDirectory();
|
||||
String[] sPathList = xFilePicker.getFiles();
|
||||
int nCount = sPathList.length;
|
||||
if (nCount>1) {
|
||||
// According to the spec, the first entry is the path and remaining entries are file names
|
||||
sPaths = new String[nCount-1];
|
||||
for (int i=1; i<nCount; i++) {
|
||||
sPaths[i-1]=sPathList[0] + sPathList[i];
|
||||
}
|
||||
}
|
||||
else if (nCount==1) {
|
||||
sPaths = sPathList;
|
||||
}
|
||||
}
|
||||
|
||||
// Dispose the file picker
|
||||
XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xFilePicker);
|
||||
xComponent.dispose();
|
||||
|
||||
return sPaths;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* FolderPicker.java
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.2 (2010-10-11)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.ui.dialogs.XFolderPicker;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class FolderPicker {
|
||||
|
||||
private XComponentContext xContext;
|
||||
|
||||
/** Convenience wrapper class for the UNO folder picker service
|
||||
*
|
||||
* @param xContext the UNO component context from which the folder picker can be created
|
||||
*/
|
||||
public FolderPicker(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
}
|
||||
|
||||
/** Get a user selected path with a folder picker
|
||||
*
|
||||
* @return the path or null if the dialog is canceled
|
||||
*/
|
||||
public String getPath() {
|
||||
// Create FolderPicker
|
||||
Object folderPicker = null;
|
||||
try {
|
||||
folderPicker = xContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FolderPicker", xContext);
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Display the FolderPicker
|
||||
XFolderPicker xFolderPicker = (XFolderPicker) UnoRuntime.queryInterface(XFolderPicker.class, folderPicker);
|
||||
XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, xFolderPicker);
|
||||
|
||||
// Get the path
|
||||
String sPath = null;
|
||||
|
||||
if (xExecutable.execute() == ExecutableDialogResults.OK) {
|
||||
sPath = xFolderPicker.getDirectory();
|
||||
}
|
||||
|
||||
// Dispose the folder picker
|
||||
XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, folderPicker);
|
||||
if (xComponent!=null) { // Seems not to be ??
|
||||
xComponent.dispose();
|
||||
}
|
||||
|
||||
return sPath;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* MacroExpander.java
|
||||
*
|
||||
* Copyright: 2002-2010 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.2 (2010-03-12)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.lang.IllegalArgumentException;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.XMacroExpander;
|
||||
|
||||
public class MacroExpander {
|
||||
|
||||
private XMacroExpander xExpander;
|
||||
|
||||
/** Convenience wrapper class for the UNO Macro Expander singleton
|
||||
*
|
||||
* @param xContext the UNO component context from which "theMacroExpander" can be created
|
||||
*/
|
||||
public MacroExpander(XComponentContext xContext) {
|
||||
Object expander = xContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander");
|
||||
xExpander = (XMacroExpander) UnoRuntime.queryInterface (XMacroExpander.class, expander);
|
||||
}
|
||||
|
||||
/** Expand macros in a string
|
||||
*
|
||||
* @param s the string
|
||||
* @return the expanded string
|
||||
*/
|
||||
public String expandMacros(String s) {
|
||||
if (xExpander!=null && s.startsWith("vnd.sun.star.expand:")) {
|
||||
// The string contains a macro, usually as a result of using %origin% in the registry
|
||||
s = s.substring(20);
|
||||
try {
|
||||
return xExpander.expandMacros(s);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// Unknown macro name found, proceed and hope for the best
|
||||
return s;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* MessageBox.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-02-16)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.awt.Rectangle;
|
||||
import com.sun.star.awt.WindowAttribute;
|
||||
import com.sun.star.awt.WindowClass;
|
||||
import com.sun.star.awt.WindowDescriptor;
|
||||
import com.sun.star.awt.XMessageBox;
|
||||
import com.sun.star.awt.XToolkit;
|
||||
import com.sun.star.awt.XWindowPeer;
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
/** This class provides simple access to a uno awt message box
|
||||
*/
|
||||
public class MessageBox {
|
||||
|
||||
private XFrame xFrame;
|
||||
private XToolkit xToolkit;
|
||||
|
||||
/** Create a new MessageBox belonging to the current frame
|
||||
*/
|
||||
public MessageBox(XComponentContext xContext) {
|
||||
this(xContext,null);
|
||||
}
|
||||
|
||||
/** Create a new MessageBox belonging to a specific frame
|
||||
*/
|
||||
public MessageBox(XComponentContext xContext, XFrame xFrame) {
|
||||
try {
|
||||
Object toolkit = xContext.getServiceManager()
|
||||
.createInstanceWithContext("com.sun.star.awt.Toolkit",xContext);
|
||||
xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class,toolkit);
|
||||
if (xFrame==null) {
|
||||
Object desktop = xContext.getServiceManager()
|
||||
.createInstanceWithContext("com.sun.star.frame.Desktop",xContext);
|
||||
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class,desktop);
|
||||
xFrame = xDesktop.getCurrentFrame();
|
||||
}
|
||||
this.xFrame = xFrame;
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Failed to get toolkit or frame
|
||||
xToolkit = null;
|
||||
xFrame = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void showMessage(String sTitle, String sMessage) {
|
||||
if (xToolkit==null || xFrame==null) { return; }
|
||||
try {
|
||||
WindowDescriptor descriptor = new WindowDescriptor();
|
||||
descriptor.Type = WindowClass.MODALTOP;
|
||||
descriptor.WindowServiceName = "infobox";
|
||||
descriptor.ParentIndex = -1;
|
||||
descriptor.Parent = (XWindowPeer) UnoRuntime.queryInterface(
|
||||
XWindowPeer.class,xFrame.getContainerWindow());
|
||||
descriptor.Bounds = new Rectangle(200,100,300,200);
|
||||
descriptor.WindowAttributes = WindowAttribute.BORDER |
|
||||
WindowAttribute.MOVEABLE | WindowAttribute.CLOSEABLE;
|
||||
XWindowPeer xPeer = xToolkit.createWindow(descriptor);
|
||||
if (xPeer!=null) {
|
||||
XMessageBox xMessageBox = (XMessageBox)
|
||||
UnoRuntime.queryInterface(XMessageBox.class,xPeer);
|
||||
if (xMessageBox!=null) {
|
||||
xMessageBox.setCaptionText(sTitle);
|
||||
xMessageBox.setMessageText(sMessage);
|
||||
xMessageBox.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore, give up...
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* PropertyHelper.java
|
||||
*
|
||||
* Copyright: 2002-2008 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.0 (2008-07-21)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
|
||||
/** This class provides access by name to a <code>PropertyValue</code> array
|
||||
*/
|
||||
public class PropertyHelper {
|
||||
|
||||
private Hashtable<String, Object> data;
|
||||
|
||||
public PropertyHelper() {
|
||||
data = new Hashtable<String, Object>();
|
||||
}
|
||||
|
||||
public PropertyHelper(PropertyValue[] props) {
|
||||
data = new Hashtable<String, Object>();
|
||||
int nLen = props.length;
|
||||
for (int i=0; i<nLen; i++) {
|
||||
data.put(props[i].Name,props[i].Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String sName, Object value) {
|
||||
data.put(sName,value);
|
||||
}
|
||||
|
||||
public Object get(String sName) {
|
||||
return data.get(sName);
|
||||
}
|
||||
|
||||
public Enumeration<String> keys() {
|
||||
return data.keys();
|
||||
}
|
||||
|
||||
public PropertyValue[] toArray() {
|
||||
int nSize = data.size();
|
||||
PropertyValue[] props = new PropertyValue[nSize];
|
||||
int i=0;
|
||||
Enumeration<String> keys = keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String sKey = keys.nextElement();
|
||||
props[i] = new PropertyValue();
|
||||
props[i].Name = sKey;
|
||||
props[i++].Value = get(sKey);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/**
|
||||
* RegistryHelper.java
|
||||
*
|
||||
* Copyright: 2002-2009 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.2 (2009-05-01)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiServiceFactory;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
|
||||
/** This class defines convenience methods to access the OOo registry
|
||||
* using a given base path
|
||||
*/
|
||||
public class RegistryHelper {
|
||||
|
||||
private XComponentContext xContext;
|
||||
|
||||
/** Construct a new RegistryHelper using a given component context
|
||||
*
|
||||
* @param xContext the context to use to create new services
|
||||
*/
|
||||
public RegistryHelper(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
}
|
||||
|
||||
/** Get a registry view relative to the given path
|
||||
*
|
||||
* @param sPath the base path within the registry
|
||||
* @param bUpdate true if we need update access
|
||||
* @return the registry view
|
||||
* @throws com.sun.star.uno.Exception
|
||||
*/
|
||||
public Object getRegistryView(String sPath, boolean bUpdate)
|
||||
throws com.sun.star.uno.Exception {
|
||||
//Object provider = xMSF.createInstance(
|
||||
Object provider = xContext.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.configuration.ConfigurationProvider", xContext);
|
||||
XMultiServiceFactory xProvider = (XMultiServiceFactory)
|
||||
UnoRuntime.queryInterface(XMultiServiceFactory.class,provider);
|
||||
PropertyValue[] args = new PropertyValue[1];
|
||||
args[0] = new PropertyValue();
|
||||
args[0].Name = "nodepath";
|
||||
args[0].Value = sPath;
|
||||
String sServiceName = bUpdate ?
|
||||
"com.sun.star.configuration.ConfigurationUpdateAccess" :
|
||||
"com.sun.star.configuration.ConfigurationAccess";
|
||||
Object view = xProvider.createInstanceWithArguments(sServiceName,args);
|
||||
return view;
|
||||
}
|
||||
|
||||
/** Dispose a previously obtained registry view
|
||||
*
|
||||
* @param view the view to dispose
|
||||
*/
|
||||
public void disposeRegistryView(Object view) {
|
||||
XComponent xComponent = (XComponent)
|
||||
UnoRuntime.queryInterface(XComponent.class,view);
|
||||
xComponent.dispose();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* SimpleDialog.java
|
||||
*
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.2 (2011-02-23)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.awt.XDialogProvider2;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
/** This is a simple helper class to display and access a dialog based on an
|
||||
* XML description (using the DialogProvider2 service).
|
||||
* Unlike DialogBase, this class creates a dialog <em>without</em> event handlers.
|
||||
*
|
||||
* TODO: Use this class in ConfigurationDialogBase
|
||||
*/
|
||||
public class SimpleDialog {
|
||||
private XDialog xDialog;
|
||||
private DialogAccess dialogAccess;
|
||||
|
||||
/** Create a new dialog
|
||||
*
|
||||
* @param xContext the component context from which to get the service manager
|
||||
* @param sDialogPath the path to the dialog
|
||||
*/
|
||||
public SimpleDialog(XComponentContext xContext, String sDialogPath) {
|
||||
XMultiComponentFactory xMCF = xContext.getServiceManager();
|
||||
try {
|
||||
Object provider = xMCF.createInstanceWithContext("com.sun.star.awt.DialogProvider2", xContext);
|
||||
XDialogProvider2 xDialogProvider = (XDialogProvider2) UnoRuntime.queryInterface(XDialogProvider2.class, provider);
|
||||
String sDialogUrl = "vnd.sun.star.script:"+sDialogPath+"?location=application";
|
||||
xDialog = xDialogProvider.createDialog(sDialogUrl);
|
||||
dialogAccess = new DialogAccess(xDialog);
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
xDialog = null;
|
||||
dialogAccess = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the UNO dialog
|
||||
*
|
||||
* @return the dialog, or null if creation failed
|
||||
*/
|
||||
public XDialog getDialog() {
|
||||
return xDialog;
|
||||
}
|
||||
|
||||
/** Get access to the controls of the dialog
|
||||
*
|
||||
* @return the control access helper, or null if creation failed
|
||||
*/
|
||||
public DialogAccess getControls() {
|
||||
return dialogAccess;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* StreamGobbler.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-05)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class StreamGobbler extends Thread {
|
||||
InputStream is;
|
||||
String type;
|
||||
|
||||
public StreamGobbler(InputStream is, String type) {
|
||||
this.is = is;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
//String line=null;
|
||||
//while ( (line = br.readLine()) != null) {
|
||||
while ( br.readLine() != null) {
|
||||
// Do nothing...
|
||||
}
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* StyleNameProvider.java
|
||||
*
|
||||
* Copyright: 2002-2009 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.2 (2009-11-08)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.star.beans.UnknownPropertyException;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.container.NoSuchElementException;
|
||||
import com.sun.star.container.XNameAccess;
|
||||
import com.sun.star.container.XNameContainer;
|
||||
import com.sun.star.frame.XController;
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.lang.WrappedTargetException;
|
||||
import com.sun.star.style.XStyleFamiliesSupplier;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
/** This class provides access to the style names and localized style names of the current document
|
||||
*/
|
||||
public class StyleNameProvider {
|
||||
private Map<String,Map<String,String>> displayNameCollection;
|
||||
private Map<String,Map<String,String>> internalNameCollection;
|
||||
|
||||
/** Construct a new <code>StyleNameProvider</code>
|
||||
*
|
||||
* @param xContext the componemt context to get the desktop from
|
||||
*/
|
||||
public StyleNameProvider(XComponentContext xContext) {
|
||||
displayNameCollection = new HashMap<String,Map<String,String>>();
|
||||
internalNameCollection = new HashMap<String,Map<String,String>>();
|
||||
|
||||
// Get the model for the current frame
|
||||
XModel xModel = null;
|
||||
try {
|
||||
Object desktop = xContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
|
||||
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop);
|
||||
XController xController = xDesktop.getCurrentFrame().getController();
|
||||
if (xController!=null) {
|
||||
xModel = xController.getModel();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// Get the styles from the model
|
||||
if (xModel!=null) {
|
||||
XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(
|
||||
XStyleFamiliesSupplier.class, xModel);
|
||||
if (xSupplier!=null) {
|
||||
XNameAccess xFamilies = xSupplier.getStyleFamilies();
|
||||
String[] sFamilyNames = xFamilies.getElementNames();
|
||||
for (String sFamilyName : sFamilyNames) {
|
||||
Map<String,String> displayNames = new HashMap<String,String>();
|
||||
displayNameCollection.put(sFamilyName, displayNames);
|
||||
Map<String,String> internalNames = new HashMap<String,String>();
|
||||
internalNameCollection.put(sFamilyName, internalNames);
|
||||
try {
|
||||
XNameContainer xFamily = (XNameContainer) UnoRuntime.queryInterface(
|
||||
XNameContainer.class, xFamilies.getByName(sFamilyName));
|
||||
if (xFamily!=null) {
|
||||
String[] sStyleNames = xFamily.getElementNames();
|
||||
for (String sStyleName : sStyleNames) {
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(
|
||||
XPropertySet.class, xFamily.getByName(sStyleName));
|
||||
if (xProps!=null) {
|
||||
String sDisplayName = (String) xProps.getPropertyValue("DisplayName");
|
||||
displayNames.put(sStyleName, sDisplayName);
|
||||
internalNames.put(sDisplayName, sStyleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WrappedTargetException e) {
|
||||
// ignore
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
// will not happen
|
||||
}
|
||||
catch (UnknownPropertyException e) {
|
||||
// will not happen
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the mapping of internal names to display names for a style family
|
||||
*
|
||||
* @param sFamily the style family (for text documents this should be CharacterStyles, ParagraphStyles, FrameStyles, PageStyles or NumberingStyles)
|
||||
* @return a read only map from internal names to display names, or null if the family is not known to the provider
|
||||
*/
|
||||
public Map<String,String> getDisplayNames(String sFamily) {
|
||||
if (displayNameCollection.containsKey(sFamily)) {
|
||||
return Collections.unmodifiableMap(displayNameCollection.get(sFamily));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Get the mapping of display names to internal names for a style family
|
||||
*
|
||||
* @param sFamily the style family (for text documents this should be CharacterStyles, ParagraphStyles, FrameStyles, PageStyles or NumberingStyles)
|
||||
* @return a read only map from display names to internal names, or null if the family is not known to the provider
|
||||
*/
|
||||
public Map<String,String> getInternalNames(String sFamily) {
|
||||
if (internalNameCollection.containsKey(sFamily)) {
|
||||
return Collections.unmodifiableMap(internalNameCollection.get(sFamily));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* XPropertySetHelper.java
|
||||
*
|
||||
* Copyright: 2002-2008 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.0 (2008-07-21)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.w2lcommon.helper;
|
||||
|
||||
import com.sun.star.beans.PropertyVetoException;
|
||||
import com.sun.star.beans.UnknownPropertyException;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.lang.IllegalArgumentException;
|
||||
import com.sun.star.lang.WrappedTargetException;
|
||||
|
||||
/** Helper class providing staic convenience methods for accesing an XPropertySet
|
||||
* The helpers will fail silently if names or data is provided, but the user is expected to
|
||||
* apply them with correct data only...
|
||||
*/
|
||||
public class XPropertySetHelper {
|
||||
|
||||
public static Object getPropertyValue(XPropertySet xProps, String sName) {
|
||||
try {
|
||||
return xProps.getPropertyValue(sName);
|
||||
}
|
||||
catch (UnknownPropertyException e) {
|
||||
return null;
|
||||
}
|
||||
catch (WrappedTargetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPropertyValue(XPropertySet xProps, String sName, Object value) {
|
||||
try {
|
||||
xProps.setPropertyValue(sName,value);
|
||||
}
|
||||
catch (UnknownPropertyException e) {
|
||||
}
|
||||
catch (PropertyVetoException e) { // unacceptable value
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
}
|
||||
catch (WrappedTargetException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPropertyValueAsString(XPropertySet xProps, String sName) {
|
||||
Object value = getPropertyValue(xProps,sName);
|
||||
return value instanceof String ? (String) value : "";
|
||||
}
|
||||
|
||||
public static int getPropertyValueAsInteger(XPropertySet xProps, String sName) {
|
||||
Object value = getPropertyValue(xProps,sName);
|
||||
return value instanceof Integer ? ((Integer) value).intValue() : 0;
|
||||
}
|
||||
|
||||
public static void setPropertyValue(XPropertySet xProps, String sName, int nValue) {
|
||||
setPropertyValue(xProps,sName,new Integer(nValue));
|
||||
}
|
||||
|
||||
public static short getPropertyValueAsShort(XPropertySet xProps, String sName) {
|
||||
Object value = getPropertyValue(xProps,sName);
|
||||
return value instanceof Short ? ((Short) value).shortValue() : 0;
|
||||
}
|
||||
|
||||
public static void setPropertyValue(XPropertySet xProps, String sName, short nValue) {
|
||||
setPropertyValue(xProps,sName,new Short(nValue));
|
||||
}
|
||||
|
||||
public static boolean getPropertyValueAsBoolean(XPropertySet xProps, String sName) {
|
||||
Object value = getPropertyValue(xProps,sName);
|
||||
return value instanceof Boolean ? ((Boolean) value).booleanValue() : false;
|
||||
}
|
||||
|
||||
public static void setPropertyValue(XPropertySet xProps, String sName, boolean bValue) {
|
||||
setPropertyValue(xProps,sName,new Boolean(bValue));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,588 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* ConfigurationDialog.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-06-16)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.filter.ConfigurationDialogBase;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.DialogAccess;
|
||||
|
||||
import com.sun.star.container.NoSuchElementException;
|
||||
import com.sun.star.lang.XServiceInfo;
|
||||
import com.sun.star.ucb.CommandAbortedException;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import w2phtml.api.Converter;
|
||||
import w2phtml.api.ConverterFactory;
|
||||
|
||||
public class ConfigurationDialog extends ConfigurationDialogBase implements XServiceInfo {
|
||||
private String sResourceDirName;
|
||||
|
||||
// Implement the interface XServiceInfo
|
||||
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.ConfigurationDialog";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.ConfigurationDialog";
|
||||
|
||||
public boolean supportsService(String sServiceName) {
|
||||
return sServiceName.equals(__serviceName);
|
||||
}
|
||||
|
||||
public String getImplementationName() {
|
||||
return __implementationName;
|
||||
}
|
||||
|
||||
public String[] getSupportedServiceNames() {
|
||||
String[] sSupportedServiceNames = { __serviceName };
|
||||
return sSupportedServiceNames;
|
||||
}
|
||||
|
||||
// Configure the base class
|
||||
@Override protected String getMIMEType() { return "text/html"; }
|
||||
|
||||
@Override protected String getDialogLibraryName() { return "w2phtml2"; }
|
||||
|
||||
@Override protected String getConfigFileName() { return "writer2xhtml.xml"; }
|
||||
|
||||
/** Construct a new <code>ConfigurationDialog</code> */
|
||||
public ConfigurationDialog(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
|
||||
// Create the resource dir name
|
||||
try {
|
||||
sResourceDirName = xPathSub.substituteVariables("$(user)/writer2xhtml-resources", false);
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
sResourceDirName = "writer2xhtml-resources";
|
||||
}
|
||||
|
||||
pageHandlers.put("General", new GeneralHandler());
|
||||
pageHandlers.put("Template", new TemplateHandler());
|
||||
pageHandlers.put("Stylesheets", new StylesheetsHandler());
|
||||
pageHandlers.put("Formatting", new FormattingHandler());
|
||||
pageHandlers.put("Styles1", new Styles1Handler());
|
||||
pageHandlers.put("Styles2", new Styles2Handler());
|
||||
pageHandlers.put("Formatting", new FormattingHandler());
|
||||
pageHandlers.put("Content", new ContentHandler());
|
||||
}
|
||||
|
||||
// Implement remaining method from XContainerWindowEventHandler
|
||||
public String[] getSupportedMethodNames() {
|
||||
String[] sNames = { "EncodingChange", // General
|
||||
"CustomTemplateChange", "LoadTemplateClick", "TemplateKeyup", // Template
|
||||
"UseCustomStylesheetChange", "IncludeCustomStylesheetClick", "LoadStylesheetClick",
|
||||
"NewResourceClick", "DeleteResourceClick", // Stylesheet
|
||||
"StyleFamilyChange", "StyleNameChange", "NewStyleClick", "DeleteStyleClick", "LoadDefaultsClick" // Styles1
|
||||
};
|
||||
return sNames;
|
||||
}
|
||||
|
||||
// the page handlers
|
||||
private final String[] sCharElements = { "span", "abbr", "acronym", "b", "big", "cite", "code", "del", "dfn", "em", "i",
|
||||
"ins", "kbd", "samp", "small", "strong", "sub", "sup", "tt", "var", "q" };
|
||||
|
||||
private class GeneralHandler extends PageHandler {
|
||||
private final String[] sEncodingValues = { "UTF-8", "UTF-16", "ISO-8859-1", "US-ASCII" };
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
checkBoxFromConfig(dlg, "NoDoctype", "no_doctype");
|
||||
listBoxFromConfig(dlg, "Encoding", "encoding", sEncodingValues, (short) 0);
|
||||
checkBoxFromConfig(dlg, "AddBOM", "add_bom");
|
||||
|
||||
if ("true".equals(config.getOption("hexadecimal_entities"))) {
|
||||
dlg.setListBoxSelectedItem("HexadecimalEntities", (short) 0);
|
||||
}
|
||||
else {
|
||||
dlg.setListBoxSelectedItem("HexadecimalEntities", (short) 1);
|
||||
}
|
||||
|
||||
|
||||
checkBoxFromConfig(dlg, "UseNamedEntities", "use_named_entities");
|
||||
checkBoxFromConfig(dlg, "Multilingual", "multilingual");
|
||||
checkBoxFromConfig(dlg, "PrettyPrint", "pretty_print");
|
||||
|
||||
encodingChange(dlg);
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
checkBoxToConfig(dlg, "NoDoctype", "no_doctype");
|
||||
listBoxToConfig(dlg, "Encoding", "encoding", sEncodingValues);
|
||||
checkBoxToConfig(dlg, "AddBOM", "add_bom");
|
||||
|
||||
config.setOption("hexadecimal_entities", Boolean.toString(dlg.getListBoxSelectedItem("HexadecimalEntities")==(short)0));
|
||||
|
||||
checkBoxToConfig(dlg, "UseNamedEntities", "use_named_entities");
|
||||
checkBoxToConfig(dlg, "Multilingual", "multilingual");
|
||||
checkBoxToConfig(dlg, "PrettyPrint", "pretty_print");
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (sMethod.equals("EncodingChange")) {
|
||||
encodingChange(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void encodingChange(DialogAccess dlg) {
|
||||
int nEncoding = dlg.getListBoxSelectedItem("Encoding");
|
||||
dlg.setControlEnabled("AddBOM", nEncoding==0); // Only for UTF-8
|
||||
dlg.setControlEnabled("HexadecimalEntitiesLabel", nEncoding>1); // Not for UNICODE
|
||||
dlg.setControlEnabled("HexadecimalEntities", nEncoding>1); // Not for UNICODE
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class TemplateHandler extends CustomFileHandler {
|
||||
|
||||
protected String getSuffix() {
|
||||
return "Template";
|
||||
}
|
||||
|
||||
protected String getFileName() {
|
||||
return "writer2xhtml-template.xhtml";
|
||||
}
|
||||
|
||||
protected void useCustomInner(DialogAccess dlg, boolean bEnable) {
|
||||
dlg.setControlEnabled("TestTemplateLabel", bEnable);
|
||||
dlg.setControlEnabled("ContentIdLabel", bEnable);
|
||||
dlg.setControlEnabled("ContentId", bEnable);
|
||||
dlg.setControlEnabled("HeaderIdLabel", bEnable);
|
||||
dlg.setControlEnabled("HeaderId", bEnable);
|
||||
dlg.setControlEnabled("FooterIdLabel", bEnable);
|
||||
dlg.setControlEnabled("FooterId", bEnable);
|
||||
dlg.setControlEnabled("PanelIdLabel", bEnable);
|
||||
dlg.setControlEnabled("PanelId", bEnable);
|
||||
}
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
super.setControls(dlg);
|
||||
String[] sCustomIds = config.getOption("template_ids").split(",");
|
||||
if (sCustomIds.length>0) { dlg.setComboBoxText("ContentId", sCustomIds[0]); }
|
||||
if (sCustomIds.length>1) { dlg.setComboBoxText("HeaderId", sCustomIds[1]); }
|
||||
if (sCustomIds.length>2) { dlg.setComboBoxText("FooterId", sCustomIds[2]); }
|
||||
if (sCustomIds.length>3) { dlg.setComboBoxText("PanelId", sCustomIds[3]); }
|
||||
testTemplate(dlg);
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
super.getControls(dlg);
|
||||
config.setOption("template_ids",
|
||||
dlg.getComboBoxText("ContentId").trim()+","+
|
||||
dlg.getComboBoxText("HeaderId").trim()+","+
|
||||
dlg.getComboBoxText("FooterId").trim()+","+
|
||||
dlg.getComboBoxText("PanelId").trim());
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (super.handleEvent(dlg, sMethod)) {
|
||||
return true;
|
||||
}
|
||||
if (sMethod.equals("TemplateKeyup")) {
|
||||
testTemplate(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override protected void loadCustomClick(DialogAccess dlg) {
|
||||
super.loadCustomClick(dlg);
|
||||
testTemplate(dlg);
|
||||
}
|
||||
|
||||
private void testTemplate(DialogAccess dlg) {
|
||||
Converter converter = ConverterFactory.createConverter("text/html");
|
||||
String sTemplate = dlg.getTextFieldText("CustomTemplate").trim();
|
||||
if (sTemplate.length()>0) { // Only display error message if there is content
|
||||
try {
|
||||
converter.readTemplate(new ByteArrayInputStream(sTemplate.getBytes()));
|
||||
dlg.setLabelText("TestTemplateLabel", "");
|
||||
} catch (IOException e) {
|
||||
dlg.setLabelText("TestTemplateLabel", "ERROR: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
dlg.setLabelText("TestTemplateLabel", "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class StylesheetsHandler extends CustomFileHandler {
|
||||
|
||||
protected String getSuffix() {
|
||||
return "Stylesheet";
|
||||
}
|
||||
|
||||
protected String getFileName() {
|
||||
return "writer2xhtml-styles.css";
|
||||
}
|
||||
|
||||
protected void useCustomInner(DialogAccess dlg, boolean bEnable) {
|
||||
dlg.setControlEnabled("ResourceLabel", bEnable);
|
||||
dlg.setControlEnabled("Resources", bEnable);
|
||||
dlg.setControlEnabled("NewResourceButton", bEnable);
|
||||
dlg.setControlEnabled("DeleteResourceButton", bEnable);
|
||||
updateResources(dlg);
|
||||
}
|
||||
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
super.setControls(dlg);
|
||||
dlg.setCheckBoxStateAsBoolean("LinkCustomStylesheet", config.getOption("custom_stylesheet").length()>0);
|
||||
textFieldFromConfig(dlg, "CustomStylesheetURL", "custom_stylesheet");
|
||||
|
||||
linkCustomStylesheetChange(dlg);
|
||||
|
||||
updateResources(dlg);
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
super.getControls(dlg);
|
||||
if (dlg.getCheckBoxStateAsBoolean("LinkCustomStylesheet")) {
|
||||
textFieldToConfig(dlg, "CustomStylesheetURL", "custom_stylesheet");
|
||||
}
|
||||
else {
|
||||
config.setOption("custom_stylesheet", "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
if (super.handleEvent(dlg, sMethod)) {
|
||||
return true;
|
||||
}
|
||||
if (sMethod.equals("LinkCustomStylesheetChange")) {
|
||||
linkCustomStylesheetChange(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("NewResourceClick")) {
|
||||
newResourceClick(dlg);
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("DeleteResourceClick")) {
|
||||
deleteResourceClick(dlg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void linkCustomStylesheetChange(DialogAccess dlg) {
|
||||
boolean bLinkCustomStylesheet = dlg.getCheckBoxStateAsBoolean("LinkCustomStylesheet");
|
||||
dlg.setControlEnabled("CustomStylesheetURLLabel", bLinkCustomStylesheet);
|
||||
dlg.setControlEnabled("CustomStylesheetURL", bLinkCustomStylesheet);
|
||||
}
|
||||
|
||||
private void newResourceClick(DialogAccess dlg) {
|
||||
String[] sFileNames=filePicker.getPaths();
|
||||
if (sFileNames!=null) {
|
||||
createResourceDir();
|
||||
for (String sFileName : sFileNames) {
|
||||
String sBaseFileName = sFileName.substring(sFileName.lastIndexOf('/')+1);
|
||||
try {
|
||||
String sTargetFileName = sResourceDirName+"/"+sBaseFileName;
|
||||
if (fileExists(sTargetFileName)) { killFile(sTargetFileName); }
|
||||
sfa2.copy(sFileName, sTargetFileName);
|
||||
} catch (CommandAbortedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
updateResources(dlg);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteResourceClick(DialogAccess dlg) {
|
||||
int nItem = dlg.getListBoxSelectedItem("Resources");
|
||||
if (nItem>=0) {
|
||||
String sFileName = dlg.getListBoxStringItemList("Resources")[nItem];
|
||||
if (deleteItem(sFileName)) {
|
||||
killFile(sResourceDirName+"/"+sFileName);
|
||||
updateResources(dlg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateResources(DialogAccess dlg) {
|
||||
createResourceDir();
|
||||
try {
|
||||
String[] sFiles = sfa2.getFolderContents(sResourceDirName, false); // do not include folders
|
||||
int nCount = sFiles.length;
|
||||
for (int i=0; i<nCount; i++) {
|
||||
sFiles[i] = sFiles[i].substring(sFiles[i].lastIndexOf('/')+1);
|
||||
}
|
||||
dlg.setListBoxStringItemList("Resources", sFiles);
|
||||
} catch (CommandAbortedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createResourceDir() {
|
||||
try {
|
||||
if (!sfa2.isFolder(sResourceDirName)) {
|
||||
sfa2.createFolder(sResourceDirName);
|
||||
}
|
||||
} catch (CommandAbortedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class Styles1Handler extends StylesPageHandler {
|
||||
private final String[] sXhtmlFamilyNames = { "text", "paragraph", "heading", "list", "frame" };
|
||||
private final String[] sXhtmlOOoFamilyNames = { "CharacterStyles", "ParagraphStyles", "ParagraphStyles", "NumberingStyles", "FrameStyles" };
|
||||
|
||||
private final String[] sParElements = { "p", "h1", "h2", "h3", "h4", "h5", "h6", "address", "dd", "dt", "pre" };
|
||||
private final String[] sParBlockElements = { "div", "blockquote", "dl" };
|
||||
private final String[] sEmpty = { };
|
||||
|
||||
private String[][] sElements = new String[5][];
|
||||
private String[][] sBlockElements = new String[5][];
|
||||
|
||||
protected Styles1Handler() {
|
||||
super(5);
|
||||
sFamilyNames = sXhtmlFamilyNames;
|
||||
sOOoFamilyNames = sXhtmlOOoFamilyNames;
|
||||
|
||||
sElements[0] = sCharElements;
|
||||
sElements[1] = sParElements;
|
||||
sElements[2] = sParElements;
|
||||
sElements[3] = sEmpty;
|
||||
sElements[4] = sEmpty;
|
||||
|
||||
sBlockElements[0] = sEmpty;
|
||||
sBlockElements[1] = sParBlockElements;
|
||||
sBlockElements[2] = sParBlockElements;
|
||||
sBlockElements[3] = sEmpty;
|
||||
sBlockElements[4] = sEmpty;
|
||||
}
|
||||
|
||||
protected String getDefaultConfigName() {
|
||||
return "cleanxhtml.xml";
|
||||
}
|
||||
|
||||
protected void setControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
if (!attr.containsKey("element")) { attr.put("element", ""); }
|
||||
if (!attr.containsKey("css")) { attr.put("css", ""); }
|
||||
dlg.setComboBoxText("Element", attr.get("element"));
|
||||
dlg.setTextFieldText("Css", none2empty(attr.get("css")));
|
||||
|
||||
if (nCurrentFamily==1 || nCurrentFamily==2) {
|
||||
if (!attr.containsKey("before")) { attr.put("before", ""); }
|
||||
if (!attr.containsKey("after")) { attr.put("after", ""); }
|
||||
dlg.setTextFieldText("Before", attr.get("before"));
|
||||
dlg.setTextFieldText("After", attr.get("after"));
|
||||
}
|
||||
else {
|
||||
dlg.setTextFieldText("Before", "");
|
||||
dlg.setTextFieldText("After", "");
|
||||
}
|
||||
|
||||
if (nCurrentFamily==1 || nCurrentFamily==2) {
|
||||
if (!attr.containsKey("block-element")) { attr.put("block-element", ""); }
|
||||
if (!attr.containsKey("block-css")) { attr.put("block-css", ""); }
|
||||
dlg.setComboBoxText("BlockElement", attr.get("block-element"));
|
||||
dlg.setTextFieldText("BlockCss", none2empty(attr.get("block-css")));
|
||||
}
|
||||
else {
|
||||
dlg.setComboBoxText("BlockElement", "");
|
||||
dlg.setTextFieldText("BlockCss", "");
|
||||
}
|
||||
}
|
||||
|
||||
protected void getControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
attr.put("element", dlg.getComboBoxText("Element"));
|
||||
attr.put("css", empty2none(dlg.getTextFieldText("Css")));
|
||||
if (nCurrentFamily==1 || nCurrentFamily==2) {
|
||||
attr.put("before", dlg.getTextFieldText("Before"));
|
||||
attr.put("after", dlg.getTextFieldText("After"));
|
||||
}
|
||||
if (nCurrentFamily==1 || nCurrentFamily==2) {
|
||||
attr.put("block-element", dlg.getComboBoxText("BlockElement"));
|
||||
attr.put("block-css", empty2none(dlg.getTextFieldText("BlockCss")));
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearControls(DialogAccess dlg) {
|
||||
dlg.setComboBoxText("Element", "");
|
||||
dlg.setTextFieldText("Css", "");
|
||||
dlg.setTextFieldText("Before", "");
|
||||
dlg.setTextFieldText("After", "");
|
||||
dlg.setComboBoxText("BlockElement", "");
|
||||
dlg.setTextFieldText("BlockCss", "");
|
||||
}
|
||||
|
||||
protected void prepareControls(DialogAccess dlg, boolean bHasMappings) {
|
||||
dlg.setListBoxStringItemList("Element", sElements[nCurrentFamily]);
|
||||
dlg.setListBoxStringItemList("BlockElement", sBlockElements[nCurrentFamily]);
|
||||
dlg.setControlEnabled("ElementLabel", bHasMappings && nCurrentFamily<=2);
|
||||
dlg.setControlEnabled("Element", bHasMappings && nCurrentFamily<=2);
|
||||
dlg.setControlEnabled("CssLabel", bHasMappings);
|
||||
dlg.setControlEnabled("Css", bHasMappings);
|
||||
dlg.setControlEnabled("BeforeLabel", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
dlg.setControlEnabled("Before", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
dlg.setControlEnabled("AfterLabel", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
dlg.setControlEnabled("After", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
dlg.setControlEnabled("BlockElementLabel", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
dlg.setControlEnabled("BlockElement", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
dlg.setControlEnabled("BlockCssLabel", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
dlg.setControlEnabled("BlockCss", bHasMappings && (nCurrentFamily==1 || nCurrentFamily==2));
|
||||
}
|
||||
}
|
||||
|
||||
private class Styles2Handler extends AttributePageHandler {
|
||||
private String[] sXhtmlAttributeNames = { "bold", "italics", "fixed", "superscript", "subscript", "underline", "overstrike" };
|
||||
|
||||
public Styles2Handler() {
|
||||
sAttributeNames = sXhtmlAttributeNames;
|
||||
}
|
||||
|
||||
@Override public void setControls(DialogAccess dlg) {
|
||||
super.setControls(dlg);
|
||||
textFieldFromConfig(dlg,"TabstopStyle","tabstop_style");
|
||||
}
|
||||
|
||||
@Override public void getControls(DialogAccess dlg) {
|
||||
super.getControls(dlg);
|
||||
textFieldToConfig(dlg,"TabstopStyle","tabstop_style");
|
||||
}
|
||||
|
||||
protected void setControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
if (!attr.containsKey("element")) { attr.put("element", ""); }
|
||||
if (!attr.containsKey("css")) { attr.put("css", ""); }
|
||||
dlg.setListBoxStringItemList("Element", sCharElements);
|
||||
dlg.setComboBoxText("Element", attr.get("element"));
|
||||
dlg.setTextFieldText("Css", none2empty(attr.get("css")));
|
||||
}
|
||||
|
||||
protected void getControls(DialogAccess dlg, Map<String,String> attr) {
|
||||
attr.put("element", dlg.getComboBoxText("Element"));
|
||||
attr.put("css", empty2none(dlg.getTextFieldText("Css")));
|
||||
}
|
||||
|
||||
protected void prepareControls(DialogAccess dlg, boolean bEnable) {
|
||||
dlg.setControlEnabled("ElementLabel", bEnable);
|
||||
dlg.setControlEnabled("Element", bEnable);
|
||||
dlg.setControlEnabled("CssLabel", bEnable);
|
||||
dlg.setControlEnabled("Css", bEnable);
|
||||
}
|
||||
}
|
||||
|
||||
private class FormattingHandler extends PageHandler {
|
||||
private final String[] sExportValues = { "convert_all", "ignore_styles", "ignore_hard", "ignore_all" };
|
||||
private final String[] sListExportValues = { "css1", "css1_hack", "hard_labels" };
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
listBoxFromConfig(dlg, "Formatting", "formatting", sExportValues, (short) 0);
|
||||
listBoxFromConfig(dlg, "FrameFormatting", "frame_formatting", sExportValues, (short) 0);
|
||||
|
||||
// OOo does not support styles for sections and tables, hence this simplified variant
|
||||
dlg.setCheckBoxStateAsBoolean("SectionFormatting",
|
||||
config.getOption("section_formatting").equals("convert_all") ||
|
||||
config.getOption("section_formatting").equals("ignore_styles"));
|
||||
dlg.setCheckBoxStateAsBoolean("TableFormatting",
|
||||
config.getOption("table_formatting").equals("convert_all") ||
|
||||
config.getOption("table_formatting").equals("ignore_styles"));
|
||||
|
||||
checkBoxFromConfig(dlg, "IgnoreTableDimensions", "ignore_table_dimensions");
|
||||
|
||||
listBoxFromConfig(dlg, "ListFormatting", "list_formatting", sListExportValues, (short) 0);
|
||||
|
||||
textFieldFromConfig(dlg, "MaxWidth", "max_width");
|
||||
|
||||
checkBoxFromConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
listBoxToConfig(dlg, "Formatting", "formatting", sExportValues);
|
||||
listBoxToConfig(dlg, "FrameFormatting", "frame_formatting", sExportValues);
|
||||
|
||||
config.setOption("section_formatting", dlg.getCheckBoxStateAsBoolean("SectionFormatting") ? "convert_all" : "ignore_all");
|
||||
config.setOption("table_formatting", dlg.getCheckBoxStateAsBoolean("TableFormatting") ? "convert_all" : "ignore_all");
|
||||
|
||||
checkBoxToConfig(dlg, "IgnoreTableDimensions", "ignore_table_dimensions");
|
||||
|
||||
listBoxToConfig(dlg, "ListFormatting", "list_formatting", sListExportValues);
|
||||
|
||||
textFieldToConfig(dlg, "MaxWidth", "max_width");
|
||||
|
||||
checkBoxToConfig(dlg, "SeparateStylesheet", "separate_stylesheet");
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ContentHandler extends PageHandler {
|
||||
private final String[] sFormulaValues = { "image+starmath", "image+latex", "starmath", "latex" };
|
||||
|
||||
@Override protected void setControls(DialogAccess dlg) {
|
||||
listBoxFromConfig(dlg, "Formulas", "formulas", sFormulaValues, (short) 0);
|
||||
textFieldFromConfig(dlg, "EndnotesHeading", "endnotes_heading");
|
||||
textFieldFromConfig(dlg, "FootnotesHeading", "footnotes_heading");
|
||||
checkBoxFromConfig(dlg, "EmbedSvg", "embed_svg");
|
||||
checkBoxFromConfig(dlg, "EmbedImg", "embed_img");
|
||||
}
|
||||
|
||||
@Override protected void getControls(DialogAccess dlg) {
|
||||
listBoxToConfig(dlg, "Formulas", "formulas", sFormulaValues);
|
||||
textFieldToConfig(dlg, "EndnotesHeading", "endnotes_heading");
|
||||
textFieldToConfig(dlg, "FootnotesHeading", "footnotes_heading");
|
||||
checkBoxToConfig(dlg, "EmbedSvg", "embed_svg");
|
||||
checkBoxToConfig(dlg, "EmbedImg", "embed_img");
|
||||
}
|
||||
|
||||
@Override protected boolean handleEvent(DialogAccess dlg, String sMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String none2empty(String s) {
|
||||
return s.equals("(none)") ? "" : s;
|
||||
}
|
||||
|
||||
private String empty2none(String s) {
|
||||
String t = s.trim();
|
||||
return t.length()==0 ? "(none)" : t;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* Epub3OptionsDialog.java
|
||||
*
|
||||
* Copyright: 2002-2016 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-05-05)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
/** This class provides a UNO component which implements a filter UI for the
|
||||
* EPUB 3 export. In this version the option to include NCX is enabled.
|
||||
*/
|
||||
public class Epub3OptionsDialog extends EpubOptionsDialog {
|
||||
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.Epub3OptionsDialog";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.Epub3OptionsDialog";
|
||||
|
||||
/** Create a new Epub3OptionsDialog */
|
||||
public Epub3OptionsDialog(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,707 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* EpubMetadataDialog.java
|
||||
*
|
||||
* Copyright: 2002-2011 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.2 (2011-07-20)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.DialogBase;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.SimpleDialog;
|
||||
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.beans.IllegalTypeException;
|
||||
import com.sun.star.beans.NotRemoveableException;
|
||||
import com.sun.star.beans.Property;
|
||||
import com.sun.star.beans.PropertyExistException;
|
||||
import com.sun.star.beans.PropertyVetoException;
|
||||
import com.sun.star.beans.UnknownPropertyException;
|
||||
import com.sun.star.beans.XPropertyContainer;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.document.XDocumentProperties;
|
||||
import com.sun.star.document.XDocumentPropertiesSupplier;
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.lang.IllegalArgumentException;
|
||||
import com.sun.star.lang.WrappedTargetException;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ui.dialogs.ExecutableDialogResults;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.DateTime;
|
||||
|
||||
import w2phtml.util.CSVList;
|
||||
import w2phtml.util.Misc;
|
||||
|
||||
// TODO: Create the UNO helper class DocumentPropertiesAccess
|
||||
|
||||
/** This class provides a UNO component which implements a custom metadata editor UI for the EPUB export
|
||||
*/
|
||||
public class EpubMetadataDialog extends DialogBase {
|
||||
// Author data
|
||||
private class AuthorInfo {
|
||||
String sName = "";
|
||||
boolean isCreator = true;
|
||||
String sRole = "";
|
||||
}
|
||||
|
||||
// Date data
|
||||
private class DateInfo {
|
||||
int nDate = 0;
|
||||
String sEvent = "";
|
||||
}
|
||||
|
||||
// All the user defined properties we handle
|
||||
private static final String IDENTIFIER="Identifier";
|
||||
private static final String CREATOR="Creator";
|
||||
private static final String CONTRIBUTOR="Contributor";
|
||||
private static final String DATE="Date";
|
||||
private static final String PUBLISHER="Publisher";
|
||||
private static final String TYPE="Type";
|
||||
private static final String FORMAT="Format";
|
||||
private static final String SOURCE="Source";
|
||||
private static final String RELATION="Relation";
|
||||
private static final String COVERAGE="Coverage";
|
||||
private static final String RIGHTS="Rights";
|
||||
|
||||
private static final String[] sRoles = {"", "adp", "ann", "arr", "art", "asn", "aut", "aqt", "aft", "aui", "ant", "bkp",
|
||||
"clb", "cmm", "dsr", "edt", "ill", "lyr", "mdc", "mus", "nrt", "oth", "pht", "prt", "red", "rev", "spn", "ths", "trc", "trl"};
|
||||
private static HashMap<String,Short> backRoles;
|
||||
static {
|
||||
backRoles = new HashMap<String,Short>();
|
||||
int nCount = sRoles.length;
|
||||
for (short i=0; i<nCount; i++) {
|
||||
backRoles.put(sRoles[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
// Access to the document properties
|
||||
private XDocumentProperties xDocumentProperties=null;
|
||||
private XPropertyContainer xUserProperties=null;
|
||||
private XPropertySet xUserPropertySet=null;
|
||||
|
||||
// Author and date bookkeeping
|
||||
private Vector<AuthorInfo> authors = new Vector<AuthorInfo>();
|
||||
private Vector<DateInfo> dates = new Vector<DateInfo>();
|
||||
|
||||
// Number formatter
|
||||
private NumberFormat formatter = new DecimalFormat("00");
|
||||
|
||||
// Pattern matcher for dates
|
||||
Pattern datePattern = Pattern.compile("(\\d{4})-(\\d{2})-(\\d{2})");
|
||||
|
||||
public EpubMetadataDialog(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
}
|
||||
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.EpubMetadataDialog";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.EpubMetadataDialog";
|
||||
|
||||
// --------------------------------------------------
|
||||
// Ensure that the super can find us :-)
|
||||
@Override public String getDialogLibraryName() {
|
||||
return "w2phtml2";
|
||||
}
|
||||
|
||||
@Override public String getDialogName() {
|
||||
return "EpubMetadata";
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Implement the interface XDialogEventHandler
|
||||
@Override public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) {
|
||||
if (sMethod.equals("UseCustomIdentifierChange")) {
|
||||
return useCustomIdentifierChange();
|
||||
}
|
||||
else if (sMethod.equals("AuthorAddClick")) {
|
||||
return authorAddclick();
|
||||
}
|
||||
else if (sMethod.equals("AuthorModifyClick")) {
|
||||
return authorModifyclick();
|
||||
}
|
||||
else if (sMethod.equals("AuthorDeleteClick")) {
|
||||
return authorDeleteclick();
|
||||
}
|
||||
else if (sMethod.equals("AuthorUpClick")) {
|
||||
return authorUpclick();
|
||||
}
|
||||
else if (sMethod.equals("AuthorDownClick")) {
|
||||
return authorDownclick();
|
||||
}
|
||||
else if (sMethod.equals("DateAddClick")) {
|
||||
return dateAddClick();
|
||||
}
|
||||
else if (sMethod.equals("DateModifyClick")) {
|
||||
return dateModifyClick();
|
||||
}
|
||||
else if (sMethod.equals("DateDeleteClick")) {
|
||||
return dateDeleteClick();
|
||||
}
|
||||
else if (sMethod.equals("DateUpClick")) {
|
||||
return dateUpClick();
|
||||
}
|
||||
else if (sMethod.equals("DateDownClick")) {
|
||||
return dateDownClick();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public String[] getSupportedMethodNames() {
|
||||
String[] sNames = { "UseCustomIdentifierChange",
|
||||
"AuthorAddClick", "AuthorModifyClick", "AuthorDeleteClick", "AuthorUpClick", "AuthorDownClick",
|
||||
"DataAddClick", "DateModifyClick", "DateDeleteClick", "DateUpClick", "DateDownClick"};
|
||||
return sNames;
|
||||
}
|
||||
|
||||
private boolean useCustomIdentifierChange() {
|
||||
boolean bEnabled = getCheckBoxStateAsBoolean("UseCustomIdentifier");
|
||||
setControlEnabled("IdentifierLabel",bEnabled);
|
||||
setControlEnabled("Identifier",bEnabled);
|
||||
setControlEnabled("IdentifierTypeLabel",bEnabled);
|
||||
setControlEnabled("IdentifierType",bEnabled);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean authorAddclick() {
|
||||
SimpleDialog dialog = new SimpleDialog(xContext,"w2phtml2.AuthorDialog");
|
||||
if (dialog.getDialog()!=null) {
|
||||
dialog.getControls().setListBoxSelectedItem("Type", (short) 0);
|
||||
dialog.getControls().setListBoxSelectedItem("Role", (short) 0);
|
||||
if (dialog.getDialog().execute()==ExecutableDialogResults.OK) {
|
||||
AuthorInfo author = new AuthorInfo();
|
||||
author.sName = dialog.getControls().getTextFieldText("Author");
|
||||
author.sRole = sRoles[dialog.getControls().getListBoxSelectedItem("Role")];
|
||||
author.isCreator = dialog.getControls().getListBoxSelectedItem("Type")==0;
|
||||
authors.add(author);
|
||||
updateAuthorList((short) (authors.size()-1));
|
||||
}
|
||||
dialog.getDialog().endExecute();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean authorModifyclick() {
|
||||
short nIndex = getListBoxSelectedItem("Authors");
|
||||
AuthorInfo author = authors.get(nIndex);
|
||||
SimpleDialog dialog = new SimpleDialog(xContext,"w2phtml2.AuthorDialog");
|
||||
if (dialog.getDialog()!=null) {
|
||||
dialog.getControls().setTextFieldText("Author", author.sName);
|
||||
dialog.getControls().setListBoxSelectedItem("Type", author.isCreator ? (short)0 : (short) 1);
|
||||
dialog.getControls().setListBoxSelectedItem("Role", backRoles.containsKey(author.sRole)? backRoles.get(author.sRole) : (short)0);
|
||||
if (dialog.getDialog().execute()==ExecutableDialogResults.OK) {
|
||||
author.sName = dialog.getControls().getTextFieldText("Author");
|
||||
author.sRole = sRoles[dialog.getControls().getListBoxSelectedItem("Role")];
|
||||
author.isCreator = dialog.getControls().getListBoxSelectedItem("Type")==0;
|
||||
updateAuthorList(nIndex);
|
||||
}
|
||||
dialog.getDialog().endExecute();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean authorDeleteclick() {
|
||||
if (authors.size()>0) {
|
||||
SimpleDialog dialog = new SimpleDialog(xContext,"w2phtml2.DeleteDialog");
|
||||
if (dialog.getDialog()!=null) {
|
||||
short nIndex = getListBoxSelectedItem("Authors");
|
||||
String sLabel = dialog.getControls().getLabelText("DeleteLabel");
|
||||
sLabel = sLabel.replaceAll("%s", authors.get(nIndex).sName);
|
||||
dialog.getControls().setLabelText("DeleteLabel", sLabel);
|
||||
if (dialog.getDialog().execute()==ExecutableDialogResults.OK) {
|
||||
authors.remove(nIndex);
|
||||
updateAuthorList(nIndex<authors.size() ? (short) nIndex : (short) (nIndex-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean authorUpclick() {
|
||||
short nIndex = getListBoxSelectedItem("Authors");
|
||||
if (nIndex>0) {
|
||||
AuthorInfo author = authors.get(nIndex);
|
||||
authors.set(nIndex, authors.get(nIndex-1));
|
||||
authors.set(nIndex-1, author);
|
||||
updateAuthorList((short) (nIndex-1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean authorDownclick() {
|
||||
short nIndex = getListBoxSelectedItem("Authors");
|
||||
if (nIndex+1<authors.size()) {
|
||||
AuthorInfo author = authors.get(nIndex);
|
||||
authors.set(nIndex, authors.get(nIndex+1));
|
||||
authors.set(nIndex+1, author);
|
||||
updateAuthorList((short) (nIndex+1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean dateAddClick() {
|
||||
SimpleDialog dialog = new SimpleDialog(xContext,"w2phtml2.DateDialog");
|
||||
if (dialog.getDialog()!=null) {
|
||||
dialog.getControls().setDateFieldValue("Date", datetime2int(xDocumentProperties.getModificationDate()));
|
||||
if (dialog.getDialog().execute()==ExecutableDialogResults.OK) {
|
||||
DateInfo date = new DateInfo();
|
||||
date.nDate = dialog.getControls().getDateFieldValue("Date");
|
||||
date.sEvent = dialog.getControls().getTextFieldText("Event").trim();
|
||||
dates.add(date);
|
||||
updateDateList((short) (dates.size()-1));
|
||||
}
|
||||
dialog.getDialog().endExecute();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean dateModifyClick() {
|
||||
short nIndex = getListBoxSelectedItem("Dates");
|
||||
DateInfo date = dates.get(nIndex);
|
||||
SimpleDialog dialog = new SimpleDialog(xContext,"w2phtml2.DateDialog");
|
||||
if (dialog.getDialog()!=null) {
|
||||
dialog.getControls().setDateFieldValue("Date", date.nDate);
|
||||
dialog.getControls().setTextFieldText("Event", date.sEvent);
|
||||
if (dialog.getDialog().execute()==ExecutableDialogResults.OK) {
|
||||
date.nDate = dialog.getControls().getDateFieldValue("Date");
|
||||
date.sEvent = dialog.getControls().getTextFieldText("Event").trim();
|
||||
updateDateList(nIndex);
|
||||
}
|
||||
dialog.getDialog().endExecute();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean dateDeleteClick() {
|
||||
if (dates.size()>0) {
|
||||
SimpleDialog dialog = new SimpleDialog(xContext,"w2phtml2.DeleteDialog");
|
||||
if (dialog.getDialog()!=null) {
|
||||
short nIndex = getListBoxSelectedItem("Dates");
|
||||
String sLabel = dialog.getControls().getLabelText("DeleteLabel");
|
||||
sLabel = sLabel.replaceAll("%s", formatDate(dates.get(nIndex).nDate));
|
||||
dialog.getControls().setLabelText("DeleteLabel", sLabel);
|
||||
if (dialog.getDialog().execute()==ExecutableDialogResults.OK) {
|
||||
dates.remove(nIndex);
|
||||
updateDateList(nIndex<dates.size() ? (short) nIndex : (short) (nIndex-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean dateUpClick() {
|
||||
short nIndex = getListBoxSelectedItem("Dates");
|
||||
if (nIndex>0) {
|
||||
DateInfo date = dates.get(nIndex);
|
||||
dates.set(nIndex, dates.get(nIndex-1));
|
||||
dates.set(nIndex-1, date);
|
||||
updateDateList((short) (nIndex-1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean dateDownClick() {
|
||||
short nIndex = getListBoxSelectedItem("Dates");
|
||||
if (nIndex+1<dates.size()) {
|
||||
DateInfo date = dates.get(nIndex);
|
||||
dates.set(nIndex, dates.get(nIndex+1));
|
||||
dates.set(nIndex+1, date);
|
||||
updateDateList((short) (nIndex+1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// Get and set properties from and to current document
|
||||
|
||||
@Override protected void initialize() {
|
||||
// Get the document properties
|
||||
XDesktop xDesktop;
|
||||
Object desktop;
|
||||
try {
|
||||
desktop = xContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
|
||||
} catch (Exception e) {
|
||||
// Failed to get desktop
|
||||
return;
|
||||
}
|
||||
xDesktop = (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);
|
||||
XComponent xComponent = xDesktop.getCurrentComponent();
|
||||
XDocumentPropertiesSupplier xSupplier = (XDocumentPropertiesSupplier) UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xComponent);
|
||||
|
||||
// Get the document properties (we need several interfaces)
|
||||
xDocumentProperties = xSupplier.getDocumentProperties();
|
||||
xUserProperties= xDocumentProperties.getUserDefinedProperties();
|
||||
xUserPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xUserProperties);
|
||||
|
||||
// Get the custom identifier and set the text fields
|
||||
String[] sIdentifiers = getProperties(IDENTIFIER,false);
|
||||
setCheckBoxStateAsBoolean("UseCustomIdentifier",sIdentifiers.length>0);
|
||||
useCustomIdentifierChange();
|
||||
if (sIdentifiers.length>0) { // Use the first if we have several...
|
||||
setTextFieldText("Identifier",getStringValue(sIdentifiers[0]));
|
||||
setTextFieldText("IdentifierType",getSuffix(sIdentifiers[0]));
|
||||
}
|
||||
|
||||
// Get the authors and set the list box
|
||||
String[] sCreators = getProperties(CREATOR,false);
|
||||
for (String sCreator : sCreators) {
|
||||
AuthorInfo creator = new AuthorInfo();
|
||||
creator.sName = getStringValue(sCreator);
|
||||
creator.sRole = getSuffix(sCreator);
|
||||
creator.isCreator = true;
|
||||
authors.add(creator);
|
||||
}
|
||||
String[] sContributors = getProperties(CONTRIBUTOR,false);
|
||||
for (String sContributor : sContributors) {
|
||||
AuthorInfo contributor = new AuthorInfo();
|
||||
contributor.sName = getStringValue(sContributor);
|
||||
contributor.sRole = getSuffix(sContributor);
|
||||
contributor.isCreator = false;
|
||||
authors.add(contributor);
|
||||
}
|
||||
updateAuthorList((short) 0);
|
||||
|
||||
// Get the dates and set the list box
|
||||
String[] sDates = getProperties(DATE,false);
|
||||
for (String sDate : sDates) {
|
||||
DateInfo date = new DateInfo();
|
||||
DateTime dt = getDateValue(sDate);
|
||||
if (dt!=null) { // We accept either a date
|
||||
date.nDate = datetime2int(dt);
|
||||
}
|
||||
else { // Or a string in the form yyyy-mm-dd
|
||||
date.nDate = parseDate(getStringValue(sDate));
|
||||
}
|
||||
date.sEvent = getSuffix(sDate);
|
||||
dates.add(date);
|
||||
}
|
||||
updateDateList((short) 0);
|
||||
|
||||
// Get the standard properties and set the text fields
|
||||
setTextFieldText("Title",xDocumentProperties.getTitle());
|
||||
setTextFieldText("Subject",xDocumentProperties.getSubject());
|
||||
String[] sKeywords = xDocumentProperties.getKeywords();
|
||||
CSVList keywords = new CSVList(", ");
|
||||
for (String sKeyword : sKeywords) {
|
||||
keywords.addValue(sKeyword);
|
||||
}
|
||||
setTextFieldText("Keywords",keywords.toString());
|
||||
setTextFieldText("Description",xDocumentProperties.getDescription());
|
||||
|
||||
// Get the simple user properties and set the text fields
|
||||
readSimpleProperty(PUBLISHER);
|
||||
readSimpleProperty(TYPE);
|
||||
readSimpleProperty(FORMAT);
|
||||
readSimpleProperty(SOURCE);
|
||||
readSimpleProperty(RELATION);
|
||||
readSimpleProperty(COVERAGE);
|
||||
readSimpleProperty(RIGHTS);
|
||||
|
||||
}
|
||||
|
||||
@Override protected void endDialog() {
|
||||
// Set the custom identifier from the text fields
|
||||
String[] sIdentifiers = getProperties(IDENTIFIER,false);
|
||||
for (String sIdentifier : sIdentifiers) { // Remove old identifier(s)
|
||||
removeProperty(sIdentifier);
|
||||
}
|
||||
if (getCheckBoxStateAsBoolean("UseCustomIdentifier")) {
|
||||
String sName = IDENTIFIER;
|
||||
if (getTextFieldText("IdentifierType").trim().length()>0) {
|
||||
sName+="."+getTextFieldText("IdentifierType").trim();
|
||||
}
|
||||
addProperty(sName);
|
||||
setValue(sName,getTextFieldText("Identifier"));
|
||||
}
|
||||
|
||||
// Set the authors from the list box
|
||||
String[] sCreators = getProperties(CREATOR,false);
|
||||
for (String sCreator : sCreators) { // remove old creators
|
||||
removeProperty(sCreator);
|
||||
}
|
||||
String[] sContributors = getProperties(CONTRIBUTOR,false);
|
||||
for (String sContributor : sContributors) { // remove old contributors
|
||||
removeProperty(sContributor);
|
||||
}
|
||||
int i=0;
|
||||
for (AuthorInfo author : authors) {
|
||||
String sName = (author.isCreator ? CREATOR : CONTRIBUTOR)+formatter.format(++i);
|
||||
if (author.sRole.length()>0) {
|
||||
sName+="."+author.sRole;
|
||||
}
|
||||
addProperty(sName);
|
||||
setValue(sName,author.sName);
|
||||
}
|
||||
|
||||
// Set the dates from the list box
|
||||
String[] sDates = getProperties(DATE,false);
|
||||
for (String sDate : sDates) { // remove old dates
|
||||
removeProperty(sDate);
|
||||
}
|
||||
i=0;
|
||||
for (DateInfo date : dates) {
|
||||
String sName = DATE+formatter.format(++i);
|
||||
if (date.sEvent.length()>0) {
|
||||
sName+="."+date.sEvent;
|
||||
}
|
||||
addProperty(sName);
|
||||
setValue(sName,formatDate(date.nDate));
|
||||
// Doesn't work (why not?)
|
||||
//setValue(sName,int2datetime(date.nDate));
|
||||
}
|
||||
|
||||
// Set the standard properties from the text fields
|
||||
xDocumentProperties.setTitle(getTextFieldText("Title"));
|
||||
xDocumentProperties.setSubject(getTextFieldText("Subject"));
|
||||
String[] sKeywords = getTextFieldText("Keywords").split(",");
|
||||
for (int j=0; j<sKeywords.length; j++) {
|
||||
sKeywords[j] = sKeywords[j].trim();
|
||||
}
|
||||
xDocumentProperties.setKeywords(sKeywords);
|
||||
xDocumentProperties.setDescription(getTextFieldText("Description"));
|
||||
|
||||
// Set the simple user properties from the text fields
|
||||
writeSimpleProperty(PUBLISHER);
|
||||
writeSimpleProperty(TYPE);
|
||||
writeSimpleProperty(FORMAT);
|
||||
writeSimpleProperty(SOURCE);
|
||||
writeSimpleProperty(RELATION);
|
||||
writeSimpleProperty(COVERAGE);
|
||||
writeSimpleProperty(RIGHTS);
|
||||
}
|
||||
|
||||
// Get the suffix of a user defined property (portion after fist ., if any)
|
||||
private String getSuffix(String sPropertyName) {
|
||||
int nDot = sPropertyName.indexOf(".");
|
||||
return nDot>-1 ? sPropertyName.substring(nDot+1) : "";
|
||||
}
|
||||
|
||||
// Get all currently defined user properties with a specific name or prefix
|
||||
private String[] getProperties(String sPrefix, boolean bComplete) {
|
||||
HashSet<String> names = new HashSet<String>();
|
||||
Property[] xProps = xUserPropertySet.getPropertySetInfo().getProperties();
|
||||
for (Property prop : xProps) {
|
||||
String sName = prop.Name;
|
||||
String sLCName = sName.toLowerCase();
|
||||
String sLCPrefix = sPrefix.toLowerCase();
|
||||
if ((bComplete && sLCName.equals(sLCPrefix)) || (!bComplete && sLCName.startsWith(sLCPrefix))) {
|
||||
names.add(sName);
|
||||
}
|
||||
}
|
||||
return Misc.sortStringSet(names);
|
||||
}
|
||||
|
||||
// Add a user property
|
||||
private void addProperty(String sName) {
|
||||
try {
|
||||
xUserProperties.addProperty(sName, (short) 128, ""); // 128 means removeable, last parameter is default value
|
||||
} catch (PropertyExistException e) {
|
||||
} catch (IllegalTypeException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a user property
|
||||
private void removeProperty(String sName) {
|
||||
try {
|
||||
xUserProperties.removeProperty(sName);
|
||||
} catch (UnknownPropertyException e) {
|
||||
} catch (NotRemoveableException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Set the value of a user property (failing silently if the property does not exist)
|
||||
private void setValue(String sName, Object value) {
|
||||
try {
|
||||
xUserPropertySet.setPropertyValue(sName, value);
|
||||
} catch (UnknownPropertyException e) {
|
||||
} catch (PropertyVetoException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (WrappedTargetException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Get the string value of a user property (returning null if the property does not exist)
|
||||
private String getStringValue(String sName) {
|
||||
Object value = getValue(sName);
|
||||
|
||||
if (value!=null && AnyConverter.isString(value)) {
|
||||
try {
|
||||
return AnyConverter.toString(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DateTime getDateValue(String sName) {
|
||||
Object value = getValue(sName);
|
||||
|
||||
if (value!=null && value instanceof DateTime) {
|
||||
return (DateTime) value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the value of a user property (returning null if the property does not exist)
|
||||
private Object getValue(String sName) {
|
||||
try {
|
||||
return xUserPropertySet.getPropertyValue(sName);
|
||||
} catch (UnknownPropertyException e) {
|
||||
return null;
|
||||
} catch (WrappedTargetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAuthorList(short nItem) {
|
||||
int nCount = authors.size();
|
||||
if (nCount>0) {
|
||||
String[] sAuthors = new String[nCount];
|
||||
for (int i=0; i<nCount; i++) {
|
||||
AuthorInfo author = authors.get(i);
|
||||
sAuthors[i] = author.sName
|
||||
+" ("
|
||||
+(author.isCreator ? "creator":"contributor")
|
||||
+(author.sRole.length()>0 ? ", "+author.sRole : "")
|
||||
+")";
|
||||
}
|
||||
setListBoxStringItemList("Authors", sAuthors);
|
||||
setListBoxSelectedItem("Authors",nItem);
|
||||
setControlEnabled("Authors", true);
|
||||
}
|
||||
else { // Display the fall-back author
|
||||
String[] sAuthors = new String[1];
|
||||
//sAuthors[0] = xDocumentProperties.getAuthor()+" (default creator)";
|
||||
sAuthors[0] = xDocumentProperties.getModifiedBy()+" (default creator)";
|
||||
setListBoxStringItemList("Authors", sAuthors);
|
||||
setControlEnabled("Authors", false);
|
||||
}
|
||||
setControlEnabled("ModifyAuthorButton",nCount>0);
|
||||
setControlEnabled("DeleteAuthorButton",nCount>0);
|
||||
setControlEnabled("AuthorUpButton",nCount>1);
|
||||
setControlEnabled("AuthorDownButton",nCount>1);
|
||||
}
|
||||
|
||||
private void updateDateList(short nItem) {
|
||||
int nCount = dates.size();
|
||||
if (nCount>0) {
|
||||
String[] sDates = new String[nCount];
|
||||
for (int i=0; i<nCount; i++) {
|
||||
DateInfo date = dates.get(i);
|
||||
sDates[i] = formatDate(date.nDate);
|
||||
if (date.sEvent.length()>0) {
|
||||
sDates[i]+=" (" + date.sEvent + ")";
|
||||
}
|
||||
}
|
||||
setListBoxStringItemList("Dates", sDates);
|
||||
setListBoxSelectedItem("Dates",nItem);
|
||||
setControlEnabled("Dates", true);
|
||||
}
|
||||
else { // Display the fall-back date
|
||||
String[] sDates = new String[1];
|
||||
sDates[0] = formatDate(datetime2int(xDocumentProperties.getModificationDate()))+" (default date)";
|
||||
setListBoxStringItemList("Dates", sDates);
|
||||
setControlEnabled("Dates", false);
|
||||
}
|
||||
setControlEnabled("ModifyDateButton",nCount>0);
|
||||
setControlEnabled("DeleteDateButton",nCount>0);
|
||||
setControlEnabled("DateUpButton",nCount>1);
|
||||
setControlEnabled("DateDownButton",nCount>1);
|
||||
}
|
||||
|
||||
private void readSimpleProperty(String sName) {
|
||||
String[] sNames = getProperties(sName,true);
|
||||
if (sNames.length>0) {
|
||||
String sValue = getStringValue(sNames[0]);
|
||||
if (sValue!=null) {
|
||||
setTextFieldText(sName, sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSimpleProperty(String sName) {
|
||||
String[] sOldNames = getProperties(sName,true);
|
||||
for (String sOldName : sOldNames) {
|
||||
removeProperty(sOldName);
|
||||
}
|
||||
String sValue = getTextFieldText(sName);
|
||||
if (sValue.length()>0) {
|
||||
addProperty(sName);
|
||||
setValue(sName,sValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Date fields uses integers for dates (format yyyymmdd)
|
||||
// Document properties uses com.sun.star.util.DateTime
|
||||
// Also dates should be formatted as yyyy-mm-dd as strings
|
||||
// Thus we need a few conversion methods
|
||||
|
||||
// Format a integer date as yyyy-mm-dd
|
||||
private String formatDate(int nDate) {
|
||||
String sDate = Integer.toString(nDate);
|
||||
if (sDate.length()==8) {
|
||||
return sDate.substring(0,4)+"-"+sDate.substring(4, 6)+"-"+sDate.substring(6);
|
||||
}
|
||||
else {
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
// Parse a string as a date in the format yyyy-mm-dd (returning 0 on failure)
|
||||
private int parseDate(String sDate) {
|
||||
Matcher matcher = datePattern.matcher(sDate);
|
||||
if (matcher.matches()) {
|
||||
return Misc.getPosInteger(matcher.group(1)+matcher.group(2)+matcher.group(3),0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert an integer to com.sun.star.util.DateTime
|
||||
/*private DateTime int2datetime(int nDate) {
|
||||
DateTime date = new DateTime();
|
||||
date.Year = (short) (nDate/10000);
|
||||
date.Month = (short) ((nDate%10000)/100);
|
||||
date.Day = (short) (nDate%100);
|
||||
return date;
|
||||
}*/
|
||||
|
||||
// Convert a com.sun.star.util.DateTime to integer
|
||||
private int datetime2int(DateTime date) {
|
||||
return 10000*date.Year+100*date.Month+date.Day;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,341 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* EpubOptionsDialog.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-28)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.filter.OptionsDialogBase;
|
||||
|
||||
/** This class provides a UNO component which implements a filter UI for the
|
||||
* EPUB export
|
||||
*/
|
||||
public class EpubOptionsDialog extends OptionsDialogBase {
|
||||
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.EpubOptionsDialog";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.EpubOptionsDialog";
|
||||
|
||||
@Override public String getDialogLibraryName() { return "w2phtml2"; }
|
||||
|
||||
/** Return the name of the dialog within the library
|
||||
*/
|
||||
@Override public String getDialogName() { return "EpubOptions"; }
|
||||
|
||||
/** Return the name of the registry path
|
||||
*/
|
||||
@Override public String getRegistryPath() {
|
||||
return "/org.openoffice.da.Writer2xhtml.Options/EpubOptions";
|
||||
}
|
||||
|
||||
/** Create a new EpubOptionsDialog */
|
||||
public EpubOptionsDialog(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
xMSF = W2XRegistration.xMultiServiceFactory;
|
||||
}
|
||||
|
||||
/** Load settings from the registry to the dialog */
|
||||
@Override protected void loadSettings(XPropertySet xProps) {
|
||||
// Style
|
||||
loadConfig(xProps);
|
||||
int nScaling = loadNumericOption(xProps, "Scaling");
|
||||
if (nScaling<=1) { // Workaround for an obscure bug in the extension manager
|
||||
setNumericFieldValue("Scaling",100);
|
||||
}
|
||||
loadCheckBoxOption(xProps, "RelativeFontSize");
|
||||
loadNumericOption(xProps, "FontScaling");
|
||||
int nFontScaling = loadNumericOption(xProps, "FontScaling");
|
||||
if (nFontScaling<=1) {
|
||||
setNumericFieldValue("FontScaling",100);
|
||||
}
|
||||
loadCheckBoxOption(xProps, "RelativeFontSize");
|
||||
loadCheckBoxOption(xProps, "UseDefaultFont");
|
||||
loadComboBoxOption(xProps, "DefaultFontName");
|
||||
loadCheckBoxOption(xProps, "ConvertToPx");
|
||||
loadListBoxOption(xProps, "ImageSize");
|
||||
|
||||
// Fill the font name list with all installed fonts
|
||||
setListBoxStringItemList("DefaultFontName",
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
|
||||
|
||||
// AutoCorrect
|
||||
loadCheckBoxOption(xProps, "IgnoreHardLineBreaks");
|
||||
loadCheckBoxOption(xProps, "IgnoreEmptyParagraphs");
|
||||
loadCheckBoxOption(xProps, "IgnoreDoubleSpaces");
|
||||
|
||||
// Special content
|
||||
loadCheckBoxOption(xProps, "DisplayHiddenText");
|
||||
loadCheckBoxOption(xProps, "Notes");
|
||||
|
||||
// Document division
|
||||
loadListBoxOption(xProps, "SplitLevel");
|
||||
loadListBoxOption(xProps, "PageBreakSplit");
|
||||
loadCheckBoxOption(xProps, "UseImageSplit");
|
||||
loadNumericOption(xProps, "ImageSplit");
|
||||
loadCheckBoxOption(xProps, "CoverImage");
|
||||
loadCheckBoxOption(xProps, "UseSplitAfter");
|
||||
loadNumericOption(xProps, "SplitAfter");
|
||||
|
||||
// Navigation table
|
||||
loadListBoxOption(xProps, "ExternalTocDepth");
|
||||
loadCheckBoxOption(xProps, "IncludeToc");
|
||||
loadCheckBoxOption(xProps, "IncludeNCX");
|
||||
|
||||
updateLockedOptions();
|
||||
enableControls();
|
||||
}
|
||||
|
||||
/** Save settings from the dialog to the registry and create FilterData */
|
||||
@Override protected void saveSettings(XPropertySet xProps, PropertyHelper helper) {
|
||||
// Style
|
||||
short nConfig = saveConfig(xProps, helper);
|
||||
switch (nConfig) {
|
||||
case 0: helper.put("ConfigURL","*default.xml"); break;
|
||||
case 1: helper.put("ConfigURL","$(user)/writer2xhtml.xml");
|
||||
helper.put("AutoCreate","true");
|
||||
helper.put("TemplateURL", "$(user)/writer2xhtml-template.xhtml");
|
||||
helper.put("StyleSheetURL", "$(user)/writer2xhtml-styles.css");
|
||||
helper.put("ResourceURL", "$(user)/writer2xhtml-resources");
|
||||
}
|
||||
|
||||
saveNumericOptionAsPercentage(xProps, helper, "Scaling", "scaling");
|
||||
saveCheckBoxOption(xProps, helper, "RelativeFontSize", "relative_font_size");
|
||||
saveNumericOptionAsPercentage(xProps, helper, "FontScaling", "font_scaling");
|
||||
saveCheckBoxOption(xProps, helper, "UseDefaultFont", "use_default_font");
|
||||
saveTextFieldOption(xProps, helper, "DefaultFontName", "default_font_name");
|
||||
saveCheckBoxOption(xProps, helper, "ConvertToPx", "convert_to_px");
|
||||
saveListBoxOption(xProps, "ImageSize");
|
||||
switch (getListBoxSelectedItem("ImageSize")) {
|
||||
case 0: helper.put("image_size", "absolute"); break;
|
||||
case 1: helper.put("image_size", "relative"); break;
|
||||
case 2: helper.put("image_size", "none");
|
||||
}
|
||||
|
||||
// AutoCorrect
|
||||
saveCheckBoxOption(xProps, helper, "IgnoreHardLineBreaks", "ignore_hard_line_breaks");
|
||||
saveCheckBoxOption(xProps, helper, "IgnoreEmptyParagraphs", "ignore_empty_paragraphs");
|
||||
saveCheckBoxOption(xProps, helper, "IgnoreDoubleSpaces", "ignore_double_spaces");
|
||||
|
||||
// Special content
|
||||
saveCheckBoxOption(xProps, helper, "DisplayHiddenText", "display_hidden_text");
|
||||
saveCheckBoxOption(xProps, helper, "Notes", "notes");
|
||||
|
||||
// Document division
|
||||
short nSplitLevel = saveListBoxOption(xProps, "SplitLevel");
|
||||
if (!isLocked("split_level")) {
|
||||
helper.put("split_level",Integer.toString(nSplitLevel));
|
||||
}
|
||||
|
||||
short nPageBreakSplit = saveListBoxOption(xProps, "PageBreakSplit");
|
||||
if (!isLocked("page_break_split")) {
|
||||
switch (nPageBreakSplit) {
|
||||
case 0: helper.put("page_break_split","none"); break;
|
||||
case 1: helper.put("page_break_split", "styles"); break;
|
||||
case 2: helper.put("page_break_split", "explicit"); break;
|
||||
case 3: helper.put("page_break_split", "all");
|
||||
}
|
||||
}
|
||||
|
||||
boolean bUseImageSplit = saveCheckBoxOption(xProps, "UseImageSplit");
|
||||
int nImageSplit = saveNumericOption(xProps, "ImageSplit");
|
||||
if (!isLocked("image_split")) {
|
||||
if (bUseImageSplit) {
|
||||
helper.put("image_split", nImageSplit+"%");
|
||||
}
|
||||
else {
|
||||
helper.put("image_split", "none");
|
||||
}
|
||||
}
|
||||
|
||||
saveCheckBoxOption(xProps, helper, "CoverImage", "cover_image");
|
||||
|
||||
boolean bUseSplitAfter = saveCheckBoxOption(xProps, "UseSplitAfter");
|
||||
int nSplitAfter = saveNumericOption(xProps, "SplitAfter");
|
||||
if (!isLocked("split_after")) {
|
||||
if (bUseSplitAfter) {
|
||||
helper.put("split_after", Integer.toString(nSplitAfter));
|
||||
}
|
||||
else {
|
||||
helper.put("split_after", "0");
|
||||
}
|
||||
}
|
||||
|
||||
// Navigation table
|
||||
short nExternalTocDepth = saveListBoxOption(xProps, "ExternalTocDepth");
|
||||
helper.put("external_toc_depth", Integer.toString(nExternalTocDepth+1));
|
||||
saveCheckBoxOption(xProps, helper, "IncludeToc", "include_toc");
|
||||
saveCheckBoxOption(xProps, helper, "IncludeNCX", "include_ncx");
|
||||
}
|
||||
|
||||
|
||||
// Implement XDialogEventHandler
|
||||
@Override public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) {
|
||||
if (sMethod.equals("ConfigChange")) {
|
||||
updateLockedOptions();
|
||||
enableControls();
|
||||
}
|
||||
else if (sMethod.equals("RelativeFontSizeChange")) {
|
||||
relativeFontSizeChange();
|
||||
}
|
||||
else if (sMethod.equals("UseDefaultFontChange")) {
|
||||
useDefaultFontChange();
|
||||
}
|
||||
else if (sMethod.equals("EditMetadataClick")) {
|
||||
editMetadataClick();
|
||||
}
|
||||
else if (sMethod.equals("UseImageSplitChange")) {
|
||||
useImageSplitChange();
|
||||
}
|
||||
else if (sMethod.equals("UseSplitAfterChange")) {
|
||||
useSplitAfterChange();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String[] getSupportedMethodNames() {
|
||||
String[] sNames = { "ConfigChange", "RelativeFontSizeChange", "UseDefaultFontChange", "EditMetadataClick",
|
||||
"UseImageSplitChange", "UseSplitAfterChange" };
|
||||
return sNames;
|
||||
}
|
||||
|
||||
private void enableControls() {
|
||||
// Style
|
||||
setControlEnabled("ScalingLabel",!isLocked("scaling"));
|
||||
setControlEnabled("Scaling",!isLocked("scaling"));
|
||||
|
||||
boolean bRelativeFontSize = getCheckBoxStateAsBoolean("RelativeFontSize");
|
||||
setControlEnabled("RelativeFontSize",!isLocked("relative_font_size"));
|
||||
setControlEnabled("FontScalingLabel", !isLocked("font_scaling") && bRelativeFontSize);
|
||||
setControlEnabled("FontScaling",!isLocked("font_scaling") && bRelativeFontSize);
|
||||
setControlEnabled("FontScalingPercentLabel", !isLocked("font_scaling") && bRelativeFontSize);
|
||||
|
||||
boolean bUseDefaultFont = getCheckBoxStateAsBoolean("UseDefaultFont");
|
||||
setControlEnabled("UseDefaultFont",!isLocked("use_default_font"));
|
||||
setControlEnabled("DefaultFontNameLabel",!isLocked("default_font_name") && bUseDefaultFont);
|
||||
setControlEnabled("DefaultFontName",!isLocked("default_font_name") && bUseDefaultFont);
|
||||
|
||||
setControlEnabled("ConvertToPx",!isLocked("convert_to_px"));
|
||||
setControlEnabled("ImageSize",!isLocked("image_size"));
|
||||
|
||||
// AutoCorrect
|
||||
setControlEnabled("IgnoreHardLineBreaks",!isLocked("ignore_hard_line_breaks"));
|
||||
setControlEnabled("IgnoreEmptyParagraphs",!isLocked("ignore_empty_paragraphs"));
|
||||
setControlEnabled("IgnoreDoubleSpaces",!isLocked("ignore_double_spaces"));
|
||||
|
||||
// Special content
|
||||
setControlEnabled("DisplayHiddenText",!isLocked("display_hidden_text"));
|
||||
setControlEnabled("Notes",!isLocked("notes"));
|
||||
|
||||
// Document division
|
||||
setControlEnabled("SplitLevelLabel",!isLocked("split_level"));
|
||||
setControlEnabled("SplitLevel",!isLocked("split_level"));
|
||||
|
||||
setControlEnabled("PageBreakSplitLabel",!isLocked("page_break_split"));
|
||||
setControlEnabled("PageBreakSplit",!isLocked("page_break_split"));
|
||||
|
||||
boolean bUseImageSplit = getCheckBoxStateAsBoolean("UseImageSplit");
|
||||
setControlEnabled("UseImageSplit",!isLocked("image_split"));
|
||||
setControlEnabled("ImageSplitLabel",!isLocked("image_split") && bUseImageSplit);
|
||||
setControlEnabled("ImageSplit",!isLocked("image_split") && bUseImageSplit);
|
||||
setControlEnabled("ImageSplitPercentLabel",!isLocked("image_split") && bUseImageSplit);
|
||||
|
||||
setControlEnabled("CoverImage", !isLocked("cover_image"));
|
||||
|
||||
boolean bUseSplitAfter = getCheckBoxStateAsBoolean("UseSplitAfter");
|
||||
setControlEnabled("UseSplitAfter",!isLocked("split_after"));
|
||||
setControlEnabled("SplitAfterLabel",!isLocked("split_after") && bUseSplitAfter);
|
||||
setControlEnabled("SplitAfter",!isLocked("split_after") && bUseSplitAfter);
|
||||
|
||||
// Navigation table
|
||||
setControlEnabled("ExternalTocDepthLabel", !isLocked("external_toc_depth"));
|
||||
setControlEnabled("ExternalTocDepth", !isLocked("external_toc_depth"));
|
||||
setControlEnabled("IncludeToc", !isLocked("include_toc"));
|
||||
setControlEnabled("IncludeNCX", (this instanceof Epub3OptionsDialog) && !isLocked("include_ncx"));
|
||||
}
|
||||
|
||||
private void relativeFontSizeChange() {
|
||||
if (!isLocked("font_scaling")) {
|
||||
boolean bState = getCheckBoxStateAsBoolean("RelativeFontSize");
|
||||
setControlEnabled("FontScalingLabel", bState);
|
||||
setControlEnabled("FontScaling", bState);
|
||||
setControlEnabled("FontScalingPercentLabel", bState);
|
||||
}
|
||||
}
|
||||
|
||||
private void useDefaultFontChange() {
|
||||
if (!isLocked("default_font_name")) {
|
||||
boolean bState = getCheckBoxStateAsBoolean("UseDefaultFont");
|
||||
setControlEnabled("DefaultFontNameLabel", bState);
|
||||
setControlEnabled("DefaultFontName", bState);
|
||||
}
|
||||
}
|
||||
|
||||
private void editMetadataClick() {
|
||||
Object dialog;
|
||||
try {
|
||||
dialog = xContext.getServiceManager().createInstanceWithContext("org.openoffice.da.writer2xhtml.EpubMetadataDialog", xContext);
|
||||
XExecutableDialog xDialog = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, dialog);
|
||||
xDialog.execute();
|
||||
// Dispose the dialog after execution (to free up the memory)
|
||||
XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, dialog);
|
||||
if (xComponent!=null) {
|
||||
xComponent.dispose();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Failed to get dialog
|
||||
}
|
||||
}
|
||||
|
||||
private void useImageSplitChange() {
|
||||
if (!isLocked("image_split")) {
|
||||
boolean bEnable = getCheckBoxStateAsBoolean("UseImageSplit");
|
||||
setControlEnabled("ImageSplitLabel",bEnable);
|
||||
setControlEnabled("ImageSplit",bEnable);
|
||||
setControlEnabled("ImageSplitPercentLabel",bEnable);
|
||||
}
|
||||
}
|
||||
|
||||
private void useSplitAfterChange() {
|
||||
if (!isLocked("split_after")) {
|
||||
boolean bState = getCheckBoxStateAsBoolean("UseSplitAfter");
|
||||
setControlEnabled("SplitAfterLabel",bState);
|
||||
setControlEnabled("SplitAfter",bState);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,261 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* ToolbarSettingsDialog.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-05)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.sun.star.awt.XContainerWindowEventHandler;
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.awt.XWindow;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.lang.XServiceInfo;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import com.sun.star.util.XChangesBatch;
|
||||
|
||||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.DialogAccess;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.FilePicker;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
|
||||
|
||||
/** This class provides a uno component which implements the configuration
|
||||
* of the writer2xhtml toolbar
|
||||
*/
|
||||
public final class ToolbarSettingsDialog
|
||||
extends WeakBase
|
||||
implements XServiceInfo, XContainerWindowEventHandler {
|
||||
|
||||
public static final String REGISTRY_PATH = "/org.openoffice.da.Writer2xhtml.toolbar.ToolbarOptions/Settings";
|
||||
|
||||
private XComponentContext xContext;
|
||||
private FilePicker filePicker;
|
||||
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.ToolbarSettingsDialog";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.ToolbarSettingsDialog";
|
||||
|
||||
/** Create a new ToolbarSettingsDialog */
|
||||
public ToolbarSettingsDialog(XComponentContext xContext) {
|
||||
this.xContext = xContext;
|
||||
filePicker = new FilePicker(xContext);
|
||||
}
|
||||
|
||||
// Implement XContainerWindowEventHandler
|
||||
public boolean callHandlerMethod(XWindow xWindow, Object event, String sMethod)
|
||||
throws com.sun.star.lang.WrappedTargetException {
|
||||
XDialog xDialog = (XDialog)UnoRuntime.queryInterface(XDialog.class, xWindow);
|
||||
DialogAccess dlg = new DialogAccess(xDialog);
|
||||
|
||||
try {
|
||||
if (sMethod.equals("external_event") ){
|
||||
return handleExternalEvent(dlg, event);
|
||||
}
|
||||
else if (sMethod.equals("XhtmlFormatChange")) {
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("XhtmlViewChange")) {
|
||||
return xhtmlViewChange(dlg);
|
||||
}
|
||||
else if (sMethod.equals("XhtmlBrowseClick")) {
|
||||
return xhtmlBrowseClick(dlg);
|
||||
}
|
||||
else if (sMethod.equals("EpubFormatChange")) {
|
||||
return true;
|
||||
}
|
||||
else if (sMethod.equals("EpubViewChange")) {
|
||||
return epubViewChange(dlg);
|
||||
}
|
||||
else if (sMethod.equals("EpubBrowseClick")) {
|
||||
return epubBrowseClick(dlg);
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.uno.RuntimeException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
throw new com.sun.star.lang.WrappedTargetException(sMethod, this, e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String[] getSupportedMethodNames() {
|
||||
String[] sNames = { "external_event", "XhtmlFormatChange", "XhtmlViewChange", "XhtmlBrowseClick",
|
||||
"EpupFormatChange", "EpubViewChange", "EpubBrowseClick" };
|
||||
return sNames;
|
||||
}
|
||||
|
||||
// Implement the interface XServiceInfo
|
||||
public boolean supportsService(String sServiceName) {
|
||||
return sServiceName.equals(__serviceName);
|
||||
}
|
||||
|
||||
public String getImplementationName() {
|
||||
return __implementationName;
|
||||
}
|
||||
|
||||
public String[] getSupportedServiceNames() {
|
||||
String[] sSupportedServiceNames = { __serviceName };
|
||||
return sSupportedServiceNames;
|
||||
}
|
||||
|
||||
// Private stuff
|
||||
|
||||
private boolean handleExternalEvent(DialogAccess dlg, Object aEventObject)
|
||||
throws com.sun.star.uno.Exception {
|
||||
try {
|
||||
String sMethod = AnyConverter.toString(aEventObject);
|
||||
if (sMethod.equals("ok")) {
|
||||
saveConfiguration(dlg);
|
||||
return true;
|
||||
} else if (sMethod.equals("back") || sMethod.equals("initialize")) {
|
||||
loadConfiguration(dlg);
|
||||
enableXhtmlExecutable(dlg);
|
||||
enableEpubExecutable(dlg);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException e) {
|
||||
throw new com.sun.star.lang.IllegalArgumentException(
|
||||
"Method external_event requires a string in the event object argument.", this,(short) -1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void loadConfiguration(DialogAccess dlg) {
|
||||
RegistryHelper registry = new RegistryHelper(xContext);
|
||||
|
||||
try {
|
||||
Object view = registry.getRegistryView(REGISTRY_PATH, false);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
|
||||
dlg.setListBoxSelectedItem("XhtmlFormat",
|
||||
XPropertySetHelper.getPropertyValueAsShort(xProps, "XhtmlFormat"));
|
||||
dlg.setListBoxSelectedItem("XhtmlView",
|
||||
XPropertySetHelper.getPropertyValueAsShort(xProps, "XhtmlView"));
|
||||
dlg.setTextFieldText("XhtmlExecutable",
|
||||
XPropertySetHelper.getPropertyValueAsString(xProps, "XhtmlExecutable"));
|
||||
dlg.setListBoxSelectedItem("EpubFormat",
|
||||
XPropertySetHelper.getPropertyValueAsShort(xProps, "EpubFormat"));
|
||||
dlg.setListBoxSelectedItem("EpubView",
|
||||
XPropertySetHelper.getPropertyValueAsShort(xProps, "EpubView"));
|
||||
dlg.setTextFieldText("EpubExecutable",
|
||||
XPropertySetHelper.getPropertyValueAsString(xProps, "EpubExecutable"));
|
||||
} catch (Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
}
|
||||
|
||||
private void saveConfiguration(DialogAccess dlg) {
|
||||
RegistryHelper registry = new RegistryHelper(xContext);
|
||||
try {
|
||||
Object view = registry.getRegistryView(REGISTRY_PATH, true);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
XPropertySetHelper.setPropertyValue(xProps, "XhtmlFormat", dlg.getListBoxSelectedItem("XhtmlFormat"));
|
||||
XPropertySetHelper.setPropertyValue(xProps, "XhtmlView", dlg.getListBoxSelectedItem("XhtmlView"));
|
||||
XPropertySetHelper.setPropertyValue(xProps, "XhtmlExecutable", dlg.getTextFieldText("XhtmlExecutable"));
|
||||
XPropertySetHelper.setPropertyValue(xProps, "EpubFormat", dlg.getListBoxSelectedItem("EpubFormat"));
|
||||
XPropertySetHelper.setPropertyValue(xProps, "EpubView", dlg.getListBoxSelectedItem("EpubView"));
|
||||
XPropertySetHelper.setPropertyValue(xProps, "EpubExecutable", dlg.getTextFieldText("EpubExecutable"));
|
||||
|
||||
// Commit registry changes
|
||||
XChangesBatch xUpdateContext = (XChangesBatch)
|
||||
UnoRuntime.queryInterface(XChangesBatch.class,view);
|
||||
try {
|
||||
xUpdateContext.commitChanges();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
registry.disposeRegistryView(view);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
}
|
||||
|
||||
private boolean xhtmlViewChange(DialogAccess dlg) {
|
||||
enableXhtmlExecutable(dlg);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void enableXhtmlExecutable(DialogAccess dlg) {
|
||||
int nItem = dlg.getListBoxSelectedItem("XhtmlView");
|
||||
dlg.setControlEnabled("XhtmlExecutable", nItem==2);
|
||||
dlg.setControlEnabled("XhtmlBrowseButton", nItem==2);
|
||||
}
|
||||
|
||||
private boolean xhtmlBrowseClick(DialogAccess dlg) {
|
||||
browseForExecutable(dlg,"XhtmlExecutable");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean epubViewChange(DialogAccess dlg) {
|
||||
enableEpubExecutable(dlg);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void enableEpubExecutable(DialogAccess dlg) {
|
||||
int nItem = dlg.getListBoxSelectedItem("EpubView");
|
||||
dlg.setControlEnabled("EpubExecutable", nItem==2);
|
||||
dlg.setControlEnabled("EpubBrowseButton", nItem==2);
|
||||
}
|
||||
|
||||
private boolean epubBrowseClick(DialogAccess dlg) {
|
||||
browseForExecutable(dlg,"EpubExecutable");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean browseForExecutable(DialogAccess dlg, String sControlName) {
|
||||
String sPath = filePicker.getPath();
|
||||
if (sPath!=null) {
|
||||
try {
|
||||
dlg.setComboBoxText(sControlName, new File(new URI(sPath)).getCanonicalPath());
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* W2XExportFilter.java
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2014-10-06)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.filter.ExportFilterBase;
|
||||
|
||||
|
||||
/** This class implements the xhtml export filter component
|
||||
*/
|
||||
public class W2XExportFilter extends ExportFilterBase {
|
||||
|
||||
/** Service name for the component */
|
||||
public static final String __serviceName = "org.openoffice.da.comp.writer2xhtml.W2XExportFilter";
|
||||
|
||||
/** Implementation name for the component */
|
||||
public static final String __implementationName = "org.openoffice.da.comp.writer2xhtml.W2XExportFilter";
|
||||
|
||||
/** Filter name to include in error messages */
|
||||
public final String __displayName = "Writer2xhtml";
|
||||
|
||||
public W2XExportFilter(XComponentContext xComponentContext1) {
|
||||
super(xComponentContext1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* W2XRegistration.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-28)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import com.sun.star.lang.XMultiServiceFactory;
|
||||
import com.sun.star.lang.XSingleServiceFactory;
|
||||
import com.sun.star.registry.XRegistryKey;
|
||||
|
||||
import com.sun.star.comp.loader.FactoryHelper;
|
||||
|
||||
/** This class provides a static method to instantiate our uno components
|
||||
* on demand (__getServiceFactory()), and a static method to give
|
||||
* information about the components (__writeRegistryServiceInfo()).
|
||||
* Furthermore, it saves the XMultiServiceFactory provided to the
|
||||
* __getServiceFactory method for future reference by the componentes.
|
||||
*/
|
||||
public class W2XRegistration {
|
||||
|
||||
public static XMultiServiceFactory xMultiServiceFactory;
|
||||
|
||||
/**
|
||||
* Returns a factory for creating the service.
|
||||
* This method is called by the <code>JavaLoader</code>
|
||||
*
|
||||
* @return returns a <code>XSingleServiceFactory</code> for creating the
|
||||
* component
|
||||
*
|
||||
* @param implName the name of the implementation for which a
|
||||
* service is desired
|
||||
* @param multiFactory the service manager to be used if needed
|
||||
* @param regKey the registryKey
|
||||
*
|
||||
* @see com.sun.star.comp.loader.JavaLoader
|
||||
*/
|
||||
public static XSingleServiceFactory __getServiceFactory(String implName,
|
||||
XMultiServiceFactory multiFactory, XRegistryKey regKey) {
|
||||
xMultiServiceFactory = multiFactory;
|
||||
XSingleServiceFactory xSingleServiceFactory = null;
|
||||
if (implName.equals(Writer2xhtml.__implementationName) ) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(Writer2xhtml.class,
|
||||
Writer2xhtml.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(W2XExportFilter.class.getName()) ) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(W2XExportFilter.class,
|
||||
W2XExportFilter.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(XhtmlOptionsDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(XhtmlOptionsDialog.class,
|
||||
XhtmlOptionsDialog.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(XhtmlOptionsDialogMath.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(XhtmlOptionsDialogMath.class,
|
||||
XhtmlOptionsDialogMath.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(EpubOptionsDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(EpubOptionsDialog.class,
|
||||
EpubOptionsDialog.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(Epub3OptionsDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(Epub3OptionsDialog.class,
|
||||
Epub3OptionsDialog.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(EpubMetadataDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(EpubMetadataDialog.class,
|
||||
EpubMetadataDialog.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(ConfigurationDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(ConfigurationDialog.class,
|
||||
ConfigurationDialog.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
else if (implName.equals(ToolbarSettingsDialog.__implementationName)) {
|
||||
xSingleServiceFactory = FactoryHelper.getServiceFactory(ToolbarSettingsDialog.class,
|
||||
ToolbarSettingsDialog.__serviceName,
|
||||
multiFactory,
|
||||
regKey);
|
||||
}
|
||||
|
||||
return xSingleServiceFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the service information into the given registry key.
|
||||
* This method is called by the <code>JavaLoader</code>
|
||||
* <p>
|
||||
* @return returns true if the operation succeeded
|
||||
* @param regKey the registryKey
|
||||
* @see com.sun.star.comp.loader.JavaLoader
|
||||
*/
|
||||
public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
|
||||
return
|
||||
FactoryHelper.writeRegistryServiceInfo(Writer2xhtml.__implementationName,
|
||||
Writer2xhtml.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(W2XExportFilter.__implementationName,
|
||||
W2XExportFilter.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(XhtmlOptionsDialog.__implementationName,
|
||||
XhtmlOptionsDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(XhtmlOptionsDialogMath.__implementationName,
|
||||
XhtmlOptionsDialogMath.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(EpubOptionsDialog.__implementationName,
|
||||
EpubOptionsDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(Epub3OptionsDialog.__implementationName,
|
||||
Epub3OptionsDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(EpubMetadataDialog.__implementationName,
|
||||
EpubMetadataDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(ConfigurationDialog.__implementationName,
|
||||
ConfigurationDialog.__serviceName, regKey) &
|
||||
FactoryHelper.writeRegistryServiceInfo(ToolbarSettingsDialog.__implementationName,
|
||||
ToolbarSettingsDialog.__serviceName, regKey);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,209 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* Writer2xhtml.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-05)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
// TODO: Create common base for dispatcher classes
|
||||
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lib.uno.helper.WeakBase;
|
||||
import com.sun.star.ui.dialogs.XExecutableDialog;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher.TargetFormat;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
|
||||
|
||||
/** This class implements the ui (dispatch) commands provided by Writer2xhtml.
|
||||
*/
|
||||
public final class Writer2xhtml extends WeakBase
|
||||
implements com.sun.star.lang.XServiceInfo,
|
||||
com.sun.star.frame.XDispatchProvider,
|
||||
com.sun.star.lang.XInitialization,
|
||||
com.sun.star.frame.XDispatch {
|
||||
|
||||
private static final String PROTOCOL = "org.openoffice.da.writer2xhtml:";
|
||||
|
||||
// From constructor+initialization
|
||||
private final XComponentContext m_xContext;
|
||||
private XFrame m_xFrame;
|
||||
private XhtmlUNOPublisher unoPublisher = null;
|
||||
|
||||
// Global data
|
||||
public static final String __implementationName = Writer2xhtml.class.getName();
|
||||
public static final String __serviceName = "com.sun.star.frame.ProtocolHandler";
|
||||
private static final String[] m_serviceNames = { __serviceName };
|
||||
|
||||
public Writer2xhtml(XComponentContext xContext) {
|
||||
m_xContext = xContext;
|
||||
}
|
||||
|
||||
// com.sun.star.lang.XInitialization:
|
||||
public void initialize( Object[] object )
|
||||
throws com.sun.star.uno.Exception {
|
||||
if ( object.length > 0 ) {
|
||||
// The first item is the current frame
|
||||
m_xFrame = (com.sun.star.frame.XFrame) UnoRuntime.queryInterface(
|
||||
com.sun.star.frame.XFrame.class, object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// com.sun.star.lang.XServiceInfo:
|
||||
public String getImplementationName() {
|
||||
return __implementationName;
|
||||
}
|
||||
|
||||
public boolean supportsService( String sService ) {
|
||||
int len = m_serviceNames.length;
|
||||
|
||||
for( int i=0; i < len; i++) {
|
||||
if (sService.equals(m_serviceNames[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String[] getSupportedServiceNames() {
|
||||
return m_serviceNames;
|
||||
}
|
||||
|
||||
|
||||
// com.sun.star.frame.XDispatchProvider:
|
||||
public com.sun.star.frame.XDispatch queryDispatch( com.sun.star.util.URL aURL,
|
||||
String sTargetFrameName, int iSearchFlags ) {
|
||||
if ( aURL.Protocol.compareTo(PROTOCOL) == 0 ) {
|
||||
if ( aURL.Path.compareTo("PublishAsXHTML") == 0 )
|
||||
return this;
|
||||
else if ( aURL.Path.compareTo("PublishAsEPUB") == 0 )
|
||||
return this;
|
||||
else if ( aURL.Path.compareTo("EditEPUBDocumentProperties") == 0 )
|
||||
return this;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public com.sun.star.frame.XDispatch[] queryDispatches(
|
||||
com.sun.star.frame.DispatchDescriptor[] seqDescriptors ) {
|
||||
int nCount = seqDescriptors.length;
|
||||
com.sun.star.frame.XDispatch[] seqDispatcher =
|
||||
new com.sun.star.frame.XDispatch[seqDescriptors.length];
|
||||
|
||||
for( int i=0; i < nCount; ++i ) {
|
||||
seqDispatcher[i] = queryDispatch(seqDescriptors[i].FeatureURL,
|
||||
seqDescriptors[i].FrameName,
|
||||
seqDescriptors[i].SearchFlags );
|
||||
}
|
||||
return seqDispatcher;
|
||||
}
|
||||
|
||||
|
||||
// com.sun.star.frame.XDispatch:
|
||||
public void dispatch( com.sun.star.util.URL aURL,
|
||||
com.sun.star.beans.PropertyValue[] aArguments ) {
|
||||
if ( aURL.Protocol.compareTo(PROTOCOL) == 0 ) {
|
||||
if ( aURL.Path.compareTo("PublishAsXHTML") == 0 ) {
|
||||
publishAsXhtml();
|
||||
return;
|
||||
}
|
||||
else if ( aURL.Path.compareTo("PublishAsEPUB") == 0 ) {
|
||||
publishAsEpub();
|
||||
return;
|
||||
}
|
||||
else if ( aURL.Path.compareTo("EditEPUBDocumentProperties") == 0 ) {
|
||||
editDocumentProperties();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addStatusListener( com.sun.star.frame.XStatusListener xControl,
|
||||
com.sun.star.util.URL aURL ) {
|
||||
}
|
||||
|
||||
public void removeStatusListener( com.sun.star.frame.XStatusListener xControl,
|
||||
com.sun.star.util.URL aURL ) {
|
||||
}
|
||||
|
||||
// The actual commands...
|
||||
private void editDocumentProperties() {
|
||||
Object dialog;
|
||||
try {
|
||||
dialog = m_xContext.getServiceManager().createInstanceWithContext("org.openoffice.da.writer2xhtml.EpubMetadataDialog", m_xContext);
|
||||
XExecutableDialog xDialog = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, dialog);
|
||||
xDialog.execute();
|
||||
// Dispose the dialog after execution (to free up the memory)
|
||||
XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, dialog);
|
||||
if (xComponent!=null) {
|
||||
xComponent.dispose();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Failed to get dialog
|
||||
}
|
||||
}
|
||||
|
||||
private void publishAsXhtml() {
|
||||
RegistryHelper registry = new RegistryHelper(m_xContext);
|
||||
try {
|
||||
Object view = registry.getRegistryView(ToolbarSettingsDialog.REGISTRY_PATH, false);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
short nXhtmlFormat = XPropertySetHelper.getPropertyValueAsShort(xProps, "XhtmlFormat");
|
||||
switch (nXhtmlFormat) {
|
||||
case 0: publish(TargetFormat.xhtml); break;
|
||||
case 1: publish(TargetFormat.xhtml11); break;
|
||||
case 2: publish(TargetFormat.xhtml_mathml); break;
|
||||
case 3: publish(TargetFormat.html5);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
}
|
||||
|
||||
private void publishAsEpub() {
|
||||
RegistryHelper registry = new RegistryHelper(m_xContext);
|
||||
try {
|
||||
Object view = registry.getRegistryView(ToolbarSettingsDialog.REGISTRY_PATH, false);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
short nEpubFormat = XPropertySetHelper.getPropertyValueAsShort(xProps, "EpubFormat");
|
||||
switch (nEpubFormat) {
|
||||
case 0: publish(TargetFormat.epub); break;
|
||||
case 1: publish(TargetFormat.epub3);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void publish(TargetFormat format) {
|
||||
if (unoPublisher==null) {
|
||||
unoPublisher = new XhtmlUNOPublisher(m_xContext,m_xFrame,"Writer2xhtml");
|
||||
}
|
||||
unoPublisher.publish(format);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,242 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* XhtmlOptionsDialog.java
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.4 (2014-09-25)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import com.sun.star.awt.XDialog;
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.filter.OptionsDialogBase;
|
||||
|
||||
/** This class provides a uno component which implements a filter ui for the
|
||||
* Xhtml export
|
||||
*/
|
||||
public class XhtmlOptionsDialog extends OptionsDialogBase {
|
||||
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.XhtmlOptionsDialog";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialog";
|
||||
|
||||
public String getDialogLibraryName() { return "w2phtml"; }
|
||||
|
||||
/** Return the name of the dialog within the library
|
||||
*/
|
||||
public String getDialogName() { return "XhtmlOptions"; }
|
||||
|
||||
/** Return the name of the registry path
|
||||
*/
|
||||
public String getRegistryPath() {
|
||||
return "/org.openoffice.da.Writer2xhtml.Options/XhtmlOptions";
|
||||
}
|
||||
|
||||
/** Create a new XhtmlOptionsDialog */
|
||||
public XhtmlOptionsDialog(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
xMSF = W2XRegistration.xMultiServiceFactory;
|
||||
}
|
||||
|
||||
/** Load settings from the registry to the dialog */
|
||||
protected void loadSettings(XPropertySet xProps) {
|
||||
// Style
|
||||
loadConfig(xProps);
|
||||
loadCheckBoxOption(xProps, "ConvertToPx");
|
||||
int nScaling = loadNumericOption(xProps, "Scaling");
|
||||
if (nScaling<=1) { // Workaround for an obscure bug in the extension manager
|
||||
setNumericFieldValue("Scaling",100);
|
||||
}
|
||||
loadTextFieldOption(xProps, "MinLetterSpacing");
|
||||
loadTextFieldOption(xProps, "MaxWidth");
|
||||
loadTextFieldOption(xProps, "PageBreakStyle");
|
||||
|
||||
loadCheckBoxOption(xProps, "InlineCSS");
|
||||
loadCheckBoxOption(xProps, "EmbedImg");
|
||||
loadCheckBoxOption(xProps, "EmbedSVG");
|
||||
loadCheckBoxOption(xProps, "Greenstone");
|
||||
|
||||
|
||||
// Special content
|
||||
loadCheckBoxOption(xProps, "Notes");
|
||||
loadCheckBoxOption(xProps, "UseDublinCore");
|
||||
|
||||
// AutoCorrect
|
||||
loadCheckBoxOption(xProps, "IgnoreHardLineBreaks");
|
||||
loadCheckBoxOption(xProps, "IgnoreEmptyParagraphs");
|
||||
loadCheckBoxOption(xProps, "IgnoreDoubleSpaces");
|
||||
|
||||
// Files
|
||||
loadCheckBoxOption(xProps, "AlignSplitsToPages");
|
||||
loadCheckBoxOption(xProps, "Split");
|
||||
loadListBoxOption(xProps, "SplitLevel");
|
||||
loadListBoxOption(xProps, "RepeatLevels");
|
||||
loadCheckBoxOption(xProps, "SaveImagesInSubdir");
|
||||
loadCheckBoxOption(xProps, "UseMathjax");
|
||||
|
||||
updateLockedOptions();
|
||||
enableControls();
|
||||
}
|
||||
|
||||
/** Save settings from the dialog to the registry and create FilterData */
|
||||
protected void saveSettings(XPropertySet xProps, PropertyHelper helper) {
|
||||
// Style
|
||||
short nConfig = saveConfig(xProps, helper);
|
||||
String[] sCoreStyles = { "Chocolate", "Midnight", "Modernist",
|
||||
"Oldstyle", "Steely", "Swiss", "Traditional", "Ultramarine" };
|
||||
switch (nConfig) {
|
||||
case 0: helper.put("ConfigURL","*default.xml"); break;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8: helper.put("ConfigURL","*cleanxhtml.xml");
|
||||
helper.put("custom_stylesheet", "http://www.w3.org/StyleSheets/Core/"+sCoreStyles[nConfig-1]);
|
||||
break;
|
||||
case 9: helper.put("ConfigURL","$(user)/writer2xhtml.xml");
|
||||
helper.put("AutoCreate","true");
|
||||
helper.put("TemplateURL", "$(user)/writer2xhtml-template.xhtml");
|
||||
helper.put("StyleSheetURL", "$(user)/writer2xhtml-styles.css");
|
||||
}
|
||||
|
||||
saveTextFieldOption(xProps, helper, "MinLetterSpacing", "min_letter_spacing");
|
||||
saveTextFieldOption(xProps, helper, "MaxWidth", "max_width");
|
||||
saveTextFieldOption(xProps, helper, "PageBreakStyle", "page_break_style");
|
||||
|
||||
saveCheckBoxOption(xProps, helper, "ConvertToPx", "convert_to_px");
|
||||
saveNumericOptionAsPercentage(xProps, helper, "Scaling", "scaling");
|
||||
|
||||
// Special content
|
||||
saveCheckBoxOption(xProps, helper, "InlineCSS", "css_inline");
|
||||
saveCheckBoxOption(xProps, helper, "EmbedImg", "embed_svg");
|
||||
saveCheckBoxOption(xProps, helper, "EmbedSVG", "embed_img");
|
||||
saveCheckBoxOption(xProps, helper, "Greenstone", "greenstone");
|
||||
|
||||
saveCheckBoxOption(xProps, helper, "AlignSplitsToPages","align_splits_to_pages");
|
||||
|
||||
saveCheckBoxOption(xProps, helper, "Notes", "notes");
|
||||
saveCheckBoxOption(xProps, helper, "UseDublinCore", "use_dublin_core");
|
||||
|
||||
// AutoCorrect
|
||||
saveCheckBoxOption(xProps, helper, "IgnoreHardLineBreaks", "ignore_hard_line_breaks");
|
||||
saveCheckBoxOption(xProps, helper, "IgnoreEmptyParagraphs", "ignore_empty_paragraphs");
|
||||
saveCheckBoxOption(xProps, helper, "IgnoreDoubleSpaces", "ignore_double_spaces");
|
||||
// Files
|
||||
boolean bSplit = saveCheckBoxOption(xProps, "Split");
|
||||
short nSplitLevel = saveListBoxOption(xProps, "SplitLevel");
|
||||
short nRepeatLevels = saveListBoxOption(xProps, "RepeatLevels");
|
||||
if (!isLocked("split_level")) {
|
||||
if (bSplit) {
|
||||
helper.put("split_level",Integer.toString(nSplitLevel+1));
|
||||
helper.put("repeat_levels",Integer.toString(nRepeatLevels));
|
||||
}
|
||||
else {
|
||||
helper.put("split_level","0");
|
||||
}
|
||||
}
|
||||
|
||||
saveCheckBoxOption(xProps, helper, "SaveImagesInSubdir", "save_images_in_subdir");
|
||||
saveCheckBoxOption(xProps, helper, "UseMathjax", "use_mathjax");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Implement XDialogEventHandler
|
||||
public boolean callHandlerMethod(XDialog xDialog, Object event, String sMethod) {
|
||||
if (sMethod.equals("ConfigChange")) {
|
||||
updateLockedOptions();
|
||||
enableControls();
|
||||
}
|
||||
else if (sMethod.equals("SplitChange")) {
|
||||
enableSplitLevel();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String[] getSupportedMethodNames() {
|
||||
String[] sNames = { "ConfigChange", "SplitChange" };
|
||||
return sNames;
|
||||
}
|
||||
|
||||
private void enableControls() {
|
||||
// Style
|
||||
setControlEnabled("ScalingLabel",!isLocked("scaling"));
|
||||
setControlEnabled("Scaling",!isLocked("scaling"));
|
||||
|
||||
setControlEnabled("MinLetterSpacing",!isLocked("min_letter_spacing"));
|
||||
setControlEnabled("MaxWidth",!isLocked("max_width"));
|
||||
setControlEnabled("PageBreakStyle",!isLocked("page_break_style"));
|
||||
|
||||
|
||||
setControlEnabled("ConvertToPx",!isLocked("convert_to_px"));
|
||||
|
||||
// Special content
|
||||
setControlEnabled("InlineCSS",!isLocked("css_inline"));
|
||||
setControlEnabled("EmbedImg",!isLocked("embed_img"));
|
||||
setControlEnabled("EmbedSVG",!isLocked("embed_svg"));
|
||||
setControlEnabled("Greenstone",!isLocked("greenstone"));
|
||||
|
||||
setControlEnabled("AlignSplitsToPages",!isLocked("align_splits_to_pages"));
|
||||
|
||||
|
||||
setControlEnabled("Notes",!isLocked("notes"));
|
||||
setControlEnabled("UseDublinCore",!isLocked("use_dublin_core"));
|
||||
|
||||
// AutoCorrect
|
||||
setControlEnabled("IgnoreHardLineBreaks",!isLocked("ignore_hard_line_breaks"));
|
||||
setControlEnabled("IgnoreEmptyParagraphs",!isLocked("ignore_empty_paragraphs"));
|
||||
setControlEnabled("IgnoreDoubleSpaces",!isLocked("ignore_double_spaces"));
|
||||
|
||||
// Files
|
||||
boolean bSplit = getCheckBoxStateAsBoolean("Split");
|
||||
setControlEnabled("Split",!isLocked("split_level"));
|
||||
setControlEnabled("SplitLevelLabel",!isLocked("split_level") && bSplit);
|
||||
setControlEnabled("SplitLevel",!isLocked("split_level") && bSplit);
|
||||
setControlEnabled("RepeatLevelsLabel",!isLocked("repeat_levels") && !isLocked("split_level") && bSplit);
|
||||
setControlEnabled("RepeatLevels",!isLocked("repeat_levels") && !isLocked("split_level") && bSplit);
|
||||
setControlEnabled("SaveImagesInSubdir",!isLocked("save_images_in_subdir"));
|
||||
setControlEnabled("UseMathjax",(this instanceof XhtmlOptionsDialogMath) && !isLocked("use_mathjax"));
|
||||
}
|
||||
|
||||
private void enableSplitLevel() {
|
||||
if (!isLocked("split_level")) {
|
||||
boolean bState = getCheckBoxStateAsBoolean("Split");
|
||||
setControlEnabled("SplitLevelLabel",bState);
|
||||
setControlEnabled("SplitLevel",bState);
|
||||
if (!isLocked("repeat_levels")) {
|
||||
setControlEnabled("RepeatLevelsLabel",bState);
|
||||
setControlEnabled("RepeatLevels",bState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* XhtmlOptionsDialogMath.java
|
||||
*
|
||||
* Copyright: 2002-2004 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.4 (2014-08-18)
|
||||
*
|
||||
*/
|
||||
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
/** This class provides a uno component which implements a filter ui for the
|
||||
* Xhtml export for the XHTML+MathML and HTML export.
|
||||
* This variant of the dialog has the MathJax setting enabled
|
||||
*/
|
||||
public class XhtmlOptionsDialogMath extends XhtmlOptionsDialog {
|
||||
/** The component will be registered under this name.
|
||||
*/
|
||||
public static String __serviceName = "org.openoffice.da.writer2xhtml.XhtmlOptionsDialogMath";
|
||||
|
||||
/** The component should also have an implementation name.
|
||||
*/
|
||||
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.XhtmlOptionsDialogMath";
|
||||
|
||||
/** Create a new XhtmlOptionsDialogMath */
|
||||
public XhtmlOptionsDialogMath(XComponentContext xContext) {
|
||||
super(xContext);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* XhtmlUNOPublisher.java
|
||||
*
|
||||
* Copyright: 2002-2015 by Henrik Just
|
||||
*
|
||||
* This file is part of Writer2LaTeX.
|
||||
*
|
||||
* Writer2LaTeX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Writer2LaTeX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Version 1.6 (2015-04-05)
|
||||
*
|
||||
*/
|
||||
package org.openoffice.da.comp.writer2xhtml;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.openoffice.da.comp.w2lcommon.filter.UNOPublisher;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.MessageBox;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.RegistryHelper;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.StreamGobbler;
|
||||
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
|
||||
|
||||
import com.sun.star.beans.XPropertySet;
|
||||
import com.sun.star.frame.XFrame;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import w2phtml.util.Misc;
|
||||
|
||||
public class XhtmlUNOPublisher extends UNOPublisher {
|
||||
|
||||
public XhtmlUNOPublisher(XComponentContext xContext, XFrame xFrame, String sAppName) {
|
||||
super(xContext, xFrame, sAppName);
|
||||
}
|
||||
|
||||
|
||||
/** Display the converted document depending on user settings
|
||||
*
|
||||
* @param sURL the URL of the converted document
|
||||
* @param format the target format
|
||||
*/
|
||||
@Override protected void postProcess(String sURL, TargetFormat format) {
|
||||
RegistryHelper registry = new RegistryHelper(xContext);
|
||||
|
||||
short nView = 1;
|
||||
String sExecutable = null;
|
||||
|
||||
try {
|
||||
Object view = registry.getRegistryView(ToolbarSettingsDialog.REGISTRY_PATH, false);
|
||||
XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,view);
|
||||
|
||||
if (format==TargetFormat.xhtml || format==TargetFormat.xhtml11 || format==TargetFormat.xhtml_mathml || format==TargetFormat.html5) {
|
||||
nView = XPropertySetHelper.getPropertyValueAsShort(xProps, "XhtmlView");
|
||||
sExecutable = XPropertySetHelper.getPropertyValueAsString(xProps, "XhtmlExecutable");
|
||||
}
|
||||
else { // EPUB
|
||||
nView = XPropertySetHelper.getPropertyValueAsShort(xProps, "EpubView");
|
||||
sExecutable = XPropertySetHelper.getPropertyValueAsString(xProps, "EpubExecutable");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Failed to get registry view
|
||||
}
|
||||
|
||||
File file = Misc.urlToFile(sURL);
|
||||
if (file.exists()) {
|
||||
if (nView==0) {
|
||||
return;
|
||||
}
|
||||
else if (nView==1) {
|
||||
if (openWithDefaultApplication(file)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (nView==2) {
|
||||
if (openWithCustomApplication(file, sExecutable)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
MessageBox msgBox = new MessageBox(xContext, xFrame);
|
||||
msgBox.showMessage("w2phtml","Error: Failed to open exported document");
|
||||
}
|
||||
|
||||
// Open the file in the default application on this system (if any)
|
||||
private boolean openWithDefaultApplication(File file) {
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
try {
|
||||
desktop.open(file);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open the file with the user defined application
|
||||
private boolean openWithCustomApplication(File file, String sExecutable) {
|
||||
try {
|
||||
Vector<String> command = new Vector<String>();
|
||||
command.add(sExecutable);
|
||||
command.add(file.getPath());
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(command);
|
||||
Process proc = pb.start();
|
||||
|
||||
// Gobble the error stream of the application
|
||||
StreamGobbler errorGobbler = new
|
||||
StreamGobbler(proc.getErrorStream(), "ERROR");
|
||||
|
||||
// Gobble the output stream of the application
|
||||
StreamGobbler outputGobbler = new
|
||||
StreamGobbler(proc.getInputStream(), "OUTPUT");
|
||||
|
||||
errorGobbler.start();
|
||||
outputGobbler.start();
|
||||
|
||||
// The application exists if the process exits with 0
|
||||
return proc.waitFor()==0;
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
135
src/main/java/pro/litvinovg/w2phtml/gui/ControlPanel.java
Normal file
135
src/main/java/pro/litvinovg/w2phtml/gui/ControlPanel.java
Normal file
|
@ -0,0 +1,135 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import static pro.litvinovg.w2phtml.gui.Contstants.*;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
|
||||
public class ControlPanel extends JPanel {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ControlPanel.class);
|
||||
private PreferencesStorage storage;
|
||||
private String configName;
|
||||
private String configType;
|
||||
private PanelFactory factory = null;
|
||||
public void setFactory(PanelFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
public ControlPanel(HashMap<String,Component> configuration, PreferencesStorage storage, String configName, String configType) {
|
||||
this.storage = storage;
|
||||
this.configName = configName;
|
||||
this.configType = configType;
|
||||
|
||||
JButton btn_Exit = new JButton(Localizer.get(BUTTON_EXIT_LABEL));
|
||||
btn_Exit.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ConfigurationWindow.getSingleFrame().setVisible(false);
|
||||
ConfigurationWindow.getSingleFrame().dispose();
|
||||
}
|
||||
});
|
||||
|
||||
JButton btn_SaveAs = new JButton(Localizer.get(BUTTON_SAVEAS_LABEL));
|
||||
btn_SaveAs.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
String newConfigName = JOptionPane.showInputDialog(Localizer.get(ENTER_NEW_CONFIG_NAME));
|
||||
if (newConfigName == null || newConfigName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (storage.has(newConfigName)) {
|
||||
JOptionPane.showMessageDialog(ConfigurationWindow.getSingleFrame(), Localizer.get(CONFIG_NAME_IS_ALREADY_IN_USE));
|
||||
return;
|
||||
}
|
||||
UIPreferences newPrefs = storage.get(configName).clone();
|
||||
newPrefs.updateFrom(configuration);
|
||||
storage.put(newConfigName, newPrefs);
|
||||
if (factory != null) {
|
||||
factory.createPanel(newConfigName);
|
||||
}
|
||||
storage.save();
|
||||
}
|
||||
});
|
||||
|
||||
JButton btn_Save = new JButton(Localizer.get(BUTTON_SAVE_LABEL));
|
||||
btn_Save.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
storage.get(configName).updateFrom(configuration);
|
||||
storage.save();
|
||||
JOptionPane.showMessageDialog(ConfigurationWindow.getSingleFrame(), Localizer.get(SUCCESSFULLY_SAVED));
|
||||
}
|
||||
});
|
||||
|
||||
JButton btn_delete = new JButton(Localizer.get(BUTTON_DELETE_LABEL));
|
||||
btn_delete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
storage.remove(configName);
|
||||
factory.removeCurPanel();
|
||||
storage.save();
|
||||
}
|
||||
});
|
||||
|
||||
if (configName == HTML || configName == RDF || configName == EPUB) {
|
||||
btn_Save.setVisible(false);
|
||||
btn_delete.setVisible(false);
|
||||
|
||||
}
|
||||
JButton btn_startConversion = new JButton(Localizer.get(BUTTON_CONVERT_LABEL));
|
||||
btn_startConversion.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
ConversionExecutor executor = new ConversionExecutor(configuration, ConfigurationWindow.getSingleFrame());
|
||||
executor.convert();
|
||||
} catch(Throwable e) {
|
||||
StringWriter errors = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(errors));
|
||||
JOptionPane.showMessageDialog(ConfigurationWindow.getSingleFrame(),errors.toString());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
GroupLayout gl_panel_control = new GroupLayout(this);
|
||||
gl_panel_control.setHorizontalGroup(
|
||||
gl_panel_control.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(gl_panel_control.createSequentialGroup()
|
||||
.addGap(83)
|
||||
.addComponent(btn_Exit, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18)
|
||||
.addComponent(btn_SaveAs, GroupLayout.PREFERRED_SIZE, 140, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18)
|
||||
.addComponent(btn_Save, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.UNRELATED)
|
||||
.addComponent(btn_delete, GroupLayout.PREFERRED_SIZE, 120, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(btn_startConversion, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(86, Short.MAX_VALUE))
|
||||
);
|
||||
gl_panel_control.setVerticalGroup(
|
||||
gl_panel_control.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(gl_panel_control.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(gl_panel_control.createParallelGroup(Alignment.TRAILING, false)
|
||||
.addComponent(btn_startConversion, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btn_delete, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btn_SaveAs, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btn_Save, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(btn_Exit, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap(54, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
this.setLayout(gl_panel_control);
|
||||
}
|
||||
}
|
99
src/main/java/pro/litvinovg/w2phtml/gui/Contstants.java
Normal file
99
src/main/java/pro/litvinovg/w2phtml/gui/Contstants.java
Normal file
|
@ -0,0 +1,99 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
public class Contstants {
|
||||
public static final String LABEL_HTML5 = "label_html5";
|
||||
public static final String BUTTON_CONVERT_LABEL = "button_convert_label";
|
||||
public static final String MESSAGE_NOT_IMPLEMENTED = "message_not_implemented";
|
||||
public static final String CONFIG_NAME_IS_ALREADY_IN_USE = "config_name_is_already_in_use";
|
||||
public static final String BUTTON_EXIT_LABEL = "button_exit_label";
|
||||
public static final String BUTTON_SAVE_LABEL = "button_save_label";
|
||||
public static final String BUTTON_DELETE_LABEL = "button_delete_label";
|
||||
public static final String ENTER_NEW_CONFIG_NAME = "enter_new_config_name";
|
||||
public static final String BUTTON_SAVEAS_LABEL = "button_saveas_label";
|
||||
public static final String ARG_PAGINATION = "pagination";
|
||||
public static final String ARG_IMAGE_RESOLUTION = "image_resolution";
|
||||
public static final String ARG_CSV_METADATA = "csv_metadata";
|
||||
public static final String ARG_RDF_TYPE = "rdf_type";
|
||||
public static final String CSV_FILE_EXTENSION = "csv";
|
||||
public static final String RDF_FILE_EXTENSION = "rdf";
|
||||
public static final String CANT_WRITE_MESSAGE = "error_cant_write";
|
||||
public static final String DEFAULT_CONFIG_CANT_BE_CHANGED = "default_config_cant_be_saved";
|
||||
public static final String SUCCESSFULLY_SAVED = "successfully_saved_config";
|
||||
public static final String HTML_FILE_EXTENSION = "html";
|
||||
public static final String ARG_MAX_WIDTH = "max_width";
|
||||
public static final String LABEL_SPLIT_BY_HEADING = "label_split_by_heading";
|
||||
public static final String DEFAULT_PAGEBREAK_STYLE_SETTINGS = "height:3em;margin-top:1em;margin-bottom:1em;background-color:#f6f6f6;";
|
||||
public static final String EPUB_FILE_EXTENSION = "epub";
|
||||
public static final String ODT_FILE_EXTENSION = "odt";
|
||||
public static final String CONVERTER_TITLE_LABEL = "converter_title_label";
|
||||
public static final String LABEL_TYPE = "label_type";
|
||||
public static final String LABEL_METADATA_PATH = "label_metadata_path";
|
||||
public static final String LABEL_FILETER_HARD_LINE_BREAKS = "label_fileter_hard_line_breaks";
|
||||
public static final String LABEL_USE_MATHJAX = "label_use_mathjax";
|
||||
public static final String LABEL_SPLIT_WHOLE_PAGES_ONLY = "label_split_whole_pages_only";
|
||||
public static final String ARG_IGNORE_HARD_LINE_BREAKS = "ignore_hard_line_breaks";
|
||||
public static final String ARG_IGNORE_EMPTY_PARAGRAPHS = "ignore_empty_paragraphs";
|
||||
public static final String ARG_GREENSTONE = "greenstone";
|
||||
public static final String ARG_SPLIT_LEVEL = "split_level";
|
||||
public static final String ARG_ALIGN_SPLITS_TO_PAGES = "align_splits_to_pages";
|
||||
public static final String ARG_USE_MATHJAX = "use_mathjax";
|
||||
public static final String ARG_OUTPUT_FILE = "outputFile";
|
||||
public static final String ARG_TARGET_FORMAT = "targetFormat";
|
||||
public static final String ARG_INPUT_FILE = "inputFile";
|
||||
public static final String ARG_CONVERT_TO_PX = "convert_to_px";
|
||||
public static final String SCALING_DEFAULT_VALUE = "100%";
|
||||
public static final String ARG_SCALING = "scaling";
|
||||
public static final String ARG_EMBED_IMG = "embed_img";
|
||||
public static final String ARG_EMBED_SVG = "embed_svg";
|
||||
public static final String ARG_CSS_INLINE = "css_inline";
|
||||
public static final String ARG_MIN_LETTER_SPACING = "min_letter_spacing";
|
||||
public static final String LABEL_PAGINATION = "label_pagination";
|
||||
public static final String LABEL_IMAGE_RESOLUTION = "label_image_resolution";
|
||||
public static final String ARG_PAGE_BREAK_STYLE = "page_break_style";
|
||||
public static final String LABEL_BREAK_STYLE = "label_break_style";
|
||||
public static final String LABEL_GREENSTONE_SPLIT = "label_greenstone_split";
|
||||
public static final String LABEL_INGNORE_EMPTY_PARS = "label_ingnore_empty_pars";
|
||||
public static final String LABEL_MIN_LETTER_SPACING = "label_min_letter_spacing";
|
||||
public static final String LABEL_MAX_BODY_WIDTH = "label_max_body_width";
|
||||
public static final String OUTPUT_FILE_PATH = "label_output_file_path";
|
||||
public static final String LABEL_BUTTON_CHOOSE = "label_button_choose";
|
||||
public static final String LABEL_TARGET_FORMAT = "label_target_format";
|
||||
public static final String LABEL_INPUT_FILE_PATH = "label_input_file_path";
|
||||
public static final String LABEL_CONVERT_TO_PX = "label_convert_to_px";
|
||||
public static final String LABEL_SCALE = "label_scale";
|
||||
public static final String LABEL_EMBED_RASTER = "label_embed_raster";
|
||||
public static final String LABEL_EMBED_VECTOR = "label_embed_vector";
|
||||
public static final String LABEL_INLINE_STYLES = "label_inline_styles";
|
||||
public static final String EPUB3_TARGET_FORMAT = "epub3";
|
||||
public static final String HTML5_TARGET_FORMAT = "html5";
|
||||
public static final String RDF_TARGET_FORMAT = "rdf";
|
||||
|
||||
|
||||
public static final String HTML = "HTML";
|
||||
public static final String EPUB = "EPUB";
|
||||
public static final String RDF = "RDF";
|
||||
public static final String PREF_RESOLUTIONS = "resolutions";
|
||||
public static final String PREF_PUBLICATION_TYPES = "publication_types";
|
||||
public static final String PREF_DEFAULT_PUBLICATION_TYPE = ARG_RDF_TYPE;
|
||||
public static final String PREF_DEFAULT_IMAGE_RESOLUTION = ARG_IMAGE_RESOLUTION;
|
||||
public static final String PREF_USE_MATHJAX = ARG_USE_MATHJAX;
|
||||
public static final String PREF_IGNORE_EMPTY_PARS = ARG_IGNORE_EMPTY_PARAGRAPHS;
|
||||
public static final String PREF_IGNORE_HARD_BREAKS = ARG_IGNORE_HARD_LINE_BREAKS;
|
||||
public static final String PREF_SPLIT_BY_LEVEL = ARG_SPLIT_LEVEL;
|
||||
public static final String PREF_GREENSTONE_TAGS = ARG_GREENSTONE;
|
||||
public static final String PREF_SPLIT_WHOLE_PAGES = ARG_ALIGN_SPLITS_TO_PAGES;
|
||||
public static final String PREF_LETTER_SPACING = ARG_MIN_LETTER_SPACING;
|
||||
public static final String PREF_INLINE_STYLES = ARG_CSS_INLINE;
|
||||
public static final String PREF_EMBED_RASTER = ARG_EMBED_IMG;
|
||||
public static final String PREF_EMBED_VECTOR = ARG_EMBED_SVG;
|
||||
public static final String PREF_SCALING = ARG_SCALING;
|
||||
public static final String PREF_MAX_WIDTH = ARG_MAX_WIDTH;
|
||||
public static final String PREF_PAGEBREAK_STYLES = ARG_PAGE_BREAK_STYLE;
|
||||
public static final String PREF_CONVERT_TO_PX = ARG_CONVERT_TO_PX;
|
||||
public static final String PREF_PAGINATION = ARG_PAGINATION;
|
||||
public static final String PREF_TYPE = "preferences_type";
|
||||
public static final String PREF_SPLIT_LEVELS = "split_levels";
|
||||
public static final String TAB_PREFERENCES = "tab_preferences";
|
||||
|
||||
|
||||
}
|
|
@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory;
|
|||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
import w2phtml.Application;
|
||||
import w2phtml.rdf.Metadata;
|
||||
import w2phtml.rdf.MetadataContainer;
|
||||
|
||||
public class ConversionExecutor {
|
||||
|
||||
|
@ -200,6 +200,7 @@ public class ConversionExecutor {
|
|||
} catch (Exception e ) {
|
||||
logger.error("Conversion failed.");
|
||||
logger.error("Params: " + Arrays.toString(prepareArgs()));
|
||||
logger.error(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
431
src/main/java/pro/litvinovg/w2phtml/gui/EpubPanel.java
Normal file
431
src/main/java/pro/litvinovg/w2phtml/gui/EpubPanel.java
Normal file
|
@ -0,0 +1,431 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
import static pro.litvinovg.w2phtml.gui.Contstants.*;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
public class EpubPanel extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private UIPreferences preferences;
|
||||
private HashMap<String, Component> configuration;
|
||||
private JTextField tf_pageBreakInlineStyle_1;
|
||||
private JComboBox cbox_image_resolution_1;
|
||||
private JCheckBox cb_Pagination_1;
|
||||
private JTextField tf_Scale_1;
|
||||
private JTextField tf_FilterLetterSpacing_1;
|
||||
private JCheckBox cb_convertToPx_1;
|
||||
private JCheckBox cb_IgnoreHardLineBreaks_1;
|
||||
private JCheckBox cb_IgnoreEmptyParagraphs_1;
|
||||
private JCheckBox cb_UseMathJax_1;
|
||||
private JCheckBox cb_EmbedVectorImages_1;
|
||||
private JCheckBox cb_InlineStyles_1;
|
||||
private JCheckBox cb_EmbedRaster_1;
|
||||
private JTextField tf_OutputFile_1;
|
||||
private JButton btn_ChooseOutputFile_1;
|
||||
private JLabel lb_TargetFormat_1;
|
||||
private JTextField tf_inputFile_1;
|
||||
private JButton btn_chooseFile_1;
|
||||
|
||||
public EpubPanel() {
|
||||
this.preferences = PreferencesStorage.getDefaultEpub(null);
|
||||
this.configuration = new HashMap<String, Component>();
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public EpubPanel(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
this.configuration = configuration;
|
||||
this.preferences = preferences;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
JLabel lb_FilterLetterSpacing = new JLabel(Localizer.get(LABEL_MIN_LETTER_SPACING));
|
||||
JLabel lb_TargetFormat_description = new JLabel(Localizer.get(LABEL_TARGET_FORMAT));
|
||||
JLabel lb_Scale = new JLabel(Localizer.get(LABEL_SCALE));
|
||||
JLabel lb_FilePath = new JLabel(Localizer.get(LABEL_INPUT_FILE_PATH));
|
||||
JLabel lb_TargetFormat = addTargetFormat(EPUB3_TARGET_FORMAT, configuration);
|
||||
JLabel lb_ImageResolution = new JLabel(Localizer.get(LABEL_IMAGE_RESOLUTION));
|
||||
JLabel lb_OutFilePath = new JLabel(Localizer.get(OUTPUT_FILE_PATH));
|
||||
JLabel lb_pageBreakInlineStyle = new JLabel(Localizer.get(LABEL_BREAK_STYLE));
|
||||
|
||||
JTextField tf_FilterLetterSpacing = addLetterSpacingFilter(configuration,preferences);
|
||||
JTextField tf_OutputFile = addOutputFileTextField(configuration,preferences);
|
||||
JTextField tf_inputFile = addInputFile(configuration,preferences);
|
||||
JTextField tf_Scale = addScaling(configuration,preferences);
|
||||
JTextField tf_pageBreakInlineStyle = addPageBreakStyle(configuration,preferences);
|
||||
|
||||
JCheckBox cb_UseMathJax = addMathJaxCB(configuration,preferences);
|
||||
JCheckBox cb_IgnoreEmptyParagraphs = addIgnoreEmptyParsCB(configuration,preferences);
|
||||
JCheckBox cb_IgnoreHardLineBreaks = addIgnoreHardLineBreaks(configuration,preferences);
|
||||
JCheckBox cb_InlineStyles = addInlineStyles(configuration,preferences);
|
||||
JCheckBox cb_EmbedVectorImages = addEmbedVectorImages(configuration,preferences);
|
||||
JCheckBox cb_EmbedRaster = addEmbedRasterImages(configuration,preferences);
|
||||
JCheckBox cb_convertToPx = addConvertToPX(configuration,preferences);
|
||||
JCheckBox cb_Pagination = addPagination(configuration,preferences);
|
||||
|
||||
JComboBox cbox_image_resolution = addImageResolution(configuration,preferences);
|
||||
|
||||
JButton btn_ChooseOutputFile = addChooseOutputButton(tf_OutputFile, EPUB_FILE_EXTENSION);
|
||||
JButton btn_chooseFile = addButtonChooseFile(tf_OutputFile, tf_inputFile);
|
||||
GroupLayout groupLayout = new GroupLayout(this);
|
||||
groupLayout.setHorizontalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_OutFilePath, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(19)
|
||||
.addComponent(tf_OutputFile_1, GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
|
||||
.addGap(12)
|
||||
.addComponent(btn_ChooseOutputFile_1, GroupLayout.PREFERRED_SIZE, 107, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_pageBreakInlineStyle, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(19)
|
||||
.addComponent(tf_pageBreakInlineStyle_1, GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE))
|
||||
.addComponent(cb_InlineStyles_1, GroupLayout.PREFERRED_SIZE, 492, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_EmbedVectorImages_1, GroupLayout.PREFERRED_SIZE, 362, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_EmbedRaster_1, GroupLayout.PREFERRED_SIZE, 492, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_convertToPx_1)
|
||||
.addComponent(cb_IgnoreHardLineBreaks_1, GroupLayout.PREFERRED_SIZE, 492, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_IgnoreEmptyParagraphs_1, GroupLayout.PREFERRED_SIZE, 492, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_UseMathJax_1, GroupLayout.PREFERRED_SIZE, 492, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_Pagination_1, GroupLayout.PREFERRED_SIZE, 362, GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_ImageResolution, GroupLayout.PREFERRED_SIZE, 249, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(cbox_image_resolution_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(tf_Scale_1, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 218, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(tf_FilterLetterSpacing_1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
|
||||
.addComponent(lb_TargetFormat_description, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
|
||||
.addGap(1)
|
||||
.addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(ComponentPlacement.UNRELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(tf_inputFile_1, GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
|
||||
.addGap(12)
|
||||
.addComponent(btn_chooseFile_1, GroupLayout.PREFERRED_SIZE, 107, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(lb_TargetFormat_1))))
|
||||
.addGap(6))
|
||||
);
|
||||
groupLayout.setVerticalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lb_TargetFormat_description)
|
||||
.addComponent(lb_TargetFormat_1))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(tf_inputFile_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(lb_FilePath)))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(3)
|
||||
.addComponent(btn_chooseFile_1)))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(lb_OutFilePath))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(3)
|
||||
.addComponent(tf_OutputFile_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(btn_ChooseOutputFile_1))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(lb_pageBreakInlineStyle)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(1)
|
||||
.addComponent(tf_pageBreakInlineStyle_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
|
||||
.addGap(8)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lb_Scale)
|
||||
.addComponent(tf_Scale_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(8)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lb_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(tf_FilterLetterSpacing_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(6)
|
||||
.addComponent(cb_InlineStyles_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_EmbedVectorImages_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_EmbedRaster_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_convertToPx_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_IgnoreHardLineBreaks_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_IgnoreEmptyParagraphs_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_UseMathJax_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_Pagination_1)
|
||||
.addGap(11)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lb_ImageResolution)
|
||||
.addComponent(cbox_image_resolution_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(4))
|
||||
);
|
||||
setLayout(groupLayout);
|
||||
}
|
||||
|
||||
|
||||
//Shared methods added here to make WindowBuilder work
|
||||
|
||||
JCheckBox addMathJaxCB(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_UseMathJax_1 = new JCheckBox(Localizer.get(LABEL_USE_MATHJAX));
|
||||
cb_UseMathJax_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_USE_MATHJAX)));
|
||||
configuration.put(ARG_USE_MATHJAX, cb_UseMathJax_1);
|
||||
return cb_UseMathJax_1;
|
||||
}
|
||||
|
||||
JCheckBox addIgnoreEmptyParsCB(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_IgnoreEmptyParagraphs_1 = new JCheckBox(Localizer.get(LABEL_INGNORE_EMPTY_PARS));
|
||||
cb_IgnoreEmptyParagraphs_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_IGNORE_EMPTY_PARS)));
|
||||
configuration.put(ARG_IGNORE_EMPTY_PARAGRAPHS, cb_IgnoreEmptyParagraphs_1);
|
||||
return cb_IgnoreEmptyParagraphs_1;
|
||||
}
|
||||
|
||||
JCheckBox addSplitWholePagesOnly(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JCheckBox cb_SplitWholePagesOnly = new JCheckBox(Localizer.get(LABEL_SPLIT_WHOLE_PAGES_ONLY));
|
||||
cb_SplitWholePagesOnly.setSelected(Boolean.parseBoolean(preferences.get(PREF_SPLIT_WHOLE_PAGES)));
|
||||
configuration.put(ARG_ALIGN_SPLITS_TO_PAGES, cb_SplitWholePagesOnly);
|
||||
return cb_SplitWholePagesOnly;
|
||||
}
|
||||
|
||||
JCheckBox addIgnoreHardLineBreaks(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_IgnoreHardLineBreaks_1 = new JCheckBox(Localizer.get(LABEL_FILETER_HARD_LINE_BREAKS));
|
||||
cb_IgnoreHardLineBreaks_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_IGNORE_HARD_BREAKS)));
|
||||
configuration.put(ARG_IGNORE_HARD_LINE_BREAKS, cb_IgnoreHardLineBreaks_1);
|
||||
return cb_IgnoreHardLineBreaks_1;
|
||||
}
|
||||
|
||||
JTextField addLetterSpacingFilter(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_FilterLetterSpacing_1 = new JTextField();
|
||||
tf_FilterLetterSpacing_1.setText(preferences.get(PREF_LETTER_SPACING));
|
||||
configuration.put(ARG_MIN_LETTER_SPACING, tf_FilterLetterSpacing_1);
|
||||
tf_FilterLetterSpacing_1.setColumns(10);
|
||||
return tf_FilterLetterSpacing_1;
|
||||
}
|
||||
|
||||
|
||||
JCheckBox addInlineStyles(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_InlineStyles_1 = new JCheckBox(Localizer.get(LABEL_INLINE_STYLES));
|
||||
cb_InlineStyles_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_INLINE_STYLES)));
|
||||
configuration.put(ARG_CSS_INLINE, cb_InlineStyles_1);
|
||||
return cb_InlineStyles_1;
|
||||
}
|
||||
|
||||
JCheckBox addGreenstoneTags(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JCheckBox cb_Greenstone = new JCheckBox(Localizer.get(LABEL_GREENSTONE_SPLIT));
|
||||
configuration.put(ARG_GREENSTONE, cb_Greenstone);
|
||||
cb_Greenstone.setSelected(Boolean.parseBoolean(preferences.get(PREF_GREENSTONE_TAGS)));
|
||||
return cb_Greenstone;
|
||||
}
|
||||
|
||||
JTextField addOutputFileTextField(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_OutputFile_1 = new JTextField("");
|
||||
configuration.put(ARG_OUTPUT_FILE, tf_OutputFile_1);
|
||||
tf_OutputFile_1.setColumns(10);
|
||||
return tf_OutputFile_1;
|
||||
}
|
||||
|
||||
JCheckBox addPagination(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_Pagination_1 = new JCheckBox(Localizer.get(LABEL_PAGINATION));
|
||||
cb_Pagination_1.setSelected(Boolean.valueOf(preferences.get(PREF_PAGINATION)));
|
||||
configuration.put(ARG_PAGINATION, cb_Pagination_1);
|
||||
return cb_Pagination_1;
|
||||
}
|
||||
|
||||
JCheckBox addConvertToPX(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_convertToPx_1 = new JCheckBox(Localizer.get(LABEL_CONVERT_TO_PX));
|
||||
cb_convertToPx_1.setSelected(Boolean.valueOf(preferences.get(PREF_CONVERT_TO_PX)));
|
||||
configuration.put(ARG_CONVERT_TO_PX, cb_convertToPx_1);
|
||||
return cb_convertToPx_1;
|
||||
}
|
||||
|
||||
JTextField addPageBreakStyle(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_pageBreakInlineStyle_1 = new JTextField(preferences.get(PREF_PAGEBREAK_STYLES));
|
||||
tf_pageBreakInlineStyle_1.setColumns(10);
|
||||
configuration.put(ARG_PAGE_BREAK_STYLE, tf_pageBreakInlineStyle_1);
|
||||
return tf_pageBreakInlineStyle_1;
|
||||
}
|
||||
|
||||
JLabel addTargetFormat(String format, HashMap<String, Component> configuration) {
|
||||
lb_TargetFormat_1 = new JLabel(format);
|
||||
configuration.put(ARG_TARGET_FORMAT, lb_TargetFormat_1);
|
||||
return lb_TargetFormat_1;
|
||||
}
|
||||
|
||||
JTextField addScaling(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_Scale_1 = new JTextField();
|
||||
tf_Scale_1.setText(preferences.get(PREF_SCALING));
|
||||
tf_Scale_1.setColumns(10);
|
||||
configuration.put(ARG_SCALING, tf_Scale_1);
|
||||
return tf_Scale_1;
|
||||
}
|
||||
|
||||
JTextField addInputFile(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_inputFile_1 = new JTextField(preferences.getSourceFileName());
|
||||
tf_inputFile_1.setColumns(10);
|
||||
configuration.put(ARG_INPUT_FILE, tf_inputFile_1);
|
||||
return tf_inputFile_1;
|
||||
}
|
||||
|
||||
JComboBox addImageResolution(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cbox_image_resolution_1 = new JComboBox(preferences.getAll(PREF_RESOLUTIONS));
|
||||
cbox_image_resolution_1.setSelectedIndex(Integer.parseInt(preferences.get(PREF_DEFAULT_IMAGE_RESOLUTION)));
|
||||
configuration.put(ARG_IMAGE_RESOLUTION, cbox_image_resolution_1);
|
||||
return cbox_image_resolution_1;
|
||||
}
|
||||
|
||||
JComboBox addSplitByLevel(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JComboBox cbox_SplitByLevel = new JComboBox(preferences.getAll(PREF_SPLIT_LEVELS));
|
||||
configuration.put(ARG_SPLIT_LEVEL, cbox_SplitByLevel);
|
||||
cbox_SplitByLevel.setSelectedIndex(Integer.parseInt(preferences.get(PREF_SPLIT_BY_LEVEL)));
|
||||
return cbox_SplitByLevel;
|
||||
}
|
||||
|
||||
JTextField addMaxWidth(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JTextField tf_MaxWidth = new JTextField(preferences.get(PREF_MAX_WIDTH));
|
||||
tf_MaxWidth.setColumns(10);
|
||||
configuration.put(ARG_MAX_WIDTH, tf_MaxWidth);
|
||||
return tf_MaxWidth;
|
||||
}
|
||||
|
||||
JCheckBox addEmbedRasterImages(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_EmbedRaster_1 = new JCheckBox(Localizer.get(LABEL_EMBED_RASTER));
|
||||
cb_EmbedRaster_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_EMBED_RASTER)));
|
||||
configuration.put(ARG_EMBED_IMG, cb_EmbedRaster_1);
|
||||
return cb_EmbedRaster_1;
|
||||
}
|
||||
|
||||
JCheckBox addEmbedVectorImages(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_EmbedVectorImages_1 = new JCheckBox(Localizer.get(LABEL_EMBED_VECTOR));
|
||||
cb_EmbedVectorImages_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_EMBED_VECTOR)));
|
||||
configuration.put(ARG_EMBED_SVG, cb_EmbedVectorImages_1);
|
||||
return cb_EmbedVectorImages_1;
|
||||
}
|
||||
|
||||
void setOutputFilePath(String newFilePath, JTextField tf_OutputFile, String extension) {
|
||||
|
||||
File inputFile = new File(newFilePath);
|
||||
if (!inputFile.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!inputFile.isDirectory()) {
|
||||
File parent = inputFile.getParentFile();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (!parent.canWrite()) {
|
||||
JOptionPane.showMessageDialog(ConfigurationWindow.getSingleFrame(), Localizer.get(CANT_WRITE_MESSAGE));
|
||||
}
|
||||
}
|
||||
if (newFilePath.length() < 3) {
|
||||
return;
|
||||
}
|
||||
String exportPath;
|
||||
if (inputFile.isDirectory()) {
|
||||
exportPath = newFilePath;
|
||||
tf_OutputFile.setText(exportPath);
|
||||
} else {
|
||||
String importExt = newFilePath.substring(newFilePath.length() - 3, newFilePath.length()).toLowerCase();
|
||||
if (importExt.equals(ODT_FILE_EXTENSION)) {
|
||||
exportPath = newFilePath.substring(0, newFilePath.length() - 3) + extension;
|
||||
tf_OutputFile.setText(exportPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JButton addChooseOutputButton(JTextField tf_OutputFile, String fileExtension) {
|
||||
btn_ChooseOutputFile_1 = new JButton(Localizer.get(LABEL_BUTTON_CHOOSE));
|
||||
btn_ChooseOutputFile_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FileDialog fileDialog = new FileDialog();
|
||||
String newFilePath = fileDialog.chooseFile(tf_OutputFile.getText(),fileExtension);
|
||||
if (newFilePath != null && !newFilePath.isEmpty()) {
|
||||
tf_OutputFile.setText(newFilePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
return btn_ChooseOutputFile_1;
|
||||
}
|
||||
|
||||
public void setMetadataFilePath(String newFilePath, JTextField tf_MetadataFile, String extension) {
|
||||
|
||||
File inputFile = new File(newFilePath);
|
||||
if (!inputFile.exists()) {
|
||||
return;
|
||||
}
|
||||
if (inputFile.isDirectory()) {
|
||||
tf_MetadataFile.setText(newFilePath);
|
||||
} else {
|
||||
File parent = inputFile.getParentFile();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (newFilePath.length() < 3) {
|
||||
return;
|
||||
}
|
||||
String importExt = newFilePath.substring(newFilePath.length()-3, newFilePath.length()).toLowerCase();
|
||||
if (importExt.equals(ODT_FILE_EXTENSION)) {
|
||||
String metadataPath = newFilePath.substring(0, newFilePath.length()-3) + extension;
|
||||
File metaFile = new File(metadataPath);
|
||||
if (metaFile.exists() && metaFile.canRead()){
|
||||
tf_MetadataFile.setText(metadataPath);
|
||||
} else {
|
||||
tf_MetadataFile.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JButton addButtonChooseFile(JTextField tf_OutputFile, JTextField tf_inputFile) {
|
||||
btn_chooseFile_1 = new JButton(Localizer.get(LABEL_BUTTON_CHOOSE));
|
||||
btn_chooseFile_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FileDialog fileDialog = new FileDialog();
|
||||
String newFilePath = fileDialog.chooseFile(tf_inputFile.getText(),ODT_FILE_EXTENSION);
|
||||
if (newFilePath != null && !newFilePath.isEmpty()) {
|
||||
tf_inputFile.setText(newFilePath);
|
||||
setOutputFilePath(newFilePath,tf_OutputFile,EPUB_FILE_EXTENSION);
|
||||
}
|
||||
}
|
||||
});
|
||||
return btn_chooseFile_1;
|
||||
}
|
||||
}
|
|
@ -37,7 +37,11 @@ public class FileDialog extends JFrame {
|
|||
int result = fileChooser.showOpenDialog(null);
|
||||
if (result == fileChooser.APPROVE_OPTION){
|
||||
selected = fileChooser.getSelectedFile();
|
||||
return selected.getAbsolutePath();
|
||||
if (selected.isDirectory()) {
|
||||
return selected.getAbsolutePath() + File.separator;
|
||||
} else {
|
||||
return selected.getAbsolutePath();
|
||||
}
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
470
src/main/java/pro/litvinovg/w2phtml/gui/HTMLPanel.java
Normal file
470
src/main/java/pro/litvinovg/w2phtml/gui/HTMLPanel.java
Normal file
|
@ -0,0 +1,470 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
import static pro.litvinovg.w2phtml.gui.Contstants.*;
|
||||
import javax.swing.SpringLayout;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
public class HTMLPanel extends JPanel{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private HashMap<String, Component> configuration = null;
|
||||
private UIPreferences preferences = null;
|
||||
private JComboBox cbox_SplitByLevel_1;
|
||||
private JCheckBox cb_Greenstone_1;
|
||||
private JCheckBox cb_IgnoreEmptyParagraphs_1;
|
||||
private JCheckBox cb_IgnoreHardLineBreaks_1;
|
||||
private JCheckBox cb_convertToPx_1;
|
||||
private JCheckBox cb_EmbedRaster_1;
|
||||
private JCheckBox cb_EmbedVectorImages_1;
|
||||
private JCheckBox cb_InlineStyles_1;
|
||||
private JTextField tf_FilterLetterSpacing_1;
|
||||
private JLabel lb_TargetFormat_1;
|
||||
private JTextField tf_OutputFile_1;
|
||||
private JTextField tf_inputFile_1;
|
||||
private JButton btn_ChooseOutputFile_1;
|
||||
private JButton btn_chooseFile_1;
|
||||
private JCheckBox cb_UseMathJax_1;
|
||||
private JCheckBox cb_SplitWholePagesOnly_1;
|
||||
private JTextField tf_Scale_1;
|
||||
private JTextField tf_pageBreakInlineStyle_1;
|
||||
private JTextField tf_MaxWidth_1;
|
||||
private JCheckBox cb_Pagination_1;
|
||||
private JComboBox cbox_image_resolution_1;
|
||||
|
||||
|
||||
public HTMLPanel() {
|
||||
this.preferences = PreferencesStorage.getDefaultHTML(null);
|
||||
this.configuration = new HashMap<String, Component>();
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public HTMLPanel(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
this.configuration = configuration;
|
||||
this.preferences = preferences;
|
||||
initComponents();
|
||||
}
|
||||
private void initComponents() {
|
||||
JLabel lb_SplitByLevel = new JLabel(Localizer.get(LABEL_SPLIT_BY_HEADING));
|
||||
JLabel lb_FilterLetterSpacing = new JLabel(Localizer.get(LABEL_MIN_LETTER_SPACING));
|
||||
JLabel lb_TargetFormat = addTargetFormat(HTML5_TARGET_FORMAT, configuration);
|
||||
JLabel lb_Scale = new JLabel(Localizer.get(LABEL_SCALE));
|
||||
JLabel lb_MaxWidth = new JLabel(Localizer.get(LABEL_MAX_BODY_WIDTH));
|
||||
JLabel lb_FilePath = new JLabel(Localizer.get(LABEL_INPUT_FILE_PATH));
|
||||
JLabel lb_TargetFormat_description = new JLabel(Localizer.get(LABEL_TARGET_FORMAT));
|
||||
JLabel lb_OutFilePath = new JLabel(Localizer.get(OUTPUT_FILE_PATH));
|
||||
JLabel lb_ImageResolution = new JLabel(Localizer.get(LABEL_IMAGE_RESOLUTION));
|
||||
JLabel lb_pageBreakInlineStyle = new JLabel(Localizer.get(LABEL_BREAK_STYLE));
|
||||
|
||||
JTextField tf_FilterLetterSpacing = addLetterSpacingFilter(configuration,preferences);
|
||||
JTextField tf_Scale = addScaling(configuration,preferences);
|
||||
JTextField tf_MaxWidth = addMaxWidth(configuration,preferences);
|
||||
JTextField tf_inputFile = addInputFile(configuration,preferences);
|
||||
JTextField tf_OutputFile = addOutputFileTextField(configuration,preferences);
|
||||
JTextField tf_pageBreakInlineStyle = addPageBreakStyle(configuration,preferences);
|
||||
|
||||
JCheckBox cb_UseMathJax = addMathJaxCB(configuration,preferences);
|
||||
JCheckBox cb_IgnoreEmptyParagraphs = addIgnoreEmptyParsCB(configuration,preferences);
|
||||
JCheckBox cb_IgnoreHardLineBreaks = addIgnoreHardLineBreaks(configuration,preferences);
|
||||
JCheckBox cb_SplitWholePagesOnly = addSplitWholePagesOnly(configuration,preferences);
|
||||
JCheckBox cb_Greenstone = addGreenstoneTags(configuration,preferences);
|
||||
JCheckBox cb_InlineStyles = addInlineStyles(configuration,preferences);
|
||||
JCheckBox cb_EmbedRaster = addEmbedRasterImages(configuration,preferences);
|
||||
JCheckBox cb_EmbedVectorImages = addEmbedVectorImages(configuration,preferences);
|
||||
JCheckBox cb_convertToPx = addConvertToPX(configuration,preferences);
|
||||
JCheckBox cb_Pagination = addPagination(configuration,preferences);
|
||||
|
||||
JComboBox cbox_image_resolution = addImageResolution(configuration,preferences);
|
||||
JComboBox cbox_SplitByLevel = addSplitByLevel(configuration,preferences);
|
||||
|
||||
JButton btn_chooseFile = addButtonChooseFile( tf_inputFile, tf_OutputFile);
|
||||
JButton btn_ChooseOutputFile = addChooseOutputButton(tf_OutputFile, HTML_FILE_EXTENSION);
|
||||
GroupLayout groupLayout = new GroupLayout(this);
|
||||
groupLayout.setHorizontalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_TargetFormat_description, GroupLayout.PREFERRED_SIZE, 218, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(12)
|
||||
.addComponent(lb_TargetFormat_1))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(37)
|
||||
.addComponent(tf_inputFile_1, GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
|
||||
.addGap(12)
|
||||
.addComponent(btn_chooseFile_1, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_OutFilePath, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(37)
|
||||
.addComponent(tf_OutputFile_1, GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
|
||||
.addGap(12)
|
||||
.addComponent(btn_ChooseOutputFile_1, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_pageBreakInlineStyle, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(37)
|
||||
.addComponent(tf_pageBreakInlineStyle_1, GroupLayout.DEFAULT_SIZE, 584, Short.MAX_VALUE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(37)
|
||||
.addComponent(tf_Scale_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_MaxWidth, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(37)
|
||||
.addComponent(tf_MaxWidth_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_FilterLetterSpacing, GroupLayout.PREFERRED_SIZE, 218, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(37)
|
||||
.addComponent(tf_FilterLetterSpacing_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(cb_InlineStyles_1)
|
||||
.addComponent(cb_EmbedVectorImages_1)
|
||||
.addComponent(cb_EmbedRaster_1)
|
||||
.addComponent(cb_convertToPx_1, GroupLayout.PREFERRED_SIZE, 698, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_IgnoreHardLineBreaks_1)
|
||||
.addComponent(cb_IgnoreEmptyParagraphs_1, GroupLayout.PREFERRED_SIZE, 698, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_Greenstone_1)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_SplitByLevel, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(12)
|
||||
.addComponent(cbox_SplitByLevel_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(cb_SplitWholePagesOnly_1)
|
||||
.addComponent(cb_UseMathJax_1)
|
||||
.addComponent(cb_Pagination_1)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_ImageResolution, GroupLayout.PREFERRED_SIZE, 249, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(6)
|
||||
.addComponent(cbox_image_resolution_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
|
||||
.addGap(6))
|
||||
);
|
||||
groupLayout.setVerticalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(lb_TargetFormat_description)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addComponent(lb_TargetFormat_1)))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(10)
|
||||
.addComponent(lb_FilePath))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addComponent(tf_inputFile_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(btn_chooseFile_1))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(lb_OutFilePath))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addComponent(tf_OutputFile_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(btn_ChooseOutputFile_1))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(2)
|
||||
.addComponent(lb_pageBreakInlineStyle))
|
||||
.addComponent(tf_pageBreakInlineStyle_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(2)
|
||||
.addComponent(lb_Scale))
|
||||
.addComponent(tf_Scale_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(2)
|
||||
.addComponent(lb_MaxWidth))
|
||||
.addComponent(tf_MaxWidth_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(2)
|
||||
.addComponent(lb_FilterLetterSpacing))
|
||||
.addComponent(tf_FilterLetterSpacing_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(6)
|
||||
.addComponent(cb_InlineStyles_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_EmbedVectorImages_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_EmbedRaster_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_convertToPx_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_IgnoreHardLineBreaks_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_IgnoreEmptyParagraphs_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_Greenstone_1)
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(lb_SplitByLevel))
|
||||
.addComponent(cbox_SplitByLevel_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(6)
|
||||
.addComponent(cb_SplitWholePagesOnly_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_UseMathJax_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_Pagination_1)
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(lb_ImageResolution))
|
||||
.addComponent(cbox_image_resolution_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
|
||||
);
|
||||
setLayout(groupLayout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Shared methods added here to make WindowBuilder work
|
||||
|
||||
JCheckBox addMathJaxCB(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_UseMathJax_1 = new JCheckBox(Localizer.get(LABEL_USE_MATHJAX));
|
||||
cb_UseMathJax_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_USE_MATHJAX)));
|
||||
configuration.put(ARG_USE_MATHJAX, cb_UseMathJax_1);
|
||||
return cb_UseMathJax_1;
|
||||
}
|
||||
|
||||
JCheckBox addIgnoreEmptyParsCB(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_IgnoreEmptyParagraphs_1 = new JCheckBox(Localizer.get(LABEL_INGNORE_EMPTY_PARS));
|
||||
cb_IgnoreEmptyParagraphs_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_IGNORE_EMPTY_PARS)));
|
||||
configuration.put(ARG_IGNORE_EMPTY_PARAGRAPHS, cb_IgnoreEmptyParagraphs_1);
|
||||
return cb_IgnoreEmptyParagraphs_1;
|
||||
}
|
||||
|
||||
JCheckBox addSplitWholePagesOnly(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_SplitWholePagesOnly_1 = new JCheckBox(Localizer.get(LABEL_SPLIT_WHOLE_PAGES_ONLY));
|
||||
cb_SplitWholePagesOnly_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_SPLIT_WHOLE_PAGES)));
|
||||
configuration.put(ARG_ALIGN_SPLITS_TO_PAGES, cb_SplitWholePagesOnly_1);
|
||||
return cb_SplitWholePagesOnly_1;
|
||||
}
|
||||
|
||||
JCheckBox addIgnoreHardLineBreaks(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_IgnoreHardLineBreaks_1 = new JCheckBox(Localizer.get(LABEL_FILETER_HARD_LINE_BREAKS));
|
||||
cb_IgnoreHardLineBreaks_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_IGNORE_HARD_BREAKS)));
|
||||
configuration.put(ARG_IGNORE_HARD_LINE_BREAKS, cb_IgnoreHardLineBreaks_1);
|
||||
return cb_IgnoreHardLineBreaks_1;
|
||||
}
|
||||
|
||||
JTextField addLetterSpacingFilter(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_FilterLetterSpacing_1 = new JTextField();
|
||||
tf_FilterLetterSpacing_1.setText(preferences.get(PREF_LETTER_SPACING));
|
||||
configuration.put(ARG_MIN_LETTER_SPACING, tf_FilterLetterSpacing_1);
|
||||
tf_FilterLetterSpacing_1.setColumns(10);
|
||||
return tf_FilterLetterSpacing_1;
|
||||
}
|
||||
|
||||
|
||||
JCheckBox addInlineStyles(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_InlineStyles_1 = new JCheckBox(Localizer.get(LABEL_INLINE_STYLES));
|
||||
cb_InlineStyles_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_INLINE_STYLES)));
|
||||
configuration.put(ARG_CSS_INLINE, cb_InlineStyles_1);
|
||||
return cb_InlineStyles_1;
|
||||
}
|
||||
|
||||
JCheckBox addGreenstoneTags(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_Greenstone_1 = new JCheckBox(Localizer.get(LABEL_GREENSTONE_SPLIT));
|
||||
configuration.put(ARG_GREENSTONE, cb_Greenstone_1);
|
||||
cb_Greenstone_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_GREENSTONE_TAGS)));
|
||||
return cb_Greenstone_1;
|
||||
}
|
||||
|
||||
JTextField addOutputFileTextField(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_OutputFile_1 = new JTextField("");
|
||||
configuration.put(ARG_OUTPUT_FILE, tf_OutputFile_1);
|
||||
tf_OutputFile_1.setColumns(10);
|
||||
return tf_OutputFile_1;
|
||||
}
|
||||
|
||||
JCheckBox addPagination(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_Pagination_1 = new JCheckBox(Localizer.get(LABEL_PAGINATION));
|
||||
cb_Pagination_1.setSelected(Boolean.valueOf(preferences.get(PREF_PAGINATION)));
|
||||
configuration.put(ARG_PAGINATION, cb_Pagination_1);
|
||||
return cb_Pagination_1;
|
||||
}
|
||||
|
||||
JCheckBox addConvertToPX(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_convertToPx_1 = new JCheckBox(Localizer.get(LABEL_CONVERT_TO_PX));
|
||||
cb_convertToPx_1.setSelected(Boolean.valueOf(preferences.get(PREF_CONVERT_TO_PX)));
|
||||
configuration.put(ARG_CONVERT_TO_PX, cb_convertToPx_1);
|
||||
return cb_convertToPx_1;
|
||||
}
|
||||
|
||||
JTextField addPageBreakStyle(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_pageBreakInlineStyle_1 = new JTextField(preferences.get(PREF_PAGEBREAK_STYLES));
|
||||
tf_pageBreakInlineStyle_1.setColumns(10);
|
||||
configuration.put(ARG_PAGE_BREAK_STYLE, tf_pageBreakInlineStyle_1);
|
||||
return tf_pageBreakInlineStyle_1;
|
||||
}
|
||||
|
||||
JLabel addTargetFormat(String format, HashMap<String, Component> configuration) {
|
||||
lb_TargetFormat_1 = new JLabel(format);
|
||||
configuration.put(ARG_TARGET_FORMAT, lb_TargetFormat_1);
|
||||
return lb_TargetFormat_1;
|
||||
}
|
||||
|
||||
JTextField addScaling(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_Scale_1 = new JTextField();
|
||||
tf_Scale_1.setText(preferences.get(PREF_SCALING));
|
||||
tf_Scale_1.setColumns(10);
|
||||
configuration.put(ARG_SCALING, tf_Scale_1);
|
||||
return tf_Scale_1;
|
||||
}
|
||||
|
||||
JTextField addInputFile(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_inputFile_1 = new JTextField(preferences.getSourceFileName());
|
||||
tf_inputFile_1.setColumns(10);
|
||||
configuration.put(ARG_INPUT_FILE, tf_inputFile_1);
|
||||
return tf_inputFile_1;
|
||||
}
|
||||
|
||||
JComboBox addImageResolution(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cbox_image_resolution_1 = new JComboBox(preferences.getAll(PREF_RESOLUTIONS));
|
||||
cbox_image_resolution_1.setSelectedIndex(Integer.parseInt(preferences.get(PREF_DEFAULT_IMAGE_RESOLUTION)));
|
||||
configuration.put(ARG_IMAGE_RESOLUTION, cbox_image_resolution_1);
|
||||
return cbox_image_resolution_1;
|
||||
}
|
||||
|
||||
JComboBox addSplitByLevel(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cbox_SplitByLevel_1 = new JComboBox(preferences.getAll(PREF_SPLIT_LEVELS));
|
||||
configuration.put(ARG_SPLIT_LEVEL, cbox_SplitByLevel_1);
|
||||
cbox_SplitByLevel_1.setSelectedIndex(Integer.parseInt(preferences.get(PREF_SPLIT_BY_LEVEL)));
|
||||
return cbox_SplitByLevel_1;
|
||||
}
|
||||
|
||||
JTextField addMaxWidth(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_MaxWidth_1 = new JTextField(preferences.get(PREF_MAX_WIDTH));
|
||||
tf_MaxWidth_1.setColumns(10);
|
||||
configuration.put(ARG_MAX_WIDTH, tf_MaxWidth_1);
|
||||
return tf_MaxWidth_1;
|
||||
}
|
||||
|
||||
JCheckBox addEmbedRasterImages(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_EmbedRaster_1 = new JCheckBox(Localizer.get(LABEL_EMBED_RASTER));
|
||||
cb_EmbedRaster_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_EMBED_RASTER)));
|
||||
configuration.put(ARG_EMBED_IMG, cb_EmbedRaster_1);
|
||||
return cb_EmbedRaster_1;
|
||||
}
|
||||
|
||||
JCheckBox addEmbedVectorImages(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_EmbedVectorImages_1 = new JCheckBox(Localizer.get(LABEL_EMBED_VECTOR));
|
||||
cb_EmbedVectorImages_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_EMBED_VECTOR)));
|
||||
configuration.put(ARG_EMBED_SVG, cb_EmbedVectorImages_1);
|
||||
return cb_EmbedVectorImages_1;
|
||||
}
|
||||
|
||||
void setOutputFilePath(String newFilePath, JTextField tf_OutputFile, String extension) {
|
||||
|
||||
File inputFile = new File(newFilePath);
|
||||
if (!inputFile.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!inputFile.isDirectory()) {
|
||||
File parent = inputFile.getParentFile();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (!parent.canWrite()) {
|
||||
JOptionPane.showMessageDialog(ConfigurationWindow.getSingleFrame(), Localizer.get(CANT_WRITE_MESSAGE));
|
||||
}
|
||||
}
|
||||
if (newFilePath.length() < 3) {
|
||||
return;
|
||||
}
|
||||
String exportPath;
|
||||
if (inputFile.isDirectory()) {
|
||||
exportPath = newFilePath;
|
||||
tf_OutputFile.setText(exportPath);
|
||||
} else {
|
||||
String importExt = newFilePath.substring(newFilePath.length() - 3, newFilePath.length()).toLowerCase();
|
||||
if (importExt.equals(ODT_FILE_EXTENSION)) {
|
||||
exportPath = newFilePath.substring(0, newFilePath.length() - 3) + extension;
|
||||
tf_OutputFile.setText(exportPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JButton addChooseOutputButton(JTextField tf_OutputFile, String fileExtension) {
|
||||
btn_ChooseOutputFile_1 = new JButton(Localizer.get(LABEL_BUTTON_CHOOSE));
|
||||
btn_ChooseOutputFile_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FileDialog fileDialog = new FileDialog();
|
||||
String newFilePath = fileDialog.chooseFile(tf_OutputFile.getText(),fileExtension);
|
||||
if (newFilePath != null && !newFilePath.isEmpty()) {
|
||||
tf_OutputFile.setText(newFilePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
return btn_ChooseOutputFile_1;
|
||||
}
|
||||
|
||||
public void setMetadataFilePath(String newFilePath, JTextField tf_MetadataFile, String extension) {
|
||||
|
||||
File inputFile = new File(newFilePath);
|
||||
if (!inputFile.exists()) {
|
||||
return;
|
||||
}
|
||||
if (inputFile.isDirectory()) {
|
||||
tf_MetadataFile.setText(newFilePath);
|
||||
} else {
|
||||
File parent = inputFile.getParentFile();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (newFilePath.length() < 3) {
|
||||
return;
|
||||
}
|
||||
String importExt = newFilePath.substring(newFilePath.length()-3, newFilePath.length()).toLowerCase();
|
||||
if (importExt.equals(ODT_FILE_EXTENSION)) {
|
||||
String metadataPath = newFilePath.substring(0, newFilePath.length()-3) + extension;
|
||||
File metaFile = new File(metadataPath);
|
||||
if (metaFile.exists() && metaFile.canRead()){
|
||||
tf_MetadataFile.setText(metadataPath);
|
||||
} else {
|
||||
tf_MetadataFile.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JButton addButtonChooseFile(JTextField tf_inputFile, JTextField tf_OutputFile) {
|
||||
btn_chooseFile_1 = new JButton(Localizer.get(LABEL_BUTTON_CHOOSE));
|
||||
btn_chooseFile_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newFilePath = FileDialog.chooseFile(tf_inputFile.getText(),ODT_FILE_EXTENSION);
|
||||
if (newFilePath != null && !newFilePath.isEmpty()) {
|
||||
tf_inputFile.setText(newFilePath);
|
||||
setOutputFilePath(newFilePath,tf_OutputFile,HTML_FILE_EXTENSION);
|
||||
}
|
||||
}
|
||||
});
|
||||
return btn_chooseFile_1;
|
||||
}
|
||||
}
|
63
src/main/java/pro/litvinovg/w2phtml/gui/Localizer.java
Normal file
63
src/main/java/pro/litvinovg/w2phtml/gui/Localizer.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Localizer {
|
||||
|
||||
private static final String TRANSLATION_NOT_FOUND = "no translation";
|
||||
private Locale currentLocale;
|
||||
private String resourceBundle = "pro.litvinovg.w2phtml.gui.localizations.w2phtml";
|
||||
private ResourceBundle translations;
|
||||
private boolean isOld = false;
|
||||
private static Localizer localizer = null;
|
||||
private Localizer() {
|
||||
currentLocale = Locale.getDefault();
|
||||
translations = ResourceBundle.getBundle(resourceBundle, currentLocale);
|
||||
this.isOld = isOldJava();
|
||||
}
|
||||
|
||||
public static Localizer getInstance() {
|
||||
if (localizer != null) {
|
||||
return localizer;
|
||||
}
|
||||
localizer = new Localizer();
|
||||
return localizer;
|
||||
}
|
||||
public static String get(String name) {
|
||||
Localizer.getInstance();
|
||||
return localizer.getTranslation(name);
|
||||
}
|
||||
|
||||
public String getTranslation(String name) {
|
||||
if (translations != null && translations.containsKey(name)) {
|
||||
String translation = translations.getString(name);
|
||||
if (isOld) {
|
||||
try {
|
||||
return new String(translation.getBytes("ISO-8859-1"), "UTF-8");
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
return translation;
|
||||
}
|
||||
}
|
||||
return TRANSLATION_NOT_FOUND;
|
||||
|
||||
}
|
||||
private boolean isOldJava() {
|
||||
try {
|
||||
String versionString = System.getProperty("java.class.version");
|
||||
Float version = Float.parseFloat(versionString);
|
||||
if (version < 53) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getLocalizedMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -41,6 +41,10 @@ public class ODTDocument {
|
|||
private XDispatchProvider dispatchProvider;
|
||||
XTextDocument textDocument;
|
||||
|
||||
public ODTDocument(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public ODTDocument(XComponentContext componentContext) {
|
||||
if (componentContext != null) {
|
||||
context = componentContext;
|
||||
|
|
79
src/main/java/pro/litvinovg/w2phtml/gui/PanelFactory.java
Normal file
79
src/main/java/pro/litvinovg/w2phtml/gui/PanelFactory.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static pro.litvinovg.w2phtml.gui.Contstants.*;
|
||||
|
||||
|
||||
public class PanelFactory {
|
||||
|
||||
private Localizer localizer;
|
||||
private PreferencesStorage storage;
|
||||
private JTabbedPane tabbedPane;
|
||||
private static final Logger logger = LoggerFactory.getLogger(PanelFactory.class);
|
||||
|
||||
public PanelFactory(Localizer localizer, PreferencesStorage storage,JTabbedPane tabbedPane) {
|
||||
this.localizer = localizer;
|
||||
this.storage = storage;
|
||||
this.tabbedPane = tabbedPane;
|
||||
}
|
||||
public JPanel createPanel(String name) {
|
||||
UIPreferences prefs = storage.get(name);
|
||||
String type = prefs.get(PREF_TYPE);
|
||||
JPanel panel = new JPanel();
|
||||
HashMap<String, Component> configuration = new HashMap<String, Component>();
|
||||
ControlPanel panel_control = new ControlPanel(configuration, storage, name, type);
|
||||
panel_control.setFactory(this);
|
||||
JPanel panel_configuration = null;
|
||||
if (EPUB.equals(type)){
|
||||
panel_configuration = new EpubPanel(configuration, storage.get(name));
|
||||
} else if (RDF.equals(type)) {
|
||||
panel_configuration = new RDFPanel(configuration, storage.get(name));
|
||||
} else {
|
||||
panel_configuration = new HTMLPanel(configuration, storage.get(name));
|
||||
}
|
||||
applyDefaultLayout(panel, panel_configuration, panel_control);
|
||||
tabbedPane.addTab(name, null, panel, null);
|
||||
tabbedPane.setSelectedComponent(panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
public void removeCurPanel() {
|
||||
tabbedPane.removeTabAt(tabbedPane.getSelectedIndex());
|
||||
}
|
||||
|
||||
private void applyDefaultLayout(JPanel tabbedPanel, JPanel configPanel, JPanel controlPanel) {
|
||||
|
||||
GroupLayout gl_panel_html = new GroupLayout(tabbedPanel);
|
||||
gl_panel_html.setHorizontalGroup(gl_panel_html.createParallelGroup(Alignment.TRAILING)
|
||||
.addGroup(gl_panel_html.createSequentialGroup().addGroup(gl_panel_html.createParallelGroup(Alignment.TRAILING)
|
||||
.addComponent(configPanel, GroupLayout.DEFAULT_SIZE, 852, Short.MAX_VALUE).addComponent(controlPanel, GroupLayout.DEFAULT_SIZE, 852, Short.MAX_VALUE)).addGap(4)));
|
||||
gl_panel_html.setVerticalGroup(gl_panel_html.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING,
|
||||
gl_panel_html.createSequentialGroup()
|
||||
.addComponent(configPanel, GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(controlPanel, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)));
|
||||
tabbedPanel.setLayout(gl_panel_html);
|
||||
}
|
||||
public void createPanels() {
|
||||
for (String name : storage.getTabNames()) {
|
||||
if (!name.equals(HTML) && !name.equals(EPUB) && !name.equals(RDF)) {
|
||||
createPanel(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
200
src/main/java/pro/litvinovg/w2phtml/gui/PreferencesStorage.java
Normal file
200
src/main/java/pro/litvinovg/w2phtml/gui/PreferencesStorage.java
Normal file
|
@ -0,0 +1,200 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static pro.litvinovg.w2phtml.gui.Contstants.*;
|
||||
|
||||
|
||||
public class PreferencesStorage {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PreferencesStorage.class);
|
||||
private Map<String,UIPreferences> tabs;
|
||||
|
||||
private Preferences storage;
|
||||
|
||||
public PreferencesStorage() {
|
||||
storage = Preferences.userRoot().node(this.getClass().getName());
|
||||
tabs = new HashMap();
|
||||
read();
|
||||
initializeDefault();
|
||||
}
|
||||
|
||||
private void initializeDefault() {
|
||||
tabs.put(HTML, getDefaultHTML(this));
|
||||
tabs.put(EPUB,getDefaultEpub(this));
|
||||
tabs.put(RDF,getDefaultRDF(this));
|
||||
}
|
||||
|
||||
public static UIPreferences getDefaultHTML(PreferencesStorage store) {
|
||||
UIPreferences prefs = new UIPreferences(store);
|
||||
prefs.put(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"} );
|
||||
prefs.put(PREF_DEFAULT_IMAGE_RESOLUTION,"2");
|
||||
prefs.put(PREF_USE_MATHJAX,"true");
|
||||
prefs.put(PREF_IGNORE_EMPTY_PARS,"false");
|
||||
prefs.put(PREF_IGNORE_HARD_BREAKS,"false");
|
||||
prefs.put(PREF_GREENSTONE_TAGS,"false");
|
||||
prefs.put(PREF_LETTER_SPACING,"0.15");
|
||||
prefs.put(PREF_INLINE_STYLES,"true");
|
||||
prefs.put(PREF_EMBED_RASTER,"true");
|
||||
prefs.put(PREF_EMBED_VECTOR,"true");
|
||||
prefs.put(PREF_CONVERT_TO_PX,"false");
|
||||
prefs.put(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS);
|
||||
prefs.put(PREF_PAGINATION,"true");
|
||||
prefs.put(PREF_SPLIT_LEVELS, new String[]{"0","1","2","3","4","5","6","7","8","9","10"} );
|
||||
prefs.put(PREF_SPLIT_BY_LEVEL,"0");
|
||||
prefs.put(PREF_TYPE,HTML);
|
||||
prefs.put(PREF_MAX_WIDTH,"");
|
||||
prefs.put(PREF_SPLIT_WHOLE_PAGES,"false");
|
||||
prefs.put(PREF_SCALING, SCALING_DEFAULT_VALUE);
|
||||
prefs.setDefault(true);
|
||||
return prefs;
|
||||
}
|
||||
|
||||
|
||||
public static UIPreferences getDefaultEpub(PreferencesStorage store) {
|
||||
UIPreferences prefs = new UIPreferences(store);
|
||||
prefs.put(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"});
|
||||
prefs.put(PREF_DEFAULT_IMAGE_RESOLUTION,"2");
|
||||
prefs.put(PREF_USE_MATHJAX,"true");
|
||||
prefs.put(PREF_IGNORE_EMPTY_PARS,"false");
|
||||
prefs.put(PREF_IGNORE_HARD_BREAKS,"false");
|
||||
prefs.put(PREF_LETTER_SPACING,"0.15");
|
||||
prefs.put(PREF_INLINE_STYLES,"true");
|
||||
prefs.put(PREF_EMBED_RASTER,"true");
|
||||
prefs.put(PREF_EMBED_VECTOR,"true");
|
||||
prefs.put(PREF_CONVERT_TO_PX,"false");
|
||||
prefs.put(PREF_SCALING, SCALING_DEFAULT_VALUE);
|
||||
prefs.put(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS);
|
||||
prefs.put(PREF_PAGINATION,"true");
|
||||
prefs.put(PREF_TYPE,EPUB);
|
||||
prefs.setDefault(true);
|
||||
return prefs;
|
||||
}
|
||||
|
||||
public static UIPreferences getDefaultRDF(PreferencesStorage store) {
|
||||
UIPreferences prefs = new UIPreferences(store);
|
||||
prefs.put(PREF_PUBLICATION_TYPES, new String[]{"elenphArticle", "encArticle", "book", "journal"} );
|
||||
prefs.put(PREF_RESOLUTIONS, new String[]{"0","72","150","300","600","1200","2400"} );
|
||||
prefs.put(PREF_DEFAULT_IMAGE_RESOLUTION,"2");
|
||||
prefs.put(PREF_DEFAULT_PUBLICATION_TYPE,"0");
|
||||
prefs.put(PREF_USE_MATHJAX,"true");
|
||||
prefs.put(PREF_IGNORE_EMPTY_PARS,"false");
|
||||
prefs.put(PREF_IGNORE_HARD_BREAKS,"false");
|
||||
prefs.put(PREF_LETTER_SPACING,"0.15");
|
||||
prefs.put(PREF_INLINE_STYLES,"true");
|
||||
prefs.put(PREF_EMBED_RASTER,"true");
|
||||
prefs.put(PREF_EMBED_VECTOR,"true");
|
||||
prefs.put(PREF_CONVERT_TO_PX,"false");
|
||||
prefs.put(PREF_PAGEBREAK_STYLES,DEFAULT_PAGEBREAK_STYLE_SETTINGS);
|
||||
prefs.put(PREF_TYPE,RDF);
|
||||
prefs.put(PREF_SCALING, SCALING_DEFAULT_VALUE);
|
||||
prefs.put(PREF_PAGINATION,"true");
|
||||
prefs.setDefault(true);
|
||||
return prefs;
|
||||
}
|
||||
|
||||
public void put(String prefName, UIPreferences newPreferences) {
|
||||
tabs.put(prefName, newPreferences);
|
||||
}
|
||||
public boolean has(String configName) {
|
||||
return tabs.containsKey(configName);
|
||||
}
|
||||
|
||||
private void add(String key, String[] strings,UIPreferences prefs) {
|
||||
prefs.put(key, strings);
|
||||
}
|
||||
|
||||
private void add(String key, String value,UIPreferences prefs) {
|
||||
prefs.put(key, new String[] {value});
|
||||
}
|
||||
|
||||
public UIPreferences get(String name) {
|
||||
if (tabs.containsKey(name)) {
|
||||
return tabs.get(name);
|
||||
} else {
|
||||
logger.error("Prefereneces with name " + name + " not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
public void remove(String name) {
|
||||
tabs.remove(name);
|
||||
}
|
||||
|
||||
public void setSourceFileName(String fileName) {
|
||||
Iterator<Entry<String, UIPreferences>> it = tabs.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, UIPreferences> pair = it.next();
|
||||
UIPreferences value = (UIPreferences) pair.getValue();
|
||||
value.setSourceFileName(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
String jsonPrefereneces = convertAllToJSON();
|
||||
storage.put(TAB_PREFERENCES, jsonPrefereneces);
|
||||
}
|
||||
|
||||
private String convertAllToJSON() {
|
||||
JSONObject json = new JSONObject();
|
||||
for (Map.Entry<String, UIPreferences> entry : tabs.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
UIPreferences prefs = entry.getValue();
|
||||
JSONObject json_prefs = prefs.getJSON();
|
||||
json.put(name, json_prefs);
|
||||
}
|
||||
return json.toString();
|
||||
}
|
||||
|
||||
public Set<String> getTabNames() {
|
||||
return tabs.keySet();
|
||||
}
|
||||
|
||||
private void read() {
|
||||
String data = storage.get(TAB_PREFERENCES, null);
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
JSONObject json = new JSONObject(data);
|
||||
Set<String> prefTabNames = json.keySet();
|
||||
for (String prefTabName : prefTabNames) {
|
||||
UIPreferences newPref = new UIPreferences(this);
|
||||
JSONObject tabData = (JSONObject) json.get(prefTabName);
|
||||
Set<String> prefKeys = tabData.keySet();
|
||||
for (String name : prefKeys) {
|
||||
JSONArray values = (JSONArray) tabData.get(name);
|
||||
if (values != null) {
|
||||
String[] valueArray = new String[values.length()];
|
||||
for (int i=0;i<values.length();i++){
|
||||
valueArray[i] = values.getString(i);
|
||||
}
|
||||
newPref.put(name, valueArray);
|
||||
}
|
||||
}
|
||||
tabs.put(prefTabName, newPref);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
logger.error("JSON parsing exception " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
logger.error("JSON parsing exception " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
494
src/main/java/pro/litvinovg/w2phtml/gui/RDFPanel.java
Normal file
494
src/main/java/pro/litvinovg/w2phtml/gui/RDFPanel.java
Normal file
|
@ -0,0 +1,494 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
import static pro.litvinovg.w2phtml.gui.Contstants.*;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
public class RDFPanel extends JPanel {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private UIPreferences preferences;
|
||||
private HashMap<String, Component> configuration;
|
||||
private JComboBox cbox_image_resolution_1;
|
||||
private JCheckBox cb_Pagination_1;
|
||||
private JCheckBox cb_convertToPx_1;
|
||||
private JCheckBox cb_EmbedRaster_1;
|
||||
private JCheckBox cb_EmbedVectorImages_1;
|
||||
private JTextField tf_FilterLetterSpacing_1;
|
||||
private JCheckBox cb_InlineStyles_1;
|
||||
private JLabel lb_TargetFormat_1;
|
||||
private JTextField tf_OutputFile_1;
|
||||
private JTextField tf_metadataPath_1;
|
||||
private JTextField tf_inputFile_1;
|
||||
private JButton btnChooseFile;
|
||||
private JButton btn_metadataChoose_1;
|
||||
private JButton btn_ChooseOutputFile_1;
|
||||
private JTextField tf_pageBreakInlineStyle_1;
|
||||
private JTextField tf_Scale_1;
|
||||
private JComboBox cbox_type_1;
|
||||
private JCheckBox cb_IgnoreEmptyParagraphs_1;
|
||||
private JCheckBox cb_UseMathJax_1;
|
||||
private JCheckBox cb_IgnoreHardLineBreaks_1;
|
||||
|
||||
public RDFPanel() {
|
||||
this.preferences = PreferencesStorage.getDefaultRDF(null);
|
||||
this.configuration = new HashMap<String, Component>();
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public RDFPanel(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
this.configuration = configuration;
|
||||
this.preferences = preferences;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
JLabel lb_FilterLetterSpacing = new JLabel(Localizer.get(LABEL_MIN_LETTER_SPACING));
|
||||
JLabel lb_TargetFormat = addTargetFormat(RDF_TARGET_FORMAT,configuration);
|
||||
JLabel lb_Scale = new JLabel(Localizer.get(LABEL_SCALE));
|
||||
JLabel lb_FilePath = new JLabel(Localizer.get(LABEL_INPUT_FILE_PATH));
|
||||
JLabel lb_TargetFormat_description = new JLabel(Localizer.get(LABEL_TARGET_FORMAT));
|
||||
JLabel lb_OutFilePath = new JLabel(Localizer.get(OUTPUT_FILE_PATH));
|
||||
JLabel lb_ImageResolution = new JLabel(Localizer.get(LABEL_IMAGE_RESOLUTION));
|
||||
JLabel lb_type = new JLabel(Localizer.get(LABEL_TYPE));
|
||||
JLabel lb_metadataFilePath = new JLabel(Localizer.get(LABEL_METADATA_PATH));
|
||||
JLabel lb_pageBreakInlineStyle = new JLabel(Localizer.get(LABEL_BREAK_STYLE));
|
||||
|
||||
JTextField tf_OutputFile = addOutputFileTextField(configuration,preferences);
|
||||
JTextField tf_FilterLetterSpacing = addLetterSpacingFilter(configuration,preferences);
|
||||
JTextField tf_Scale = addScaling(configuration,preferences);
|
||||
JTextField tf_inputFile = addInputFile(configuration,preferences);
|
||||
JTextField tf_metadataPath = addMetadataPath(configuration);
|
||||
JTextField tf_pageBreakInlineStyle = addPageBreakStyle(configuration,preferences);
|
||||
|
||||
JCheckBox cb_UseMathJax = addMathJaxCB(configuration,preferences);
|
||||
JCheckBox cb_IgnoreEmptyParagraphs = addIgnoreEmptyParsCB(configuration,preferences);
|
||||
JCheckBox cb_IgnoreHardLineBreaks = addIgnoreHardLineBreaks(configuration,preferences);
|
||||
JCheckBox cb_InlineStyles = addInlineStyles(configuration,preferences);
|
||||
cb_InlineStyles.setEnabled(false);
|
||||
JCheckBox cb_EmbedVectorImages = addEmbedVectorImages(configuration,preferences);
|
||||
cb_EmbedVectorImages.setEnabled(false);
|
||||
JCheckBox cb_EmbedRaster = addEmbedRasterImages(configuration,preferences);
|
||||
cb_EmbedRaster.setEnabled(false);
|
||||
JCheckBox cb_convertToPx = addConvertToPX(configuration,preferences);
|
||||
JCheckBox cb_Pagination = addPagination(configuration,preferences);
|
||||
|
||||
JComboBox cbox_image_resolution = addImageResolution(configuration,preferences);
|
||||
JComboBox cbox_type = addPubTypes(configuration, preferences);
|
||||
|
||||
JButton btn_ChooseOutputFile = addChooseOutputButton(tf_OutputFile, RDF_FILE_EXTENSION);
|
||||
JButton btn_ChooseFile = addChooseFile(tf_OutputFile, tf_inputFile, tf_metadataPath);
|
||||
JButton btn_metadataChoose = addMetadataButton(tf_metadataPath);
|
||||
GroupLayout groupLayout = new GroupLayout(this);
|
||||
groupLayout.setHorizontalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_metadataFilePath, GroupLayout.PREFERRED_SIZE, 198, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(12)
|
||||
.addComponent(tf_metadataPath_1, GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
|
||||
.addGap(19)
|
||||
.addComponent(btn_metadataChoose_1, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_OutFilePath, GroupLayout.PREFERRED_SIZE, 198, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(12)
|
||||
.addComponent(tf_OutputFile_1, GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
|
||||
.addGap(19)
|
||||
.addComponent(btn_ChooseOutputFile_1, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_pageBreakInlineStyle, GroupLayout.PREFERRED_SIZE, 198, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(12)
|
||||
.addComponent(tf_pageBreakInlineStyle_1, GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_type, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(27)
|
||||
.addComponent(cbox_type_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(cb_InlineStyles_1)
|
||||
.addComponent(cb_EmbedVectorImages_1)
|
||||
.addComponent(cb_EmbedRaster_1)
|
||||
.addComponent(cb_convertToPx_1, GroupLayout.PREFERRED_SIZE, 658, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_IgnoreHardLineBreaks_1, GroupLayout.PREFERRED_SIZE, 382, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_IgnoreEmptyParagraphs_1, GroupLayout.PREFERRED_SIZE, 382, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_UseMathJax_1, GroupLayout.PREFERRED_SIZE, 382, GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(cb_Pagination_1, GroupLayout.PREFERRED_SIZE, 382, GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(lb_ImageResolution, GroupLayout.PREFERRED_SIZE, 245, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(cbox_image_resolution_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(tf_Scale_1, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(lb_FilterLetterSpacing)
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addComponent(tf_FilterLetterSpacing_1, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
|
||||
.addComponent(lb_TargetFormat_description, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(lb_FilePath, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE))
|
||||
.addGap(12)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(lb_TargetFormat_1, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addComponent(tf_inputFile_1, GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
|
||||
.addGap(19)
|
||||
.addComponent(btnChooseFile, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE)))))
|
||||
.addGap(6))
|
||||
);
|
||||
groupLayout.setVerticalGroup(
|
||||
groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(lb_TargetFormat_description)
|
||||
.addComponent(lb_TargetFormat_1))
|
||||
.addPreferredGap(ComponentPlacement.RELATED)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(lb_FilePath))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(3)
|
||||
.addComponent(tf_inputFile_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(btnChooseFile))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(lb_metadataFilePath))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(6)
|
||||
.addComponent(tf_metadataPath_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(btn_metadataChoose_1))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(5)
|
||||
.addComponent(lb_OutFilePath))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(3)
|
||||
.addComponent(tf_OutputFile_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(btn_ChooseOutputFile_1))
|
||||
.addGap(6)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addComponent(lb_pageBreakInlineStyle, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(2)
|
||||
.addComponent(tf_pageBreakInlineStyle_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addGap(11)
|
||||
.addComponent(lb_type))
|
||||
.addGroup(groupLayout.createSequentialGroup()
|
||||
.addPreferredGap(ComponentPlacement.UNRELATED)
|
||||
.addComponent(cbox_type_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
|
||||
.addGap(8)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lb_Scale)
|
||||
.addComponent(tf_Scale_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(10)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lb_FilterLetterSpacing)
|
||||
.addComponent(tf_FilterLetterSpacing_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(8)
|
||||
.addComponent(cb_InlineStyles_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_EmbedVectorImages_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_EmbedRaster_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_convertToPx_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_IgnoreHardLineBreaks_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_IgnoreEmptyParagraphs_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_UseMathJax_1)
|
||||
.addGap(6)
|
||||
.addComponent(cb_Pagination_1)
|
||||
.addGap(11)
|
||||
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
|
||||
.addComponent(lb_ImageResolution, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(cbox_image_resolution_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
);
|
||||
setLayout(groupLayout);
|
||||
}
|
||||
|
||||
private JButton addMetadataButton( JTextField tf_metadataPath) {
|
||||
btn_metadataChoose_1 = new JButton(Localizer.get(LABEL_BUTTON_CHOOSE));
|
||||
btn_metadataChoose_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newFilePath = FileDialog.chooseFile(tf_metadataPath.getText(),CSV_FILE_EXTENSION);
|
||||
if (newFilePath != null && !newFilePath.isEmpty()) {
|
||||
tf_metadataPath.setText(newFilePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
return btn_metadataChoose_1;
|
||||
}
|
||||
|
||||
private JTextField addMetadataPath(HashMap<String, Component> configuration) {
|
||||
tf_metadataPath_1 = new JTextField("");
|
||||
tf_metadataPath_1.setColumns(10);
|
||||
configuration.put(ARG_CSV_METADATA, tf_metadataPath_1);
|
||||
return tf_metadataPath_1;
|
||||
}
|
||||
|
||||
private JButton addChooseFile( JTextField tf_OutputFile, JTextField tf_inputFile,
|
||||
JTextField tf_metadataPath) {
|
||||
btnChooseFile = new JButton(Localizer.get(LABEL_BUTTON_CHOOSE));
|
||||
btnChooseFile.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String newFilePath = FileDialog.chooseFile(tf_inputFile.getText(),ODT_FILE_EXTENSION);
|
||||
if (newFilePath != null && !newFilePath.isEmpty()) {
|
||||
tf_inputFile.setText(newFilePath);
|
||||
setOutputFilePath(newFilePath,tf_OutputFile,RDF_FILE_EXTENSION);
|
||||
setMetadataFilePath(newFilePath,tf_metadataPath,CSV_FILE_EXTENSION);
|
||||
}
|
||||
}
|
||||
});
|
||||
return btnChooseFile;
|
||||
}
|
||||
|
||||
private JComboBox addPubTypes(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cbox_type_1 = new JComboBox(preferences.getAll(PREF_PUBLICATION_TYPES));
|
||||
cbox_type_1.setSelectedIndex(Integer.parseInt(preferences.get(PREF_DEFAULT_PUBLICATION_TYPE)));
|
||||
configuration.put(ARG_RDF_TYPE, cbox_type_1);
|
||||
return cbox_type_1;
|
||||
}
|
||||
//Shared methods added here to make WindowBuilder work
|
||||
|
||||
JCheckBox addMathJaxCB(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_UseMathJax_1 = new JCheckBox(Localizer.get(LABEL_USE_MATHJAX));
|
||||
cb_UseMathJax_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_USE_MATHJAX)));
|
||||
configuration.put(ARG_USE_MATHJAX, cb_UseMathJax_1);
|
||||
return cb_UseMathJax_1;
|
||||
}
|
||||
|
||||
JCheckBox addIgnoreEmptyParsCB(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_IgnoreEmptyParagraphs_1 = new JCheckBox(Localizer.get(LABEL_INGNORE_EMPTY_PARS));
|
||||
cb_IgnoreEmptyParagraphs_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_IGNORE_EMPTY_PARS)));
|
||||
configuration.put(ARG_IGNORE_EMPTY_PARAGRAPHS, cb_IgnoreEmptyParagraphs_1);
|
||||
return cb_IgnoreEmptyParagraphs_1;
|
||||
}
|
||||
|
||||
JCheckBox addSplitWholePagesOnly(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JCheckBox cb_SplitWholePagesOnly = new JCheckBox(Localizer.get(LABEL_SPLIT_WHOLE_PAGES_ONLY));
|
||||
cb_SplitWholePagesOnly.setSelected(Boolean.parseBoolean(preferences.get(PREF_SPLIT_WHOLE_PAGES)));
|
||||
configuration.put(ARG_ALIGN_SPLITS_TO_PAGES, cb_SplitWholePagesOnly);
|
||||
return cb_SplitWholePagesOnly;
|
||||
}
|
||||
|
||||
JCheckBox addIgnoreHardLineBreaks(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_IgnoreHardLineBreaks_1 = new JCheckBox(Localizer.get(LABEL_FILETER_HARD_LINE_BREAKS));
|
||||
cb_IgnoreHardLineBreaks_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_IGNORE_HARD_BREAKS)));
|
||||
configuration.put(ARG_IGNORE_HARD_LINE_BREAKS, cb_IgnoreHardLineBreaks_1);
|
||||
return cb_IgnoreHardLineBreaks_1;
|
||||
}
|
||||
|
||||
JTextField addLetterSpacingFilter(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_FilterLetterSpacing_1 = new JTextField();
|
||||
tf_FilterLetterSpacing_1.setText(preferences.get(PREF_LETTER_SPACING));
|
||||
configuration.put(ARG_MIN_LETTER_SPACING, tf_FilterLetterSpacing_1);
|
||||
tf_FilterLetterSpacing_1.setColumns(10);
|
||||
return tf_FilterLetterSpacing_1;
|
||||
}
|
||||
|
||||
|
||||
JCheckBox addInlineStyles(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_InlineStyles_1 = new JCheckBox(Localizer.get(LABEL_INLINE_STYLES));
|
||||
cb_InlineStyles_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_INLINE_STYLES)));
|
||||
configuration.put(ARG_CSS_INLINE, cb_InlineStyles_1);
|
||||
return cb_InlineStyles_1;
|
||||
}
|
||||
|
||||
JCheckBox addGreenstoneTags(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JCheckBox cb_Greenstone = new JCheckBox(Localizer.get(LABEL_GREENSTONE_SPLIT));
|
||||
configuration.put(ARG_GREENSTONE, cb_Greenstone);
|
||||
cb_Greenstone.setSelected(Boolean.parseBoolean(preferences.get(PREF_GREENSTONE_TAGS)));
|
||||
return cb_Greenstone;
|
||||
}
|
||||
|
||||
JTextField addOutputFileTextField(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_OutputFile_1 = new JTextField("");
|
||||
configuration.put(ARG_OUTPUT_FILE, tf_OutputFile_1);
|
||||
tf_OutputFile_1.setColumns(10);
|
||||
return tf_OutputFile_1;
|
||||
}
|
||||
|
||||
JCheckBox addPagination(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_Pagination_1 = new JCheckBox(Localizer.get(LABEL_PAGINATION));
|
||||
cb_Pagination_1.setSelected(Boolean.valueOf(preferences.get(PREF_PAGINATION)));
|
||||
configuration.put(ARG_PAGINATION, cb_Pagination_1);
|
||||
return cb_Pagination_1;
|
||||
}
|
||||
|
||||
JCheckBox addConvertToPX(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_convertToPx_1 = new JCheckBox(Localizer.get(LABEL_CONVERT_TO_PX));
|
||||
cb_convertToPx_1.setSelected(Boolean.valueOf(preferences.get(PREF_CONVERT_TO_PX)));
|
||||
configuration.put(ARG_CONVERT_TO_PX, cb_convertToPx_1);
|
||||
return cb_convertToPx_1;
|
||||
}
|
||||
|
||||
JTextField addPageBreakStyle(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_pageBreakInlineStyle_1 = new JTextField(preferences.get(PREF_PAGEBREAK_STYLES));
|
||||
tf_pageBreakInlineStyle_1.setColumns(10);
|
||||
configuration.put(ARG_PAGE_BREAK_STYLE, tf_pageBreakInlineStyle_1);
|
||||
return tf_pageBreakInlineStyle_1;
|
||||
}
|
||||
|
||||
JLabel addTargetFormat(String format, HashMap<String, Component> configuration) {
|
||||
lb_TargetFormat_1 = new JLabel(format);
|
||||
configuration.put(ARG_TARGET_FORMAT, lb_TargetFormat_1);
|
||||
return lb_TargetFormat_1;
|
||||
}
|
||||
|
||||
JTextField addScaling(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_Scale_1 = new JTextField();
|
||||
tf_Scale_1.setText(preferences.get(PREF_SCALING));
|
||||
tf_Scale_1.setColumns(10);
|
||||
configuration.put(ARG_SCALING, tf_Scale_1);
|
||||
return tf_Scale_1;
|
||||
}
|
||||
|
||||
JTextField addInputFile(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
tf_inputFile_1 = new JTextField(preferences.getSourceFileName());
|
||||
tf_inputFile_1.setColumns(10);
|
||||
configuration.put(ARG_INPUT_FILE, tf_inputFile_1);
|
||||
return tf_inputFile_1;
|
||||
}
|
||||
|
||||
JComboBox addImageResolution(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cbox_image_resolution_1 = new JComboBox(preferences.getAll(PREF_RESOLUTIONS));
|
||||
cbox_image_resolution_1.setSelectedIndex(Integer.parseInt(preferences.get(PREF_DEFAULT_IMAGE_RESOLUTION)));
|
||||
configuration.put(ARG_IMAGE_RESOLUTION, cbox_image_resolution_1);
|
||||
return cbox_image_resolution_1;
|
||||
}
|
||||
|
||||
JComboBox addSplitByLevel(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JComboBox cbox_SplitByLevel = new JComboBox(preferences.getAll(PREF_SPLIT_LEVELS));
|
||||
configuration.put(ARG_SPLIT_LEVEL, cbox_SplitByLevel);
|
||||
cbox_SplitByLevel.setSelectedIndex(Integer.parseInt(preferences.get(PREF_SPLIT_BY_LEVEL)));
|
||||
return cbox_SplitByLevel;
|
||||
}
|
||||
|
||||
JTextField addMaxWidth(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
JTextField tf_MaxWidth = new JTextField(preferences.get(PREF_MAX_WIDTH));
|
||||
tf_MaxWidth.setColumns(10);
|
||||
configuration.put(ARG_MAX_WIDTH, tf_MaxWidth);
|
||||
return tf_MaxWidth;
|
||||
}
|
||||
|
||||
JCheckBox addEmbedRasterImages(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_EmbedRaster_1 = new JCheckBox(Localizer.get(LABEL_EMBED_RASTER));
|
||||
cb_EmbedRaster_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_EMBED_RASTER)));
|
||||
configuration.put(ARG_EMBED_IMG, cb_EmbedRaster_1);
|
||||
return cb_EmbedRaster_1;
|
||||
}
|
||||
|
||||
JCheckBox addEmbedVectorImages(HashMap<String, Component> configuration, UIPreferences preferences) {
|
||||
cb_EmbedVectorImages_1 = new JCheckBox(Localizer.get(LABEL_EMBED_VECTOR));
|
||||
cb_EmbedVectorImages_1.setSelected(Boolean.parseBoolean(preferences.get(PREF_EMBED_VECTOR)));
|
||||
configuration.put(ARG_EMBED_SVG, cb_EmbedVectorImages_1);
|
||||
return cb_EmbedVectorImages_1;
|
||||
}
|
||||
|
||||
void setOutputFilePath(String newFilePath, JTextField tf_OutputFile, String extension) {
|
||||
|
||||
File inputFile = new File(newFilePath);
|
||||
if (!inputFile.exists()) {
|
||||
return;
|
||||
}
|
||||
if (!inputFile.isDirectory()) {
|
||||
File parent = inputFile.getParentFile();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (!parent.canWrite()) {
|
||||
JOptionPane.showMessageDialog(ConfigurationWindow.getSingleFrame(), Localizer.get(CANT_WRITE_MESSAGE));
|
||||
}
|
||||
}
|
||||
if (newFilePath.length() < 3) {
|
||||
return;
|
||||
}
|
||||
String exportPath;
|
||||
if (inputFile.isDirectory()) {
|
||||
exportPath = newFilePath;
|
||||
tf_OutputFile.setText(exportPath);
|
||||
} else {
|
||||
String importExt = newFilePath.substring(newFilePath.length() - 3, newFilePath.length()).toLowerCase();
|
||||
if (importExt.equals(ODT_FILE_EXTENSION)) {
|
||||
exportPath = newFilePath.substring(0, newFilePath.length() - 3) + extension;
|
||||
tf_OutputFile.setText(exportPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JButton addChooseOutputButton(JTextField tf_OutputFile, String fileExtension) {
|
||||
btn_ChooseOutputFile_1 = new JButton(Localizer.get(LABEL_BUTTON_CHOOSE));
|
||||
btn_ChooseOutputFile_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FileDialog fileDialog = new FileDialog();
|
||||
String newFilePath = fileDialog.chooseFile(tf_OutputFile.getText(),fileExtension);
|
||||
if (newFilePath != null && !newFilePath.isEmpty()) {
|
||||
tf_OutputFile.setText(newFilePath);
|
||||
}
|
||||
}
|
||||
});
|
||||
return btn_ChooseOutputFile_1;
|
||||
}
|
||||
|
||||
public void setMetadataFilePath(String newFilePath, JTextField tf_MetadataFile, String extension) {
|
||||
|
||||
File inputFile = new File(newFilePath);
|
||||
if (!inputFile.exists()) {
|
||||
return;
|
||||
}
|
||||
if (inputFile.isDirectory()) {
|
||||
tf_MetadataFile.setText(newFilePath);
|
||||
} else {
|
||||
File parent = inputFile.getParentFile();
|
||||
if (parent == null) {
|
||||
return;
|
||||
}
|
||||
if (newFilePath.length() < 3) {
|
||||
return;
|
||||
}
|
||||
String importExt = newFilePath.substring(newFilePath.length()-3, newFilePath.length()).toLowerCase();
|
||||
if (importExt.equals(ODT_FILE_EXTENSION)) {
|
||||
String metadataPath = newFilePath.substring(0, newFilePath.length()-3) + extension;
|
||||
File metaFile = new File(metadataPath);
|
||||
if (metaFile.exists() && metaFile.canRead()){
|
||||
tf_MetadataFile.setText(metadataPath);
|
||||
} else {
|
||||
tf_MetadataFile.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -2,12 +2,10 @@ package pro.litvinovg.w2phtml.gui;
|
|||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
|
@ -16,16 +14,20 @@ import pro.litvinovg.w2phtml.SingleLogArray;
|
|||
import javax.swing.GroupLayout;
|
||||
import javax.swing.GroupLayout.Alignment;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.Color;
|
||||
import javax.swing.LayoutStyle.ComponentPlacement;
|
||||
import java.awt.Toolkit;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
|
||||
public class ResultsDialog extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JTextArea txt_conversionLogs;
|
||||
private static ResultsDialog dialog = null;
|
||||
|
@ -38,6 +40,8 @@ public class ResultsDialog extends JDialog {
|
|||
dialog = new ResultsDialog();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
dialog.setModal(true);
|
||||
dialog.setModalityType (ModalityType.APPLICATION_MODAL);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -60,6 +64,7 @@ public class ResultsDialog extends JDialog {
|
|||
SingleLogArray singleLogArray = SingleLogArray.create();
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
|
||||
JTextArea txtrConversionCompleted = new JTextArea();
|
||||
txtrConversionCompleted.setBackground(Color.WHITE);
|
||||
|
|
126
src/main/java/pro/litvinovg/w2phtml/gui/UIPreferences.java
Normal file
126
src/main/java/pro/litvinovg/w2phtml/gui/UIPreferences.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
package pro.litvinovg.w2phtml.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static pro.litvinovg.w2phtml.gui.Contstants.*;
|
||||
|
||||
public class UIPreferences {
|
||||
private static final Logger logger = LoggerFactory.getLogger(UIPreferences.class);
|
||||
|
||||
private Map<String,String[]> prefs;
|
||||
|
||||
private String sourceFileName = "";
|
||||
|
||||
private boolean defaultTemplate = false;
|
||||
|
||||
private PreferencesStorage storage;
|
||||
|
||||
public void setDefault(boolean defaultTemplate) {
|
||||
this.defaultTemplate = defaultTemplate;
|
||||
}
|
||||
|
||||
public UIPreferences(PreferencesStorage storage) {
|
||||
this.storage = storage;
|
||||
prefs = new HashMap<String,String[]>();
|
||||
}
|
||||
|
||||
public UIPreferences(Map<String,String[]> sourcePrefs) {
|
||||
Iterator<Entry<String, String[]>> it = sourcePrefs.entrySet().iterator();
|
||||
prefs = new HashMap<String,String[]>();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, String[]> pair = (Entry<String, String[]>) it.next();
|
||||
prefs.put(new String(pair.getKey()), Arrays.copyOf(pair.getValue(), pair.getValue().length));
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String name, String[]values) {
|
||||
prefs.put(name, values);
|
||||
}
|
||||
|
||||
public void put(String name, String value) {
|
||||
prefs.put(name, new String[] {value});
|
||||
}
|
||||
|
||||
|
||||
public String getSourceFileName() {
|
||||
return sourceFileName;
|
||||
}
|
||||
|
||||
public void setSourceFileName(String sourceFileName) {
|
||||
this.sourceFileName = sourceFileName;
|
||||
}
|
||||
|
||||
public String[] getAll(String name) {
|
||||
if (prefs.containsKey(name)) {
|
||||
return prefs.get(name);
|
||||
}
|
||||
if (defaultTemplate) {
|
||||
logger.error("Default preferences doesn't have values for " + name);
|
||||
return new String[]{""};
|
||||
}
|
||||
String[] type = prefs.get(PREF_TYPE);
|
||||
if (type == null) {
|
||||
logger.error("Tab preferences doesn't have type!");
|
||||
return new String[] {""};
|
||||
}
|
||||
if (storage == null) {
|
||||
logger.error("Storage is null");
|
||||
return new String[] {""};
|
||||
}
|
||||
UIPreferences defaultPreferences = storage.get(type[0]);
|
||||
return defaultPreferences.getAll(name);
|
||||
}
|
||||
|
||||
public String get(String name) {
|
||||
return getAll(name)[0];
|
||||
}
|
||||
|
||||
public UIPreferences clone() {
|
||||
UIPreferences clonedPrefs = new UIPreferences(prefs);
|
||||
clonedPrefs.setSourceFileName(sourceFileName);
|
||||
return clonedPrefs;
|
||||
}
|
||||
public void updateFrom(HashMap<String, Component> configuration) {
|
||||
Set<String> keys = configuration.keySet();
|
||||
for (String key : keys) {
|
||||
String value = null;
|
||||
Component component = configuration.get(key);
|
||||
if (component.getClass().equals(JTextField.class)) {
|
||||
value = ((JTextField) component).getText();
|
||||
} else if (component.getClass().equals(JCheckBox.class)) {
|
||||
value = Boolean.toString(((JCheckBox) component).isSelected());
|
||||
} else if (component.getClass().equals(JLabel.class)) {
|
||||
value = ((JLabel) component).getText();
|
||||
} else if (component.getClass().equals(JComboBox.class)) {
|
||||
value = Integer.toString(((JComboBox) component).getSelectedIndex());
|
||||
}
|
||||
prefs.put(key, new String[] {value});
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject getJSON() {
|
||||
JSONObject prefObject = new JSONObject();
|
||||
for (Map.Entry<String, String[]> entry : prefs.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
String[] values = entry.getValue();
|
||||
prefObject.put(name, values);
|
||||
}
|
||||
return prefObject;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
converter_title_label=Converter from ODT to HTML, ePub and RDF
|
||||
button_saveas_label=Save As
|
||||
button_save_label=Save
|
||||
button_exit_label=Exit
|
||||
button_convert_label=Convert
|
||||
label_target_format=Output file format
|
||||
label_input_file_path=Input file path
|
||||
label_output_file_path=Output file path
|
||||
label_convert_to_px=Convert dimensions to pixels instead of REM (root em)
|
||||
label_scale=Scale
|
||||
label_embed_raster=Embed raster images
|
||||
label_embed_vector=Embed vector images
|
||||
label_inline_styles=Inline styles
|
||||
label_button_choose=Choose
|
||||
label_max_body_width=Max body width
|
||||
label_min_letter_spacing=Filter letter spacing less than
|
||||
label_ingnore_empty_pars=Filter empty paragraphs
|
||||
label_greenstone_split=Split document into subsections for Greenstone digital library
|
||||
label_break_style=Page break inline style
|
||||
label_pagination=Pagination
|
||||
label_split_whole_pages_only=Split on whole pages only
|
||||
label_use_mathjax=Use MathJax
|
||||
label_fileter_hard_line_breaks=Filter hard line breaks
|
||||
label_metadata_path=Metadata path
|
||||
label_type=Type
|
||||
label_split_by_heading=Split by heading level
|
||||
label_html5=html5
|
||||
error_cant_write=Attention. Can't save file in output directory.
|
||||
message_not_implemented=Not implemented
|
||||
label_image_resolution=Resize image resolution to (PPI)
|
||||
enter_new_config_name=Enter name for new tab
|
||||
config_name_is_already_in_use=Config name is already in use
|
||||
default_config_cant_be_saved=Default tabs configuration can't be saved
|
||||
successfully_saved_config=Tab configuration saved
|
||||
button_delete_label=Delete
|
|
@ -0,0 +1,35 @@
|
|||
converter_title_label=Конвертер из формата ODT в HTML, ePub или RDF
|
||||
button_saveas_label=Сохранить как
|
||||
button_save_label=Сохранить
|
||||
button_exit_label=Закрыть
|
||||
button_convert_label=Запуск
|
||||
label_target_format=Целевой формат файла
|
||||
label_input_file_path=Путь к входному файлу
|
||||
label_output_file_path=Путь к выходному файлу
|
||||
label_convert_to_px=Конвертировать в пиксели (вместо rem)
|
||||
label_scale=Масштаб
|
||||
label_embed_raster=Встроить растровые изображения
|
||||
label_embed_vector=Встроить векторные изображения
|
||||
label_inline_styles=Применить стили внутри html элементов
|
||||
label_button_choose=Выбрать
|
||||
label_max_body_width=Максимальная ширина
|
||||
label_min_letter_spacing=Фильтр утяжки символов
|
||||
label_ingnore_empty_pars=Не конвертировать пустые параграфы
|
||||
label_greenstone_split=Встроить комментарии для содержаний в Greenstone
|
||||
label_break_style=Стиль разрывов страниц
|
||||
label_pagination=Требуется пагинация
|
||||
label_split_whole_pages_only=Разрывы только по границам страниц
|
||||
label_use_mathjax=Встроить библиотеку MathJax для формул
|
||||
label_fileter_hard_line_breaks=Не конвертировать жесткие разрывы строк
|
||||
label_metadata_path=Путь к метаданным
|
||||
label_type=Вид
|
||||
label_split_by_heading=Разделять по заголовкам
|
||||
label_html5=html5
|
||||
error_cant_write=Ошибка. Не удалось сохранить файл в целевую директорию
|
||||
message_not_implemented=Данная функциональность еще не реализована
|
||||
label_image_resolution=Разрешение изображений (PPI)
|
||||
enter_new_config_name=Введите имя новой вкладки
|
||||
config_name_is_already_in_use=Такое имя вкладки уже используется
|
||||
default_config_cant_be_saved=Настройки вкладок по умолчанию нельзя сохранять
|
||||
successfully_saved_config=Настройки вкладки сохранены
|
||||
button_delete_label=Удалить
|
|
@ -67,9 +67,13 @@ public final class Application {
|
|||
* The argument passed on the command line.
|
||||
*/
|
||||
public static final void main(String[] args) throws Exception {
|
||||
if (args.length == 0) {
|
||||
showUsage("");
|
||||
ConfigurationWindow.runGUI(null);
|
||||
if (args.length < 2) {
|
||||
showUsage("");
|
||||
String fileName = "";
|
||||
if (args.length == 1){
|
||||
fileName = args[0];
|
||||
}
|
||||
ConfigurationWindow.runGUI(fileName);
|
||||
} else {
|
||||
try {
|
||||
long time = System.currentTimeMillis();
|
||||
|
|
|
@ -47,8 +47,10 @@ public class ConverterFactory {
|
|||
InputStream stream = loader.getResourceAsStream(propPath);
|
||||
String version = "Failed to get version";
|
||||
try {
|
||||
prop.load(stream);
|
||||
version = (String) prop.get("releaseVersion");
|
||||
if (stream != null) {
|
||||
prop.load(stream);
|
||||
version = (String) prop.get("releaseVersion");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -65,8 +67,10 @@ public class ConverterFactory {
|
|||
InputStream stream = loader.getResourceAsStream(propPath);
|
||||
String date = "Failed to get date";
|
||||
try {
|
||||
prop.load(stream);
|
||||
date = (String) prop.get("releaseDate");
|
||||
if (stream != null) {
|
||||
prop.load(stream);
|
||||
date = (String) prop.get("releaseDate");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -39,11 +39,15 @@ import javax.imageio.ImageIO;
|
|||
import org.apache.commons.imaging.ImageInfo;
|
||||
import org.apache.commons.imaging.ImageReadException;
|
||||
import org.apache.commons.imaging.Imaging;
|
||||
import org.imgscalr.Scalr;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import w2phtml.api.OutputFile;
|
||||
import w2phtml.office.MIMETypes;
|
||||
import w2phtml.office.StyleWithProperties;
|
||||
import w2phtml.util.DimensionsConverter;
|
||||
import w2phtml.xhtml.XhtmlConfig;
|
||||
|
||||
/** This class is used to represent a binary graphics document to be included in the converter result.
|
||||
* I may also represent a linked image, which should <em>not</em> be included (and will produce an empty file
|
||||
|
@ -51,11 +55,12 @@ import w2phtml.util.DimensionsConverter;
|
|||
*/
|
||||
public class BinaryGraphicsDocument implements OutputFile {
|
||||
|
||||
private String sFileName;
|
||||
private String sMimeType;
|
||||
|
||||
private boolean bAcceptedFormat;
|
||||
|
||||
private String sFileName;
|
||||
private String sMimeType;
|
||||
private String imageName = "";
|
||||
|
||||
private boolean bAcceptedFormat;
|
||||
|
||||
private boolean bRecycled = false;
|
||||
|
||||
// Data for an embedded image
|
||||
|
@ -65,6 +70,8 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
private boolean cropped = false;
|
||||
private float horizontalPPI = 96.0F;
|
||||
private float verticalPPI = 96.0F;
|
||||
private static final Logger logger = LoggerFactory.getLogger(BinaryGraphicsDocument.class);
|
||||
|
||||
|
||||
/**Constructs a new graphics document.
|
||||
* Until data is added using the <code>read</code> methods, the document is considered a link to
|
||||
|
@ -90,6 +97,7 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
this.sMimeType = bgd.getMIMEType();
|
||||
this.blob = bgd.getData();
|
||||
this.bAcceptedFormat = bgd.isAcceptedFormat();
|
||||
this.imageName = bgd.getImageName();
|
||||
this.bRecycled = true;
|
||||
|
||||
}
|
||||
|
@ -106,6 +114,7 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
this.horizontalPPI = widthDPI;
|
||||
}
|
||||
} catch (ImageReadException | IOException e) {
|
||||
logger.error("Image " + getImageName() + " error reading image info.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -216,48 +225,116 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
|
||||
/* Crop image from byte array */
|
||||
public void cropImage(StyleWithProperties style) {
|
||||
if (blob == null || style == null) {
|
||||
return;
|
||||
}
|
||||
if (sMimeType == null || (
|
||||
!sMimeType.equals(MIMETypes.PNG)
|
||||
&& !sMimeType.equals(MIMETypes.JPEG)
|
||||
&& !sMimeType.equals(MIMETypes.GIF)
|
||||
&& !sMimeType.equals(MIMETypes.TIFF)
|
||||
)){
|
||||
if (blob == null || style == null || isInvalidImageFormat()) {
|
||||
return;
|
||||
}
|
||||
extractPPI();
|
||||
int[] offsets = getOffsets(style);
|
||||
if (offsets[0] == 0 && offsets[1] == 0 && offsets[2] == 0 && offsets[3] == 0) {
|
||||
if (isNotCropped(offsets)) {
|
||||
return;
|
||||
}
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(blob);
|
||||
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(bis);
|
||||
if (image == null) {
|
||||
logger.error("Image " + getImageName() + " couldn't be processed as it is damaged or has unknown format.");
|
||||
return;
|
||||
}
|
||||
int height = image.getHeight();
|
||||
int width = image.getWidth();
|
||||
String formatName = MIMETypes.getFormatType(blob);
|
||||
int leftOffset = offsets[3];
|
||||
int topOffset = offsets[0];
|
||||
int newWidth = width - offsets[3] - offsets[1];
|
||||
int newHeight = height - offsets[0] - offsets[2];
|
||||
BufferedImage croppedImage = image.getSubimage(leftOffset, topOffset, newWidth , newHeight );
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
int croppedWidth = width - offsets[3] - offsets[1];
|
||||
int croppedHeight = height - offsets[0] - offsets[2];
|
||||
if ( croppedHeight <= 0) {
|
||||
throw new IOException("Cropped image height < 0");
|
||||
}
|
||||
if ( croppedWidth <= 0 ) {
|
||||
throw new IOException("Cropped image width < 0");
|
||||
}
|
||||
|
||||
BufferedImage croppedImage = new BufferedImage(croppedWidth, croppedHeight, BufferedImage.TYPE_3BYTE_BGR);
|
||||
int px[] = new int[croppedWidth * croppedHeight];
|
||||
image.getRGB(leftOffset, topOffset, croppedWidth, croppedHeight, px, 0, croppedWidth);
|
||||
croppedImage.setRGB(0, 0, croppedWidth, croppedHeight, px, 0, croppedWidth);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(croppedImage, "JPG", baos);
|
||||
sMimeType = MIMETypes.JPEG;
|
||||
this.blob = baos.toByteArray();
|
||||
if (blob.length == 0) {
|
||||
throw new IOException();
|
||||
}
|
||||
this.cropped = true;
|
||||
updateFileName(offsets);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.error("Error. Image " + getImageName() + " " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
} catch (RasterFormatException e ) {
|
||||
System.out.println(e.getLocalizedMessage());
|
||||
logger.error("Error. Image " + getImageName() + " " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void applyQuality(StyleWithProperties style, XhtmlConfig config) {
|
||||
float targetPPI = config.getImageResolution();
|
||||
//int targetQuality = config.getImageQuality();
|
||||
//float quality = targetQuality / 100;
|
||||
if (blob == null || style == null || isInvalidImageFormat() || targetPPI < 1) {
|
||||
return;
|
||||
}
|
||||
extractPPI();
|
||||
if (targetPPI >= verticalPPI || targetPPI >= horizontalPPI ) {
|
||||
return;
|
||||
}
|
||||
float minPPI = Math.min(verticalPPI, horizontalPPI);
|
||||
double divider = minPPI / targetPPI;
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(blob);
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(bis);
|
||||
if (image == null) {
|
||||
logger.error("Image " + getImageName() + " couldn't be processed as it is damaged or has unknown format.");
|
||||
return;
|
||||
}
|
||||
int width = image.getWidth();
|
||||
if (width > 0) {
|
||||
Integer newWidth = (int) ( width/divider);
|
||||
BufferedImage resizedImage = Scalr.resize(image, newWidth);
|
||||
BufferedImage jpgImage = getJPGImage(resizedImage);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(jpgImage, "JPG", baos);
|
||||
this.blob = baos.toByteArray();
|
||||
extractPPI();
|
||||
} else {
|
||||
logger.error("Error. Image " + getImageName() + " width = 0");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Error. Image " + getImageName() + " " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage getJPGImage(BufferedImage resizedImage) {
|
||||
if (resizedImage.getType() == BufferedImage.TYPE_3BYTE_BGR){
|
||||
return resizedImage;
|
||||
}
|
||||
BufferedImage jpgImage = new BufferedImage(resizedImage.getWidth(), resizedImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
|
||||
int px[] = new int[resizedImage.getWidth() * resizedImage.getHeight()];
|
||||
resizedImage.getRGB(0, 0, resizedImage.getWidth(), resizedImage.getHeight(), px, 0, resizedImage.getWidth());
|
||||
jpgImage.setRGB(0, 0, resizedImage.getWidth(), resizedImage.getHeight(), px, 0, resizedImage.getWidth());
|
||||
return jpgImage;
|
||||
}
|
||||
|
||||
private boolean isNotCropped(int[] offsets) {
|
||||
return offsets[0] == 0 && offsets[1] == 0 && offsets[2] == 0 && offsets[3] == 0;
|
||||
}
|
||||
|
||||
private boolean isInvalidImageFormat() {
|
||||
return sMimeType == null || (
|
||||
!sMimeType.equals(MIMETypes.PNG)
|
||||
&& !sMimeType.equals(MIMETypes.JPEG)
|
||||
&& !sMimeType.equals(MIMETypes.GIF)
|
||||
&& !sMimeType.equals(MIMETypes.TIFF)
|
||||
);
|
||||
}
|
||||
|
||||
private void updateFileName(int[] offsets) {
|
||||
|
@ -293,6 +370,16 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
return offsets;
|
||||
}
|
||||
|
||||
public void setImageName(String imageName) {
|
||||
this.imageName = imageName;
|
||||
}
|
||||
|
||||
public String getImageName() {
|
||||
if (imageName == null || imageName.isEmpty()) {
|
||||
return sFileName;
|
||||
}
|
||||
return imageName;
|
||||
}
|
||||
/** Does this document contain formulas?
|
||||
*
|
||||
* @return false - a graphics file does not contain formulas
|
||||
|
@ -300,4 +387,7 @@ public class BinaryGraphicsDocument implements OutputFile {
|
|||
public boolean containsMath() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -195,6 +195,7 @@ public final class ImageConverter {
|
|||
private BinaryGraphicsDocument getImage(Element node, String sName) {
|
||||
assert(XMLString.DRAW_IMAGE.equals(node.getTagName()));
|
||||
|
||||
String imageName = getImageName(node);
|
||||
// Image data
|
||||
String sExt = null;
|
||||
String sMIME = null;
|
||||
|
@ -234,8 +235,8 @@ public final class ImageConverter {
|
|||
// This is a linked image
|
||||
// TODO: Add option to download image from the URL?
|
||||
String sFileName = ofr.fixRelativeLink(sHref);
|
||||
BinaryGraphicsDocument bgd
|
||||
= new BinaryGraphicsDocument(sFileName,null);
|
||||
BinaryGraphicsDocument bgd = new BinaryGraphicsDocument(sFileName,null);
|
||||
bgd.setImageName(imageName);
|
||||
return bgd;
|
||||
}
|
||||
}
|
||||
|
@ -281,8 +282,8 @@ public final class ImageConverter {
|
|||
int[] offlen = new int[2];
|
||||
if (SVMReader.readSVM(blob,offlen)) {
|
||||
String sFileName = sName+MIMETypes.EPS_EXT;
|
||||
BinaryGraphicsDocument bgd
|
||||
= new BinaryGraphicsDocument(sFileName, MIMETypes.EPS);
|
||||
BinaryGraphicsDocument bgd = new BinaryGraphicsDocument(sFileName, MIMETypes.EPS);
|
||||
bgd.setImageName(imageName);
|
||||
bgd.setData(blob,offlen[0],offlen[1],true);
|
||||
return bgd;
|
||||
}
|
||||
|
@ -319,6 +320,7 @@ public final class ImageConverter {
|
|||
if (isAcceptedFormat(sMIME) || bAcceptOtherFormats) {
|
||||
String sFileName = sName+sExt;
|
||||
BinaryGraphicsDocument bgd = new BinaryGraphicsDocument(sFileName,sMIME);
|
||||
bgd.setImageName(imageName);
|
||||
bgd.setData(blob,isAcceptedFormat(sMIME));
|
||||
if (sId!=null) {
|
||||
recycledImages.put(sId, new BinaryGraphicsDocument(bgd));
|
||||
|
@ -330,13 +332,23 @@ public final class ImageConverter {
|
|||
}
|
||||
}
|
||||
|
||||
private Element getAlternativeImage(Element node) {
|
||||
Node sibling = node.getNextSibling();
|
||||
if (sibling!=null && Misc.isElement(sibling, XMLString.DRAW_IMAGE)) {
|
||||
return (Element) sibling;
|
||||
private String getImageName(Element node) {
|
||||
Node parent = node.getParentNode();
|
||||
if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE || parent.getNodeName() != XMLString.DRAW_FRAME) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Element frame = (Element) parent;
|
||||
String name = frame.getAttribute(XMLString.DRAW_NAME);
|
||||
return name;
|
||||
}
|
||||
|
||||
private Element getAlternativeImage(Element node) {
|
||||
Node sibling = node.getNextSibling();
|
||||
if (sibling != null && Misc.isElement(sibling, XMLString.DRAW_IMAGE)) {
|
||||
return (Element) sibling;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create a fingerprint of a blob. The fingerprint concatenates the MD5 hash with the first 10 bytes of the blob.
|
||||
private String createId(byte[] blob) {
|
||||
|
|
|
@ -111,13 +111,13 @@ public class ListCounter {
|
|||
}
|
||||
|
||||
public String getLabelAndSuffix() {
|
||||
String sLabel="";
|
||||
if (style != null && style.isNumber(nLevel)) {
|
||||
String sLabel="";
|
||||
if (sNumFormat[nLevel]==null) return "";
|
||||
int nLevels = Misc.getPosInteger(style.getLevelProperty(nLevel,
|
||||
XMLString.TEXT_DISPLAY_LEVELS),1);
|
||||
String sSuffix = style.getLevelProperty(nLevel,XMLString.STYLE_NUM_SUFFIX);
|
||||
String sSpace = "nothing".equals(style.getLevelStyleProperty(nLevel, XMLString.TEXT_LABEL_FOLLOWED_BY)) ? "" : " ";
|
||||
String sSuffix = getSuffix();
|
||||
String sSpace = getSpace();
|
||||
for (int j=nLevel-nLevels+1; j<nLevel; j++) {
|
||||
sLabel+=formatNumber(nCounter[j],sNumFormat[j],true)+".";
|
||||
}
|
||||
|
@ -125,15 +125,23 @@ public class ListCounter {
|
|||
sLabel+=formatNumber(nCounter[nLevel],sNumFormat[nLevel],true);
|
||||
if (sSuffix!=null) { sLabel+=sSuffix; }
|
||||
if (sLabel.length()>0 && sSpace!=null) { sLabel+=sSpace; }
|
||||
return sLabel;
|
||||
}
|
||||
else if (style != null && style.isBullet(nLevel)) {
|
||||
return style.getLevelProperty(nLevel,XMLString.TEXT_BULLET_CHAR);
|
||||
sLabel = style.getLevelProperty(nLevel,XMLString.TEXT_BULLET_CHAR);
|
||||
String sSpace = getSpace();
|
||||
if (sLabel.length()>0 && sSpace!=null) { sLabel+=sSpace; }
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
|
||||
return sLabel;
|
||||
}
|
||||
|
||||
private String getSpace() {
|
||||
return "nothing".equals(style.getLevelStyleProperty(nLevel, XMLString.TEXT_LABEL_FOLLOWED_BY)) ? "" : " ";
|
||||
}
|
||||
|
||||
private String getSuffix() {
|
||||
return style.getLevelProperty(nLevel,XMLString.STYLE_NUM_SUFFIX);
|
||||
}
|
||||
|
||||
// Utility method to generate number
|
||||
private String formatNumber(int number,String sStyle,boolean bLetterSync) {
|
||||
|
|
|
@ -101,6 +101,14 @@ public class BasicSplitter {
|
|||
return false;
|
||||
}
|
||||
|
||||
protected static boolean isRootElement(Node node) {
|
||||
Node parent = node.getParentNode();
|
||||
if (parent.getNodeName().equals("office:text")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static void removeSPB(Node node) {
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
if (node.getNodeName().equals(TEXT_SOFT_PAGE_BREAK)) {
|
||||
|
|
73
src/main/java/w2phtml/pageSplitters/ListBreaksFix.java
Normal file
73
src/main/java/w2phtml/pageSplitters/ListBreaksFix.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
package w2phtml.pageSplitters;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import pro.litvinovg.w2phtml.gui.ConversionExecutor;
|
||||
import pro.litvinovg.xml.Debug;
|
||||
import w2phtml.office.OfficeReader;
|
||||
import w2phtml.office.StyleWithProperties;
|
||||
import w2phtml.util.Misc;
|
||||
|
||||
import static w2phtml.office.XMLString.TEXT_LIST_ITEM;
|
||||
import static w2phtml.office.XMLString.TEXT_SOFT_PAGE_BREAK;
|
||||
import static w2phtml.office.XMLString.TEXT_STYLE_NAME;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static w2phtml.office.XMLString.TEXT_P;
|
||||
import static w2phtml.office.XMLString.TEXT_H;
|
||||
import static w2phtml.office.XMLString.FO_BREAK_BEFORE;
|
||||
|
||||
|
||||
|
||||
public class ListBreaksFix {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ListBreaksFix.class);
|
||||
private OfficeReader ofr;
|
||||
|
||||
public ListBreaksFix(OfficeReader ofr) {
|
||||
this.ofr = ofr;
|
||||
}
|
||||
// Hack to fix hard breaks splitting in lists
|
||||
public void addSPBsBeforeBreaksInLists(Node onode) {
|
||||
try {
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
||||
Document document = onode.getOwnerDocument();
|
||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||
String expression = "//*[starts-with(local-name(),'list-item')]//*[starts-with(local-name(),'p') ]";
|
||||
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET);
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
Node paragraph = nodeList.item(i);
|
||||
if (hasBreakBefore(paragraph)) {
|
||||
Node spb = document.createElement(TEXT_SOFT_PAGE_BREAK);
|
||||
paragraph.getParentNode().insertBefore(spb, paragraph);
|
||||
}
|
||||
}
|
||||
} catch (XPathExpressionException e) {
|
||||
logger.error("Error fixing hard breaks in lists" + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
logger.error("Error fixing hard breaks in lists" + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private boolean hasBreakBefore(Node node) {
|
||||
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(node,TEXT_STYLE_NAME));
|
||||
if (style != null && "page".equals(style.getProperty(FO_BREAK_BEFORE))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -38,8 +38,11 @@ public class ListItemSplitter extends BasicSplitter implements ISplitter {
|
|||
listItem.removeChild(listItemChild);
|
||||
//System.out.println("LIST ITEM SPLITTER REMOVE SPB");
|
||||
} else if (nodeName.equals(TEXT_LIST)) {
|
||||
factory.split(listItemChild);
|
||||
|
||||
SplitResults listSplitResults = factory.split(listItemChild);
|
||||
if (listSplitResults.isDataMoved()) {
|
||||
listItemFirstPart.appendChild(listSplitResults.getFirstPart());
|
||||
results.setDataMoved(true);
|
||||
}
|
||||
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
|
||||
if (factory.split(listItemChild).isDataMoved()){
|
||||
listItemFirstPart.appendChild(listItemChild.getPreviousSibling());
|
||||
|
|
|
@ -6,13 +6,11 @@ import static w2phtml.office.XMLString.TEXT_LIST_ITEM;
|
|||
import static w2phtml.office.XMLString.TEXT_LIST;
|
||||
import static w2phtml.office.XMLString.TEXT_SOFT_PAGE_BREAK;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import pro.litvinovg.xml.Debug;
|
||||
import w2phtml.office.OfficeReader;
|
||||
|
||||
public class ListSplitter extends BasicSplitter implements ISplitter {
|
||||
|
@ -25,7 +23,7 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
|
|||
public SplitResults Split(Node list) {
|
||||
Node parent = list.getParentNode();
|
||||
// System.out.println("----Start ListSplitter------");
|
||||
// Debug.prettyPrintXml(parent);
|
||||
//Debug.prettyPrintXml(list.getOwnerDocument());
|
||||
Node listFirstPart = list.cloneNode(false);
|
||||
NodeList listNodes = list.getChildNodes();
|
||||
Document document = list.getOwnerDocument();
|
||||
|
@ -60,9 +58,14 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
|
|||
} else {
|
||||
list.removeChild(child);
|
||||
}
|
||||
} else {
|
||||
//Debug.printNode(child);
|
||||
//Found SPB at start of the list
|
||||
//Add SPB before the list
|
||||
if (isRootElement(list)) {
|
||||
parent.insertBefore(softPageBreak, list);
|
||||
}
|
||||
}
|
||||
// Debug.printNode(child);
|
||||
|
||||
break;
|
||||
} else {
|
||||
// Not with SPB yet, move node, set dataMoved=true
|
||||
|
@ -76,14 +79,18 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
|
|||
}
|
||||
}
|
||||
if (results.isDataMoved()) {
|
||||
//Debug.prettyPrintXml(list.getOwnerDocument());
|
||||
((Element) list).setAttribute(TEXT_CONTINUE_NUMBERING, "true");
|
||||
parent.insertBefore(listFirstPart, list);
|
||||
parent.insertBefore(softPageBreak, list);
|
||||
if (isRootElement(list)) {
|
||||
parent.insertBefore(softPageBreak, list);
|
||||
}
|
||||
results.setSPB(softPageBreak);
|
||||
// System.out.println("LIST FIRST PART");
|
||||
// Debug.printNode(listFirstPart);
|
||||
// TODO: Create dummy list style to override list item to not teleport
|
||||
// second part but making it list item without list mark
|
||||
//Debug.prettyPrintXml(list.getOwnerDocument());
|
||||
|
||||
if (nextPageItemPart != null) {
|
||||
Node nextPageFirstNode = nextPageItemPart.getFirstChild();
|
||||
|
@ -92,14 +99,16 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
|
|||
while (freeNodes.getLength() > 0) {
|
||||
Node freeNode = freeNodes.item(i);
|
||||
String freeNodeName = freeNode.getNodeName();
|
||||
if (StringUtils.equals(TEXT_LIST, freeNodeName)) {
|
||||
if (TEXT_LIST.equals(freeNodeName)) {
|
||||
break;
|
||||
}
|
||||
parent.insertBefore(freeNode, list);
|
||||
}
|
||||
//Debug.prettyPrintXml(list.getOwnerDocument());
|
||||
if (!nextPageItemPart.hasChildNodes()) {
|
||||
list.removeChild(nextPageItemPart);
|
||||
}
|
||||
//Debug.prettyPrintXml(list.getOwnerDocument());
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -108,8 +117,7 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
|
|||
}
|
||||
// System.out.println("----Finish ListSplitter------");
|
||||
|
||||
// Debug.prettyPrintXml(parent);
|
||||
|
||||
//Debug.prettyPrintXml(list.getOwnerDocument());
|
||||
return results;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.w3c.dom.Element;
|
|||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import pro.litvinovg.xml.Debug;
|
||||
import w2phtml.office.OfficeReader;
|
||||
|
||||
public class SectionSplitter extends BasicSplitter implements ISplitter {
|
||||
|
@ -53,8 +54,11 @@ public class SectionSplitter extends BasicSplitter implements ISplitter {
|
|||
continue;
|
||||
} else if (nodeName.equals(TABLE_TABLE)) {
|
||||
if (factory.split(child).isDataMoved()){
|
||||
//Debug.prettyPrintXml(section.getOwnerDocument());
|
||||
sectionFirstPart.appendChild(child.getPreviousSibling());
|
||||
results.setDataMoved(true);
|
||||
//Debug.prettyPrintXml(section.getOwnerDocument());
|
||||
|
||||
}
|
||||
} else if (nodeName.equals(TEXT_SECTION)) {
|
||||
if (factory.split(child).isDataMoved()){
|
||||
|
@ -66,10 +70,6 @@ public class SectionSplitter extends BasicSplitter implements ISplitter {
|
|||
if (listSplitResults.isDataMoved()){
|
||||
results.setDataMoved(true);
|
||||
sectionFirstPart.appendChild(listSplitResults.getFirstPart());
|
||||
Node textListSpb = listSplitResults.getSPB();
|
||||
if (textListSpb != null) {
|
||||
textListSpb.getParentNode().removeChild(textListSpb);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Error. SPB in Section child node " + nodeName);
|
||||
|
|
|
@ -9,6 +9,7 @@ import static w2phtml.office.XMLString.TEXT_SOFT_PAGE_BREAK;
|
|||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import pro.litvinovg.xml.Debug;
|
||||
import w2phtml.office.OfficeReader;
|
||||
|
||||
public class TableCellSplitter extends BasicSplitter implements ISplitter {
|
||||
|
@ -40,10 +41,16 @@ public class TableCellSplitter extends BasicSplitter implements ISplitter {
|
|||
results.setDataMoved(true);
|
||||
}
|
||||
} else if (nodeName.equals(TEXT_LIST)) {
|
||||
if (factory.split(cellChildNode).isDataMoved()){
|
||||
cellFirstPart.appendChild(cellChildNode.getPreviousSibling());
|
||||
SplitResults listSplitResults = factory.split(cellChildNode);
|
||||
if (listSplitResults.isDataMoved()){
|
||||
//Debug.prettyPrintXml(cellNode.getOwnerDocument());
|
||||
cellFirstPart.appendChild(listSplitResults.getFirstPart());
|
||||
results.setDataMoved(true);
|
||||
//Debug.prettyPrintXml(cellNode.getOwnerDocument());
|
||||
}
|
||||
if (!cellChildNode.hasChildNodes()) {
|
||||
cellNode.removeChild(cellChildNode);
|
||||
}
|
||||
} else if (nodeName.equals(TABLE_TABLE)) {
|
||||
if (factory.split(cellChildNode).isDataMoved()){
|
||||
cellFirstPart.appendChild(cellChildNode.getPreviousSibling());
|
||||
|
@ -69,6 +76,8 @@ public class TableCellSplitter extends BasicSplitter implements ISplitter {
|
|||
if (results.isDataMoved()) {
|
||||
parent.insertBefore(cellFirstPart, cellNode);
|
||||
}
|
||||
//Debug.prettyPrintXml(cellNode.getOwnerDocument());
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
|
|
|
@ -37,9 +37,9 @@ public class DocumentPart {
|
|||
private String parentPath;
|
||||
private String name = null;
|
||||
private String order = null;
|
||||
private Metadata metadata = null;
|
||||
private MetadataContainer metadata = null;
|
||||
|
||||
public DocumentPart(XhtmlDocument document,Metadata metadata) {
|
||||
public DocumentPart(XhtmlDocument document,MetadataContainer metadata) {
|
||||
this.excerptDoc = document;
|
||||
this.metadata = metadata;
|
||||
extractPath();
|
||||
|
@ -50,7 +50,7 @@ public class DocumentPart {
|
|||
extractAnnotationMetadata();
|
||||
}
|
||||
|
||||
public DocumentPart(String path, Metadata metadata) {
|
||||
public DocumentPart(String path, MetadataContainer metadata) {
|
||||
this.path = path;
|
||||
this.metadata = metadata;
|
||||
this.name = "";
|
||||
|
|
|
@ -19,28 +19,28 @@ import org.slf4j.LoggerFactory;
|
|||
import com.opencsv.CSVReaderHeaderAware;
|
||||
import com.opencsv.exceptions.CsvValidationException;
|
||||
|
||||
public class Metadata {
|
||||
public class MetadataContainer {
|
||||
private static final String SUBTITLE = "subtitle";
|
||||
private static final String FILENAME = "Filename";
|
||||
private static final String SECTION = "Section";
|
||||
private static final Logger logger = LoggerFactory.getLogger(Metadata.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(MetadataContainer.class);
|
||||
|
||||
private HashMap<String, ArrayList<Map<String, String>>> sectionsMetadata;
|
||||
|
||||
public Metadata() {
|
||||
public MetadataContainer() {
|
||||
sectionsMetadata = new HashMap<String, ArrayList<Map<String, String>>>();
|
||||
|
||||
}
|
||||
|
||||
public void read(String metadataFilePath) {
|
||||
if (metadataFilePath == null) {
|
||||
public void read(String filePath) {
|
||||
if (filePath == null) {
|
||||
return;
|
||||
}
|
||||
File file = new File(metadataFilePath);
|
||||
File file = new File(filePath);
|
||||
if (!file.exists() || !file.canRead()) {
|
||||
return;
|
||||
}
|
||||
readCSVFile(metadataFilePath);
|
||||
readCSVFile(filePath);
|
||||
}
|
||||
|
||||
private void readCSVFile(String filePath) {
|
|
@ -2,39 +2,8 @@ package w2phtml.rdf;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.stream.events.Namespace;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.apache.jena.rdf.model.Model;
|
||||
import org.apache.jena.rdf.model.ModelFactory;
|
||||
import org.apache.jena.rdf.model.Property;
|
||||
import org.apache.jena.rdf.model.Resource;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.ls.DOMImplementationLS;
|
||||
import org.w3c.dom.ls.LSSerializer;
|
||||
|
||||
import com.sun.org.apache.xml.internal.utils.NameSpace;
|
||||
|
||||
import pro.litvinovg.xml.Debug;
|
||||
import w2phtml.api.ConverterResult;
|
||||
import w2phtml.api.OutputFile;
|
||||
import w2phtml.base.ConverterResultImpl;
|
||||
import w2phtml.xhtml.Converter;
|
||||
import w2phtml.xhtml.XhtmlDocument;
|
||||
|
|
|
@ -18,6 +18,9 @@ import org.apache.jena.ontology.OntModel;
|
|||
import org.apache.jena.rdf.model.ModelFactory;
|
||||
import org.apache.jena.rdf.model.Resource;
|
||||
import org.apache.jena.vocabulary.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import static w2phtml.util.Transliteration.*;
|
||||
|
||||
import w2phtml.xhtml.XhtmlConfig;
|
||||
import w2phtml.xhtml.XhtmlDocument;
|
||||
|
@ -25,18 +28,32 @@ import w2phtml.xhtml.XhtmlDocument;
|
|||
import org.apache.jena.rdf.model.Property;
|
||||
|
||||
|
||||
public class DocumentStructure {
|
||||
public class RDFDocument {
|
||||
|
||||
private static final String FORMAT_RDF = "RDF/XML-ABBREV";
|
||||
private static final String AFFILIATED_ORGANIZATION_POSTAL_CODE = "affiliated organization postal code";
|
||||
private static final String AFFILIATED_ORGANIZATION_ADDRESS = "affiliated organization address";
|
||||
private static final String AFFILIATED_ORGANIZATION_OFFICIAL_NAME = "affiliated organization official name";
|
||||
private static final String AFFILIATED_ORGANIZATION_NAME = "affiliated organization name";
|
||||
private static final String AUTHOR_INITIALS = "author initials";
|
||||
private static final String AUTHOR_EMAIL = "author email";
|
||||
private static final String AUTHOR_FAMILY = "author family";
|
||||
private static final Logger logger = LoggerFactory.getLogger(RDFDocument.class);
|
||||
private static final String AUTHOR_GIVEN_NAME = "author given name";
|
||||
private static final String MODIFICATION_TIME = "modificationTime";
|
||||
private static final String HTML_EXCERPT_PROPERTY = "htmlExcerpt";
|
||||
private static final String TOCITEM = "TOCItem";
|
||||
private static final String TOC_ITEM = "TOCItem";
|
||||
private static final String TS = "https://litvinovg.pro/text_structures#";
|
||||
private static final String PARSERNAME = "w2phtml";
|
||||
private static final String POINTS_TO = TS + "pointsTo";
|
||||
private static final String ITEM_NUMBER = TS + "itemNumber";
|
||||
private static final String HAS_TOC_ITEM = TS + "hasTOCItem";
|
||||
private static final String HAS_TEXT = TS + "hasText";
|
||||
//private static final String PARSERNAME = "w2phtml";
|
||||
private static final String TEXT_EXCERPT = "textExcerpt";
|
||||
private static final String TOC_LEVEL = "TOCLevel";
|
||||
private static final String TABLE_OF_CONTENTS = "TOC";
|
||||
private static final String PARTICIPANT = "publicationParticipant";
|
||||
private static final String ORGANIZATION = "organization";
|
||||
|
||||
private static final String PUBLICATION = "publication";
|
||||
private static final String BOOK = "book";
|
||||
private static final String JOURNAL = "journal";
|
||||
|
@ -61,10 +78,10 @@ public class DocumentStructure {
|
|||
|
||||
private HashMap<String, Resource> tocLevels;
|
||||
private HashMap<String, DocumentPart> inputParts;
|
||||
private Metadata metadata;
|
||||
private MetadataContainer metadata;
|
||||
private Date currentTime;
|
||||
|
||||
public DocumentStructure(Vector<XhtmlDocument> files,String fileName, XhtmlConfig config,Metadata metadata) {
|
||||
public RDFDocument(Vector<XhtmlDocument> files,String fileName, XhtmlConfig config, MetadataContainer metadata) {
|
||||
this.tocLevels = new HashMap<String, Resource>();
|
||||
this.inputParts = new HashMap<String, DocumentPart>();
|
||||
this.m = ModelFactory.createOntologyModel();
|
||||
|
@ -74,11 +91,10 @@ public class DocumentStructure {
|
|||
this.tocClass = textOntology.createClass(TS + TABLE_OF_CONTENTS);
|
||||
this.organizationClass = textOntology.createClass(TS + ORGANIZATION);
|
||||
this.participantClass = textOntology.createClass(TS + PARTICIPANT);
|
||||
this.itemClass = textOntology.createClass(TS + TOCITEM);
|
||||
this.docID = fileName;
|
||||
this.itemClass = textOntology.createClass(TS + TOC_ITEM);
|
||||
formatDocID(fileName);
|
||||
this.currentTime = Calendar.getInstance().getTime();
|
||||
String publicationType = config.getRDFType();
|
||||
setPublicationType(publicationType);
|
||||
setPublicationType(config.getRDFType());
|
||||
this.documentClass = textOntology.createClass(TS + documentType);
|
||||
this.excerptClass = textOntology.createClass(TS + excerptType);
|
||||
for(int i = 0 ; i< files.size();i++) {
|
||||
|
@ -88,6 +104,12 @@ public class DocumentStructure {
|
|||
addPart(part);
|
||||
}
|
||||
addEmptyParts();
|
||||
createElements();
|
||||
createTOCItems();
|
||||
}
|
||||
|
||||
public void printModel(OutputStream os) {
|
||||
m.write(os,FORMAT_RDF);
|
||||
}
|
||||
|
||||
private void setPublicationType(String publicationType) {
|
||||
|
@ -135,37 +157,13 @@ public class DocumentStructure {
|
|||
}
|
||||
return emptyPath.toString();
|
||||
}
|
||||
|
||||
public void printModel(String fileName) {
|
||||
File outFile = new File(fileName + ".rdf");
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
outFile.createNewFile();
|
||||
fw = new FileWriter(outFile);
|
||||
m.write(fw,"RDF/XML-ABBREV");
|
||||
|
||||
} catch (IOException e) {
|
||||
System.out.println("File couldn't be created");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
fw.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void printModel(OutputStream os) {
|
||||
m.write(os,"RDF/XML-ABBREV");
|
||||
}
|
||||
|
||||
private void addPart(DocumentPart docExcerpt) {
|
||||
inputParts.put(docExcerpt.getPath(), docExcerpt);
|
||||
}
|
||||
|
||||
private Resource createExcerpt(DocumentPart docExcerpt) {
|
||||
String excerptName = TS + excerptType + "/" + PARSERNAME + "_" + docID + docExcerpt.getSafePath();
|
||||
String excerptName = TS + excerptType + "/" + docID + docExcerpt.getSafePath();
|
||||
Resource excerpt = m.createIndividual(excerptName, excerptClass);
|
||||
addModificationTime(excerpt);
|
||||
if (!docExcerpt.getBody().isEmpty()) {
|
||||
|
@ -176,7 +174,7 @@ public class DocumentStructure {
|
|||
}
|
||||
|
||||
private void createTOCLevel(DocumentPart docPart) {
|
||||
String levelName = TS + TOC_LEVEL + "/" + PARSERNAME + "_" + docID + docPart.getSafePath();
|
||||
String levelName = TS + TOC_LEVEL + "/" + docID + docPart.getSafePath();
|
||||
Resource level = m.createIndividual(levelName,tocLevelClass);
|
||||
level.addProperty( RDFS.label, docPart.getName());
|
||||
tocLevels.put(docPart.getPath(), level);
|
||||
|
@ -184,13 +182,13 @@ public class DocumentStructure {
|
|||
}
|
||||
|
||||
private void createDocument(DocumentPart docPart) {
|
||||
String documentURI = TS + documentType + "/" + PARSERNAME + "_" + docID ;
|
||||
String documentURI = TS + documentType + "/" + docID ;
|
||||
Resource mainResource = m.createResource(documentURI, documentClass);
|
||||
mainResource.addProperty( RDFS.label, docPart.getName());
|
||||
|
||||
addModificationTime(mainResource);
|
||||
|
||||
String tocURI = TS + TABLE_OF_CONTENTS + "/" + PARSERNAME + "_" + docID ;
|
||||
String tocURI = TS + TABLE_OF_CONTENTS + "/" + docID ;
|
||||
Resource toc = m.createResource(tocURI, tocClass);
|
||||
toc.addProperty( RDFS.label, docPart.getName());
|
||||
|
||||
|
@ -211,80 +209,79 @@ public class DocumentStructure {
|
|||
mainResource.addProperty( property, todayAsString);
|
||||
}
|
||||
|
||||
private void addAuthor(Resource resource, DocumentPart docPart) {
|
||||
private void addAuthor(Resource excerpt, DocumentPart docPart) {
|
||||
String order = docPart.getOrder();
|
||||
ArrayList<Map<String, String>> sectionMeta = metadata.getSection(order);
|
||||
for (Map<String, String> map : sectionMeta) {
|
||||
Set<String> names = map.keySet();
|
||||
if (names.contains("author given name")) {
|
||||
attachAuthor(resource, map, order);
|
||||
for (String givenNameKey : names) {
|
||||
if (givenNameKey.startsWith(AUTHOR_GIVEN_NAME)) {
|
||||
String postfix = givenNameKey.replaceFirst(AUTHOR_GIVEN_NAME, "");
|
||||
if (!postfix.matches("[a-zA-Z0-9]*")) {
|
||||
logger.error("Metadata author postfix is bad. Should contain only symbols a-zA-Z0-9, but "
|
||||
+ postfix + " found. Author givenName field is " + givenNameKey );
|
||||
System.exit(1);
|
||||
}
|
||||
String participantURI = TS + PARTICIPANT + "/" + docID + order + "author" + postfix;
|
||||
Resource participant = m.createResource(participantURI, participantClass);
|
||||
Property hasAuthor = m.createProperty(TS + "hasAuthor");
|
||||
excerpt.addProperty(hasAuthor, participant);
|
||||
String givenName = map.get(givenNameKey);
|
||||
Property givenNameProperty = m.createProperty(TS + "participantGivenName");
|
||||
participant.addProperty( givenNameProperty, givenName.trim());
|
||||
|
||||
String family = map.get(AUTHOR_FAMILY + postfix);
|
||||
if (family != null) {
|
||||
Property familyProperty = m.createProperty(TS + "participantFamily");
|
||||
participant.addProperty( familyProperty, family.trim());
|
||||
}
|
||||
String labelName = givenNameKey.trim();
|
||||
if (family != null ) {
|
||||
labelName += " " + family;
|
||||
}
|
||||
participant.addProperty(RDFS.label, labelName);
|
||||
|
||||
String email = map.get(AUTHOR_EMAIL + postfix);
|
||||
if (email != null) {
|
||||
Property emailProperty = m.createProperty(TS + "participantEmail");
|
||||
participant.addProperty( emailProperty, email.trim());
|
||||
}
|
||||
String authorInitials = map.get(AUTHOR_INITIALS + postfix);
|
||||
if (email != null) {
|
||||
Property initialsProperty = m.createProperty(TS + "participantInitials");
|
||||
participant.addProperty( initialsProperty, authorInitials.trim());
|
||||
}
|
||||
addOrganization(participant, map, order, postfix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attachAuthor(Resource resource, Map<String, String> map, String order) {
|
||||
String participantURI = TS + PARTICIPANT + "/" + PARSERNAME + "_" + docID + order ;
|
||||
Resource participant = m.createResource(participantURI, participantClass);
|
||||
Property hasAuthor = m.createProperty(TS + "hasAuthor");
|
||||
resource.addProperty(hasAuthor, participant);
|
||||
createParticipant(map, order, participant);
|
||||
}
|
||||
|
||||
private void createParticipant(Map<String, String> map, String order, Resource participant) {
|
||||
String givenName = map.get("author given name");
|
||||
if (givenName != null) {
|
||||
Property givenNameProperty = m.createProperty(TS + "participantGivenName");
|
||||
participant.addProperty( givenNameProperty, givenName.trim());
|
||||
}
|
||||
String family = map.get("author family");
|
||||
if (family != null) {
|
||||
Property familyProperty = m.createProperty(TS + "participantFamily");
|
||||
participant.addProperty( familyProperty, family.trim());
|
||||
}
|
||||
if (givenName != null ) {
|
||||
String labelName = givenName.trim();
|
||||
if (family != null ) {
|
||||
labelName += " " + family;
|
||||
}
|
||||
participant.addProperty(RDFS.label, labelName);
|
||||
}
|
||||
String email = map.get("author email");
|
||||
if (email != null) {
|
||||
Property emailProperty = m.createProperty(TS + "participantEmail");
|
||||
participant.addProperty( emailProperty, email.trim());
|
||||
}
|
||||
String authorInitials = map.get("author initials");
|
||||
if (email != null) {
|
||||
Property initialsProperty = m.createProperty(TS + "participantInitials");
|
||||
participant.addProperty( initialsProperty, authorInitials.trim());
|
||||
}
|
||||
attachOrganization(participant, map, order);
|
||||
}
|
||||
|
||||
private void attachOrganization(Resource participant, Map<String, String> map, String order) {
|
||||
String orgName = map.get("affiliated organization name");
|
||||
System.out.println(orgName);
|
||||
private void addOrganization(Resource participant, Map<String, String> map, String order, String postfix) {
|
||||
String orgName = map.get(AFFILIATED_ORGANIZATION_NAME + postfix);
|
||||
if (orgName == null) {
|
||||
System.out.println(orgName + " not found");
|
||||
logger.warn("No " + AFFILIATED_ORGANIZATION_NAME + postfix + " found.");
|
||||
return;
|
||||
}
|
||||
String organizationUri = TS + ORGANIZATION + "/" + PARSERNAME + "_" + docID + order;
|
||||
String organizationUri = TS + ORGANIZATION + "/" + docID + order + "author" + postfix;
|
||||
Resource organization = m.createResource(organizationUri, organizationClass);
|
||||
Property affiliatedWith = m.createProperty(TS + "affiliatedWith");
|
||||
participant.addProperty(affiliatedWith, organization);
|
||||
|
||||
organization.addProperty(RDFS.label, orgName);
|
||||
|
||||
String officialName = map.get("affiliated organization official name");
|
||||
String officialName = map.get(AFFILIATED_ORGANIZATION_OFFICIAL_NAME + postfix);
|
||||
if (officialName != null) {
|
||||
Property officialNameProperty = m.createProperty(TS + "officialOrganizationName");
|
||||
organization.addProperty(officialNameProperty, officialName);
|
||||
}
|
||||
String orgAddress = map.get("affiliated organization address");
|
||||
String orgAddress = map.get(AFFILIATED_ORGANIZATION_ADDRESS + postfix);
|
||||
if (orgAddress != null) {
|
||||
Property orgAddressProperty = m.createProperty(TS + "organizationAddress");
|
||||
organization.addProperty(orgAddressProperty, orgAddress);
|
||||
}
|
||||
String postalCode = map.get("affiliated organization postal code");
|
||||
String postalCode = map.get(AFFILIATED_ORGANIZATION_POSTAL_CODE + postfix);
|
||||
if (postalCode != null) {
|
||||
Property postalCodeProperty = m.createProperty(TS + "organizationPostalCode");
|
||||
organization.addProperty(postalCodeProperty, postalCode);
|
||||
|
@ -383,19 +380,18 @@ public class DocumentStructure {
|
|||
return true;
|
||||
}
|
||||
private void createTOCItem(DocumentPart docPart) {
|
||||
String tocItemName = TS + TOCITEM + "/" + PARSERNAME + "_" + docID + docPart.getSafePath();
|
||||
Resource tocItem = m.createIndividual(tocItemName,itemClass);
|
||||
String tocItemUri = TS + TOC_ITEM + "/" + docID + docPart.getSafePath();
|
||||
Resource tocItem = m.createIndividual(tocItemUri,itemClass);
|
||||
tocItem.addProperty( RDFS.label, docPart.getName());
|
||||
Property pointsTo = m.createProperty(TS + "pointsTo");
|
||||
Property itemNumber = m.createProperty(TS + "itemNumber");
|
||||
Property hasTOCItem = m.createProperty(TS + "hasTOCItem");
|
||||
Property pointsTo = m.createProperty(POINTS_TO);
|
||||
Property itemNumber = m.createProperty(ITEM_NUMBER);
|
||||
Property hasTOCItem = m.createProperty(HAS_TOC_ITEM);
|
||||
tocItem.addLiteral(itemNumber, docPart.getNumber());
|
||||
m.add(tocItem, pointsTo, tocLevels.get(docPart.getPath()));
|
||||
if (!docPart.getPath().isEmpty()) {
|
||||
Resource parent = tocLevels.get(docPart.getParentPath());
|
||||
m.add(parent, hasTOCItem, tocItem);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void attachExcerpt(DocumentPart docPart, Resource element) {
|
||||
|
@ -407,7 +403,7 @@ public class DocumentStructure {
|
|||
}
|
||||
Resource excerpt = createExcerpt(docPart);
|
||||
excerpt.addProperty( RDFS.label, docPart.getName());
|
||||
Property hasText = m.createProperty(TS + "hasText");
|
||||
Property hasText = m.createProperty(HAS_TEXT);
|
||||
element.addProperty(hasText, excerpt);
|
||||
if (!docPart.isMasterPart()) {
|
||||
addMetadataProperties(excerpt, docPart);
|
||||
|
@ -416,11 +412,6 @@ public class DocumentStructure {
|
|||
}
|
||||
}
|
||||
|
||||
public void createTree() {
|
||||
createElements();
|
||||
createTOCItems();
|
||||
}
|
||||
|
||||
private void createTOCItems() {
|
||||
Set<String> paths = inputParts.keySet();
|
||||
for (String path : paths) {
|
||||
|
@ -442,5 +433,11 @@ public class DocumentStructure {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void formatDocID(String fileName) {
|
||||
String identifier = fileName.replaceAll("\\s+", "_");
|
||||
identifier = transliterateToEn(identifier);
|
||||
identifier = identifier.replaceAll("[^a-zA-Z0-9_.-]", "");
|
||||
this.docID = identifier;
|
||||
}
|
||||
}
|
|
@ -17,17 +17,15 @@ public class RDFDocumentResult implements OutputFile {
|
|||
private ConverterResult xhtmlResult;
|
||||
private String sFileName;
|
||||
private XhtmlConfig config;
|
||||
private DocumentStructure rdfStructure = null;
|
||||
private RDFDocument rdfDocument = null;
|
||||
|
||||
|
||||
public RDFDocumentResult(Vector<XhtmlDocument> outFiles, String fileName, XhtmlConfig config) {
|
||||
this.sFileName = Misc.removeExtension(fileName);
|
||||
this.config = config;
|
||||
Metadata metadata = new Metadata();
|
||||
MetadataContainer metadata = new MetadataContainer();
|
||||
metadata.read(config.getCSVMetadataFile());
|
||||
rdfStructure = new DocumentStructure(outFiles,sFileName,config,metadata);
|
||||
rdfStructure.createTree();
|
||||
|
||||
rdfDocument = new RDFDocument(outFiles,sFileName,config,metadata);
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,7 +46,7 @@ public class RDFDocumentResult implements OutputFile {
|
|||
}
|
||||
|
||||
@Override public void write(OutputStream os) throws IOException {
|
||||
rdfStructure.printModel(os);
|
||||
rdfDocument.printModel(os);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>The package writer2latex.util</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>Some general utility classes.</p>
|
||||
</body>
|
||||
</html>
|
41
src/main/java/w2phtml/util/Transliteration.java
Normal file
41
src/main/java/w2phtml/util/Transliteration.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package w2phtml.util;
|
||||
|
||||
public class Transliteration {
|
||||
|
||||
public static String transliterateToEn(String fileName) {
|
||||
return fileName
|
||||
.replaceAll("[аА]", "a")
|
||||
.replaceAll("[бБ]", "b")
|
||||
.replaceAll("[вВ]", "v")
|
||||
.replaceAll("[гГ]", "g")
|
||||
.replaceAll("[дД]", "d")
|
||||
.replaceAll("[еЕ]", "e")
|
||||
.replaceAll("[ёЁ]", "e")
|
||||
.replaceAll("[жЖ]", "zh")
|
||||
.replaceAll("[зЗ]", "z")
|
||||
.replaceAll("[иИ]", "i")
|
||||
.replaceAll("[йЙ]", "y")
|
||||
.replaceAll("[кК]", "k")
|
||||
.replaceAll("[лЛ]", "l")
|
||||
.replaceAll("[мМ]", "m")
|
||||
.replaceAll("[нН]", "n")
|
||||
.replaceAll("[оО]", "o")
|
||||
.replaceAll("[пП]", "p")
|
||||
.replaceAll("[рР]", "r")
|
||||
.replaceAll("[сС]", "s")
|
||||
.replaceAll("[тТ]", "t")
|
||||
.replaceAll("[уУ]", "u")
|
||||
.replaceAll("[фФ]", "f")
|
||||
.replaceAll("[хХ]", "kh")
|
||||
.replaceAll("[цЦ]", "ts")
|
||||
.replaceAll("[чЧ]", "ch")
|
||||
.replaceAll("[шШ]", "sh")
|
||||
.replaceAll("[щЩ]", "sch")
|
||||
.replaceAll("[ъЪ]", "")
|
||||
.replaceAll("[ыЫ]", "y")
|
||||
.replaceAll("[ьЬ]", "")
|
||||
.replaceAll("[эЭ]", "e")
|
||||
.replaceAll("[юЮ]", "yu")
|
||||
.replaceAll("[яЯ]", "ya");
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue