Various work on w2l 1.2

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@20 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2009-05-01 22:12:12 +00:00
parent 6a79fd28a9
commit 0e2d725c17
14 changed files with 574 additions and 117 deletions

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-10-14)
* Version 1.2 (2009-05-01)
*
*/
@ -50,6 +50,7 @@ import com.sun.star.util.XMacroExpander;
import org.openoffice.da.comp.w2lcommon.helper.DialogBase;
import org.openoffice.da.comp.w2lcommon.helper.PropertyHelper;
import org.openoffice.da.comp.w2lcommon.helper.XPropertySetHelper;
/** This class provides an abstract uno component which implements a filter ui
*/
@ -205,7 +206,7 @@ public abstract class OptionsDialogBase extends DialogBase implements
XPropertySet xDocInfo = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, docInfo);
return getPropertyValueAsString(xDocInfo,"Template");
return XPropertySetHelper.getPropertyValueAsString(xDocInfo,"Template");
}
catch (Exception e) {
return "";
@ -287,7 +288,7 @@ public abstract class OptionsDialogBase extends DialogBase implements
UnoRuntime.queryInterface(XPropertySet.class,view);
// Get the available configurations
Object configurations = getPropertyValue(xProps,"Configurations");
Object configurations = XPropertySetHelper.getPropertyValue(xProps,"Configurations");
XNameAccess xConfigurations = (XNameAccess)
UnoRuntime.queryInterface(XNameAccess.class,configurations);
@ -296,7 +297,7 @@ public abstract class OptionsDialogBase extends DialogBase implements
Object config = xConfigurations.getByName(sName);
XPropertySet xCfgProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,config);
sLockedOptions = getPropertyValueAsString(xCfgProps,"LockedOptions");
sLockedOptions = XPropertySetHelper.getPropertyValueAsString(xCfgProps,"LockedOptions");
// Dispose the registry view
disposeRegistryView(view);
@ -330,7 +331,7 @@ public abstract class OptionsDialogBase extends DialogBase implements
String[] sStdConfigs = getListBoxStringItemList("Config");
int nStdConfigs = sStdConfigs.length;
Object configurations = getPropertyValue(xProps,"Configurations");
Object configurations = XPropertySetHelper.getPropertyValue(xProps,"Configurations");
XNameAccess xConfigurations = (XNameAccess)
UnoRuntime.queryInterface(XNameAccess.class,configurations);
sConfigNames = xConfigurations.getElementNames();
@ -346,7 +347,7 @@ public abstract class OptionsDialogBase extends DialogBase implements
Object config = xConfigurations.getByName(sConfigNames[i]);
XPropertySet xCfgProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,config);
sAllConfigs[nStdConfigs+i] = getPropertyValueAsString(xCfgProps,"DisplayName");
sAllConfigs[nStdConfigs+i] = XPropertySetHelper.getPropertyValueAsString(xCfgProps,"DisplayName");
}
catch (Exception e) {
sAllConfigs[nStdConfigs+i] = "";
@ -363,7 +364,7 @@ public abstract class OptionsDialogBase extends DialogBase implements
// Select item based on template name
String sTheTemplateName = getTemplateName();
Object templates = getPropertyValue(xProps,"Templates");
Object templates = XPropertySetHelper.getPropertyValue(xProps,"Templates");
XNameAccess xTemplates = (XNameAccess)
UnoRuntime.queryInterface(XNameAccess.class,templates);
String[] sTemplateNames = xTemplates.getElementNames();
@ -372,9 +373,9 @@ public abstract class OptionsDialogBase extends DialogBase implements
Object template = xTemplates.getByName(sTemplateNames[i]);
XPropertySet xTplProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,template);
String sTemplateName = getPropertyValueAsString(xTplProps,"TemplateName");
String sTemplateName = XPropertySetHelper.getPropertyValueAsString(xTplProps,"TemplateName");
if (sTemplateName.equals(sTheTemplateName)) {
String sConfigName = getPropertyValueAsString(xTplProps,"ConfigName");
String sConfigName = XPropertySetHelper.getPropertyValueAsString(xTplProps,"ConfigName");
for (short j=0; j<nRegConfigs; j++) {
if (sConfigNames[j].equals(sConfigName)) {
setListBoxSelectedItem("Config",(short) (nStdConfigs+j));
@ -389,12 +390,12 @@ public abstract class OptionsDialogBase extends DialogBase implements
}
// Select item based on value stored in registry
short nConfig = getPropertyValueAsShort(xProps,"Config");
short nConfig = XPropertySetHelper.getPropertyValueAsShort(xProps,"Config");
if (nConfig<nStdConfigs) {
setListBoxSelectedItem("Config",nConfig);
}
else { // Registry configurations are stored by name
String sConfigName = getPropertyValueAsString(xProps,"ConfigName");
String sConfigName = XPropertySetHelper.getPropertyValueAsString(xProps,"ConfigName");
for (short i=0; i<nRegConfigs; i++) {
if (sConfigNames[i].equals(sConfigName)) {
setListBoxSelectedItem("Config",(short) (nStdConfigs+i));
@ -405,7 +406,7 @@ public abstract class OptionsDialogBase extends DialogBase implements
protected short saveConfig(XPropertySet xProps, PropertyHelper filterData) {
// The Config list box is common for all dialogs
Object configurations = getPropertyValue(xProps,"Configurations");
Object configurations = XPropertySetHelper.getPropertyValue(xProps,"Configurations");
XNameAccess xNameAccess = (XNameAccess)
UnoRuntime.queryInterface(XNameAccess.class,configurations);
@ -418,29 +419,29 @@ public abstract class OptionsDialogBase extends DialogBase implements
Object config = xNameAccess.getByName(sConfigNames[i]);
XPropertySet xCfgProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class,config);
filterData.put("ConfigURL",expandMacros(getPropertyValueAsString(xCfgProps,"ConfigURL")));
filterData.put("TemplateURL",expandMacros(getPropertyValueAsString(xCfgProps,"TargetTemplateURL")));
setPropertyValue(xProps,"ConfigName",sConfigNames[i]);
filterData.put("ConfigURL",expandMacros(XPropertySetHelper.getPropertyValueAsString(xCfgProps,"ConfigURL")));
filterData.put("TemplateURL",expandMacros(XPropertySetHelper.getPropertyValueAsString(xCfgProps,"TargetTemplateURL")));
XPropertySetHelper.setPropertyValue(xProps,"ConfigName",sConfigNames[i]);
bFound = true;
}
catch (Exception e) {
}
}
setPropertyValue(xProps,"Config",nConfig);
if (!bFound) { setPropertyValue(xProps,"ConfigName",""); }
XPropertySetHelper.setPropertyValue(xProps,"Config",nConfig);
if (!bFound) { XPropertySetHelper.setPropertyValue(xProps,"ConfigName",""); }
return nConfig;
}
// Check box option (boolean)
protected boolean loadCheckBoxOption(XPropertySet xProps, String sName) {
boolean bValue = getPropertyValueAsBoolean(xProps,sName);
boolean bValue = XPropertySetHelper.getPropertyValueAsBoolean(xProps,sName);
setCheckBoxStateAsBoolean(sName, bValue);
return bValue;
}
protected boolean saveCheckBoxOption(XPropertySet xProps, String sName) {
boolean bValue = getCheckBoxStateAsBoolean(sName);
setPropertyValue(xProps, sName, bValue);
XPropertySetHelper.setPropertyValue(xProps, sName, bValue);
return bValue;
}
@ -455,14 +456,14 @@ public abstract class OptionsDialogBase extends DialogBase implements
// List box option
protected short loadListBoxOption(XPropertySet xProps, String sName) {
short nValue = getPropertyValueAsShort(xProps, sName);
short nValue = XPropertySetHelper.getPropertyValueAsShort(xProps, sName);
setListBoxSelectedItem(sName ,nValue);
return nValue;
}
protected short saveListBoxOption(XPropertySet xProps, String sName) {
short nValue = getListBoxSelectedItem(sName);
setPropertyValue(xProps, sName, nValue);
XPropertySetHelper.setPropertyValue(xProps, sName, nValue);
return nValue;
}
@ -477,14 +478,14 @@ public abstract class OptionsDialogBase extends DialogBase implements
// Combo box option
protected String loadComboBoxOption(XPropertySet xProps, String sName) {
String sValue = getPropertyValueAsString(xProps, sName);
String sValue = XPropertySetHelper.getPropertyValueAsString(xProps, sName);
setComboBoxText(sName ,sValue);
return sValue;
}
protected String saveComboBoxOption(XPropertySet xProps, String sName) {
String sValue = getComboBoxText(sName);
setPropertyValue(xProps, sName, sValue);
XPropertySetHelper.setPropertyValue(xProps, sName, sValue);
return sValue;
}
@ -499,14 +500,14 @@ public abstract class OptionsDialogBase extends DialogBase implements
// Text Field option
protected String loadTextFieldOption(XPropertySet xProps, String sName) {
String sValue = getPropertyValueAsString(xProps, sName);
String sValue = XPropertySetHelper.getPropertyValueAsString(xProps, sName);
setTextFieldText(sName ,sValue);
return sValue;
}
protected String saveTextFieldOption(XPropertySet xProps, String sName) {
String sValue = getTextFieldText(sName);
setPropertyValue(xProps, sName, sValue);
XPropertySetHelper.setPropertyValue(xProps, sName, sValue);
return sValue;
}
@ -521,14 +522,14 @@ public abstract class OptionsDialogBase extends DialogBase implements
// Numeric option
protected int loadNumericOption(XPropertySet xProps, String sName) {
int nValue = getPropertyValueAsInteger(xProps, sName);
int nValue = XPropertySetHelper.getPropertyValueAsInteger(xProps, sName);
setNumericFieldValue(sName, nValue);
return nValue;
}
protected int saveNumericOption(XPropertySet xProps, String sName) {
int nValue = getNumericFieldValue(sName);
setPropertyValue(xProps, sName, nValue);
XPropertySetHelper.setPropertyValue(xProps, sName, nValue);
return nValue;
}

View file

@ -32,11 +32,11 @@ import com.sun.star.awt.XControlModel;
import com.sun.star.awt.XDialog;
import com.sun.star.awt.XDialogEventHandler;
import com.sun.star.awt.XDialogProvider2;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
//import com.sun.star.beans.PropertyVetoException;
//import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
//import com.sun.star.lang.IllegalArgumentException;
//import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XServiceName;
@ -436,67 +436,6 @@ msgBox.showMessage("Error",e.toString()+" "+e.getStackTrace()[0].toString());
}
}
// Helpers for access to an XPropertySet. The helpers will fail silently if
// names or data is provided, but the subclass is expected to use them with
// correct data only...
protected Object getPropertyValue(XPropertySet xProps, String sName) {
try {
return xProps.getPropertyValue(sName);
}
catch (UnknownPropertyException e) {
return null;
}
catch (WrappedTargetException e) {
return null;
}
}
protected void setPropertyValue(XPropertySet xProps, String sName, Object value) {
try {
xProps.setPropertyValue(sName,value);
}
catch (UnknownPropertyException e) {
}
catch (PropertyVetoException e) { // unacceptable value
}
catch (IllegalArgumentException e) {
}
catch (WrappedTargetException e) {
}
}
protected String getPropertyValueAsString(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof String ? (String) value : "";
}
protected int getPropertyValueAsInteger(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof Integer ? ((Integer) value).intValue() : 0;
}
protected void setPropertyValue(XPropertySet xProps, String sName, int nValue) {
setPropertyValue(xProps,sName,new Integer(nValue));
}
protected short getPropertyValueAsShort(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof Short ? ((Short) value).shortValue() : 0;
}
protected void setPropertyValue(XPropertySet xProps, String sName, short nValue) {
setPropertyValue(xProps,sName,new Short(nValue));
}
protected boolean getPropertyValueAsBoolean(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof Boolean ? ((Boolean) value).booleanValue() : false;
}
protected void setPropertyValue(XPropertySet xProps, String sName, boolean bValue) {
setPropertyValue(xProps,sName,new Boolean(bValue));
}
}

