diff --git a/source/distro/changelog.txt b/source/distro/changelog.txt index b096c6f..cad6aed 100644 --- a/source/distro/changelog.txt +++ b/source/distro/changelog.txt @@ -2,7 +2,9 @@ Changelog for Writer2LaTeX version 1.0 -> 1.2 ---------- version 1.1.7 ---------- -[w2x] Standard meta data as well as custom meta data can now be edited directly from the EPUB export dialog +[w2x] Added opf:file-as attribute to EPUB metadata (creators and contributors) + +[w2x] EPUB meta data can now be edited directly from the export dialog [w2x] Revised the internal structure of EPUB files: Text files are named chapter.xhtml, images are placed in the subdirectory images and name image, styles are placed in the subdirectory styles and names styles.css (custom diff --git a/source/java/org/openoffice/da/comp/w2lcommon/helper/SimpleDialog.java b/source/java/org/openoffice/da/comp/w2lcommon/helper/SimpleDialog.java new file mode 100644 index 0000000..36bc69e --- /dev/null +++ b/source/java/org/openoffice/da/comp/w2lcommon/helper/SimpleDialog.java @@ -0,0 +1,79 @@ +/************************************************************************ + * + * SimpleDialog.java + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * Copyright: 2002-2011 by Henrik Just + * + * All Rights Reserved. + * + * 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 without 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; + } +} diff --git a/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java b/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java index 00350d9..c544690 100644 --- a/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java +++ b/source/java/org/openoffice/da/comp/writer2xhtml/EpubMetadataDialog.java @@ -20,17 +20,21 @@ * * All Rights Reserved. * - * Version 1.2 (2011-02-23) + * Version 1.2 (2011-02-24) * */ package org.openoffice.da.comp.writer2xhtml; +import java.util.HashMap; import java.util.HashSet; +import java.util.Vector; import org.openoffice.da.comp.w2lcommon.helper.DialogBase; +import org.openoffice.da.comp.w2lcommon.helper.SimpleDialog; import writer2latex.util.CSVList; +import writer2latex.util.Misc; import com.sun.star.awt.XDialog; import com.sun.star.beans.IllegalTypeException; @@ -47,6 +51,7 @@ 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; @@ -55,6 +60,13 @@ import com.sun.star.uno.XComponentContext; /** 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 = ""; + } + // All the user defined properties we handle private static final String IDENTIFIER="Identifier"; private static final String CREATOR="Creator"; @@ -67,11 +79,25 @@ public class EpubMetadataDialog extends DialogBase { 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 backRoles; + static { + backRoles = new HashMap(); + int nCount = sRoles.length; + for (short i=0; i authors = new Vector(); public EpubMetadataDialog(XComponentContext xContext) { super(xContext); @@ -145,27 +171,78 @@ public class EpubMetadataDialog extends DialogBase { } private boolean authorAddclick() { - System.out.println("AuthorAddClick"); + SimpleDialog dialog = new SimpleDialog(xContext,"W2XDialogs2.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() { - System.out.println("AuthorModifyClick"); + short nIndex = getListBoxSelectedItem("Authors"); + AuthorInfo author = authors.get(nIndex); + SimpleDialog dialog = new SimpleDialog(xContext,"W2XDialogs2.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() { - System.out.println("AuthorDeleteClick"); + if (authors.size()>0) { + SimpleDialog dialog = new SimpleDialog(xContext,"W2XDialogs2.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(nIndex0) { + 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() { - System.out.println("AuthorDownClick"); + short nIndex = getListBoxSelectedItem("Authors"); + if (nIndex+10) { // Use the first if we have several... setTextFieldText("Identifier",getValue(sIdentifiers[0])); - int nDot = sIdentifiers[0].indexOf("."); - setTextFieldText("IdentifierType",nDot>-1 ? sIdentifiers[0].substring(nDot+1) : ""); + 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 = getValue(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 = getValue(sContributor); + contributor.sRole = getSuffix(sContributor); + contributor.isCreator = false; + authors.add(contributor); + } + updateAuthorList((short) 0); + + // Get the dates and set the list box + // TODO + updateDateList((short) 0); + // Get the standard properties and set the text fields setTextFieldText("Title",xDocumentProperties.getTitle()); setTextFieldText("Subject",xDocumentProperties.getSubject()); @@ -253,12 +352,34 @@ public class EpubMetadataDialog extends DialogBase { 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)+(++i); + if (author.sRole.length()>0) { + sName+="."+author.sRole; + } + addProperty(sName); + setValue(sName,author.sName); + } + + // Set the dates from the list box + // TODO + // Set the standard properties from the text fields xDocumentProperties.setTitle(getTextFieldText("Title")); xDocumentProperties.setSubject(getTextFieldText("Subject")); String[] sKeywords = getTextFieldText("Keywords").split(","); - for (int i=0; i-1 ? sPropertyName.substring(nDot+1) : ""; + } // Get all currently defined user properties with a specific name or prefix private String[] getProperties(String sPrefix, boolean bComplete) { @@ -285,7 +412,7 @@ public class EpubMetadataDialog extends DialogBase { names.add(sName); } } - return names.toArray(new String[names.size()]); + return Misc.sortStringSet(names); } // Add a user property @@ -293,14 +420,8 @@ public class EpubMetadataDialog extends DialogBase { try { xUserProperties.addProperty(sName, (short) 128, ""); // 128 means removeable, last parameter is default value } catch (PropertyExistException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } catch (IllegalTypeException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } @@ -309,11 +430,7 @@ public class EpubMetadataDialog extends DialogBase { try { xUserProperties.removeProperty(sName); } catch (UnknownPropertyException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } catch (NotRemoveableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } } @@ -349,6 +466,31 @@ public class EpubMetadataDialog extends DialogBase { return null; } + private void updateAuthorList(short nItem) { + int nCount = authors.size(); + String[] sAuthors = new String[nCount]; + for (int i=0; i0 ? ", "+author.sRole : "") + +")"; + } + setListBoxStringItemList("Authors", sAuthors); + setListBoxSelectedItem("Authors",nItem); + setControlEnabled("ModifyAuthorButton",nCount>0); + setControlEnabled("DeleteAuthorButton",nCount>0); + setControlEnabled("AuthorUpButton",nCount>1); + setControlEnabled("AuthorDownButton",nCount>1); + } + + private void updateDateList(short nItem) { + setControlEnabled("AddDateButton",false); + setControlEnabled("ModifyDateButton",false); + setControlEnabled("DeleteDateButton",false); + } + private void readSimpleProperty(String sName) { String[] sNames = getProperties(sName,true); if (sNames.length>0) { diff --git a/source/java/writer2latex/api/ConverterFactory.java b/source/java/writer2latex/api/ConverterFactory.java index 6f4fe26..48bc6b0 100644 --- a/source/java/writer2latex/api/ConverterFactory.java +++ b/source/java/writer2latex/api/ConverterFactory.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * Version 1.2 (2011-02-23) + * Version 1.2 (2011-02-24) * */ @@ -33,7 +33,7 @@ public class ConverterFactory { // Version information private static final String VERSION = "1.1.7"; - private static final String DATE = "2011-02-23"; + private static final String DATE = "2011-02-24"; /** Return the Writer2LaTeX version in the form * (major version).(minor version).(patch level)
diff --git a/source/java/writer2latex/epub/OPFWriter.java b/source/java/writer2latex/epub/OPFWriter.java index a7ac822..9209dec 100644 --- a/source/java/writer2latex/epub/OPFWriter.java +++ b/source/java/writer2latex/epub/OPFWriter.java @@ -20,7 +20,7 @@ * * All Rights Reserved. * - * version 1.2 (2011-02-23) + * version 1.2 (2011-02-24) * */ @@ -147,6 +147,7 @@ public class OPFWriter extends NewDOMDocument { } else if (sKey.startsWith("creator")) { Element creator = appendElement(contentDOM, metadata, "dc:creator", sValue); + creator.setAttribute("opf:file-as", fileAs(sValue)); if (sAttributeValue!=null) { creator.setAttribute("opf:role", sAttributeValue); } @@ -154,6 +155,7 @@ public class OPFWriter extends NewDOMDocument { } else if (sKey.startsWith("contributor")) { Element contributor = appendElement(contentDOM, metadata, "dc:contributor", sValue); + contributor.setAttribute("opf:file-as", fileAs(sValue)); if (sAttributeValue!=null) { contributor.setAttribute("opf:role", sAttributeValue); } @@ -270,6 +272,16 @@ public class OPFWriter extends NewDOMDocument { return sUID; } + private String fileAs(String sName) { + int nSpace = sName.lastIndexOf(' '); + if (nSpace>-1) { + return sName.substring(nSpace+1).trim()+", "+sName.substring(0, nSpace).trim(); + } + else { + return sName.trim(); + } + } + private Element appendElement(Document contentDOM, Element node, String sTagName, String sContent) { Element child = contentDOM.createElement(sTagName); node.appendChild(child); diff --git a/source/oxt/writer2xhtml/W2XDialogs2/AuthorDialog.xdl b/source/oxt/writer2xhtml/W2XDialogs2/AuthorDialog.xdl new file mode 100644 index 0000000..0c5f071 --- /dev/null +++ b/source/oxt/writer2xhtml/W2XDialogs2/AuthorDialog.xdl @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/oxt/writer2xhtml/W2XDialogs2/DateDialog.xdl b/source/oxt/writer2xhtml/W2XDialogs2/DateDialog.xdl new file mode 100644 index 0000000..32310f6 --- /dev/null +++ b/source/oxt/writer2xhtml/W2XDialogs2/DateDialog.xdl @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/source/oxt/writer2xhtml/W2XDialogs2/dialog.xlb b/source/oxt/writer2xhtml/W2XDialogs2/dialog.xlb index c930b62..41ea3e1 100644 --- a/source/oxt/writer2xhtml/W2XDialogs2/dialog.xlb +++ b/source/oxt/writer2xhtml/W2XDialogs2/dialog.xlb @@ -14,4 +14,6 @@ + + \ No newline at end of file