forked from metaschema-framework/metaschema-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the adjust-dateTime-to-timezone Metapath function.
- Loading branch information
1 parent
97d1b7b
commit 4fbe0af
Showing
14 changed files
with
396 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...ov/nist/secauto/metaschema/core/metapath/function/library/FnAdjustDateTimeToTimezone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.metapath.function.library; | ||
|
||
import gov.nist.secauto.metaschema.core.metapath.DynamicContext; | ||
import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; | ||
import gov.nist.secauto.metaschema.core.metapath.function.FunctionUtils; | ||
import gov.nist.secauto.metaschema.core.metapath.function.IArgument; | ||
import gov.nist.secauto.metaschema.core.metapath.function.IFunction; | ||
import gov.nist.secauto.metaschema.core.metapath.item.IItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.ISequence; | ||
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDayTimeDurationItem; | ||
|
||
import java.util.List; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* Implements the XPath 3.1 | ||
* <a href= "https://www.w3.org/TR/xpath-functions-31/#func-current-time">fn:current-time</a> | ||
* function. | ||
*/ | ||
public final class FnAdjustDateTimeToTimezone { | ||
private static final String NAME = "adjust-dateTime-to-timezone"; | ||
@NonNull | ||
static final IFunction ONE_ARG_SIGNATURE = IFunction.builder() | ||
.name(NAME) | ||
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS) | ||
.deterministic() | ||
.contextDependent() | ||
.focusIndependent() | ||
.argument(IArgument.builder() | ||
.name("arg") | ||
.type(IDateTimeItem.type()) | ||
.zeroOrOne() | ||
.build()) | ||
.returnType(IDateTimeItem.type()) | ||
.returnZeroOrOne() | ||
.functionHandler(FnAdjustDateTimeToTimezone::executeOneArg) | ||
.build(); | ||
@NonNull | ||
static final IFunction TWO_ARG_SIGNATURE = IFunction.builder() | ||
.name(NAME) | ||
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS) | ||
.deterministic() | ||
.contextIndependent() | ||
.focusIndependent() | ||
.argument(IArgument.builder() | ||
.name("arg") | ||
.type(IDateTimeItem.type()) | ||
.zeroOrOne() | ||
.build()) | ||
.argument(IArgument.builder() | ||
.name("timezone") | ||
.type(IDayTimeDurationItem.type()) | ||
.zeroOrOne() | ||
.build()) | ||
.returnType(IDateTimeItem.type()) | ||
.returnZeroOrOne() | ||
.functionHandler(FnAdjustDateTimeToTimezone::executeTwoArg) | ||
.build(); | ||
|
||
private FnAdjustDateTimeToTimezone() { | ||
// disable construction | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@NonNull | ||
private static ISequence<IDateTimeItem> executeOneArg( | ||
@NonNull IFunction function, | ||
@NonNull List<ISequence<?>> arguments, | ||
@NonNull DynamicContext dynamicContext, | ||
IItem focus) { | ||
IDateTimeItem arg = FunctionUtils.asTypeOrNull(arguments.get(0).getFirstItem(true)); | ||
// get the implicit timezone | ||
IDayTimeDurationItem timezone = dynamicContext.getImplicitTimeZoneAsDayTimeDuration(); | ||
return arg == null ? ISequence.empty() : ISequence.of(arg.replaceTimezone(timezone)); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@NonNull | ||
private static ISequence<IDateTimeItem> executeTwoArg( | ||
@NonNull IFunction function, | ||
@NonNull List<ISequence<?>> arguments, | ||
@NonNull DynamicContext dynamicContext, | ||
IItem focus) { | ||
IDateTimeItem arg = FunctionUtils.asTypeOrNull(arguments.get(0).getFirstItem(true)); | ||
IDayTimeDurationItem timezone = FunctionUtils.asTypeOrNull(arguments.get(1).getFirstItem(true)); | ||
return arg == null ? ISequence.empty() : ISequence.of(arg.replaceTimezone(timezone)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.