| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.lib; |
| 9 | |
| 10 | |
| 11 | /** |
| 12 | * This class contains constants and static methods to manipulate the validation |
| 13 | * property of a type. |
| 14 | */ |
| 15 | |
| 16 | public final class Validation { |
| 17 | |
| 18 | /** |
| 19 | * Code indicating that the value of a validation request was invalid |
| 20 | */ |
| 21 | |
| 22 | public static final int INVALID = -1; |
| 23 | |
| 24 | /** |
| 25 | * Code for strict validation |
| 26 | */ |
| 27 | |
| 28 | public static final int STRICT = 1; |
| 29 | |
| 30 | /** |
| 31 | * Code for lax validation |
| 32 | */ |
| 33 | |
| 34 | public static final int LAX = 2; |
| 35 | |
| 36 | /** |
| 37 | * Code corresponding to the XSLT option validation=preserve, which indicates |
| 38 | * that existing type annotations are to be preserved but no new validation is performed. |
| 39 | */ |
| 40 | |
| 41 | public static final int PRESERVE = 3; |
| 42 | |
| 43 | /** |
| 44 | * Code corresponding to the XSLT option validation=strip, which indicates |
| 45 | * that existing type annotations are to be removed and no new validation is performed. |
| 46 | */ |
| 47 | |
| 48 | public static final int STRIP = 4; |
| 49 | |
| 50 | /** |
| 51 | * Synonym for {@link #STRIP}, corresponding to XQuery usage |
| 52 | */ |
| 53 | |
| 54 | public static final int SKIP = 4; // synonym provided for the XQuery API |
| 55 | |
| 56 | /** |
| 57 | * Code indicating that no specific validation options were requested |
| 58 | */ |
| 59 | |
| 60 | public static final int DEFAULT = 0; |
| 61 | |
| 62 | /** |
| 63 | * Code indicating that validation against a named type was requested |
| 64 | */ |
| 65 | |
| 66 | public static final int BY_TYPE = 8; |
| 67 | |
| 68 | /** |
| 69 | * This class is never instantiated |
| 70 | */ |
| 71 | |
| 72 | private Validation() { |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get the integer validation code corresponding to a given string |
| 77 | * |
| 78 | * @param value one of "strict", "lax", "preserve", or "strip" |
| 79 | * @return the corresponding code {@link #STRICT}, {@link #LAX}, |
| 80 | * {@link #PRESERVE}, or {@link #STRIP} |
| 81 | */ |
| 82 | |
| 83 | public static int getCode(String value) { |
| 84 | if (value.equals("strict")) { |
| 85 | return STRICT; |
| 86 | } else if (value.equals("lax")) { |
| 87 | return LAX; |
| 88 | } else if (value.equals("preserve")) { |
| 89 | return PRESERVE; |
| 90 | } else if (value.equals("strip")) { |
| 91 | return STRIP; |
| 92 | } else { |
| 93 | return INVALID; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get a string representation of a validation code |
| 99 | * |
| 100 | * @param value one of the validation codes defined in this class |
| 101 | * @return one of the strings "strict", "lax", "preserve", "skip" (sic), or "invalid" |
| 102 | */ |
| 103 | |
| 104 | /*@NotNull*/ |
| 105 | public static String toString(int value) { |
| 106 | switch (value) { |
| 107 | case STRICT: |
| 108 | return "strict"; |
| 109 | case LAX: |
| 110 | return "lax"; |
| 111 | case PRESERVE: |
| 112 | return "preserve"; |
| 113 | case STRIP: |
| 114 | return "skip"; // for XQuery |
| 115 | case BY_TYPE: |
| 116 | return "by type"; |
| 117 | default: |
| 118 | return "invalid"; |
| 119 | } |
| 120 | } |
| 121 | } |