LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / reportbuilder / java / org / libreoffice / report / pentaho / StarFunctionDescription.java
blob2eddaf307ae90093bad994020451134b33670d2d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package org.libreoffice.report.pentaho;
20 import com.sun.star.lib.uno.helper.PropertySetMixin;
21 import com.sun.star.lib.uno.helper.WeakBase;
22 import com.sun.star.report.meta.XFunctionCategory;
23 import com.sun.star.sheet.FunctionArgument;
24 import com.sun.star.uno.Type;
25 import com.sun.star.uno.XComponentContext;
27 import java.util.Locale;
28 import java.util.MissingResourceException;
30 import org.pentaho.reporting.libraries.formula.DefaultFormulaContext;
31 import org.pentaho.reporting.libraries.formula.function.FunctionDescription;
33 public final class StarFunctionDescription extends WeakBase
34 implements com.sun.star.report.meta.XFunctionDescription
37 private final PropertySetMixin m_prophlp;
38 private final FunctionDescription functionDescription;
39 private final XFunctionCategory category;
40 private final Locale defaultLocale;
42 public StarFunctionDescription(final DefaultFormulaContext defaultContext, final XComponentContext context, final XFunctionCategory category, final FunctionDescription functionDescription)
44 this.category = category;
45 Locale locale;
46 try
48 functionDescription.getDisplayName(defaultContext.getLocalizationContext().getLocale());
49 locale = defaultContext.getLocalizationContext().getLocale();
51 catch (MissingResourceException e)
53 locale = Locale.ENGLISH;
55 this.defaultLocale = locale;
57 this.functionDescription = functionDescription;
58 // use the last parameter of the PropertySetMixin constructor
59 // for your optional attributes if necessary. See the documentation
60 // of the PropertySetMixin helper for further information.
61 // Ensure that your attributes are initialized correctly!
62 m_prophlp = new PropertySetMixin(context, this,
63 new Type(com.sun.star.report.meta.XFunctionDescription.class), null);
66 // com.sun.star.beans.XPropertySet:
67 public com.sun.star.beans.XPropertySetInfo getPropertySetInfo()
69 return m_prophlp.getPropertySetInfo();
72 public void setPropertyValue(String aPropertyName, Object aValue) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.beans.PropertyVetoException, com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
74 m_prophlp.setPropertyValue(aPropertyName, aValue);
77 public Object getPropertyValue(String aPropertyName) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException
79 return m_prophlp.getPropertyValue(aPropertyName);
82 public void addPropertyChangeListener(String aPropertyName, com.sun.star.beans.XPropertyChangeListener xListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException
84 m_prophlp.addPropertyChangeListener(aPropertyName, xListener);
87 public void removePropertyChangeListener(String aPropertyName, com.sun.star.beans.XPropertyChangeListener xListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException
89 m_prophlp.removePropertyChangeListener(aPropertyName, xListener);
92 public void addVetoableChangeListener(String aPropertyName, com.sun.star.beans.XVetoableChangeListener xListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException
94 m_prophlp.addVetoableChangeListener(aPropertyName, xListener);
97 public void removeVetoableChangeListener(String aPropertyName, com.sun.star.beans.XVetoableChangeListener xListener) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException
99 m_prophlp.removeVetoableChangeListener(aPropertyName, xListener);
102 // com.sun.star.report.meta.XFunctionDescription:
103 public com.sun.star.report.meta.XFunctionCategory getCategory()
105 return category;
108 public String getName()
112 return functionDescription.getDisplayName(defaultLocale);
114 catch (Exception ex)
117 return "Missing function name for " + this.getClass().getName();
120 public String getDescription()
124 return functionDescription.getDescription(defaultLocale);
126 catch (Exception ex)
129 return "Missing function description for " + this.getClass().getName();
132 public String getSignature()
134 final int count = functionDescription.getParameterCount();
135 final StringBuffer signature = new StringBuffer(getName());
136 signature.append('(');
137 for (int i = 0; i < count; i++)
139 signature.append(functionDescription.getParameterDisplayName(i, defaultLocale));
140 if (i != (count - 1))
142 signature.append(';');
145 signature.append(')');
146 return signature.toString();
149 public com.sun.star.sheet.FunctionArgument[] getArguments()
151 int count = functionDescription.getParameterCount();
152 final boolean infinite = functionDescription.isInfiniteParameterCount();
153 if (infinite)
155 // Identical value as VAR_ARGS from formula/funcvarargs.h
156 count = 255;
158 final FunctionArgument[] args = new FunctionArgument[count];
159 for (int i = 0; i < args.length; i++)
161 final int pos = infinite ? 0 : i;
162 args[i] = new FunctionArgument();
163 args[i].Description = functionDescription.getParameterDescription(pos, defaultLocale);
164 args[i].Name = functionDescription.getParameterDisplayName(pos, defaultLocale);
165 args[i].IsOptional = !functionDescription.isParameterMandatory(pos);
167 return args;
170 public String createFormula(String[] arguments) throws com.sun.star.lang.DisposedException, com.sun.star.lang.IllegalArgumentException, com.sun.star.uno.Exception
172 final boolean infinite = functionDescription.isInfiniteParameterCount();
173 final int count = functionDescription.getParameterCount();
174 if (!infinite && arguments.length > count)
176 throw new com.sun.star.lang.IllegalArgumentException();
179 final StringBuffer formula = new StringBuffer(getName());
180 formula.append('(');
181 for (int i = 0; i < arguments.length; ++i)
183 if (arguments[i].length() == 0)
185 break;
187 formula.append(arguments[i]);
188 if (i < (arguments.length - 1) && arguments[i + 1].length() != 0)
190 formula.append(';');
193 formula.append(')');
194 return formula.toString();