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.
Work towards supporting base64 encoding/decoding in Metapath. Impleme…
…nted and tested adapter methods. Implemented Metapath encode function.
- Loading branch information
1 parent
b2e2409
commit f7932f3
Showing
5 changed files
with
222 additions
and
34 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
61 changes: 61 additions & 0 deletions
61
.../main/java/gov/nist/secauto/metaschema/core/metapath/function/library/MpBase64Encode.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,61 @@ | ||
/* | ||
* 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.IBase64BinaryItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; | ||
import gov.nist.secauto.metaschema.core.util.ObjectUtils; | ||
|
||
import java.util.List; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* Provides new Metapath functions that evaluate a Metapath recursively over sequences generated by | ||
* evaluating that expression. | ||
*/ | ||
public final class MpBase64Encode { | ||
private static final String NAME = "base64-encode-text"; | ||
|
||
@NonNull | ||
static final IFunction SIGNATURE_ONE_ARG = IFunction.builder() | ||
.name(NAME) | ||
.namespace(MetapathConstants.NS_METAPATH_FUNCTIONS_EXTENDED) | ||
.deterministic() | ||
.contextIndependent() | ||
.focusIndependent() | ||
.argument(IArgument.builder() | ||
.name("text") | ||
.type(IStringItem.type()) | ||
.one() | ||
.build()) | ||
.returnType(IBase64BinaryItem.type()) | ||
.returnOne() | ||
.functionHandler(MpBase64Encode::executeOneArg) | ||
.build(); | ||
|
||
private MpBase64Encode() { | ||
// disable construction | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@NonNull | ||
private static ISequence<IBase64BinaryItem> executeOneArg( | ||
@NonNull IFunction function, | ||
@NonNull List<ISequence<?>> arguments, | ||
@NonNull DynamicContext dynamicContext, | ||
IItem focus) { | ||
IStringItem text = FunctionUtils.asType(ObjectUtils.requireNonNull(arguments.get(0).getFirstItem(true))); | ||
return ISequence.of(text.encode()); | ||
} | ||
} |
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