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

@ -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 {