wizards/Jar_commonwizards.mk | 1 wizards/com/sun/star/wizards/common/ConfigGroup.java | 6 wizards/com/sun/star/wizards/common/ConfigNode.java | 6 wizards/com/sun/star/wizards/common/ConfigSet.java | 2 wizards/com/sun/star/wizards/common/Configuration.java | 102 - wizards/com/sun/star/wizards/common/DebugHelper.java | 6 wizards/com/sun/star/wizards/common/Desktop.java | 201 +- wizards/com/sun/star/wizards/common/FileAccess.java | 464 ++++ wizards/com/sun/star/wizards/common/Helper.java | 102 - wizards/com/sun/star/wizards/common/IRenderer.java | 2 wizards/com/sun/star/wizards/common/Indexable.java | 2 wizards/com/sun/star/wizards/common/JavaTools.java | 163 + wizards/com/sun/star/wizards/common/NamedValueCollection.java | 20 wizards/com/sun/star/wizards/common/NumberFormatter.java | 47 wizards/com/sun/star/wizards/common/NumericalHelper.java | 980 +++++++++- wizards/com/sun/star/wizards/common/ParaStyled.java | 4 wizards/com/sun/star/wizards/common/PlaceholderTextElement.java | 14 wizards/com/sun/star/wizards/common/Properties.java | 4 wizards/com/sun/star/wizards/common/PropertyNames.java | 2 wizards/com/sun/star/wizards/common/PropertySetHelper.java | 124 + wizards/com/sun/star/wizards/common/Resource.java | 25 wizards/com/sun/star/wizards/common/SystemDialog.java | 105 - wizards/com/sun/star/wizards/common/TemplateElement.java | 2 wizards/com/sun/star/wizards/common/TextElement.java | 1 wizards/com/sun/star/wizards/common/UCB.java | 17 wizards/com/sun/star/wizards/common/XMLProvider.java | 2 wizards/com/sun/star/wizards/db/BlindtextCreator.java | 12 wizards/com/sun/star/wizards/db/ColumnPropertySet.java | 16 wizards/com/sun/star/wizards/db/CommandMetaData.java | 146 + wizards/com/sun/star/wizards/db/CommandName.java | 27 wizards/com/sun/star/wizards/db/DBMetaData.java | 69 wizards/com/sun/star/wizards/db/FieldColumn.java | 18 wizards/com/sun/star/wizards/db/QueryMetaData.java | 38 wizards/com/sun/star/wizards/db/RecordParser.java | 23 wizards/com/sun/star/wizards/db/SQLQueryComposer.java | 43 wizards/com/sun/star/wizards/db/TableDescriptor.java | 71 wizards/com/sun/star/wizards/db/TypeInspector.java | 48 wizards/com/sun/star/wizards/document/Control.java | 42 wizards/com/sun/star/wizards/document/DatabaseControl.java | 14 wizards/com/sun/star/wizards/document/FormHandler.java | 147 + wizards/com/sun/star/wizards/document/GridControl.java | 7 wizards/com/sun/star/wizards/document/OfficeDocument.java | 165 + wizards/com/sun/star/wizards/document/Shape.java | 4 wizards/com/sun/star/wizards/document/TimeStampControl.java | 28 wizards/com/sun/star/wizards/form/CallFormWizard.java | 31 wizards/com/sun/star/wizards/form/DataEntrySetter.java | 21 wizards/com/sun/star/wizards/form/FieldLinker.java | 19 wizards/com/sun/star/wizards/form/Finalizer.java | 27 wizards/com/sun/star/wizards/form/FormConfiguration.java | 98 - wizards/com/sun/star/wizards/form/FormControlArranger.java | 25 wizards/com/sun/star/wizards/form/FormDocument.java | 65 wizards/com/sun/star/wizards/form/FormWizard.java | 26 wizards/com/sun/star/wizards/form/StyleApplier.java | 108 - wizards/com/sun/star/wizards/form/UIControlArranger.java | 41 wizards/com/sun/star/wizards/query/CallQueryWizard.java | 12 wizards/com/sun/star/wizards/query/Finalizer.java | 20 wizards/com/sun/star/wizards/query/QuerySummary.java | 16 wizards/com/sun/star/wizards/query/QueryWizard.java | 21 wizards/com/sun/star/wizards/report/CallReportWizard.java | 6 wizards/com/sun/star/wizards/report/DBColumn.java | 58 wizards/com/sun/star/wizards/report/Dataimport.java | 25 wizards/com/sun/star/wizards/report/GroupFieldHandler.java | 9 wizards/com/sun/star/wizards/report/IReportBuilderLayouter.java | 37 wizards/com/sun/star/wizards/report/IReportDefinitionReadAccess.java | 7 wizards/com/sun/star/wizards/report/IReportDocument.java | 106 - wizards/com/sun/star/wizards/report/RecordTable.java | 9 wizards/com/sun/star/wizards/report/ReportFinalizer.java | 61 wizards/com/sun/star/wizards/report/ReportImplementationHelper.java | 4 wizards/com/sun/star/wizards/report/ReportLayouter.java | 57 wizards/com/sun/star/wizards/report/ReportTextDocument.java | 96 wizards/com/sun/star/wizards/report/ReportTextImplementation.java | 25 wizards/com/sun/star/wizards/report/ReportWizard.java | 30 wizards/com/sun/star/wizards/report/report.component | 2 wizards/com/sun/star/wizards/reportbuilder/ReportBuilderImplementation.java | 5 wizards/com/sun/star/wizards/reportbuilder/layout/ColumnarSingleColumn.java | 2 wizards/com/sun/star/wizards/reportbuilder/layout/ColumnarThreeColumns.java | 3 wizards/com/sun/star/wizards/reportbuilder/layout/ColumnarTwoColumns.java | 2 wizards/com/sun/star/wizards/reportbuilder/layout/DesignTemplate.java | 10 wizards/com/sun/star/wizards/reportbuilder/layout/InBlocksLabelsAbove.java | 4 wizards/com/sun/star/wizards/reportbuilder/layout/InBlocksLabelsLeft.java | 4 wizards/com/sun/star/wizards/reportbuilder/layout/ReportBuilderLayouter.java | 101 - wizards/com/sun/star/wizards/reportbuilder/layout/SectionEmptyObject.java | 1 wizards/com/sun/star/wizards/reportbuilder/layout/SectionLabel.java | 4 wizards/com/sun/star/wizards/reportbuilder/layout/SectionObject.java | 2 wizards/com/sun/star/wizards/reportbuilder/layout/SectionTextField.java | 3 wizards/com/sun/star/wizards/reportbuilder/layout/Tabular.java | 3 wizards/com/sun/star/wizards/table/CGCategory.java | 10 wizards/com/sun/star/wizards/table/CGTable.java | 8 wizards/com/sun/star/wizards/table/CallTableWizard.java | 19 wizards/com/sun/star/wizards/table/FieldDescription.java | 2 wizards/com/sun/star/wizards/table/FieldFormatter.java | 203 +- wizards/com/sun/star/wizards/table/Finalizer.java | 48 wizards/com/sun/star/wizards/table/PrimaryKeyHandler.java | 49 wizards/com/sun/star/wizards/table/ScenarioSelector.java | 47 wizards/com/sun/star/wizards/table/TableWizard.java | 72 wizards/com/sun/star/wizards/text/TextDocument.java | 184 + wizards/com/sun/star/wizards/text/TextFieldHandler.java | 40 wizards/com/sun/star/wizards/text/TextSectionHandler.java | 26 wizards/com/sun/star/wizards/text/TextStyleHandler.java | 2 wizards/com/sun/star/wizards/text/TextTableHandler.java | 40 wizards/com/sun/star/wizards/text/ViewHandler.java | 3 wizards/com/sun/star/wizards/ui/AggregateComponent.java | 94 wizards/com/sun/star/wizards/ui/ButtonList.java | 111 + wizards/com/sun/star/wizards/ui/CommandFieldSelection.java | 37 wizards/com/sun/star/wizards/ui/ControlScroller.java | 100 - wizards/com/sun/star/wizards/ui/DBLimitedFieldSelection.java | 29 wizards/com/sun/star/wizards/ui/FieldSelection.java | 72 wizards/com/sun/star/wizards/ui/FilterComponent.java | 125 - wizards/com/sun/star/wizards/ui/ImageList.java | 90 wizards/com/sun/star/wizards/ui/PathSelection.java | 19 wizards/com/sun/star/wizards/ui/PeerConfig.java | 83 wizards/com/sun/star/wizards/ui/SortingComponent.java | 90 wizards/com/sun/star/wizards/ui/TitlesComponent.java | 41 wizards/com/sun/star/wizards/ui/UIConsts.java | 88 wizards/com/sun/star/wizards/ui/UnoDialog.java | 209 +- wizards/com/sun/star/wizards/ui/UnoDialog2.java | 149 + wizards/com/sun/star/wizards/ui/WizardDialog.java | 201 +- wizards/com/sun/star/wizards/ui/XCommandSelectionListener.java | 24 wizards/com/sun/star/wizards/ui/XCompletion.java | 7 wizards/com/sun/star/wizards/ui/XFieldSelectionListener.java | 12 wizards/com/sun/star/wizards/ui/XPathSelectionListener.java | 2 wizards/com/sun/star/wizards/ui/event/AbstractListener.java | 7 wizards/com/sun/star/wizards/ui/event/CommonListener.java | 5 wizards/com/sun/star/wizards/ui/event/DataAware.java | 92 wizards/com/sun/star/wizards/ui/event/DataAwareFields.java | 13 wizards/com/sun/star/wizards/ui/event/EventNames.java | 30 wizards/com/sun/star/wizards/ui/event/ListModelBinder.java | 5 wizards/com/sun/star/wizards/ui/event/MethodInvocation.java | 17 wizards/com/sun/star/wizards/ui/event/RadioDataAware.java | 6 wizards/com/sun/star/wizards/ui/event/SimpleDataAware.java | 34 wizards/com/sun/star/wizards/ui/event/Task.java | 77 wizards/com/sun/star/wizards/ui/event/TaskEvent.java | 5 wizards/com/sun/star/wizards/ui/event/TaskListener.java | 9 wizards/com/sun/star/wizards/ui/event/UnoDataAware.java | 108 - 134 files changed, 5798 insertions(+), 1474 deletions(-)
New commits: commit 04f43cd6a0159da29a0df4bf8e27387156f321e5 Author: Noel Grandin <n...@peralex.com> Date: Mon Sep 22 12:23:28 2014 +0200 84059 - form wizard : files required could not be found I've essentially unwound most the Java changes I made te wizards module in the last few months. I will revisit my changes at a later date and make them more carefully :-) Change-Id: I9221a825dc8de6edc96d6db07072aefcd1a37107 diff --git a/wizards/Jar_commonwizards.mk b/wizards/Jar_commonwizards.mk index 3932223..a13a114 100644 --- a/wizards/Jar_commonwizards.mk +++ b/wizards/Jar_commonwizards.mk @@ -105,6 +105,7 @@ $(eval $(call gb_Jar_add_sourcefiles,commonwizards,\ wizards/com/sun/star/wizards/ui/UIConsts \ wizards/com/sun/star/wizards/ui/UnoDialog \ wizards/com/sun/star/wizards/ui/UnoDialog2 \ + wizards/com/sun/star/wizards/ui/XCommandSelectionListener \ wizards/com/sun/star/wizards/ui/XFieldSelectionListener \ wizards/com/sun/star/wizards/ui/XPathSelectionListener \ wizards/com/sun/star/wizards/ui/XCompletion \ diff --git a/wizards/com/sun/star/wizards/common/ConfigGroup.java b/wizards/com/sun/star/wizards/common/ConfigGroup.java index 238e3fb..0a71af2 100644 --- a/wizards/com/sun/star/wizards/common/ConfigGroup.java +++ b/wizards/com/sun/star/wizards/common/ConfigGroup.java @@ -68,7 +68,9 @@ public class ConfigGroup implements ConfigNode * convert the primitive type value of the * given Field object to the corresponding * Java Object value. + * @param field * @return the value of the field as a Object. + * @throws IllegalAccessException */ public Object convertValue(Field field) throws IllegalAccessException { @@ -78,11 +80,11 @@ public class ConfigGroup implements ConfigNode } if (field.getType().equals(Integer.TYPE)) { - return Integer.valueOf(field.getInt(this)); + return new Integer(field.getInt(this)); } if (field.getType().equals(Short.TYPE)) { - return Short.valueOf(field.getShort(this)); + return new Short(field.getShort(this)); } if (field.getType().equals(Float.TYPE)) { diff --git a/wizards/com/sun/star/wizards/common/ConfigNode.java b/wizards/com/sun/star/wizards/common/ConfigNode.java index 0d2abd8..4803ec1 100644 --- a/wizards/com/sun/star/wizards/common/ConfigNode.java +++ b/wizards/com/sun/star/wizards/common/ConfigNode.java @@ -35,9 +35,9 @@ public interface ConfigNode * to be used in a tree like way, reading objects and subobjects and so on, * it might be practical to be able to pass an extra parameter, for a free use. */ - void readConfiguration(Object configurationView, Object param); + public void readConfiguration(Object configurationView, Object param); - void writeConfiguration(Object configurationView, Object param); + public void writeConfiguration(Object configurationView, Object param); - void setRoot(Object root); + public void setRoot(Object root); } diff --git a/wizards/com/sun/star/wizards/common/ConfigSet.java b/wizards/com/sun/star/wizards/common/ConfigSet.java index 75aaa51..2e97984 100644 --- a/wizards/com/sun/star/wizards/common/ConfigSet.java +++ b/wizards/com/sun/star/wizards/common/ConfigSet.java @@ -382,6 +382,8 @@ public class ConfigSet implements ConfigNode, XMLProvider, ListModel * This method reindexes the given member to be * the index number 0 * Do not forget to call commit() after calling this method. + * @param confView + * @param memberName */ public void reindexSet(Object confView, String memberName, String indexPropertyName) throws Exception { diff --git a/wizards/com/sun/star/wizards/common/Configuration.java b/wizards/com/sun/star/wizards/common/Configuration.java index bed4b9c..2eb3827 100644 --- a/wizards/com/sun/star/wizards/common/Configuration.java +++ b/wizards/com/sun/star/wizards/common/Configuration.java @@ -26,6 +26,7 @@ import com.sun.star.uno.AnyConverter; import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import com.sun.star.lang.Locale; +import com.sun.star.util.XChangesBatch; /** * This class gives access to the OO configuration API. @@ -108,14 +109,30 @@ public abstract class Configuration public static void set(int value, String name, Object parent) throws Exception { - set(Integer.valueOf(value), name, parent); + set(new Integer(value), name, parent); } + public static void set(short value, String name, Object parent) throws Exception + { + set(new Short(value), name, parent); + } + public static void set(String value, String name, Object parent) throws Exception + { + set((Object) value, name, parent); + } - - - + public static void set(boolean value, String name, Object parent) throws Exception + { + if (value) + { + set(Boolean.TRUE, name, parent); + } + else + { + set(Boolean.FALSE, name, parent); + } + } public static void set(Object value, String name, Object parent) throws com.sun.star.lang.IllegalArgumentException, PropertyVetoException, UnknownPropertyException, WrappedTargetException { @@ -123,6 +140,10 @@ public abstract class Configuration } /** Creates a new instance of RegistryEntry + * @param name + * @param parent + * @return + * @throws Exception */ public static Object getConfigurationNode(String name, Object parent) throws Exception { @@ -179,7 +200,7 @@ public abstract class Configuration } } - private static String getLocaleString(XMultiServiceFactory xMSF, String root, String key) + public static String getLocaleString(XMultiServiceFactory xMSF, String root, String key) { String sLocale = PropertyNames.EMPTY_STRING; try @@ -198,7 +219,7 @@ public abstract class Configuration return sLocale; } - private static Locale getLocale(XMultiServiceFactory xMSF, String root, String key) + public static Locale getLocale(XMultiServiceFactory xMSF, String root, String key) { Locale aLocLocale = new Locale(); String sLocale = getLocaleString(xMSF, root, key); @@ -216,18 +237,33 @@ public abstract class Configuration return getLocale(xMSF, "org.openoffice.Setup/L10N/", "ooSetupSystemLocale"); } + public static Locale getUILocale(XMultiServiceFactory xMSF) + { + return getLocale(xMSF, "org.openoffice.Setup/L10N/", "ooLocale"); + } + public static String getLocaleString(XMultiServiceFactory xMSF) + { + return getLocaleString(xMSF, "org.openoffice.Setup/L10N/", "ooSetupSystemLocale"); + } - - - + public static String getUILocaleString(XMultiServiceFactory xMSF) + { + return getLocaleString(xMSF, "org.openoffice.Setup/L10N/", "ooLocale"); + } /** * This method creates a new configuration node and adds it * to the given view. Note that if a node with the given name * already exists it will be completely removed from * the configuration. + * @param configView + * @param name * @return the new created configuration node. + * @throws com.sun.star.lang.WrappedTargetException + * @throws ElementExistException + * @throws NoSuchElementException + * @throws com.sun.star.uno.Exception */ public static Object addConfigNode(Object configView, String name) throws com.sun.star.lang.WrappedTargetException, ElementExistException, NoSuchElementException, com.sun.star.uno.Exception { @@ -264,11 +300,28 @@ public abstract class Configuration } } + public static void commit(Object configView) throws WrappedTargetException + { + XChangesBatch xUpdateControl = UnoRuntime.queryInterface(XChangesBatch.class, configView); + xUpdateControl.commitChanges(); + } + public static void updateConfiguration(XMultiServiceFactory xmsf, String path, String name, ConfigNode node, Object param) throws com.sun.star.uno.Exception, com.sun.star.container.ElementExistException, NoSuchElementException, WrappedTargetException + { + Object view = Configuration.getConfigurationRoot(xmsf, path, true); + addConfigNode(path, name); + node.writeConfiguration(view, param); + XChangesBatch xUpdateControl = UnoRuntime.queryInterface(XChangesBatch.class, view); + xUpdateControl.commitChanges(); + } - - - + public static void removeNode(XMultiServiceFactory xmsf, String path, String name) throws com.sun.star.uno.Exception, com.sun.star.container.ElementExistException, NoSuchElementException, WrappedTargetException + { + Object view = Configuration.getConfigurationRoot(xmsf, path, true); + removeNode(view, name); + XChangesBatch xUpdateControl = UnoRuntime.queryInterface(XChangesBatch.class, view); + xUpdateControl.commitChanges(); + } public static String[] getNodeDisplayNames(XNameAccess _xNameAccessNode) { @@ -334,7 +387,32 @@ public abstract class Configuration return null; } + public static XNameAccess getChildNodebyDisplayName(XNameAccess _xNameAccessNode, String _displayname) + { + return getChildNodebyDisplayName(_xNameAccessNode, _displayname, PropertyNames.PROPERTY_NAME); + } + public static XNameAccess getChildNodebyDisplayName(XNameAccess _xNameAccessNode, String _displayname, String _nodename) + { + String[] snames = null; + try + { + snames = _xNameAccessNode.getElementNames(); + for (int i = 0; i < snames.length; i++) + { + String curdisplayname = (String) Helper.getUnoPropertyValue(_xNameAccessNode.getByName(snames[i]), _nodename); + if (curdisplayname.equals(_displayname)) + { + return UnoRuntime.queryInterface(XNameAccess.class, _xNameAccessNode.getByName(snames[i])); + } + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + return null; + } public static XNameAccess getChildNodebyDisplayName(XMultiServiceFactory _xMSF, Locale _aLocale, XNameAccess _xNameAccessNode, String _displayname, String _nodename, int _nmaxcharcount) { diff --git a/wizards/com/sun/star/wizards/common/DebugHelper.java b/wizards/com/sun/star/wizards/common/DebugHelper.java index cc3bdf3..16c39fb 100644 --- a/wizards/com/sun/star/wizards/common/DebugHelper.java +++ b/wizards/com/sun/star/wizards/common/DebugHelper.java @@ -21,7 +21,11 @@ import com.sun.star.uno.Exception; public class DebugHelper { - +//TODO - Verify these methods. Can not remove? + public static void exception(String DetailedMessage, Exception ex, int err, String additionalArgument) throws java.lang.Exception + { +// throw new UnsupportedOperationException("Not supported yet."); + } public static void exception(int err, String additionalArgument) throws java.lang.Exception { diff --git a/wizards/com/sun/star/wizards/common/Desktop.java b/wizards/com/sun/star/wizards/common/Desktop.java index 5d71d92..8b2c39a 100644 --- a/wizards/com/sun/star/wizards/common/Desktop.java +++ b/wizards/com/sun/star/wizards/common/Desktop.java @@ -18,16 +18,25 @@ package com.sun.star.wizards.common; import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.WrappedTargetException; +import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sheet.XSpreadsheetDocument; +import com.sun.star.text.XTextDocument; +import com.sun.star.uno.Any; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.util.XURLTransformer; import com.sun.star.lang.Locale; +import com.sun.star.uno.XInterface; import com.sun.star.bridge.XUnoUrlResolver; import com.sun.star.comp.helper.Bootstrap; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XEnumeration; import com.sun.star.container.XHierarchicalNameAccess; import com.sun.star.container.XNameAccess; +import com.sun.star.util.XStringSubstitution; import com.sun.star.frame.*; import com.sun.star.i18n.KParseType; import com.sun.star.i18n.ParseResult; @@ -36,6 +45,11 @@ import com.sun.star.i18n.XCharacterClassification; public class Desktop { + /** Creates a new instance of Desktop */ + public Desktop() + { + } + public static XDesktop getDesktop(XMultiServiceFactory xMSF) { com.sun.star.uno.XInterface xInterface = null; @@ -66,7 +80,25 @@ public class Desktop return xFrameSuppl.getActiveFrame(); } - private static XDispatch getDispatcher(XFrame xFrame, String _stargetframe, com.sun.star.util.URL oURL) + public static XComponent getActiveComponent(XMultiServiceFactory _xMSF) + { + XFrame xFrame = getActiveFrame(_xMSF); + return UnoRuntime.queryInterface(XComponent.class, xFrame.getController().getModel()); + } + + public static XTextDocument getActiveTextDocument(XMultiServiceFactory _xMSF) + { + XComponent xComponent = getActiveComponent(_xMSF); + return UnoRuntime.queryInterface(XTextDocument.class, xComponent); + } + + public static XSpreadsheetDocument getActiveSpreadsheetDocument(XMultiServiceFactory _xMSF) + { + XComponent xComponent = getActiveComponent(_xMSF); + return UnoRuntime.queryInterface(XSpreadsheetDocument.class, xComponent); + } + + public static XDispatch getDispatcher(XMultiServiceFactory xMSF, XFrame xFrame, String _stargetframe, com.sun.star.util.URL oURL) { try { @@ -82,7 +114,7 @@ public class Desktop return null; } - private static com.sun.star.util.URL getDispatchURL(XMultiServiceFactory xMSF, String _sURL) + public static com.sun.star.util.URL getDispatchURL(XMultiServiceFactory xMSF, String _sURL) { try { @@ -101,10 +133,10 @@ public class Desktop return null; } - private static void dispatchURL(XMultiServiceFactory xMSF, String sURL, XFrame xFrame, String _stargetframe) + public static void dispatchURL(XMultiServiceFactory xMSF, String sURL, XFrame xFrame, String _stargetframe) { com.sun.star.util.URL oURL = getDispatchURL(xMSF, sURL); - XDispatch xDispatch = getDispatcher(xFrame, _stargetframe, oURL); + XDispatch xDispatch = getDispatcher(xMSF, xFrame, _stargetframe, oURL); dispatchURL(xDispatch, oURL); } @@ -113,13 +145,13 @@ public class Desktop dispatchURL(xMSF, sURL, xFrame, PropertyNames.EMPTY_STRING); } - private static void dispatchURL(XDispatch _xDispatch, com.sun.star.util.URL oURL) + public static void dispatchURL(XDispatch _xDispatch, com.sun.star.util.URL oURL) { PropertyValue[] oArg = new PropertyValue[0]; _xDispatch.dispatch(oURL, oArg); } - private static XMultiComponentFactory getMultiComponentFactory() throws com.sun.star.uno.Exception, RuntimeException, java.lang.Exception + public static XMultiComponentFactory getMultiComponentFactory() throws com.sun.star.uno.Exception, RuntimeException, java.lang.Exception { XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext(null); // initial serviceManager @@ -156,7 +188,7 @@ public class Desktop return sIncSuffix; } - private static String getIncrementSuffix(XHierarchicalNameAccess xElementContainer, String ElementName) + public static String getIncrementSuffix(XHierarchicalNameAccess xElementContainer, String ElementName) { boolean bElementexists = true; int i = 1; @@ -178,7 +210,7 @@ public class Desktop return sIncSuffix; } - private static int checkforfirstSpecialCharacter(XMultiServiceFactory _xMSF, String _sString, Locale _aLocale) + public static int checkforfirstSpecialCharacter(XMultiServiceFactory _xMSF, String _sString, Locale _aLocale) { try { @@ -214,6 +246,8 @@ public class Desktop /** * Checks if the passed Element Name already exists in the ElementContainer. If yes it appends a * suffix to make it unique + * @param xElementContainer + * @param sElementName * @return a unique Name ready to be added to the container. */ public static String getUniqueName(XNameAccess xElementContainer, String sElementName) @@ -225,6 +259,8 @@ public class Desktop /** * Checks if the passed Element Name already exists in the ElementContainer. If yes it appends a * suffix to make it unique + * @param xElementContainer + * @param sElementName * @return a unique Name ready to be added to the container. */ public static String getUniqueName(XHierarchicalNameAccess xElementContainer, String sElementName) @@ -236,6 +272,9 @@ public class Desktop /** * Checks if the passed Element Name already exists in the list If yes it appends a * suffix to make it unique + * @param _slist + * @param _sElementName + * @param _sSuffixSeparator * @return a unique Name not being in the passed list. */ public static String getUniqueName(String[] _slist, String _sElementName, String _sSuffixSeparator) @@ -265,9 +304,67 @@ public class Desktop return PropertyNames.EMPTY_STRING; } + /** + * @deprecated use Configuration.getConfigurationRoot() with the same parameters instead + * @param xMSF + * @param KeyName + * @param bForUpdate + * @return + */ + public static XInterface getRegistryKeyContent(XMultiServiceFactory xMSF, String KeyName, boolean bForUpdate) + { + try + { + Object oConfigProvider; + PropertyValue[] aNodePath = new PropertyValue[1]; + oConfigProvider = xMSF.createInstance("com.sun.star.configuration.ConfigurationProvider"); + aNodePath[0] = new PropertyValue(); + aNodePath[0].Name = "nodepath"; + aNodePath[0].Value = KeyName; + XMultiServiceFactory xMSFConfig = UnoRuntime.queryInterface(XMultiServiceFactory.class, oConfigProvider); + if (bForUpdate) + { + return (XInterface) xMSFConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aNodePath); + } + else + { + return (XInterface) xMSFConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath); + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } + + /** + * @deprecated used to retrieve the most common paths used in the office application + */ + public class OfficePathRetriever + { + public String TemplatePath; + public String BitmapPath; + public String UserTemplatePath; + public String WorkPath; - private static String getTemplatePath(XMultiServiceFactory _xMSF) + public OfficePathRetriever(XMultiServiceFactory xMSF) + { + try + { + TemplatePath = FileAccess.getOfficePath(xMSF, "Template", "share", "/wizard"); + UserTemplatePath = FileAccess.getOfficePath(xMSF, "Template", "user", PropertyNames.EMPTY_STRING); + BitmapPath = FileAccess.combinePaths(xMSF, TemplatePath, "/../wizard/bitmap"); + WorkPath = FileAccess.getOfficePath(xMSF, "Work", PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING); + } + catch (NoValidPathException nopathexception) + { + } + } + } + + public static String getTemplatePath(XMultiServiceFactory _xMSF) { try { @@ -279,7 +376,17 @@ public class Desktop return PropertyNames.EMPTY_STRING; } - + public static String getUserTemplatePath(XMultiServiceFactory _xMSF) + { + try + { + return FileAccess.getOfficePath(_xMSF, "Template", "user", PropertyNames.EMPTY_STRING); + } + catch (NoValidPathException nopathexception) + { + } + return PropertyNames.EMPTY_STRING; + } public static String getBitmapPath(XMultiServiceFactory _xMSF) { @@ -293,9 +400,83 @@ public class Desktop return PropertyNames.EMPTY_STRING; } + public static String getWorkPath(XMultiServiceFactory _xMSF) + { + try + { + return FileAccess.getOfficePath(_xMSF, "Work", PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING); + } + catch (NoValidPathException nopathexception) + { + } + return PropertyNames.EMPTY_STRING; + } + public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) + { + Object xPathSubst = null; + try + { + xPathSubst = xMSF.createInstance("com.sun.star.util.PathSubstitution"); + } + catch (com.sun.star.uno.Exception e) + { + e.printStackTrace(); + } + if (xPathSubst != null) + { + return UnoRuntime.queryInterface(XStringSubstitution.class, xPathSubst); + } + else + { + return null; + } + } + /** + * This method searches (and hopefully finds...) a frame + * with a componentWindow. + * It does it in three phases: + * 1. Check if the given desktop argument has a componentWindow. + * If it is null, the myFrame argument is taken. + * 2. Go up the tree of frames and search a frame with a component window. + * 3. Get from the desktop all the components, and give the first one + * which has a frame. + * @param xMSF + * @param myFrame + * @param desktop + * @return + * @throws NoSuchElementException + * @throws WrappedTargetException + */ + public static XFrame findAFrame(XMultiServiceFactory xMSF, XFrame myFrame, XFrame desktop) + throws NoSuchElementException, + WrappedTargetException + { + if (desktop == null) + { + desktop = myFrame; // we go up in the tree... + } + while (desktop != null && desktop.getComponentWindow() == null) + { + desktop = desktop.findFrame("_parent", FrameSearchFlag.PARENT); + } + if (desktop == null) + { + for (XEnumeration e = Desktop.getDesktop(xMSF).getComponents().createEnumeration(); e.hasMoreElements();) + { + Object comp = ((Any) e.nextElement()).getObject(); + XModel xModel = UnoRuntime.queryInterface(XModel.class, comp); + XFrame xFrame = xModel.getCurrentController().getFrame(); + if (xFrame != null && xFrame.getComponentWindow() != null) + { + return xFrame; + } + } + } + return desktop; + } } diff --git a/wizards/com/sun/star/wizards/common/FileAccess.java b/wizards/com/sun/star/wizards/common/FileAccess.java index 58af791..862f1b8 100644 --- a/wizards/com/sun/star/wizards/common/FileAccess.java +++ b/wizards/com/sun/star/wizards/common/FileAccess.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Vector; +import com.sun.star.awt.VclWindowPeerAttribute; import com.sun.star.io.XActiveDataSink; import com.sun.star.io.XInputStream; import com.sun.star.io.XTextInputStream; @@ -33,6 +34,7 @@ import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.ucb.*; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; +import com.sun.star.util.DateTime; import com.sun.star.beans.PropertyValue; import com.sun.star.document.XDocumentProperties; @@ -50,9 +52,36 @@ import com.sun.star.document.XDocumentProperties; public class FileAccess { + /** + * + * @param xMSF + * @param sPath + * @param sAddPath + */ + public static void addOfficePath(XMultiServiceFactory xMSF, String sPath, String sAddPath) + { + XSimpleFileAccess xSimpleFileAccess = null; + String ResultPath = getOfficePath(xMSF, sPath, xSimpleFileAccess); + // As there are several conventions about the look of Url (e.g. with " " or with "%20") you cannot make a + // simple String comparison to find out, if a path is already in "ResultPath" + String[] PathList = JavaTools.ArrayoutofString(ResultPath, PropertyNames.SEMI_COLON); + int MaxIndex = PathList.length - 1; + String CompCurPath; + String CompAddPath = JavaTools.replaceSubString(sAddPath, PropertyNames.EMPTY_STRING, "/"); + String CurPath; + for (int i = 0; i <= MaxIndex; i++) + { + CurPath = JavaTools.convertfromURLNotation(PathList[i]); + CompCurPath = JavaTools.replaceSubString(CurPath, PropertyNames.EMPTY_STRING, "/"); + if (CompCurPath.equals(CompAddPath)) + { + return; + } + } + ResultPath += PropertyNames.SEMI_COLON + sAddPath; + } - - private static String deleteLastSlashfromUrl(String _sPath) + public static String deleteLastSlashfromUrl(String _sPath) { if (_sPath.endsWith("/")) { @@ -67,6 +96,9 @@ public class FileAccess /** * Further information on arguments value see in OO Developer Guide, * chapter 6.2.7 + * @param xMSF + * @param sPath + * @param xSimpleFileAccess * @return the respective path of the office application. A probable following "/" at the end is trimmed. */ public static String getOfficePath(XMultiServiceFactory xMSF, String sPath, XSimpleFileAccess xSimpleFileAccess) @@ -89,8 +121,13 @@ public class FileAccess /** * Further information on arguments value see in OO Developer Guide, * chapter 6.2.7 + * @param xMSF + * @param sPath * @param sType use "share" or "user". Set to PropertyNames.EMPTY_STRING if not needed eg for the WorkPath; * In the return Officepath a possible slash at the end is cut off + * @param sSearchDir + * @return + * @throws NoValidPathException */ public static String getOfficePath(XMultiServiceFactory xMSF, String sPath, String sType, String sSearchDir) throws NoValidPathException { @@ -164,7 +201,7 @@ public class FileAccess return ResultPath; } - public static ArrayList<String> getOfficePaths(XMultiServiceFactory xMSF, String _sPath) + public static ArrayList<String> getOfficePaths(XMultiServiceFactory xMSF, String _sPath, String sType, String sSearchDir) { //This method currently only works with sPath="Template" @@ -338,10 +375,190 @@ public class FileAccess return ReturnPath; } + public static boolean createSubDirectory(XMultiServiceFactory xMSF, XSimpleFileAccess xSimpleFileAccess, String Path) + { + String sNoDirCreation = PropertyNames.EMPTY_STRING; + try + { + Resource oResource = new Resource(xMSF, "ImportWizard", "imp"); + sNoDirCreation = oResource.getResText(1050); + String sMsgDirNotThere = oResource.getResText(1051); + String sQueryForNewCreation = oResource.getResText(1052); + String OSPath = JavaTools.convertfromURLNotation(Path); + String sQueryMessage = JavaTools.replaceSubString(sMsgDirNotThere, OSPath, "%1"); + sQueryMessage = sQueryMessage + (char) 13 + sQueryForNewCreation; + int icreate = SystemDialog.showMessageBox(xMSF, "QueryBox", VclWindowPeerAttribute.YES_NO, sQueryMessage); + if (icreate == 2) + { + xSimpleFileAccess.createFolder(Path); + return true; + } + return false; + } + catch (com.sun.star.ucb.CommandAbortedException exception) + { + String sMsgNoDir = JavaTools.replaceSubString(sNoDirCreation, Path, "%1"); + SystemDialog.showMessageBox(xMSF, "ErrorBox", VclWindowPeerAttribute.OK, sMsgNoDir); + return false; + } + catch (com.sun.star.uno.Exception unoexception) + { + String sMsgNoDir = JavaTools.replaceSubString(sNoDirCreation, Path, "%1"); + SystemDialog.showMessageBox(xMSF, "ErrorBox", VclWindowPeerAttribute.OK, sMsgNoDir); + return false; + } + } + + // checks if the root of a path exists. if the parameter xWindowPeer is not null then also the directory is + // created when it does not exists and the user + public static boolean PathisValid(XMultiServiceFactory xMSF, String Path, String sMsgFilePathInvalid, boolean baskbeforeOverwrite) + { + try + { + String SubDir; + String SubDirPath = PropertyNames.EMPTY_STRING; + int SubLen; + int NewLen; + int RestLen; + boolean bexists; + boolean bSubDirexists = true; + String LowerCasePath; + String NewPath = Path; + XInterface xInterface = (XInterface) xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); + XSimpleFileAccess xSimpleFileAccess = UnoRuntime.queryInterface(XSimpleFileAccess.class, xInterface); + if (baskbeforeOverwrite) + { + if (xSimpleFileAccess.exists(Path)) + { + Resource oResource = new Resource(xMSF, "ImportWizard", "imp"); + String sFileexists = oResource.getResText(1053); + String NewString = JavaTools.convertfromURLNotation(Path); + sFileexists = JavaTools.replaceSubString(sFileexists, NewString, "<1>"); + sFileexists = JavaTools.replaceSubString(sFileexists, String.valueOf((char) 13), "<CR>"); + int iLeave = SystemDialog.showMessageBox(xMSF, "QueryBox", VclWindowPeerAttribute.YES_NO, sFileexists); + if (iLeave == 3) + { + return false; + } + } + } + String[] DirArray = JavaTools.ArrayoutofString(Path, "/"); + int MaxIndex = DirArray.length - 1; + if (MaxIndex > 0) + { + for (int i = MaxIndex; i >= 0; i--) + { + SubDir = DirArray[i]; + SubLen = SubDir.length(); + NewLen = NewPath.length(); + RestLen = NewLen - SubLen; + if (RestLen > 0) + { + NewPath = NewPath.substring(0, NewLen - SubLen - 1); + if (i == MaxIndex) + { + SubDirPath = NewPath; + } + bexists = xSimpleFileAccess.exists(NewPath); + if (bexists) + { + LowerCasePath = NewPath.toLowerCase(); + bexists = (!((LowerCasePath.equals("file:///")) || (LowerCasePath.equals("file://")) || (LowerCasePath.equals("file:/")) || (LowerCasePath.equals("file:")))); + } + if (bexists) + { + if (!bSubDirexists) + { + return createSubDirectory(xMSF, xSimpleFileAccess, SubDirPath); + } + return true; + } + else + { + bSubDirexists = false; + } + } + } + } + SystemDialog.showMessageBox(xMSF, "ErrorBox", VclWindowPeerAttribute.OK, sMsgFilePathInvalid); + return false; + } + catch (com.sun.star.uno.Exception exception) + { + exception.printStackTrace(System.err); + SystemDialog.showMessageBox(xMSF, "ErrorBox", VclWindowPeerAttribute.OK, sMsgFilePathInvalid); + return false; + } + } + + /** + * searches a directory for files which start with a certain + * prefix, and returns their URLs and document-titles. + * @param xMSF + * @param FilterName the prefix of the filename. a "-" is added to the prefix ! + * @param FolderName the folder (URL) to look for files... + * @return an array with two array members. The first one, with document titles, + * the second with the corresponding URLs. + * @deprecated please use the getFolderTitles() with ArrayList + */ + public static String[][] getFolderTitles(com.sun.star.lang.XMultiServiceFactory xMSF, String FilterName, String FolderName) + { + String[][] LocLayoutFiles = new String[2][]; + try + { + java.util.ArrayList<String> TitleVector = null; + java.util.ArrayList<String> NameVector = null; + + XInterface xDocInterface = (XInterface) xMSF.createInstance("com.sun.star.document.DocumentProperties"); + XDocumentProperties xDocProps = UnoRuntime.queryInterface(XDocumentProperties.class, xDocInterface); + + XInterface xInterface = (XInterface) xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); + com.sun.star.ucb.XSimpleFileAccess xSimpleFileAccess = UnoRuntime.queryInterface(XSimpleFileAccess.class, xInterface); + + String[] nameList = xSimpleFileAccess.getFolderContents(FolderName, false); + + TitleVector = new java.util.ArrayList<String>(/*nameList.length*/); + NameVector = new java.util.ArrayList<String>(nameList.length); + + FilterName = FilterName == null || FilterName.equals(PropertyNames.EMPTY_STRING) ? null : FilterName + "-"; + + String fileName = PropertyNames.EMPTY_STRING; + PropertyValue[] noArgs = { }; + for (int i = 0; i < nameList.length; i++) + { + fileName = getFilename(nameList[i]); + + if (FilterName == null || fileName.startsWith(FilterName)) + { + xDocProps.loadFromMedium(nameList[i], noArgs); + NameVector.add(nameList[i]); + TitleVector.add(xDocProps.getTitle()); + } + } + String[] LocNameList = new String[NameVector.size()]; + String[] LocTitleList = new String[TitleVector.size()]; + + NameVector.toArray(LocNameList); + TitleVector.toArray(LocTitleList); + LocLayoutFiles[1] = LocNameList; + LocLayoutFiles[0] = LocTitleList; + + JavaTools.bubblesortList(LocLayoutFiles); + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + return LocLayoutFiles; + } + /** * We search in all given path for a given file + * @param _sPath + * @param _sPath2 + * @return */ - private static String addPath(String _sPath, String _sPath2) + public static String addPath(String _sPath, String _sPath2) { String sNewPath; if (!_sPath.endsWith("/")) @@ -380,6 +597,14 @@ public class FileAccess return sFoundFile; } + /** + * + * @param xMSF + * @param _sStartFilterName + * @param FolderNames + * @return + * @throws com.sun.star.wizards.common.NoValidPathException + */ public static String[][] getFolderTitles(com.sun.star.lang.XMultiServiceFactory xMSF, String _sStartFilterName, ArrayList<String> FolderNames) throws NoValidPathException { @@ -486,7 +711,7 @@ public class FileAccess return LocLayoutFiles; } public XSimpleFileAccess2 fileAccess; - private XFileIdentifierConverter filenameConverter; + public XFileIdentifierConverter filenameConverter; public FileAccess(XMultiServiceFactory xmsf) throws com.sun.star.uno.Exception { @@ -505,15 +730,22 @@ public class FileAccess return filenameConverter.getFileURLFromSystemPath(parentPath, f.getAbsolutePath()); } + public String getURL(String path) + { + File f = new File(path); + return filenameConverter.getFileURLFromSystemPath(path, f.getAbsolutePath()); + } + public String getPath(String parentURL, String childURL) { return filenameConverter.getSystemPathFromFileURL(parentURL + (((childURL == null || childURL.equals(PropertyNames.EMPTY_STRING)) ? PropertyNames.EMPTY_STRING : "/" + childURL))); } /** + * @param filename * @return the extension of the given filename. */ - private static String getExtension(String filename) + public static String getExtension(String filename) { int p = filename.indexOf('.'); if (p == -1) @@ -532,6 +764,29 @@ public class FileAccess } /** + * @param s + * @return + */ + public boolean mkdir(String s) + { + try + { + fileAccess.createFolder(s); + return true; + } + catch (CommandAbortedException cax) + { + cax.printStackTrace(); + } + catch (com.sun.star.uno.Exception ex) + { + ex.printStackTrace(); + } + return false; + } + + /** + * @param filename * @param def what to return in case of an exception * @return true if the given file exists or not. * if an exception accures, returns the def value. @@ -552,14 +807,96 @@ public class FileAccess return def; } + /** + * @param filename + * @return + */ + public boolean isDirectory(String filename) + { + try + { + return fileAccess.isFolder(filename); + } + catch (CommandAbortedException e) + { + } + catch (Exception e) + { + } + + return false; + } + + /** + * lists the files in a given directory + * @param dir + * @param includeFolders + * @return + */ + public String[] listFiles(String dir, boolean includeFolders) + { + try + { + return fileAccess.getFolderContents(dir, includeFolders); + } + catch (CommandAbortedException e) + { + } + catch (Exception e) + { + } + + return new String[0]; + } + + /** + * @param file + * @return + */ + public boolean delete(String file) + { + try + { + fileAccess.kill(file); + return true; + } + catch (CommandAbortedException e) + { + e.printStackTrace(System.err); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + + return false; + } + + /** + * @param path + * @return + */ public static String getFilename(String path) { return getFilename(path, "/"); } + /** + * return the filename out of a system-dependent path + * @param path + * @return + */ + public static String getPathFilename(String path) + { + return getFilename(path, File.separator); + } - - private static String getFilename(String path, String pathSeparator) + /** + * @param path + * @param pathSeparator + * @return + */ + public static String getFilename(String path, String pathSeparator) { String[] s = JavaTools.ArrayoutofString(path, pathSeparator); return s[s.length - 1]; @@ -572,11 +909,45 @@ public class FileAccess return filename.substring(0, filename.length() - (sExtension.length() + 1)); } + /** + * @param source + * @param target + * @return + */ + public boolean copy(String source, String target) + { + try + { + fileAccess.copy(source, target); + return true; + } + catch (CommandAbortedException e) + { + } + catch (Exception e) + { + } + return false; + } - + public DateTime getLastModified(String url) + { + try + { + return fileAccess.getDateTimeModified(url); + } + catch (CommandAbortedException e) + { + } + catch (Exception e) + { + } + return null; + } /** + * @param url * @return the parent dir of the given url. * if the path points to file, gives the directory in which the file is. */ @@ -595,7 +966,50 @@ public class FileAccess return url.substring(0, lastPos); } + public String createNewDir(String parentDir, String name) + { + String s = getNewFile(parentDir, name, PropertyNames.EMPTY_STRING); + if (mkdir(s)) + { + return s; + } + else + { + return null; + } + } + + public String getNewFile(String parentDir, String name, String extension) + { + int i = 0; + String url; + do + { + String filename = filename(name, extension, i++); + url = getURL(parentDir, filename); + } + while (exists(url, true)); + + return url; + } + + private static String filename(String name, String ext, int i) + { + return name + (i == 0 ? PropertyNames.EMPTY_STRING : String.valueOf(i)) + (ext.equals(PropertyNames.EMPTY_STRING) ? PropertyNames.EMPTY_STRING : "." + ext); + } + + public int getSize(String url) + { + try + { + return fileAccess.getSize(url); + } + catch (Exception ex) + { + return -1; + } + } public static String connectURLs(String urlFolder, String urlFilename) { @@ -635,4 +1049,36 @@ public class FileAccess return sFileData; } + /** + * shortens a filename to a user displayable representation. + * @param path + * @param maxLength + * @return + */ + public static String getShortFilename(String path, int maxLength) + { + int firstPart = 0; + + if (path.length() > maxLength) + { + if (path.startsWith("/")) + { // unix + int nextSlash = path.indexOf("/", 1) + 1; + firstPart = Math.min(nextSlash, (maxLength - 3) / 2); + } + else + { //windows + firstPart = Math.min(10, (maxLength - 3) / 2); + } + + String s1 = path.substring(0, firstPart); + String s2 = path.substring(path.length() - (maxLength - (3 + firstPart))); + + return s1 + "..." + s2; + } + else + { + return path; + } + } } diff --git a/wizards/com/sun/star/wizards/common/Helper.java b/wizards/com/sun/star/wizards/common/Helper.java index cc5c243..3aa4628 100644 --- a/wizards/com/sun/star/wizards/common/Helper.java +++ b/wizards/com/sun/star/wizards/common/Helper.java @@ -22,6 +22,7 @@ import com.sun.star.util.XMacroExpander; import java.util.Calendar; import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; import com.sun.star.lang.Locale; import com.sun.star.lang.XMultiServiceFactory; @@ -35,6 +36,11 @@ import com.sun.star.util.XNumberFormatter; public class Helper { + /** Creates a new instance of Helper */ + public Helper() + { + } + public static long convertUnoDatetoInteger(com.sun.star.util.Date DateValue) { java.util.Calendar oCal = java.util.Calendar.getInstance(); @@ -86,7 +92,21 @@ public class Helper } } - + public static Object getPropertyValue(PropertyValue[] CurPropertyValue, String PropertyName) + { + int MaxCount = CurPropertyValue.length; + for (int i = 0; i < MaxCount; i++) + { + if (CurPropertyValue[i] != null) + { + if (CurPropertyValue[i].Name.equals(PropertyName)) + { + return CurPropertyValue[i].Value; + } + } + } + throw new RuntimeException(); + } public static Object getUnoPropertyValue(Object oUnoObject, String PropertyName, java.lang.Class<?> xClass) { @@ -114,9 +134,53 @@ public class Helper } } + public static Object getPropertyValuefromAny(Object[] CurPropertyValue, String PropertyName) + { + if (CurPropertyValue != null) + { + int MaxCount = CurPropertyValue.length; + for (int i = 0; i < MaxCount; i++) + { + if (CurPropertyValue[i] != null) + { + PropertyValue aValue = (PropertyValue) CurPropertyValue[i]; + if (aValue != null && aValue.Name.equals(PropertyName)) + { + return aValue.Value; + } + } + } + } + return null; + } - - + public static Object getPropertyValuefromAny(Object[] CurPropertyValue, String PropertyName, java.lang.Class<?> xClass) + { + try + { + if (CurPropertyValue != null) + { + int MaxCount = CurPropertyValue.length; + for (int i = 0; i < MaxCount; i++) + { + if (CurPropertyValue[i] != null) + { + PropertyValue aValue = (PropertyValue) CurPropertyValue[i]; + if (aValue != null && aValue.Name.equals(PropertyName)) + { + return com.sun.star.uno.AnyConverter.toObject(new com.sun.star.uno.Type(xClass), aValue.Value); + } + } + } + } + return null; + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + return null; + } + } public static Object getUnoPropertyValue(Object oUnoObject, String PropertyName) { @@ -206,7 +270,7 @@ public class Helper * @param oValue the parameter that has to represent an object * @return a null reference if the array is empty */ - private static Object getArrayValue(Object oValue) + public static Object getArrayValue(Object oValue) { try { @@ -262,6 +326,7 @@ public class Helper /** * @param format a constant of the enumeration NumberFormatIndex + * @return */ public int getFormat(short format) { @@ -283,7 +348,7 @@ public class Helper * @param date a VCL date in form of 20041231 * @return a document relative date */ - private synchronized double getDocumentDateAsDouble(int date) + public synchronized double getDocumentDateAsDouble(int date) { calendar.clear(); calendar.set(date / 10000, @@ -298,17 +363,40 @@ public class Helper return (date1 - docNullTime) / DAY_IN_MILLIS + 1; } - private double getDocumentDateAsDouble(DateTime date) + public double getDocumentDateAsDouble(DateTime date) { return getDocumentDateAsDouble(date.Year * 10000 + date.Month * 100 + date.Day); } - public String format(int formatIndex, DateTime date) + public synchronized double getDocumentDateAsDouble(long javaTimeInMillis) + { + calendar.clear(); + JavaTools.setTimeInMillis(calendar, javaTimeInMillis); + + long date1 = getTimeInMillis(); + + /* + * docNullTime and date1 are in millis, but + * I need a day... + */ + return (date1 - docNullTime) / DAY_IN_MILLIS + 1; + + } + + public String format(int formatIndex, int date) { return formatter.convertNumberToString(formatIndex, getDocumentDateAsDouble(date)); } + public String format(int formatIndex, DateTime date) + { + return formatter.convertNumberToString(formatIndex, getDocumentDateAsDouble(date)); + } + public String format(int formatIndex, long javaTimeInMillis) + { + return formatter.convertNumberToString(formatIndex, getDocumentDateAsDouble(javaTimeInMillis)); + } } public static XComponentContext getComponentContext(XMultiServiceFactory _xMSF) diff --git a/wizards/com/sun/star/wizards/common/IRenderer.java b/wizards/com/sun/star/wizards/common/IRenderer.java index c704ed6..c4513ea 100644 --- a/wizards/com/sun/star/wizards/common/IRenderer.java +++ b/wizards/com/sun/star/wizards/common/IRenderer.java @@ -26,5 +26,5 @@ package com.sun.star.wizards.common; public interface IRenderer { - String render(Object object); + public String render(Object object); } diff --git a/wizards/com/sun/star/wizards/common/Indexable.java b/wizards/com/sun/star/wizards/common/Indexable.java index d838c35..b20fd17 100644 --- a/wizards/com/sun/star/wizards/common/Indexable.java +++ b/wizards/com/sun/star/wizards/common/Indexable.java @@ -25,6 +25,6 @@ package com.sun.star.wizards.common; public interface Indexable { - int getIndex(); + public int getIndex(); } diff --git a/wizards/com/sun/star/wizards/common/JavaTools.java b/wizards/com/sun/star/wizards/common/JavaTools.java index 4f81e43..d7935b5 100644 --- a/wizards/com/sun/star/wizards/common/JavaTools.java +++ b/wizards/com/sun/star/wizards/common/JavaTools.java @@ -17,6 +17,7 @@ */ package com.sun.star.wizards.common; +import com.sun.star.util.DateTime; import com.sun.star.beans.PropertyValue; import java.util.*; import java.io.File; @@ -28,6 +29,43 @@ import java.net.URL; public class JavaTools { + /** Creates a new instance of JavaTools */ + public JavaTools() + { + } + + public static String[] copyStringArray(String[] FirstArray) + { + if (FirstArray != null) + { + String[] SecondArray = new String[FirstArray.length]; + System.arraycopy(FirstArray, 0, SecondArray, 0, FirstArray.length); + return SecondArray; + } + else + { + return null; + } + } + + public static Object[] initializeArray(Object[] olist, Object ovalue) + { + for (int i = 0; i < olist.length; i++) + { + olist[i] = ovalue; + } + return olist; + } + + public static Object[][] initializeMultiDimArray(Object[][] olist, Object[] ovalue) + { + for (int i = 0; i < olist.length; i++) + { + olist[i] = ovalue; + } + return olist; + } + public static String[] ArrayOutOfMultiDimArray(String _sMultiDimArray[][], int _index) { String[] sRetArray = null; @@ -42,9 +80,24 @@ public class JavaTools return sRetArray; } + public static int[] initializeintArray(int FieldCount, int nValue) + { + int[] LocintArray = new int[FieldCount]; + for (int i = 0; i < LocintArray.length; i++) + { + LocintArray[i] = nValue; + } + return LocintArray; + } + /**converts a list of Integer values included in an Integer vector to a list of int values + * + * + * @param _aIntegerVector + * @return */ - public static int[] IntegerTointList(java.util.List<Integer> _aIntegerVector) { + public static int[] IntegerTointList(java.util.List<Integer> _aIntegerVector) + { int[] nintValues = null; if (_aIntegerVector.size() > 0) { int i = 0; @@ -57,8 +110,13 @@ public class JavaTools } /**converts a list of Boolean values included in a Boolean vector to a list of boolean values + * + * + * @param _aBooleanVector + * @return */ - public static boolean[] BooleanTobooleanList(java.util.List<Boolean> _aBooleanVector) { + public static boolean[] BooleanTobooleanList(java.util.List<Boolean> _aBooleanVector) + { boolean[] bbooleanValues = null; if (_aBooleanVector.size() > 0) { int i = 0; @@ -70,6 +128,19 @@ public class JavaTools return bbooleanValues; } + public static String[] multiDimListToArray(String[][] multidimlist) + { + String[] retlist = new String[] + { + }; + retlist = new String[multidimlist.length]; + for (int i = 0; i < multidimlist.length; i++) + { + retlist[i] = multidimlist[i][0]; + } + return retlist; + } + public static String getlongestArrayItem(String[] StringArray) { String sLongestItem = PropertyNames.EMPTY_STRING; @@ -87,12 +158,13 @@ public class JavaTools return sLongestItem; } - public static String ArraytoString(String[] LocArray) { + public static String ArraytoString(String[] LocArray) + { StringBuilder ResultString = new StringBuilder(PropertyNames.EMPTY_STRING); boolean bActive = false; for (String str : LocArray) { if (bActive) { - ResultString.append(PropertyNames.SEMI_COLON); + ResultString.append(PropertyNames.SEMI_COLON); } else { bActive = true; } @@ -102,6 +174,8 @@ public class JavaTools } /** + * @param SearchList + * @param SearchString * @return the index of the field that contains the string 'SearchString' or '-1' if not it is * not contained within the array */ @@ -116,7 +190,26 @@ public class JavaTools return retvalue; } - public static int FieldInTable(String[][] SearchList, String SearchString) { + public static int FieldInList(String[] SearchList, String SearchString, int StartIndex) + { + int FieldLen = SearchList.length; + int retvalue = -1; + if (StartIndex < FieldLen) + { + for (int i = StartIndex; i < FieldLen; i++) + { + if (SearchList[i].equals(SearchString)) + { + retvalue = i; + break; + } + } + } + return retvalue; + } + + public static int FieldInTable(String[][] SearchList, String SearchString) + { int retvalue = -1; int FieldLen = SearchList.length; if (FieldLen > 0) { @@ -203,6 +296,11 @@ public class JavaTools return SortList; } + /** + * @param MainString + * @param Token + * @return + */ public static String[] ArrayoutofString(String MainString, String Token) { String[] StringArray; @@ -261,6 +359,24 @@ public class JavaTools } } + public static String getFilenameOutOfPath(String sPath) + { + String[] Hierarchy = ArrayoutofString(sPath, "/"); + return Hierarchy[Hierarchy.length - 1]; + } + + public static String getFileDescription(String sPath) + { + String sFilename = getFilenameOutOfPath(sPath); + String[] FilenameList = ArrayoutofString(sFilename, "."); + StringBuilder FileDescription = new StringBuilder(PropertyNames.EMPTY_STRING); + for (int i = 0; i < FilenameList.length - 1; i++) + { + FileDescription.append(FilenameList[i]); + } + return FileDescription.toString(); + } + public static String convertfromURLNotation(String _sURLPath) { String sPath = PropertyNames.EMPTY_STRING; @@ -277,6 +393,27 @@ public class JavaTools return sPath; } + public static DateTime getDateTime(long timeMillis) + { + java.util.Calendar cal = java.util.Calendar.getInstance(); + setTimeInMillis(cal, timeMillis); + DateTime dt = new DateTime(); + dt.Year = (short) cal.get(Calendar.YEAR); + dt.Day = (short) cal.get(Calendar.DAY_OF_MONTH); + dt.Month = (short) (cal.get(Calendar.MONTH) + 1); + dt.Hours = (short) cal.get(Calendar.HOUR); + dt.Minutes = (short) cal.get(Calendar.MINUTE); + dt.Seconds = (short) cal.get(Calendar.SECOND); + dt.NanoSeconds = cal.get(Calendar.MILLISECOND)*1000000; + return dt; + } + + public static long getTimeInMillis(Calendar _calendar) + { + java.util.Date dDate = _calendar.getTime(); + return dDate.getTime(); + } + public static void setTimeInMillis(Calendar _calendar, long _timemillis) { java.util.Date dDate = new java.util.Date(); @@ -284,6 +421,13 @@ public class JavaTools _calendar.setTime(dDate); } + public static long getMillis(DateTime time) + { + java.util.Calendar cal = java.util.Calendar.getInstance(); + cal.set(time.Year, time.Month, time.Day, time.Hours, time.Minutes, time.Seconds); + return getTimeInMillis(cal); + } + public static String[] removeOutdatedFields(String[] baselist, String[] _complist) { String[] retarray = new String[] @@ -371,6 +515,8 @@ public class JavaTools * MasterFieldName1;MasterFieldName2;MasterFieldName3 * The entries SlaveFieldNameX and MasterFieldNameX are grouped together and then the created groups are compared * If a group is duplicate the entry of the second group is returned. + * @param _scomplist + * @return */ public static int getDuplicateFieldIndex(String[][] _scomplist) { @@ -397,6 +543,8 @@ public class JavaTools /** * not tested!!!!! + * @param scomplist + * @return */ public static int getDuplicateFieldIndex(String[] scomplist) { @@ -434,7 +582,7 @@ public class JavaTools return -1; } - private static boolean isEqual(PropertyValue firstPropValue, PropertyValue secPropValue) + public static boolean isEqual(PropertyValue firstPropValue, PropertyValue secPropValue) { if (!firstPropValue.Name.equals(secPropValue.Name)) { @@ -510,6 +658,9 @@ public class JavaTools /** * compares two strings. If one of them is empty and the other one is null it also returns true + * @param sFirstString + * @param sSecondString + * @return */ public static boolean isSame(String sFirstString, String sSecondString) { diff --git a/wizards/com/sun/star/wizards/common/NamedValueCollection.java b/wizards/com/sun/star/wizards/common/NamedValueCollection.java index 32cc0cd..2813b22 100644 --- a/wizards/com/sun/star/wizards/common/NamedValueCollection.java +++ b/wizards/com/sun/star/wizards/common/NamedValueCollection.java @@ -45,7 +45,20 @@ public class NamedValueCollection m_values.put( i_name, i_value ); } - + @SuppressWarnings("unchecked") + public final < T > T getOrDefault( final String i_key, final T i_default ) + { + if ( m_values.containsKey( i_key ) ) + { + final Object value = m_values.get( i_key ); + try + { + return (T)value; + } + catch ( ClassCastException e ) { } + } + return i_default; + } public final < T extends XInterface > T queryOrDefault( final String i_key, final T i_default, Class<T> i_interfaceClass ) { @@ -57,6 +70,11 @@ public class NamedValueCollection return i_default; } + public final boolean has( final String i_key ) + { + return m_values.containsKey( i_key ); + } + public final PropertyValue[] getPropertyValues() { PropertyValue[] values = new PropertyValue[ m_values.size() ]; diff --git a/wizards/com/sun/star/wizards/common/NumberFormatter.java b/wizards/com/sun/star/wizards/common/NumberFormatter.java index 1d9a9c3..05fb55f 100644 --- a/wizards/com/sun/star/wizards/common/NumberFormatter.java +++ b/wizards/com/sun/star/wizards/common/NumberFormatter.java @@ -36,17 +36,17 @@ import com.sun.star.util.XNumberFormatter; public class NumberFormatter { - private int iDateFormatKey = -1; - private int iDateTimeFormatKey = -1; - private int iNumberFormatKey = -1; - private int iTextFormatKey = -1; - private int iTimeFormatKey = -1; - private int iLogicalFormatKey = -1; - private long lDateCorrection; - private XNumberFormatter xNumberFormatter; - private XNumberFormats xNumberFormats; - private XNumberFormatTypes xNumberFormatTypes; - private XPropertySet xNumberFormatSettings; + public int iDateFormatKey = -1; + public int iDateTimeFormatKey = -1; + public int iNumberFormatKey = -1; + public int iTextFormatKey = -1; + public int iTimeFormatKey = -1; + public int iLogicalFormatKey = -1; + public long lDateCorrection; + public XNumberFormatter xNumberFormatter; + public XNumberFormats xNumberFormats; + public XNumberFormatTypes xNumberFormatTypes; + public XPropertySet xNumberFormatSettings; private boolean bNullDateCorrectionIsDefined = false; private Locale aLocale; @@ -72,6 +72,14 @@ public class NumberFormatter } + /** + * @param _xMSF + * @param _xNumberFormatsSupplier + * @return + * @throws Exception + * @deprecated + * + */ public static XNumberFormatter createNumberFormatter(XMultiServiceFactory _xMSF, XNumberFormatsSupplier _xNumberFormatsSupplier) throws Exception { Object oNumberFormatter = _xMSF.createInstance("com.sun.star.util.NumberFormatter"); @@ -90,6 +98,7 @@ public class NumberFormatter * XNumberFormatter nf = Desktop.createNumberFormatter(xmsf, nsf); * nf.convertNumberToString( key, 1972 ); * </pre> + * @param numberFormatsSupplier * @param type - a constant out of i18n.NumberFormatIndex enumeration. * @return a key to use with a util.NumberFormat instance. * @@ -108,7 +117,10 @@ public class NumberFormatter } - + public static String convertNumberToString(XNumberFormatter _xNumberFormatter, int _nkey, double _dblValue) + { + return _xNumberFormatter.convertNumberToString(_nkey, _dblValue); + } public double convertStringToNumber(int _nkey, String _sString)throws Exception @@ -146,9 +158,12 @@ public class NumberFormatter /** - * @return a numberformat for a FormatString. + * returns a numberformat for a FormatString. + * @param _FormatString + * @param _aLocale + * @return */ - private int defineNumberFormat(String _FormatString, Locale _aLocale) + public int defineNumberFormat(String _FormatString, Locale _aLocale) { try { @@ -183,11 +198,11 @@ public class NumberFormatter } if (xPSet.getPropertySetInfo().hasPropertyByName("NumberFormat")) { - xPSet.setPropertyValue("NumberFormat", Integer.valueOf(NewFormatKey)); + xPSet.setPropertyValue("NumberFormat", new Integer(NewFormatKey)); } else if (xPSet.getPropertySetInfo().hasPropertyByName("FormatKey")) { - xPSet.setPropertyValue("FormatKey", Integer.valueOf(NewFormatKey)); + xPSet.setPropertyValue("FormatKey", new Integer(NewFormatKey)); } else { diff --git a/wizards/com/sun/star/wizards/common/NumericalHelper.java b/wizards/com/sun/star/wizards/common/NumericalHelper.java index f2c6e76..ab1cd36 100644 --- a/wizards/com/sun/star/wizards/common/NumericalHelper.java +++ b/wizards/com/sun/star/wizards/common/NumericalHelper.java @@ -33,20 +33,20 @@ import com.sun.star.uno.TypeClass; public class NumericalHelper { - private static final int UNKNOWN_TYPE = -32768; - private static final int BYTE_TYPE = 0; - private static final int SHORT_TYPE = 1; - private static final int INT_TYPE = 2; - private static final int LONG_TYPE = 3; - private static final int FLOAT_TYPE = 4; - private static final int DOUBLE_TYPE = 5; - private static final int CHAR_TYPE = 6; - private static final int STRING_TYPE = -1; - private static final int BOOLEAN_TYPE = -2; - private static final int SEQUENCE_TYPE = -3; - - - + public static final int UNKNOWN_TYPE = -32768; + public static final int BYTE_TYPE = 0; + public static final int SHORT_TYPE = 1; + public static final int INT_TYPE = 2; + public static final int LONG_TYPE = 3; + public static final int FLOAT_TYPE = 4; + public static final int DOUBLE_TYPE = 5; + public static final int CHAR_TYPE = 6; + public static final int STRING_TYPE = -1; + public static final int BOOLEAN_TYPE = -2; + public static final int SEQUENCE_TYPE = -3; + public static final int ASCII_VALUE_0 = 48; + public static final int ASCII_VALUE_A = 65; + public static final int COUNT_CHARS_IN_ALPHABET = 26; private static final int HEX_BASE = 16; private static final int DEC_BASE = 10; private static final int ASCII_LETTER_A_OFFSET = 55; @@ -59,17 +59,458 @@ public class NumericalHelper // private c'tor, so no one can instantiate } - - /** - * get an int value from the object - * @return an int + * get the type of an object: returns all types that can possibly converted + * with this class. + * @param obj an object that is checked for conversion + * @return the type of the object + */ + public static int getType(Object obj) + { + try + { + TypeObject aTypeObject = getTypeObject(obj); + return aTypeObject.iType; + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore this one; just return unknown type + } + return UNKNOWN_TYPE; + } + + /** + * get a byte value from the object + * @param aValue + * @return a byte + * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted + */ + public static byte toByte(Object aValue) + throws com.sun.star.lang.IllegalArgumentException + { + + byte retValue = 0; + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case BYTE_TYPE: + retValue = getByte(aTypeObject); + break; + case CHAR_TYPE: + retValue = (byte) getChar(aTypeObject); + break; + case SHORT_TYPE: + retValue = (byte) getShort(aTypeObject); + break; + case INT_TYPE: + retValue = (byte) getInt(aTypeObject); + break; + case LONG_TYPE: + retValue = (byte) getLong(aTypeObject); + break; + case FLOAT_TYPE: + retValue = (byte) getFloat(aTypeObject); + break; + case DOUBLE_TYPE: + retValue = (byte) getDouble(aTypeObject); + break; + case STRING_TYPE: + try + { + retValue = Byte.parseByte((String) aTypeObject.aValue); + } + catch (java.lang.NumberFormatException e) + { + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert to byte: " + aTypeObject.aValue); + } + break; + case BOOLEAN_TYPE: + retValue = getBool(aTypeObject) ? (byte) -1 : (byte) 0; + break; + default: + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert this type: " + aValue.getClass().getName()); + } + return retValue; + } + + /** + * get a char value from the object + * @param aValue + * @return a char + * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted + */ + public static char toChar(Object aValue) + throws com.sun.star.lang.IllegalArgumentException + { + + char retValue = 0; + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case CHAR_TYPE: + retValue = getChar(aTypeObject); + break; + case BYTE_TYPE: + retValue = (char) getByte(aTypeObject); + break; + case SHORT_TYPE: + retValue = (char) getShort(aTypeObject); + break; + case INT_TYPE: + retValue = (char) getInt(aTypeObject); + break; + case LONG_TYPE: + retValue = (char) getLong(aTypeObject); + break; + case FLOAT_TYPE: + retValue = (char) getFloat(aTypeObject); + break; + case DOUBLE_TYPE: + retValue = (char) getDouble(aTypeObject); + break; + case STRING_TYPE: + try + { + String s = (String) aTypeObject.aValue; + if (s.length() > 0) + { + retValue = s.charAt(0); + } + else + { + retValue = (char) 0; + } + } + catch (java.lang.NumberFormatException e) + { + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert to char: " + aTypeObject.aValue); + } + break; + case BOOLEAN_TYPE: + retValue = getBool(aTypeObject) ? (char) -1 : (char) 0; + break; + default: + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert this type: " + aValue.getClass().getName()); + } + return retValue; + } + + /** + * get a short value from the object + * @param aValue + * @return a short + * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted + */ + public static short toShort(Object aValue) + throws com.sun.star.lang.IllegalArgumentException + { + short retValue = 0; + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case BYTE_TYPE: + retValue = getByte(aTypeObject); + break; + case CHAR_TYPE: + retValue = (byte) getChar(aTypeObject); + break; + case SHORT_TYPE: + retValue = getShort(aTypeObject); + break; + case INT_TYPE: + retValue = (short) getInt(aTypeObject); + break; + case LONG_TYPE: + retValue = (short) getLong(aTypeObject); + break; + case FLOAT_TYPE: + retValue = (short) getFloat(aTypeObject); + break; + case DOUBLE_TYPE: + retValue = (short) getDouble(aTypeObject); + break; + case STRING_TYPE: + try + { + retValue = Short.parseShort((String) aTypeObject.aValue); + } + catch (java.lang.NumberFormatException e) + { + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert to short: " + aTypeObject.aValue); + } + break; + case BOOLEAN_TYPE: + retValue = getBool(aTypeObject) ? (short) -1 : (short) 0; + break; + default: + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert this type: " + aValue.getClass().getName()); + } + return retValue; + } + + public static boolean isValidAndNumerical(Object aValue) throws com.sun.star.lang.IllegalArgumentException + { + if (aValue != null) + { + if (!AnyConverter.isVoid(aValue)) + { + return (NumericalHelper.isNumerical(aValue)); + } + } + return false; + } + + public static boolean isValidAndBoolean(Object aValue) throws com.sun.star.lang.IllegalArgumentException + { + if (aValue != null) + { + if (!AnyConverter.isVoid(aValue)) + { + int nType = AnyConverter.getType(aValue).getTypeClass().getValue(); + return (nType == TypeClass.BOOLEAN_value); + } + } + return false; + } + + public static boolean isValid(Object aValue) + { + if (aValue != null) + { + if (!AnyConverter.isVoid(aValue)) + { + return true; + } + } + return false; + } + + /** + @param aValue a object this can contain anything + @return true, if the parameter aValue is type of real numbers + @deprecate, use isRealNumber() instead. + */ + public static boolean isNumerical(Object aValue) + { + try + { + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case BYTE_TYPE: + case CHAR_TYPE: + case SHORT_TYPE: + case INT_TYPE: + case LONG_TYPE: + case DOUBLE_TYPE: + case FLOAT_TYPE: + return true; + default: + return false; + } + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + return false; + } + } + + /** + @param _aValue a object this can contain anything + @return true, if the parameter aValue is type of real numbers + + see also http://en.wikipedia.org/wiki/Mathematics + */ + public static boolean isRealNumber(Object _aValue) + { + return isNumerical(_aValue); + } + + /** + @param aValue a object this can contain anything + * @return true, if the value is type of any integer values. double / float are not(!) integer values + * @throws com.sun.star.lang.IllegalArgumentException + */ + public static boolean isInteger(Object aValue) throws com.sun.star.lang.IllegalArgumentException + { + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case BYTE_TYPE: + case CHAR_TYPE: + case SHORT_TYPE: + case INT_TYPE: + case LONG_TYPE: + return true; + default: + return false; + } + } + + /** + * Can a given object be converted to a String array? + * @param aValue the object to test + * @return true, if the object can be converted to a String array. + */ + public static boolean isStringArray(Object aValue) + { + try + { + toStringArray(aValue); + return true; + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore + } + return false; + } + + /** + * Can a given object be converted to an int array? + * @param aValue the object to test + * @return true, if the object can be converted to an Integer array. + */ + public static boolean isIntegerArray(Object aValue) + { + try + { + toIntArray(aValue); + return true; + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore + } + return false; + } + + /** + * get an int value from the object + * @param aValue + * @return an int + * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted + */ + public static int toInt(Object aValue) + throws com.sun.star.lang.IllegalArgumentException + { + int retValue = 0; + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case BYTE_TYPE: + retValue = getByte(aTypeObject); + break; + case CHAR_TYPE: + retValue = getChar(aTypeObject); + break; + case SHORT_TYPE: + retValue = getShort(aTypeObject); + break; + case INT_TYPE: + retValue = getInt(aTypeObject); + break; + case LONG_TYPE: + retValue = (int) getLong(aTypeObject); + break; + case FLOAT_TYPE: + retValue = (int) getFloat(aTypeObject); + break; + case DOUBLE_TYPE: + retValue = (int) getDouble(aTypeObject); + break; + case STRING_TYPE: + try + { + retValue = Integer.parseInt((String) aTypeObject.aValue); + } + catch (java.lang.NumberFormatException e) + { + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert to int: " + aTypeObject.aValue); + } + break; + case BOOLEAN_TYPE: + retValue = getBool(aTypeObject) ? -1 : 0; + break; + default: + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert this type: " + aValue.getClass().getName()); + } + return retValue; + } + + /** + * get a long value from the object + * @param aValue + * @return a long + * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted + */ + public static long toLong(Object aValue) + throws com.sun.star.lang.IllegalArgumentException + { + long retValue = 0; + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case BYTE_TYPE: + retValue = getByte(aTypeObject); + break; + case CHAR_TYPE: + retValue = getChar(aTypeObject); + break; + case SHORT_TYPE: + retValue = getShort(aTypeObject); + break; + case INT_TYPE: + retValue = getInt(aTypeObject); + break; + case LONG_TYPE: + retValue = getLong(aTypeObject); + break; + case FLOAT_TYPE: + retValue = (long) getFloat(aTypeObject); + break; + case DOUBLE_TYPE: + retValue = (long) getDouble(aTypeObject); + break; + case STRING_TYPE: + try + { + retValue = Long.parseLong((String) aTypeObject.aValue); + } + catch (java.lang.NumberFormatException e) + { + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert to short: " + aTypeObject.aValue); + } + break; + case BOOLEAN_TYPE: + retValue = getBool(aTypeObject) ? -1 : 0; + break; + default: + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert this type: " + aValue.getClass().getName()); + } + return retValue; + } + + /** + * get a float value from the object + * @param aValue + * @return a float * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted */ - public static int toInt(Object aValue) + public static float toFloat(Object aValue) throws com.sun.star.lang.IllegalArgumentException { - int retValue = 0; + float retValue = (float) 0.0; TypeObject aTypeObject = getTypeObject(aValue); switch (aTypeObject.iType) { @@ -86,27 +527,27 @@ public class NumericalHelper retValue = getInt(aTypeObject); break; case LONG_TYPE: - retValue = (int) getLong(aTypeObject); + retValue = getLong(aTypeObject); break; case FLOAT_TYPE: - retValue = (int) getFloat(aTypeObject); + retValue = getFloat(aTypeObject); break; case DOUBLE_TYPE: - retValue = (int) getDouble(aTypeObject); + retValue = (float) getDouble(aTypeObject); break; case STRING_TYPE: try { - retValue = Integer.parseInt((String) aTypeObject.aValue); + retValue = Float.parseFloat((String) aTypeObject.aValue); } catch (java.lang.NumberFormatException e) { throw new com.sun.star.lang.IllegalArgumentException( - "Cannot convert to int: " + aTypeObject.aValue); + "Cannot convert to short: " + aTypeObject.aValue); } break; case BOOLEAN_TYPE: - retValue = getBool(aTypeObject) ? -1 : 0; + retValue = getBool(aTypeObject) ? (float) -1 : (float) 0; break; default: throw new com.sun.star.lang.IllegalArgumentException( @@ -117,6 +558,7 @@ public class NumericalHelper /** * get a double value from the object + * @param aValue * @return a double * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted */ @@ -170,7 +612,58 @@ public class NumericalHelper } /** + * get a String value from the object + * @param aValue + * @return a String + * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted + */ + public static String toString(Object aValue) + throws com.sun.star.lang.IllegalArgumentException + { + String retValue = null; + TypeObject aTypeObject = getTypeObject(aValue); + switch (aTypeObject.iType) + { + case BYTE_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case CHAR_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case SHORT_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case INT_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case LONG_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case FLOAT_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case DOUBLE_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case STRING_TYPE: + retValue = (String) aTypeObject.aValue; + break; + case BOOLEAN_TYPE: + retValue = aTypeObject.aValue.toString(); + break; + case SEQUENCE_TYPE: + retValue = new String(toByteArray((aValue))); + break; + default: + throw new com.sun.star.lang.IllegalArgumentException( + "Cannot convert this type: " + aValue.getClass().getName()); + } + return retValue; + } + + /** * get a boolean value from the object + * @param aValue * @return a boolean * @throws com.sun.star.lang.IllegalArgumentException if the object cannot be converted */ @@ -224,6 +717,320 @@ public class NumericalHelper } /** + * get an int array from an object + * @param anArrayValue a value that is constructed into an array + * @return an integer array + * @throws com.sun.star.lang.IllegalArgumentException + */ + public static int[] toIntArray(Object anArrayValue) + throws com.sun.star.lang.IllegalArgumentException + { + int[] retValue = null; + TypeObject aTypeObject = getTypeObject(anArrayValue); + if (aTypeObject.iType == SEQUENCE_TYPE) + { + Object[] obj = convertSequenceToObjectArray(aTypeObject); + retValue = new int[obj.length]; + for (int i = 0; i < obj.length; i++) + { + retValue[i] = toInt(obj[i]); + } + } + else + { // object is not really an array + retValue = new int[] + { + toInt(anArrayValue) + }; + } + return retValue; + } + + /** + * get an byte array from an object + * @param anArrayValue a value that is constructed into an array + * @return a byte array + * @throws com.sun.star.lang.IllegalArgumentException + */ + public static byte[] toByteArray(Object anArrayValue) + throws com.sun.star.lang.IllegalArgumentException + { + byte[] retValue = null; + TypeObject aTypeObject = getTypeObject(anArrayValue); + if (aTypeObject.iType == SEQUENCE_TYPE) + { + Object[] obj = convertSequenceToObjectArray(aTypeObject); + retValue = new byte[obj.length]; + for (int i = 0; i < obj.length; i++) + { + retValue[i] = toByte(obj[i]); + } + } + else + { // object is not really an array + retValue = new byte[] + { + toByte(anArrayValue) + }; + } + return retValue; + } + + /** + * get a short array from an object + * @param anArrayValue a value that is constructed into an array + * @return a short array + * @throws com.sun.star.lang.IllegalArgumentException + */ + public static short[] toShortArray(Object anArrayValue) + throws com.sun.star.lang.IllegalArgumentException + { + short[] retValue = null; + TypeObject aTypeObject = getTypeObject(anArrayValue); + if (aTypeObject.iType == SEQUENCE_TYPE) + { + Object[] obj = convertSequenceToObjectArray(aTypeObject); + retValue = new short[obj.length]; + for (int i = 0; i < obj.length; i++) + { + retValue[i] = toShort(obj[i]); + } + } + else + { // object is not really an array + retValue = new short[] + { + toShort(anArrayValue) + }; + } + return retValue; + } + + /** + * get a string array from an object + * @param anArrayValue a value that is constructed into an array + * @return a short array + * @throws com.sun.star.lang.IllegalArgumentException + */ + public static String[] toStringArray(Object anArrayValue) + throws com.sun.star.lang.IllegalArgumentException + { + String[] retValue = null; + TypeObject aTypeObject = getTypeObject(anArrayValue); + if (aTypeObject.iType == SEQUENCE_TYPE) + { + Object[] obj = convertSequenceToObjectArray(aTypeObject); + retValue = new String[obj.length]; + for (int i = 0; i < obj.length; i++) + { + retValue[i] = toString(obj[i]); + } + } + else + { // object is not really an array + retValue = new String[] + { + toString(anArrayValue) + }; + } + return retValue; + } + + /** + * get an int from an object + * @param _aValue a value that is constructed into an int + * @param _ndefaultValue the value that is returned, if conversion fails, or if 'aValue' is null + * @return an int value + * @throws java.lang.Exception + */ + public static int toInt(Object _aValue, int _ndefaultValue) throws Exception + { + int nreturn = _ndefaultValue; + try + { + if ((_aValue != null) && (!(AnyConverter.isVoid(_aValue)))) + { + if (isInteger(_aValue)) + { + nreturn = toInt(_aValue); + } + else + { + DebugHelper.exception(1/* BasicErrorCode.SbERR_CONVERSION*/, PropertyNames.EMPTY_STRING); + } + } + } + catch (com.sun.star.uno.Exception e) + { + DebugHelper.exception(1 /*BasicErrorCode.SbERR_METHOD_FAILED*/, PropertyNames.EMPTY_STRING); + } + return nreturn; + } + + /** + * get a long from an object + * @param aValue a value that is constructed into a long + * @param defaultValue the value that is returned, if conversion fails + * @return a long value + */ + public static long toLong(Object aValue, long defaultValue) + { + try + { + return toLong(aValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a float from an object + * @param aValue a value that is constructed into a float + * @param defaultValue the value that is returned, if conversion fails + * @return a long value + */ + public static float toFloat(Object aValue, float defaultValue) + { + try + { + return toFloat(aValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a double from an object + * @param aValue a value that is constructed into a double + * @param defaultValue the value that is returned, if conversion fails + * @return a double value + */ + public static double toDouble(Object aValue, double defaultValue) + { + try + { + return toDouble(aValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a string from an object + * @param aValue a value that is constructed into a string + * @param defaultValue the value that is returned, if conversion fails + * @return a string value + */ + public static String toString(Object aValue, String defaultValue) + { + try + { + return toString(aValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a boolean from an object + * @param aValue a value that is constructed into a boolean + * @param defaultValue the value that is returned, if conversion fails + * @return a boolean value + */ + public static boolean toBoolean(Object aValue, boolean defaultValue) + { + try + { + return toBoolean(aValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a int array from an object + * @param anArrayValue a value that is constructed into an int array + * @param defaultValue the value that is returned, if conversion fails + * @return an int array + */ + public static int[] toIntArray(Object anArrayValue, int[] defaultValue) + { + try + { + return toIntArray(anArrayValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a short array from an object + * @param anArrayValue a value that is constructed into a short array + * @param defaultValue the value that is returned, if conversion fails + * @return a short array + */ + public static short[] toShortArray(Object anArrayValue, short[] defaultValue) + { + try + { + return toShortArray(anArrayValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a string array from an object + * @param anArrayValue a value that is constructed into a string array + * @param defaultValue the value that is returned, if conversion fails + * @return a string array + */ + public static String[] toStringArray(Object anArrayValue, String[] defaultValue) + { + try + { + return toStringArray(anArrayValue); + } + catch (com.sun.star.lang.IllegalArgumentException e) + { + // ignore exception + } + return defaultValue; + } + + /** + * get a hexadecimal representation from a number + * @param number the number to transform + * @return a String with the hex code of the number + */ + public static String getHexStringFromNumber(long number) + { + TransformNumToHex num = new TransformNumToHex(number); + return num.getResult(); + } + + /** * get the type object from the given object * @param aValue an object representing a (numerical) value; can also be an 'any' * @return a type object: the object together with the its type information @@ -246,19 +1053,19 @@ public class NumericalHelper break; case TypeClass.BYTE_value: aTypeObject.iType = BYTE_TYPE; - aTypeObject.aValue = Byte.valueOf(AnyConverter.toByte(aValue)); + aTypeObject.aValue = new Byte(AnyConverter.toByte(aValue)); break; case TypeClass.SHORT_value: aTypeObject.iType = SHORT_TYPE; - aTypeObject.aValue = Short.valueOf(AnyConverter.toShort(aValue)); + aTypeObject.aValue = new Short(AnyConverter.toShort(aValue)); break; case TypeClass.LONG_value: aTypeObject.iType = INT_TYPE; - aTypeObject.aValue = Integer.valueOf(AnyConverter.toInt(aValue)); + aTypeObject.aValue = new Integer(AnyConverter.toInt(aValue)); break; case TypeClass.HYPER_value: aTypeObject.iType = LONG_TYPE; - aTypeObject.aValue = Long.valueOf(AnyConverter.toLong(aValue)); + aTypeObject.aValue = new Long(AnyConverter.toLong(aValue)); break; case TypeClass.FLOAT_value: aTypeObject.iType = FLOAT_TYPE; @@ -335,7 +1142,7 @@ public class NumericalHelper * @return * @throws com.sun.star.lang.IllegalArgumentException */ - private static int getInt(TypeObject typeObject) + static int getInt(TypeObject typeObject) throws com.sun.star.lang.IllegalArgumentException { if (typeObject.iType != INT_TYPE) @@ -350,7 +1157,7 @@ public class NumericalHelper * get the simple float type * @throws com.sun.star.lang.IllegalArgumentException */ - private static float getFloat(TypeObject typeObject) + static float getFloat(TypeObject typeObject) throws com.sun.star.lang.IllegalArgumentException { if (typeObject.iType != FLOAT_TYPE) @@ -444,5 +1251,114 @@ public class NumericalHelper transform(number); } } + + public String getResult() + { + return val.toString(); + } + } + + private static Object[] convertSequenceToObjectArray( + TypeObject sourceObject) + throws com.sun.star.lang.IllegalArgumentException + { + Object array = sourceObject.aValue; + Class<?> c = array.getClass(); + Object[] aShortVal = null; + if (c.equals(byte[].class)) + { + byte[] vals = (byte[]) array; + aShortVal = new Object[vals.length]; + for (int i = 0; i < vals.length; i++) + { + aShortVal[i] = new Byte(vals[i]); + } + } + else if (c.equals(short[].class)) + { + short[] vals = (short[]) array; + aShortVal = new Object[vals.length]; + for (int i = 0; i < vals.length; i++) + { + aShortVal[i] = new Short(vals[i]); + } + } + else if (c.equals(int[].class)) + { + int[] vals = (int[]) array; + aShortVal = new Object[vals.length]; + for (int i = 0; i < vals.length; i++) + { + aShortVal[i] = new Integer(vals[i]); + } + } + else if (c.equals(long[].class)) + { + long[] vals = (long[]) array; + aShortVal = new Object[vals.length]; + for (int i = 0; i < vals.length; i++) + { + aShortVal[i] = new Long(vals[i]); + } + } + else if (c.equals(float[].class)) + { + float[] vals = (float[]) array; + aShortVal = new Object[vals.length]; + for (int i = 0; i < vals.length; i++) + { + aShortVal[i] = new Float(vals[i]); + } + } + else if (c.equals(double[].class)) + { + double[] vals = (double[]) array; + aShortVal = new Object[vals.length]; + for (int i = 0; i < vals.length; i++) + { + aShortVal[i] = new Double(vals[i]); + } + } + else if (c.equals(boolean[].class)) + { + boolean[] vals = (boolean[]) array; + aShortVal = new Object[vals.length]; + for (int i = 0; i < vals.length; i++) + { + aShortVal[i] = Boolean.valueOf(vals[i]); + } + } + // if nothing did match, try this + if (aShortVal == null) + { + try + { + aShortVal = (Object[]) array; + } + catch (java.lang.ClassCastException e) + { + // unknown type cannot be converted ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits