001/* 002 * Portions of this software was developed by employees of the National Institute 003 * of Standards and Technology (NIST), an agency of the Federal Government and is 004 * being made available as a public service. Pursuant to title 17 United States 005 * Code Section 105, works of NIST employees are not subject to copyright 006 * protection in the United States. This software may be subject to foreign 007 * copyright. Permission in the United States and in foreign countries, to the 008 * extent that NIST may hold copyright, to use, copy, modify, create derivative 009 * works, and distribute this software and its documentation without fee is hereby 010 * granted on a non-exclusive basis, provided that this notice and disclaimer 011 * of warranty appears in all copies. 012 * 013 * THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER 014 * EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY 015 * THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF 016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM 017 * INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE 018 * SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT 019 * SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, 020 * INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, 021 * OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY, 022 * CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR 023 * PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT 024 * OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER. 025 */ 026 027package gov.nist.secauto.metaschema.core.metapath.function.library; 028 029import com.google.auto.service.AutoService; 030 031import gov.nist.secauto.metaschema.core.metapath.MetapathConstants; 032import gov.nist.secauto.metaschema.core.metapath.function.FunctionLibrary; 033import gov.nist.secauto.metaschema.core.metapath.function.IFunctionLibrary; 034import gov.nist.secauto.metaschema.core.metapath.item.atomic.IBooleanItem; 035import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateItem; 036import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDateTimeItem; 037import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDecimalItem; 038import gov.nist.secauto.metaschema.core.metapath.item.atomic.IDurationItem; 039import gov.nist.secauto.metaschema.core.metapath.item.atomic.IIntegerItem; 040import gov.nist.secauto.metaschema.core.metapath.item.atomic.INcNameItem; 041import gov.nist.secauto.metaschema.core.metapath.item.atomic.INonNegativeIntegerItem; 042import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem; 043import gov.nist.secauto.metaschema.core.metapath.item.atomic.IPositiveIntegerItem; 044import gov.nist.secauto.metaschema.core.metapath.item.atomic.IStringItem; 045 046@AutoService(IFunctionLibrary.class) 047public class DefaultFunctionLibrary 048 extends FunctionLibrary { 049 050 /** 051 * Initialize the built-in function library. 052 */ 053 public DefaultFunctionLibrary() { // NOPMD - intentional 054 // https://www.w3.org/TR/xpath-functions-31/#func-abs 055 registerFunction(NumericFunction.signature(MetapathConstants.NS_XPATH_FUNCTIONS, "abs", INumericItem::abs)); 056 // https://www.w3.org/TR/xpath-functions-31/#func-adjust-dateTime-to-timezone 057 // https://www.w3.org/TR/xpath-functions-31/#func-adjust-date-to-timezone 058 // https://www.w3.org/TR/xpath-functions-31/#func-adjust-time-to-timezone 059 // P1: https://www.w3.org/TR/xpath-functions-31/#func-avg 060 // https://www.w3.org/TR/xpath-functions-31/#func-base-uri 061 registerFunction(FnBaseUri.SIGNATURE_NO_ARG); 062 registerFunction(FnBaseUri.SIGNATURE_ONE_ARG); 063 // https://www.w3.org/TR/xpath-functions-31/#func-boolean 064 registerFunction(FnBoolean.SIGNATURE); 065 // https://www.w3.org/TR/xpath-functions-31/#func-ceiling 066 registerFunction(NumericFunction.signature(MetapathConstants.NS_XPATH_FUNCTIONS, "ceiling", INumericItem::ceiling)); 067 // P1: https://www.w3.org/TR/xpath-functions-31/#func-compare 068 registerFunction(FnCompare.SIGNATURE); 069 // P1: https://www.w3.org/TR/xpath-functions-31/#func-concat 070 // P1: https://www.w3.org/TR/xpath-functions-31/#func-contains 071 // P1: https://www.w3.org/TR/xpath-functions-31/#func-count 072 // https://www.w3.org/TR/xpath-functions-31/#func-current-date 073 // https://www.w3.org/TR/xpath-functions-31/#func-current-dateTime 074 // https://www.w3.org/TR/xpath-functions-31/#func-current-time 075 // https://www.w3.org/TR/xpath-functions-31/#func-data 076 registerFunction(FnData.SIGNATURE_NO_ARG); 077 registerFunction(FnData.SIGNATURE_ONE_ARG); 078 // https://www.w3.org/TR/xpath-functions-31/#func-day-from-date 079 // https://www.w3.org/TR/xpath-functions-31/#func-day-from-dateTime 080 // https://www.w3.org/TR/xpath-functions-31/#func-days-from-duration 081 // P1: https://www.w3.org/TR/xpath-functions-31/#func-deep-equal 082 // P1: https://www.w3.org/TR/xpath-functions-31/#func-distinct-values 083 // https://www.w3.org/TR/xpath-functions-31/#func-doc 084 registerFunction(FnDoc.SIGNATURE); 085 // https://www.w3.org/TR/xpath-functions-31/#func-doc-available 086 // https://www.w3.org/TR/xpath-functions-31/#func-document-uri 087 registerFunction(FnDocumentUri.SIGNATURE_NO_ARG); 088 registerFunction(FnDocumentUri.SIGNATURE_ONE_ARG); 089 // P1: https://www.w3.org/TR/xpath-functions-31/#func-empty 090 // https://www.w3.org/TR/xpath-functions-31/#func-encode-for-uri 091 // P1: https://www.w3.org/TR/xpath-functions-31/#func-ends-with 092 // https://www.w3.org/TR/xpath-functions-31/#func-exactly-one 093 // https://www.w3.org/TR/xpath-functions-31/#func-exists 094 registerFunction(FnExists.SIGNATURE); 095 registerFunction(FnFalse.SIGNATURE); 096 // https://www.w3.org/TR/xpath-functions-31/#func-floor 097 registerFunction(NumericFunction.signature(MetapathConstants.NS_XPATH_FUNCTIONS, "floor", INumericItem::floor)); 098 // https://www.w3.org/TR/xpath-functions-31/#func-format-date 099 // https://www.w3.org/TR/xpath-functions-31/#func-format-dateTime 100 // https://www.w3.org/TR/xpath-functions-31/#func-format-integer 101 // https://www.w3.org/TR/xpath-functions-31/#func-format-number 102 // https://www.w3.org/TR/xpath-functions-31/#func-format-time 103 // P1: https://www.w3.org/TR/xpath-functions-31/#func-generate-id 104 // https://www.w3.org/TR/xpath-functions-31/#func-has-children 105 // P1: https://www.w3.org/TR/xpath-functions-31/#func-head 106 // https://www.w3.org/TR/xpath-functions-31/#func-hours-from-dateTime 107 // https://www.w3.org/TR/xpath-functions-31/#func-hours-from-duration 108 // https://www.w3.org/TR/xpath-functions-31/#func-hours-from-time 109 // https://www.w3.org/TR/xpath-functions-31/#func-implicit-timezone 110 // P1: https://www.w3.org/TR/xpath-functions-31/#func-index-of 111 // https://www.w3.org/TR/xpath-functions-31/#func-innermost 112 // P1: https://www.w3.org/TR/xpath-functions-31/#func-insert-before 113 // https://www.w3.org/TR/xpath-functions-31/#func-iri-to-uri 114 // https://www.w3.org/TR/xpath-functions-31/#func-last 115 // P1: https://www.w3.org/TR/xpath-functions-31/#func-lower-case 116 // P1: https://www.w3.org/TR/xpath-functions-31/#func-matches 117 // P1: https://www.w3.org/TR/xpath-functions-31/#func-max 118 // P1: https://www.w3.org/TR/xpath-functions-31/#func-min 119 // https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-dateTime 120 // https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-duration 121 // https://www.w3.org/TR/xpath-functions-31/#func-minutes-from-time 122 // https://www.w3.org/TR/xpath-functions-31/#func-month-from-date 123 // https://www.w3.org/TR/xpath-functions-31/#func-month-from-dateTime 124 // https://www.w3.org/TR/xpath-functions-31/#func-months-from-duration 125 // https://www.w3.org/TR/xpath-functions-31/#func-normalize-space 126 // https://www.w3.org/TR/xpath-functions-31/#func-normalize-unicode 127 // https://www.w3.org/TR/xpath-functions-31/#func-not 128 registerFunction(FnNot.SIGNATURE); 129 // https://www.w3.org/TR/xpath-functions-31/#func-number 130 // https://www.w3.org/TR/xpath-functions-31/#func-one-or-more 131 // https://www.w3.org/TR/xpath-functions-31/#func-outermost 132 // https://www.w3.org/TR/xpath-functions-31/#func-parse-ietf-date 133 // https://www.w3.org/TR/xpath-functions-31/#func-path 134 registerFunction(FnPath.SIGNATURE_NO_ARG); 135 registerFunction(FnPath.SIGNATURE_ONE_ARG); 136 // https://www.w3.org/TR/xpath-functions-31/#func-position 137 // P1: https://www.w3.org/TR/xpath-functions-31/#func-remove 138 // P1: https://www.w3.org/TR/xpath-functions-31/#func-replace 139 // https://www.w3.org/TR/xpath-functions-31/#func-resolve-uri 140 registerFunction(FnResolveUri.SIGNATURE_ONE_ARG); 141 registerFunction(FnResolveUri.SIGNATURE_TWO_ARG); 142 // P1: https://www.w3.org/TR/xpath-functions-31/#func-reverse 143 // P1: https://www.w3.org/TR/xpath-functions-31/#func-root 144 // https://www.w3.org/TR/xpath-functions-31/#func-round 145 registerFunction(FnRound.SIGNATURE); 146 registerFunction(FnRound.SIGNATURE_WITH_PRECISION); 147 // https://www.w3.org/TR/xpath-functions-31/#func-round-half-to-even 148 // https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-dateTime 149 // https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-duration 150 // https://www.w3.org/TR/xpath-functions-31/#func-seconds-from-time 151 // https://www.w3.org/TR/xpath-functions-31/#func-starts-with 152 registerFunction(FnStartsWith.SIGNATURE); 153 // https://www.w3.org/TR/xpath-functions-31/#func-static-base-uri 154 registerFunction(FnStaticBaseUri.SIGNATURE); 155 // P1: https://www.w3.org/TR/xpath-functions-31/#func-string-join 156 // P1: https://www.w3.org/TR/xpath-functions-31/#func-string-length 157 // https://www.w3.org/TR/xpath-functions-31/#func-subsequence 158 // P1: https://www.w3.org/TR/xpath-functions-31/#func-substring 159 // P1: https://www.w3.org/TR/xpath-functions-31/#func-substring-after 160 // P1: https://www.w3.org/TR/xpath-functions-31/#func-substring-before 161 // P1: https://www.w3.org/TR/xpath-functions-31/#func-sum 162 // P1: https://www.w3.org/TR/xpath-functions-31/#func-tail 163 // https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-date 164 // https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-dateTime 165 // https://www.w3.org/TR/xpath-functions-31/#func-timezone-from-time 166 // P1: https://www.w3.org/TR/xpath-functions-31/#func-tokenize 167 // P1: https://www.w3.org/TR/xpath-functions-31/#func-translate 168 registerFunction(FnTrue.SIGNATURE); 169 // https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text 170 // https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text-available 171 // https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text-lines 172 // P1: https://www.w3.org/TR/xpath-functions-31/#func-upper-case 173 // https://www.w3.org/TR/xpath-functions-31/#func-year-from-date 174 // https://www.w3.org/TR/xpath-functions-31/#func-year-from-dateTime 175 // https://www.w3.org/TR/xpath-functions-31/#func-years-from-duration 176 // https://www.w3.org/TR/xpath-functions-31/#func-zero-or-one 177 178 // xpath casting functions 179 registerFunction( 180 CastFunction.signature(MetapathConstants.NS_XML_SCHEMA, "boolean", IBooleanItem.class, IBooleanItem::cast)); 181 registerFunction(CastFunction.signature( 182 MetapathConstants.NS_XML_SCHEMA, "date", IDateItem.class, IDateItem::cast)); 183 registerFunction(CastFunction.signature( 184 MetapathConstants.NS_XML_SCHEMA, "dateTime", IDateTimeItem.class, IDateTimeItem::cast)); 185 registerFunction(CastFunction.signature( 186 MetapathConstants.NS_XML_SCHEMA, "decimal", IDecimalItem.class, IDecimalItem::cast)); 187 registerFunction(CastFunction.signature( 188 MetapathConstants.NS_XML_SCHEMA, "duration", IDurationItem.class, IDurationItem::cast)); 189 registerFunction(CastFunction.signature( 190 MetapathConstants.NS_XML_SCHEMA, "integer", IIntegerItem.class, IIntegerItem::cast)); 191 registerFunction(CastFunction.signature( 192 MetapathConstants.NS_XML_SCHEMA, "NCName", INcNameItem.class, INcNameItem::cast)); 193 registerFunction(CastFunction.signature( 194 MetapathConstants.NS_XML_SCHEMA, "nonNegativeInteger", INonNegativeIntegerItem.class, 195 INonNegativeIntegerItem::cast)); 196 registerFunction(CastFunction.signature( 197 MetapathConstants.NS_XML_SCHEMA, "positiveInteger", IPositiveIntegerItem.class, 198 IPositiveIntegerItem::cast)); 199 registerFunction(CastFunction.signature( 200 MetapathConstants.NS_XML_SCHEMA, "string", IStringItem.class, IStringItem::cast)); 201 202 // metapath casting functions 203 registerFunction(CastFunction.signature( 204 MetapathConstants.NS_METAPATH, "boolean", IBooleanItem.class, IBooleanItem::cast)); 205 registerFunction(CastFunction.signature( 206 MetapathConstants.NS_METAPATH, "date", IDateItem.class, IDateItem::cast)); 207 registerFunction(CastFunction.signature( 208 MetapathConstants.NS_METAPATH, "date-time", IDateTimeItem.class, IDateTimeItem::cast)); 209 registerFunction(CastFunction.signature( 210 MetapathConstants.NS_METAPATH, "decimal", IDecimalItem.class, IDecimalItem::cast)); 211 registerFunction(CastFunction.signature( 212 MetapathConstants.NS_METAPATH, "duration", IDurationItem.class, IDurationItem::cast)); 213 registerFunction(CastFunction.signature( 214 MetapathConstants.NS_METAPATH, "integer", IIntegerItem.class, IIntegerItem::cast)); 215 registerFunction(CastFunction.signature( 216 MetapathConstants.NS_METAPATH, "ncname", INcNameItem.class, INcNameItem::cast)); 217 registerFunction(CastFunction.signature( 218 MetapathConstants.NS_METAPATH, "non-negative-integer", INonNegativeIntegerItem.class, 219 INonNegativeIntegerItem::cast)); 220 registerFunction(CastFunction.signature( 221 MetapathConstants.NS_METAPATH, "positive-integer", IPositiveIntegerItem.class, 222 IPositiveIntegerItem::cast)); 223 registerFunction(CastFunction.signature( 224 MetapathConstants.NS_METAPATH, "string", IStringItem.class, IStringItem::cast)); 225 226 // extra functions 227 registerFunction(MpRecurseDepth.SIGNATURE_ONE_ARG); 228 registerFunction(MpRecurseDepth.SIGNATURE_TWO_ARG); 229 } 230 231}