View file

@ -0,0 +1,86 @@
/**
* RegistryHelper.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-2009 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2009-05-01)
*
*
*/
package org.openoffice.da.comp.w2lcommon.helper;
import com.sun.star.beans.PropertyValue;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
/** This class defines convenience methods to access the OOo registry
* using a given base path
*/
public class RegistryHelper {
private XComponentContext xContext;
/** Construct a new RegistryHelper using a given component context
*
* @param xContext the context to use to create new services
*/
public RegistryHelper(XComponentContext xContext) {
this.xContext = xContext;
}
/** Get a registry view relative to the given path
*
* @param sPath the base path witin the registry
* @param bUpdate true if we need update access
* @return the registry view
* @throws com.sun.star.uno.Exception
*/
public Object getRegistryView(String sPath, boolean bUpdate)
throws com.sun.star.uno.Exception {
//Object provider = xMSF.createInstance(
Object provider = xContext.getServiceManager().createInstanceWithContext(
"com.sun.star.configuration.ConfigurationProvider", xContext);
XMultiServiceFactory xProvider = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class,provider);
PropertyValue[] args = new PropertyValue[1];
args[0] = new PropertyValue();
args[0].Name = "nodepath";
args[0].Value = sPath;
String sServiceName = bUpdate ?
"com.sun.star.configuration.ConfigurationUpdateAccess" :
"com.sun.star.configuration.ConfigurationAccess";
Object view = xProvider.createInstanceWithArguments(sServiceName,args);
return view;
}
/** Dispose a previously obtained registry view
*
* @param view the view to dispose
*/
public void disposeRegistryView(Object view) {
XComponent xComponent = (XComponent)
UnoRuntime.queryInterface(XComponent.class,view);
xComponent.dispose();
}
}

