Skip to content

Commit

Permalink
Minor clean-up and removed deprecation warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerco Ballintijn committed Jun 10, 2021
1 parent 56b9d90 commit edac389
Showing 1 changed file with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
This file is part of the Navajo Project.
It is subject to the license terms in the COPYING file found in the top-level directory of this distribution and at https://www.gnu.org/licenses/agpl-3.0.txt.
No part of the Navajo Project, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYING file.
*/
/*
* Created on May 23, 2005
* This file is part of the Navajo Project.
*
* It is subject to the license terms in the COPYING file found in the top-level directory of
* this distribution and at https://www.gnu.org/licenses/agpl-3.0.txt. No part of the Navajo
* Project, including this file, may be copied, modified, propagated, or distributed except
* according to the terms contained in the COPYING file.
*/

package com.dexels.navajo.functions;

import org.osgi.framework.BundleContext;
Expand All @@ -20,23 +20,21 @@

import navajofunctions.Version;

/**
* @author cbrouwer
*
*/
public class GetValidationDescription extends FunctionInterface {
private static final String DEFAULT_LOCALE = "nl";

private final static Logger logger = LoggerFactory.getLogger(GetValidationDescription.class);

private static final String DEFAULT_LOCALE = "nl";

@Override
public String remarks() {
return "Returns the description of a validation code";
}

@Override
public Object evaluate() throws TMLExpressionException {
Object o = getOperand(0);

Object o = getOperands().get(0);
String key = null;
if (o instanceof Integer) {
key = ((Integer) o).toString();
Expand All @@ -45,50 +43,53 @@ public Object evaluate() throws TMLExpressionException {
} else {
throw new TMLExpressionException(this, "Invalid operand: " + o.getClass().getName());
}
String tenant = getAccess().getTenant();

String tenant = getAccess().getTenant();
if (getOperands().size() > 1) {
Object tenantO = getOperand(1);
Object tenantO = getOperands().get(1);
if (!(tenantO instanceof String)) {
throw new TMLExpressionException(this, "Invalid operand: " + tenantO.getClass().getName());

throw new TMLExpressionException(this,
"Invalid operand: " + tenantO.getClass().getName());

}

tenant = (String) tenantO;
}

String locale = getDefaultLocale();
if (getOperands().size() > 2) {
Object localeO = getOperand(2);
Object localeO = getOperands().get(2);
if (!(localeO instanceof String)) {
throw new TMLExpressionException(this, "Invalid operand: " + localeO.getClass().getName());

throw new TMLExpressionException(this,
"Invalid operand: " + localeO.getClass().getName());

}

locale = (String) localeO;
}

if (locale == null) {
// If still null, default to NL?
locale = DEFAULT_LOCALE;
}

ResourceBundleStore rb = getResourceBundleService();
if (rb == null) {
return null;
}
return rb.getValidationDescription(key,tenant, locale);

return rb.getValidationDescription(key, tenant, locale);
}

private String getDefaultLocale() {
return getAccess().getInDoc().getHeader().getHeaderAttribute("locale");
}

private ResourceBundleStore getResourceBundleService() {
BundleContext context = Version.getDefaultBundleContext();
ServiceReference<ResourceBundleStore> servicereference;

try {

servicereference = context.getServiceReference(ResourceBundleStore.class);
BundleContext context = Version.getDefaultBundleContext();
ServiceReference<ResourceBundleStore> servicereference =
context.getServiceReference(ResourceBundleStore.class);

if (servicereference != null) {
ResourceBundleStore rbs = context.getService(servicereference);
Expand All @@ -101,12 +102,8 @@ private ResourceBundleStore getResourceBundleService() {
} catch (Throwable t) {
logger.error("Exception in retrieving ResourceBundleStore!", t);
}
return null;

}

public static void main(String[] args) throws Exception {

return null;
}

}

0 comments on commit edac389

Please sign in to comment.