w2x: UI for custom template now verifies that the template is well-formed XML

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@236 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2015-04-09 11:58:46 +00:00
parent 199616dde6
commit 188effe5c6
6 changed files with 67 additions and 17 deletions

View file

@ -4,6 +4,8 @@ Changelog for Writer2LaTeX version 1.4 -> 1.6
Items marked with * are work in progress
[w2x] The template page in the configuration now displays an error message if the template is not well-formed XML.
[w2x] Added toolbar configuration dialog: Select XHTML and EPUB export format and behavior after export (do nothing,
display in default viewer or display with custom application)

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2014 by Henrik Just
* Copyright: 2002-2015 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.4 (2014-09-16)
* Version 1.5 (2015-04-09)
*
*/
@ -329,7 +329,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
public CustomFileHandler() {
super();
try {
sCustomFileName = xPathSub.substituteVariables("$(user)/"+getFileName(), false);
sCustomFileName = xPathSub.substituteVariables("$(user)/"+getFileName(), false);
}
catch (NoSuchElementException e) {
sCustomFileName = getFileName();
@ -392,7 +392,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
useCustomInner(dlg,bUseCustom);
}
private void loadCustomClick(DialogAccess dlg) {
protected void loadCustomClick(DialogAccess dlg) {
String sFileName=filePicker.getPath();
if (sFileName!=null) {
String sText = loadFile(sFileName);

View file

@ -20,16 +20,20 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-01-14)
* Version 1.6 (2015-04-09)
*
*/
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 writer2latex.api.Converter;
import writer2latex.api.ConverterFactory;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.lang.XServiceInfo;
@ -95,7 +99,7 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
// Implement remaining method from XContainerWindowEventHandler
public String[] getSupportedMethodNames() {
String[] sNames = { "EncodingChange", // General
"CustomTemplateChange", "LoadTemplateClick", // Template
"CustomTemplateChange", "LoadTemplateClick", "TemplateKeyup", // Template
"UseCustomStylesheetChange", "IncludeCustomStylesheetClick", "LoadStylesheetClick",
"NewResourceClick", "DeleteResourceClick", // Stylesheet
"StyleFamilyChange", "StyleNameChange", "NewStyleClick", "DeleteStyleClick", "LoadDefaultsClick" // Styles1
@ -170,6 +174,7 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
}
protected void useCustomInner(DialogAccess dlg, boolean bEnable) {
dlg.setControlEnabled("TestTemplateLabel", bEnable);
dlg.setControlEnabled("ContentIdLabel", bEnable);
dlg.setControlEnabled("ContentId", bEnable);
dlg.setControlEnabled("HeaderIdLabel", bEnable);
@ -181,12 +186,15 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
}
@Override protected void setControls(DialogAccess dlg) {
System.out.println("set controls");
super.setControls(dlg);
System.out.println("done setting controls");
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) {
@ -198,6 +206,38 @@ public class ConfigurationDialog extends ConfigurationDialogBase implements XSer
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 {

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.6 (2015-04-01)
* Version 1.6 (2015-04-09)
*
*/
@ -33,7 +33,7 @@ public class ConverterFactory {
// Version information
private static final String VERSION = "1.5.2";
private static final String DATE = "2015-04-01";
private static final String DATE = "2015-04-09";
/** Return the Writer2LaTeX version in the form
* (major version).(minor version).(patch level)<br/>

View file

@ -1,34 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="Template" dlg:left="139" dlg:top="84" dlg:width="260" dlg:height="185" dlg:closeable="true" dlg:moveable="true" dlg:title="Template" dlg:withtitlebar="false">
<dlg:styles>
<dlg:style dlg:style-id="0" dlg:text-color="0xff3333"/>
</dlg:styles>
<dlg:bulletinboard>
<dlg:checkbox dlg:id="UseCustomTemplate" dlg:tab-index="0" dlg:left="10" dlg:top="8" dlg:width="240" dlg:height="12" dlg:value="Use custom XHTML template" dlg:checked="false" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:UseCustomTemplate">
<script:event script:event-name="on-itemstatechange" script:macro-name="vnd.sun.star.UNO:UseCustomTemplateChange" script:language="UNO"/>
</dlg:checkbox>
<dlg:textfield dlg:id="CustomTemplate" dlg:tab-index="1" dlg:left="18" dlg:top="22" dlg:width="232" dlg:height="96" dlg:hscroll="true" dlg:vscroll="true" dlg:multiline="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:UseCustomTemplate"/>
<dlg:textfield dlg:id="CustomTemplate" dlg:tab-index="1" dlg:left="18" dlg:top="22" dlg:width="232" dlg:height="96" dlg:hscroll="true" dlg:vscroll="true" dlg:multiline="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:UseCustomTemplate">
<script:event script:event-name="on-keyup" script:macro-name="vnd.sun.star.UNO:TemplateKeyup" script:language="UNO"/>
</dlg:textfield>
<dlg:button dlg:id="LoadTemplateButton" dlg:tab-index="2" dlg:left="18" dlg:top="120" dlg:width="60" dlg:height="12" dlg:value="Load..." dlg:help-url="org.openoffice.da.writer2xhtml.oxt:LoadTemplate">
<script:event script:event-name="on-mouseup" script:macro-name="vnd.sun.star.UNO:LoadTemplateClick" script:language="UNO"/>
</dlg:button>
<dlg:text dlg:id="ContentIdLabel" dlg:tab-index="4" dlg:left="18" dlg:top="140" dlg:width="50" dlg:height="12" dlg:value="Content id"/>
<dlg:combobox dlg:id="ContentId" dlg:tab-index="5" dlg:left="72" dlg:top="138" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:ContentId">
<dlg:text dlg:id="TestTemplateLabel" dlg:style-id="0" dlg:tab-index="3" dlg:left="90" dlg:top="122" dlg:width="160" dlg:height="24" dlg:value="Test" dlg:multiline="true"/>
<dlg:text dlg:id="ContentIdLabel" dlg:tab-index="4" dlg:left="18" dlg:top="154" dlg:width="50" dlg:height="12" dlg:value="Content id"/>
<dlg:combobox dlg:id="ContentId" dlg:tab-index="5" dlg:left="72" dlg:top="152" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:ContentId">
<dlg:menupopup>
<dlg:menuitem dlg:value="content"/>
</dlg:menupopup>
</dlg:combobox>
<dlg:text dlg:id="PanelIdLabel" dlg:tab-index="6" dlg:left="18" dlg:top="154" dlg:width="50" dlg:height="12" dlg:value="Panel id"/>
<dlg:combobox dlg:id="PanelId" dlg:tab-index="7" dlg:left="72" dlg:top="152" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:PanelId">
<dlg:text dlg:id="PanelIdLabel" dlg:tab-index="6" dlg:left="18" dlg:top="168" dlg:width="50" dlg:height="12" dlg:value="Panel id"/>
<dlg:combobox dlg:id="PanelId" dlg:tab-index="7" dlg:left="72" dlg:top="166" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:PanelId">
<dlg:menupopup>
<dlg:menuitem dlg:value="panel"/>
</dlg:menupopup>
</dlg:combobox>
<dlg:text dlg:id="HeaderIdLabel" dlg:tab-index="8" dlg:left="146" dlg:top="140" dlg:width="50" dlg:height="12" dlg:value="Header id"/>
<dlg:combobox dlg:id="HeaderId" dlg:tab-index="9" dlg:left="200" dlg:top="138" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:HeaderId">
<dlg:text dlg:id="HeaderIdLabel" dlg:tab-index="8" dlg:left="146" dlg:top="154" dlg:width="50" dlg:height="12" dlg:value="Header id"/>
<dlg:combobox dlg:id="HeaderId" dlg:tab-index="9" dlg:left="200" dlg:top="152" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:HeaderId">
<dlg:menupopup>
<dlg:menuitem dlg:value="header"/>
</dlg:menupopup>
</dlg:combobox>
<dlg:text dlg:id="FooterIdLabel" dlg:tab-index="10" dlg:left="146" dlg:top="154" dlg:width="50" dlg:height="12" dlg:value="Footer id"/>
<dlg:combobox dlg:id="FooterId" dlg:tab-index="11" dlg:left="200" dlg:top="152" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:FooterId">
<dlg:text dlg:id="FooterIdLabel" dlg:tab-index="10" dlg:left="146" dlg:top="168" dlg:width="50" dlg:height="12" dlg:value="Footer id"/>
<dlg:combobox dlg:id="FooterId" dlg:tab-index="11" dlg:left="200" dlg:top="166" dlg:width="50" dlg:height="12" dlg:spin="true" dlg:help-url="org.openoffice.da.writer2xhtml.oxt:FooterId">
<dlg:menupopup>
<dlg:menuitem dlg:value="footer"/>
</dlg:menupopup>

View file

@ -39,6 +39,8 @@
</listitem>
</list>
<paragraph role="paragraph" xml-lang="en-US">You can change the names of the id attributes at the bottom of this page.</paragraph>
<paragraph role="paragraph" xml-lang="en-US">The template must be well-formed XML. If this is not the case, an error message
is displayed below the template. A template with errors will be ignored in the export.</paragraph>
<paragraph role="paragraph" xml-lang="en-US">A simple template including a header might look like this:</paragraph>
<paragraph role="code" xml-lang="en-US">
&lt;html&gt;<br/>