EPUB meta data editor second draft

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@92 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2011-02-23 11:09:09 +00:00
parent bb1cc87bab
commit 3dd2833a4e
16 changed files with 336 additions and 238 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2011-02-22)
* Version 1.2 (2011-02-23)
*
*/
@ -30,6 +30,9 @@ import java.util.HashSet;
import org.openoffice.da.comp.w2lcommon.helper.DialogBase;
import writer2latex.util.CSVList;
import com.sun.star.awt.XDialog;
import com.sun.star.beans.IllegalTypeException;
import com.sun.star.beans.NotRemoveableException;
import com.sun.star.beans.Property;
@ -65,7 +68,8 @@ public class EpubMetadataDialog extends DialogBase {
private static final String COVERAGE="Coverage";
private static final String RIGHTS="Rights";
// Access to the user defined properties
// Access to the document properties
private XDocumentProperties xDocumentProperties=null;
private XPropertyContainer xUserProperties=null;
private XPropertySet xUserPropertySet=null;
@ -81,15 +85,193 @@ public class EpubMetadataDialog extends DialogBase {
*/
public static String __implementationName = "org.openoffice.da.comp.writer2xhtml.EpubMetadataDialog";
@Override
public String getDialogLibraryName() {
// --------------------------------------------------
// Ensure that the super can find us :-)
@Override public String getDialogLibraryName() {
return "W2XDialogs2";
}
@Override
public String getDialogName() {
@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();
}
return false;
}
@Override public String[] getSupportedMethodNames() {
String[] sNames = { "UseCustomIdentifierChange",
"AuthorAddClick", "AuthorModifyClick", "AuthorDeleteClick", "AuthorUpClick", "AuthorDownClick",
"DataAddClick", "DateModifyClick", "DateDeleteClick"};
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() {
System.out.println("AuthorAddClick");
return true;
}
private boolean authorModifyclick() {
System.out.println("AuthorModifyClick");
return true;
}
private boolean authorDeleteclick() {
System.out.println("AuthorDeleteClick");
return true;
}
private boolean authorUpclick() {
System.out.println("AuthorUpClick");
return true;
}
private boolean authorDownclick() {
System.out.println("AuthorDownClick");
return true;
}
private boolean dateAddClick() {
System.out.println("DateAddClick");
return true;
}
private boolean dateModifyClick() {
System.out.println("DateModifyClick");
return true;
}
private boolean dateDeleteClick() {
System.out.println("DateDeleteClick");
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",getValue(sIdentifiers[0]));
int nDot = sIdentifiers[0].indexOf(".");
setTextFieldText("IdentifierType",nDot>-1 ? sIdentifiers[0].substring(nDot+1) : "");
}
// 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 standard properties from the text fields
xDocumentProperties.setTitle(getTextFieldText("Title"));
xDocumentProperties.setSubject(getTextFieldText("Subject"));
String[] sKeywords = getTextFieldText("Keywords").split(",");
for (int i=0; i<sKeywords.length; i++) {
sKeywords[i] = sKeywords[i].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 all currently defined user properties with a specific name or prefix
private String[] getProperties(String sPrefix, boolean bComplete) {
@ -189,52 +371,5 @@ public class EpubMetadataDialog extends DialogBase {
}
}
@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
System.out.println("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);
XDocumentProperties xProperties = xSupplier.getDocumentProperties();
// Get the user defined properties from the properties (we need several interfaces)
xUserProperties= xProperties.getUserDefinedProperties();
xUserPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xUserProperties);
// Get and fill the simple values
readSimpleProperty(PUBLISHER);
readSimpleProperty(TYPE);
readSimpleProperty(FORMAT);
readSimpleProperty(SOURCE);
readSimpleProperty(RELATION);
readSimpleProperty(COVERAGE);
readSimpleProperty(RIGHTS);
}
@Override
protected void finalize() {
// Set the simple values
writeSimpleProperty(PUBLISHER);
writeSimpleProperty(TYPE);
writeSimpleProperty(FORMAT);
writeSimpleProperty(SOURCE);
writeSimpleProperty(RELATION);
writeSimpleProperty(COVERAGE);
writeSimpleProperty(RIGHTS);
xUserProperties = null;
xUserPropertySet = null;
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2011-02-22)
* Version 1.2 (2011-02-23)
*
*/
@ -29,14 +29,8 @@ package org.openoffice.da.comp.writer2xhtml;
import java.awt.GraphicsEnvironment;
import com.sun.star.awt.XDialog;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XDispatchHelper;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XFrame;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
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;
@ -103,7 +97,6 @@ public class EpubOptionsDialog extends OptionsDialogBase {
loadCheckBoxOption(xProps, "DisplayHiddenText");
loadCheckBoxOption(xProps, "Notes");
loadCheckBoxOption(xProps, "UseDublinCore");
loadCheckBoxOption(xProps, "UseCustomMetadata");
// Document division
loadCheckBoxOption(xProps, "Split");
@ -151,7 +144,6 @@ public class EpubOptionsDialog extends OptionsDialogBase {
saveCheckBoxOption(xProps, helper, "DisplayHiddenText", "display_hidden_text");
saveCheckBoxOption(xProps, helper, "Notes", "notes");
saveCheckBoxOption(xProps, helper, "UseDublinCore", "use_dublin_core");
saveCheckBoxOption(xProps, helper, "UseCustomMetadata", "use_custom_metadata");
// Document division
boolean bSplit = saveCheckBoxOption(xProps, "Split");
@ -213,9 +205,6 @@ public class EpubOptionsDialog extends OptionsDialogBase {
else if (sMethod.equals("EditMetadataClick")) {
editMetadataClick();
}
else if (sMethod.equals("EditCustomMetadataClick")) {
editCustomMetadataClick();
}
else if (sMethod.equals("SplitChange")) {
splitChange();
}
@ -229,8 +218,7 @@ public class EpubOptionsDialog extends OptionsDialogBase {
}
@Override public String[] getSupportedMethodNames() {
String[] sNames = { "ConfigChange", "RelativeFontSizeChange", "UseDefaultFontChange",
"EditMetadataClick", "EditCustomMetadataClick",
String[] sNames = { "ConfigChange", "RelativeFontSizeChange", "UseDefaultFontChange", "EditMetadataClick",
"SplitChange", "UsePageBreakSplitChange", "UseSplitAfterChange" };
return sNames;
}
@ -265,7 +253,6 @@ public class EpubOptionsDialog extends OptionsDialogBase {
// Special content
setControlEnabled("Notes",!isLocked("notes"));
setControlEnabled("UseDublinCore",!isLocked("use_dublin_core"));
setControlEnabled("UseCustomMetadata",!isLocked("use_custom_metadata"));
// Document division
boolean bSplit = getCheckBoxStateAsBoolean("Split");
@ -307,49 +294,22 @@ public class EpubOptionsDialog extends OptionsDialogBase {
}
private void editMetadataClick() {
// Get the DispatchHelper service
XMultiComponentFactory xMCF = xContext.getServiceManager();
XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xMCF);
Object dispatchHelper;
try {
dispatchHelper = xFactory.createInstance("com.sun.star.frame.DispatchHelper");
} catch (Exception e) {
// Failed to get dispatch helper, cannot execute dispatch
System.out.println("Failed to get dispatch helper");
return;
}
XDispatchHelper helper = (XDispatchHelper) UnoRuntime.queryInterface(XDispatchHelper.class, dispatchHelper);
// Get the current frame
XDesktop xDesktop;
Object desktop;
try {
desktop = xContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
} catch (Exception e) {
// Failed to get desktop
System.out.println("Failed to get desktop");
return;
}
xDesktop = (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);
XFrame xFrame =xDesktop.getCurrentFrame();
// Get the DispatchProvider for the current frame
XDispatchProvider xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
PropertyValue[] props = new PropertyValue[0];
helper.executeDispatch(xDispatchProvider, ".uno:SetDocumentProperties","", 0, props);
}
private void editCustomMetadataClick() {
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) {
System.out.println("Disposing the dialog!");
xComponent.dispose();
}
} catch (Exception e) {
// Failed to get dialog
}
}
private void splitChange() {
if (!isLocked("split_level")) {
boolean bState = getCheckBoxStateAsBoolean("Split");