View file

@ -0,0 +1,100 @@
/************************************************************************
*
* XPropertySetHelper.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-2008 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-07-21)
*
*/
package org.openoffice.da.comp.w2lcommon.helper;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
/** Helper class providing staic convenience methods for accesing an XPropertySet
* The helpers will fail silently if names or data is provided, but the user is expected to
* apply them with correct data only...
*/
public class XPropertySetHelper {
public static Object getPropertyValue(XPropertySet xProps, String sName) {
try {
return xProps.getPropertyValue(sName);
}
catch (UnknownPropertyException e) {
return null;
}
catch (WrappedTargetException e) {
return null;
}
}
public static void setPropertyValue(XPropertySet xProps, String sName, Object value) {
try {
xProps.setPropertyValue(sName,value);
}
catch (UnknownPropertyException e) {
}
catch (PropertyVetoException e) { // unacceptable value
}
catch (IllegalArgumentException e) {
}
catch (WrappedTargetException e) {
}
}
public static String getPropertyValueAsString(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof String ? (String) value : "";
}
public static int getPropertyValueAsInteger(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof Integer ? ((Integer) value).intValue() : 0;
}
public static void setPropertyValue(XPropertySet xProps, String sName, int nValue) {
setPropertyValue(xProps,sName,new Integer(nValue));
}
public static short getPropertyValueAsShort(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof Short ? ((Short) value).shortValue() : 0;
}
public static void setPropertyValue(XPropertySet xProps, String sName, short nValue) {
setPropertyValue(xProps,sName,new Short(nValue));
}
public static boolean getPropertyValueAsBoolean(XPropertySet xProps, String sName) {
Object value = getPropertyValue(xProps,sName);
return value instanceof Boolean ? ((Boolean) value).booleanValue() : false;
}
public static void setPropertyValue(XPropertySet xProps, String sName, boolean bValue) {
setPropertyValue(xProps,sName,new Boolean(bValue));
}
}