diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java
index ae0f38f..7df3b6e 100644
--- a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java
+++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java
@@ -18,20 +18,17 @@ import pro.litvinovg.xml.Debug;
public class ConfigurationReader {
- List checkBoxes = new ArrayList();
- List textFields = new ArrayList();
- List labels = new ArrayList();
+ HashMap options = new HashMap();
private XComponentContext context;
-
public ConfigurationReader(HashMap configuration, XComponentContext context) {
this.context = context;
readOptions(configuration);
}
private void readOptions(HashMap configuration) {
- Set options = configuration.keySet();
- for (String optionName : options) {
+ Set keys = configuration.keySet();
+ for (String optionName : keys) {
String optionValue = null;
Component component = configuration.get(optionName);
if (component.getClass().equals(JTextField.class)) {
@@ -41,7 +38,8 @@ public class ConfigurationReader {
} else if (component.getClass().equals(JLabel.class)) {
optionValue = ((JLabel) component).getText();
}
- Debug.printLog(optionName + " : " + optionValue, context);
+ options.put(optionName, optionValue);
+ //Debug.printLog(optionName + " : " + optionValue, context);
}
@@ -49,7 +47,46 @@ public class ConfigurationReader {
}
public String[] getCommandLine() {
- return null;
+ List args = new ArrayList();
+ String format = options.get("targetFormat");
+ if (format == null) {
+ Debug.printLog("target format is not set", context);
+ return null;
+ } else {
+ options.remove("targetFormat");
+ }
+ String inputFile = options.get("inputFile");
+ if (inputFile == null) {
+ Debug.printLog("no input file", context);
+ return null;
+ } else {
+ options.remove("inputFile");
+ }
+ String outputFile = options.get("outputFile");
+ if (outputFile == null) {
+ Debug.printLog("no output file set", context);
+ } else {
+ options.remove("outputFile");
+ }
+ args.add("-"+format);
+ for (String key: options.keySet()) {
+ String value = options.get(key);
+ if( value != null && !value.isEmpty()) {
+ args.add("-"+key);
+ args.add(value);
+ }
+ }
+ args.add(inputFile);
+ if (outputFile != null) {
+ args.add(outputFile);
+ }
+ String sout = "";
+ for (String val: args) {
+ sout += val+" ";;
+ }
+ Debug.printLog(sout, context);
+ String[] array = args.toArray(new String[0]);
+ return array;
}
}
diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java
index 5efdc89..c4b73bc 100644
--- a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java
+++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java
@@ -28,6 +28,8 @@ import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import java.awt.event.ActionListener;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.HashMap;
import java.util.Set;
import java.awt.event.ActionEvent;
@@ -60,7 +62,7 @@ public class ConfigurationWindow extends JFrame {
}
private XComponentContext context;
- private JTextField tf_FilePath;
+ private String fileName = "";
/**
* Create the application.
@@ -73,8 +75,9 @@ public class ConfigurationWindow extends JFrame {
createEvents();
}
- public ConfigurationWindow(XComponentContext context) {
+ public ConfigurationWindow(XComponentContext context, Document doc) {
this.context = context;
+ fileName = doc.getFileName();
setTitle("Converter from ODT to HTML, ePub and RDF");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setIconImage(Toolkit.getDefaultToolkit().getImage(ConfigurationWindow.class.getResource("/pro/litvinovg/w2phtml/gui/resources/w2phtml.png")));
@@ -344,14 +347,14 @@ public class ConfigurationWindow extends JFrame {
JPanel panel_configHTML = new JPanel();
JCheckBox cb_UseMathJax = new JCheckBox("Use MathJax");
- configuration.put("useMathJax", cb_UseMathJax);
+ configuration.put("use_mathjax", cb_UseMathJax);
JCheckBox cb_SplitWholePagesOnly = new JCheckBox("Split on whole pages only");
- configuration.put("splitWholePagesOnly", cb_SplitWholePagesOnly);
+ configuration.put("align_splits_to_pages", cb_SplitWholePagesOnly);
JLabel lb_SplitByLevel = new JLabel("Split into multiple files by heading level");
JTextField tf_SplitByLevel = new JTextField();
- configuration.put("splitByLevel", tf_SplitByLevel);
+ configuration.put("split_level", tf_SplitByLevel);
tf_SplitByLevel.setColumns(10);
@@ -359,49 +362,51 @@ public class ConfigurationWindow extends JFrame {
configuration.put("greenstone", cb_Greenstone);
JCheckBox cb_IgnoreEmptyParagraphs = new JCheckBox("Filter empty paragraphs");
- configuration.put("filterEmptyParagraphs", cb_IgnoreEmptyParagraphs);
+ configuration.put("ignore_empty_paragraphs", cb_IgnoreEmptyParagraphs);
JCheckBox cb_IgnoreHardLineBreaks = new JCheckBox("Filter hard line breaks");
- configuration.put("filterHardLineBreaks", cb_IgnoreHardLineBreaks);
+ configuration.put("ignore_hard_line_breaks", cb_IgnoreHardLineBreaks);
JLabel lb_FilterLetterSpacing = new JLabel("Filter letter spacing less than");
JTextField tf_FilterLetterSpacing = new JTextField();
- configuration.put("filterLetterSpacing", tf_FilterLetterSpacing);
+ configuration.put("min_letter_spacing", tf_FilterLetterSpacing);
tf_FilterLetterSpacing.setColumns(10);
JCheckBox cb_InlineStyles = new JCheckBox("Inline styles");
- configuration.put("inlineStyles", cb_InlineStyles);
+ configuration.put("css_inline", cb_InlineStyles);
JCheckBox cb_EmbedVectorImages = new JCheckBox("Embed vector images");
- configuration.put("embedVectorImages", cb_EmbedVectorImages);
+ configuration.put("embed_svg", cb_EmbedVectorImages);
JCheckBox cb_EmbedRaster = new JCheckBox("Embed raster images");
- configuration.put("embedRaster", cb_EmbedRaster);
+ configuration.put("embed_img", cb_EmbedRaster);
JLabel lb_Scale = new JLabel("Scale");
JTextField tf_Scale = new JTextField();
- configuration.put("scale", tf_Scale);
+ configuration.put("scaling", tf_Scale);
tf_Scale.setColumns(10);
JLabel lb_MaxWidth = new JLabel("Max body width");
JTextField tf_MaxWidth = new JTextField();
- configuration.put("maxWidth", tf_MaxWidth);
+ configuration.put("max_width", tf_MaxWidth);
tf_MaxWidth.setColumns(10);
- JCheckBox cb_ConversionToRem = new JCheckBox("Convert dimensions to REM");
- configuration.put("conversionToRem", cb_ConversionToRem);
+ JCheckBox cb_convertToPx = new JCheckBox("Convert dimensions to pixels instead of REM (root em)");
+ configuration.put("convert_to_px", cb_convertToPx);
JLabel lb_FilePath = new JLabel("File path");
- tf_FilePath = new JTextField();
- tf_FilePath.setColumns(10);
+ JTextField tf_inputFile = new JTextField(fileName);
+ tf_inputFile.setColumns(10);
+ configuration.put("inputFile", tf_inputFile);
+
- JLabel lb_TargetFormat = new JLabel("HTML");
+ JLabel lb_TargetFormat = new JLabel("html5");
configuration.put("targetFormat", lb_TargetFormat);
@@ -422,7 +427,7 @@ public class ConfigurationWindow extends JFrame {
.addGroup(gl_panel_configHTML.createSequentialGroup()
.addComponent(lb_FilePath, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
.addGap(18)
- .addComponent(tf_FilePath, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE))
+ .addComponent(tf_inputFile, GroupLayout.DEFAULT_SIZE, 755, Short.MAX_VALUE))
.addComponent(cb_UseMathJax, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE)
.addGroup(gl_panel_configHTML.createSequentialGroup()
.addComponent(lb_Scale, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
@@ -439,7 +444,7 @@ public class ConfigurationWindow extends JFrame {
.addComponent(cb_InlineStyles, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE)
.addComponent(cb_EmbedVectorImages, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE)
.addComponent(cb_EmbedRaster, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE)
- .addComponent(cb_ConversionToRem, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE)
+ .addComponent(cb_convertToPx, GroupLayout.PREFERRED_SIZE, 592, GroupLayout.PREFERRED_SIZE)
.addComponent(cb_IgnoreHardLineBreaks, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE)
.addComponent(cb_IgnoreEmptyParagraphs, GroupLayout.PREFERRED_SIZE, 303, GroupLayout.PREFERRED_SIZE)
.addComponent(cb_Greenstone, GroupLayout.PREFERRED_SIZE, 482, GroupLayout.PREFERRED_SIZE)
@@ -462,7 +467,7 @@ public class ConfigurationWindow extends JFrame {
.addGroup(gl_panel_configHTML.createSequentialGroup()
.addGap(2)
.addComponent(lb_FilePath))
- .addComponent(tf_FilePath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+ .addComponent(tf_inputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_panel_configHTML.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_configHTML.createSequentialGroup()
@@ -488,7 +493,7 @@ public class ConfigurationWindow extends JFrame {
.addGap(7)
.addComponent(cb_EmbedRaster)
.addGap(7)
- .addComponent(cb_ConversionToRem)
+ .addComponent(cb_convertToPx)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(cb_IgnoreHardLineBreaks)
.addGap(7)
@@ -528,9 +533,17 @@ public class ConfigurationWindow extends JFrame {
JButton btn_Convert = new JButton("Convert");
btn_Convert.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
+ public void actionPerformed(ActionEvent actionEvent) {
+ try {
ConfigurationReader reader = new ConfigurationReader(configuration, context);
- //Application.main(reader.getCommandLine());
+ Application.main(reader.getCommandLine());
+ Debug.printLog("Finish", context);
+
+ } catch(Throwable e) {
+ StringWriter errors = new StringWriter();
+ e.printStackTrace(new PrintWriter(errors));
+ Debug.printLog(errors.toString(), context);
+ }
}
});
@@ -579,7 +592,7 @@ public class ConfigurationWindow extends JFrame {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
- ConfigurationWindow frame = new ConfigurationWindow(context);
+ ConfigurationWindow frame = new ConfigurationWindow(context,doc);
singleFrame = frame;
frame.setBounds(100, 100, 800, 800);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/Document.java b/src/main/java/pro/litvinovg/w2phtml/gui/Document.java
index 2feb046..484b301 100644
--- a/src/main/java/pro/litvinovg/w2phtml/gui/Document.java
+++ b/src/main/java/pro/litvinovg/w2phtml/gui/Document.java
@@ -54,6 +54,7 @@ public class Document {
private XDocumentPropertiesSupplier documentPropertiesSupplier;
private XText text = null;
private XFrame frame;
+ private String fileName = "";
private XDispatchProvider dispatchProvider;
XTextDocument textDocument;
@@ -85,23 +86,23 @@ public class Document {
if (storable == null || storable.isReadonly()) {
Debug.printLog("Document is read only", componentContext);
} else {
- Debug.printLog("Document is in rw mode", componentContext);
+ //Debug.printLog("Document is in rw mode", componentContext);
}
XModifiable modifieable = UnoRuntime.queryInterface(XModifiable.class, textDoc);
if (modifieable == null || modifieable.isModified()) {
Debug.printLog("Document is modified", componentContext);
} else {
- Debug.printLog("Document isn't modified", componentContext);
+ //Debug.printLog("Document isn't modified", componentContext);
}
String url = model.getURL();
URI uri = new URI(url);
File file = new File(uri);
- if (file.exists()) {
- Debug.printLog("File exists!", componentContext);
+ if (file.exists() && file.canRead()) {
+ //Debug.printLog("File exists!", componentContext);
+ fileName = file.getAbsolutePath();
}
- Debug.printLog("Document url " + url, componentContext);
} catch (Exception e) {
System.out.println("xDesktop inaccessible. Can not proceed.");
@@ -112,6 +113,10 @@ public class Document {
}
+ public String getFileName() {
+ return fileName;
+ }
+
private boolean isSupported(Object object, String service) {
XServiceInfo info = UnoRuntime.queryInterface(XServiceInfo.class, object);
if (info == null) {