├── .github └── workflows │ └── push.yml ├── .gitignore ├── LICENSE.txt ├── README.md ├── bin ├── annotation-replacer.sh ├── netex-download-extract.sh └── version_updater.sh ├── bindings.xjb ├── pom.xml ├── renovate.json └── src ├── main └── java │ └── org │ └── rutebanken │ ├── netex │ ├── OmitNullsToStringStyle.java │ ├── client │ │ └── PublicationDeliveryClient.java │ └── validation │ │ ├── NeTExValidator.java │ │ └── PredefinedSchemaListClasspathResourceResolver.java │ └── util │ ├── LocalDateTimeISO8601XmlAdapter.java │ ├── LocalDateXmlAdapter.java │ └── LocalTimeISO8601XmlAdapter.java └── test ├── java └── org │ └── rutebanken │ └── netex │ ├── model │ ├── AbstractUnmarshalFrameTest.java │ ├── MarshalUnmarshalTest.java │ ├── ToStringTest.java │ ├── UnmarshalResourceFrameTest.java │ ├── UnmarshalServiceCalendarFrameTest.java │ ├── UnmarshalServiceFrameTest.java │ ├── UnmarshalSiteFrameTest.java │ └── UnmarshalTimetableFrameTest.java │ └── validation │ └── NeTExValidatorTest.java └── resources ├── date_time_examples.xml └── simplelogger.properties /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: Build and push 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | env: 10 | JFROG_USER: ${{ secrets.ARTIFACTORY_AUTH_USER }} 11 | JFROG_PASS: ${{ secrets.ARTIFACTORY_AUTH_TOKEN }} 12 | 13 | jobs: 14 | maven-package: 15 | if: "!contains(github.event.head_commit.message, 'ci skip')" 16 | runs-on: ubuntu-24.04 17 | steps: 18 | - uses: actions/checkout@v4 19 | with: 20 | fetch-depth: 0 21 | - name: Install xmlstarlet 22 | run: | 23 | sudo rm -rf /var/lib/apt/lists/* 24 | sudo apt-get update 25 | sudo apt-get -y install xmlstarlet 26 | - name: Copy maven settings 27 | run: | 28 | wget https://raw.githubusercontent.com/entur/ror-maven-settings/master/.m2/settings.xml -O .github/workflows/settings.xml 29 | - uses: actions/setup-java@v4 30 | with: 31 | java-version: 17.0.15 32 | distribution: temurin 33 | - name: Cache Maven dependencies 34 | uses: actions/cache@v4 35 | with: 36 | path: ~/.m2/repository 37 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 38 | restore-keys: | 39 | ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 40 | ${{ runner.os }}-maven- 41 | ${{ runner.os }}- 42 | 43 | - name: Run maven build 44 | run: mvn package -s .github/workflows/settings.xml 45 | - name: Sonar Scan 46 | env: 47 | SONAR_TOKEN: ${{ secrets.ENTUR_SONAR_PASSWORD }} 48 | SONAR_PROJECT_NAME: ${{ github.event.repository.name }} 49 | SONAR_PROJECT_KEY: entur_${{ github.event.repository.name }} 50 | run: | 51 | mvn -Psonar -s .github/workflows/settings.xml \ 52 | org.jacoco:jacoco-maven-plugin:prepare-agent verify \ 53 | org.jacoco:jacoco-maven-plugin:report sonar:sonar \ 54 | -Dmaven.main.skip \ 55 | -DskipTests \ 56 | -Dsonar.projectKey=${SONAR_PROJECT_KEY} \ 57 | -Dsonar.organization=enturas-github \ 58 | -Dsonar.projectName=${SONAR_PROJECT_NAME} \ 59 | -Dsonar.host.url=https://sonarcloud.io \ 60 | -Dsonar.token=${SONAR_TOKEN} 61 | 62 | deploy-artifactory: 63 | if: github.repository_owner == 'entur' && github.event_name == 'push' && github.ref == 'refs/heads/master' 64 | needs: [maven-package] 65 | runs-on: ubuntu-24.04 66 | steps: 67 | - uses: actions/checkout@v4 68 | with: 69 | fetch-depth: 0 70 | - name: Install xmlstarlet 71 | run: | 72 | sudo rm -rf /var/lib/apt/lists/* 73 | sudo apt-get update 74 | sudo apt-get -y install xmlstarlet 75 | - name: Copy maven settings 76 | run: | 77 | wget https://raw.githubusercontent.com/entur/ror-maven-settings/master/.m2/settings.xml -O .github/workflows/settings.xml 78 | - uses: actions/setup-java@v4 79 | with: 80 | java-version: 17.0.15 81 | distribution: temurin 82 | - name: Cache Maven dependencies 83 | uses: actions/cache@v4 84 | with: 85 | path: ~/.m2/repository 86 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 87 | restore-keys: | 88 | ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 89 | ${{ runner.os }}-maven- 90 | ${{ runner.os }}- 91 | 92 | - name: Deploy to Entur Artifactory 93 | run: mvn deploy -s .github/workflows/settings.xml -DskipTests 94 | 95 | 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | profile 11 | .idea 12 | *.iml 13 | src/main/resources/xsd/ 14 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | EUROPEAN UNION PUBLIC LICENCE v. 1.2 2 | EUPL © the European Union 2007, 2016 3 | 4 | This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the 5 | terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such 6 | use is covered by a right of the copyright holder of the Work). 7 | The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following 8 | notice immediately following the copyright notice for the Work: 9 | Licensed under the EUPL 10 | or has expressed by any other means his willingness to license under the EUPL. 11 | 12 | 1.Definitions 13 | In this Licence, the following terms have the following meaning: 14 | — ‘The Licence’:this Licence. 15 | — ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available 16 | as Source Code and also as Executable Code as the case may be. 17 | — ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or 18 | modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work 19 | required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in 20 | the country mentioned in Article 15. 21 | — ‘The Work’:the Original Work or its Derivative Works. 22 | — ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and 23 | modify. 24 | — ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by 25 | a computer as a program. 26 | — ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence. 27 | — ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to 28 | the creation of a Derivative Work. 29 | — ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the 30 | Licence. 31 | — ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating, 32 | transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential 33 | functionalities at the disposal of any other natural or legal person. 34 | 35 | 2.Scope of the rights granted by the Licence 36 | The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for 37 | the duration of copyright vested in the Original Work: 38 | — use the Work in any circumstance and for all usage, 39 | — reproduce the Work, 40 | — modify the Work, and make Derivative Works based upon the Work, 41 | — communicate to the public, including the right to make available or display the Work or copies thereof to the public 42 | and perform publicly, as the case may be, the Work, 43 | — distribute the Work or copies thereof, 44 | — lend and rent the Work or copies thereof, 45 | — sublicense rights in the Work or copies thereof. 46 | Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the 47 | applicable law permits so. 48 | In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed 49 | by law in order to make effective the licence of the economic rights here above listed. 50 | The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the 51 | extent necessary to make use of the rights granted on the Work under this Licence. 52 | 53 | 3.Communication of the Source Code 54 | The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as 55 | Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with 56 | each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to 57 | the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to 58 | distribute or communicate the Work. 59 | 60 | 4.Limitations on copyright 61 | Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the 62 | exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations 63 | thereto. 64 | 65 | 5.Obligations of the Licensee 66 | The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those 67 | obligations are the following: 68 | 69 | Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to 70 | the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the 71 | Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work 72 | to carry prominent notices stating that the Work has been modified and the date of modification. 73 | 74 | Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this 75 | Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless 76 | the Original Work is expressly distributed only under this version of the Licence — for example by communicating 77 | ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the 78 | Work or Derivative Work that alter or restrict the terms of the Licence. 79 | 80 | Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both 81 | the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done 82 | under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed 83 | in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with 84 | his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. 85 | 86 | Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide 87 | a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available 88 | for as long as the Licensee continues to distribute or communicate the Work. 89 | Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names 90 | of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and 91 | reproducing the content of the copyright notice. 92 | 93 | 6.Chain of Authorship 94 | The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or 95 | licensed to him/her and that he/she has the power and authority to grant the Licence. 96 | Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or 97 | licensed to him/her and that he/she has the power and authority to grant the Licence. 98 | Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions 99 | to the Work, under the terms of this Licence. 100 | 101 | 7.Disclaimer of Warranty 102 | The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work 103 | and may therefore contain defects or ‘bugs’ inherent to this type of development. 104 | For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind 105 | concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or 106 | errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this 107 | Licence. 108 | This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. 109 | 110 | 8.Disclaimer of Liability 111 | Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be 112 | liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the 113 | Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss 114 | of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, 115 | the Licensor will be liable under statutory product liability laws as far such laws apply to the Work. 116 | 117 | 9.Additional agreements 118 | While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services 119 | consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole 120 | responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, 121 | defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by 122 | the fact You have accepted any warranty or additional liability. 123 | 124 | 10.Acceptance of the Licence 125 | The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window 126 | displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of 127 | applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms 128 | and conditions. 129 | Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You 130 | by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution 131 | or Communication by You of the Work or copies thereof. 132 | 133 | 11.Information to the public 134 | In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, 135 | by offering to download the Work from a remote location) the distribution channel or media (for example, a website) 136 | must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence 137 | and the way it may be accessible, concluded, stored and reproduced by the Licensee. 138 | 139 | 12.Termination of the Licence 140 | The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms 141 | of the Licence. 142 | Such a termination will not terminate the licences of any person who has received the Work from the Licensee under 143 | the Licence, provided such persons remain in full compliance with the Licence. 144 | 145 | 13.Miscellaneous 146 | Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the 147 | Work. 148 | If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or 149 | enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid 150 | and enforceable. 151 | The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of 152 | the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. 153 | New versions of the Licence will be published with a unique version number. 154 | All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take 155 | advantage of the linguistic version of their choice. 156 | 157 | 14.Jurisdiction 158 | Without prejudice to specific agreement between parties, 159 | — any litigation resulting from the interpretation of this License, arising between the European Union institutions, 160 | bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice 161 | of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union, 162 | — any litigation arising between other parties and resulting from the interpretation of this License, will be subject to 163 | the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. 164 | 165 | 15.Applicable Law 166 | Without prejudice to specific agreement between parties, 167 | — this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, 168 | resides or has his registered office, 169 | — this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside 170 | a European Union Member State. 171 | 172 | 173 | Appendix 174 | 175 | ‘Compatible Licences’ according to Article 5 EUPL are: 176 | — GNU General Public License (GPL) v. 2, v. 3 177 | — GNU Affero General Public License (AGPL) v. 3 178 | — Open Software License (OSL) v. 2.1, v. 3.0 179 | — Eclipse Public License (EPL) v. 1.0 180 | — CeCILL v. 2.0, v. 2.1 181 | — Mozilla Public Licence (MPL) v. 2 182 | — GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 183 | — Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software 184 | — European Union Public Licence (EUPL) v. 1.1, v. 1.2 185 | — Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+). 186 | 187 | The European Commission may update this Appendix to later versions of the above licences without producing 188 | a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the 189 | covered Source Code from exclusive appropriation. 190 | All other changes or additions to this Appendix require the production of a new EUPL version. 191 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # netex-java-model [![Build and push](https://github.com/entur/netex-java-model/actions/workflows/push.yml/badge.svg)](https://github.com/entur/netex-java-model/actions/workflows/push.yml) 2 | 3 | Downloads the NeTEx-XML XSD files from https://github.com/entur/NeTEx and generates java model using jaxb. 4 | 5 | You need xmlstarlet installed. 6 | 7 | ```mvn clean install``` 8 | 9 | 10 | ## Maven central 11 | This project is available in the central maven repository. 12 | See https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.entur%22 13 | 14 | # Related project 15 | 16 | See https://github.com/entur/netex-protobuf for a conversion of NeTEx xsd files to protobuf descriptors. 17 | -------------------------------------------------------------------------------- /bin/annotation-replacer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Replaces annotations in NetEX xmls 4 | # See https://java.net/jira/browse/JAXB-420 5 | 6 | if ! type xmlstarlet > /dev/null; 7 | then echo "you need xmlstarlet for this to run"; 8 | exit 1; 9 | fi 10 | 11 | NETEX_VERSION=$1 12 | if [ -z $NETEX_VERSION ]; then 13 | echo "USAGE: $0 " 14 | exit 1 15 | fi 16 | 17 | XSD_FOLDER="./src/main/resources/xsd/${NETEX_VERSION}/" 18 | find $XSD_FOLDER -name "*.xsd" -exec xmlstarlet ed --inplace -d "//xsd:annotation" {} \; 19 | -------------------------------------------------------------------------------- /bin/netex-download-extract.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Download and extract NetTex 4 | : ${ZIP_PATH_TO_EXTRACT:="${NETEX_REPO}-${GIT_BRANCH}/xsd/*"} 5 | 6 | validate () { 7 | NAME=$1 8 | VALUE=$2 9 | 10 | if [ -z ${VALUE} ]; 11 | then 12 | echo "$NAME not set" 13 | exit 1 14 | fi 15 | } 16 | 17 | validate "ZIP_PATH_TO_EXTRACT" ${ZIP_PATH_TO_EXTRACT} 18 | validate "GITHUB_URL" ${GITHUB_URL} 19 | validate "DESTINATION_PATH" ${DESTINATION_PATH} 20 | 21 | ZIP_FILE=downloaded.zip 22 | 23 | echo "NETEX repo github URL: $GITHUB_URL" 24 | 25 | echo "Removing any existing contents in $DESTINATION_PATH" 26 | rm -rf ${DESTINATION_PATH}/* 27 | mkdir -p ${DESTINATION_PATH} 28 | 29 | if [ -f ${ZIP_FILE} ]; then 30 | echo "Removing existing file $ZIP_FILE" 31 | rm ${ZIP_FILE} 32 | fi 33 | 34 | WGET_URL="${GITHUB_URL}" 35 | echo "About to download from $WGET_URL" 36 | wget -q ${WGET_URL} -O ${ZIP_FILE} 37 | 38 | if [ -f ${ZIP_FILE} ]; then 39 | echo "Done" 40 | { 41 | echo "Create ${DESTINATION_PATH}" && 42 | mkdir -p ${DESTINATION_PATH} && 43 | 44 | echo "Unzip path ${ZIP_PATH_TO_EXTRACT} from zip file ${ZIP_FILE} to ${DESTINATION_PATH}" && 45 | unzip -q ${ZIP_FILE} ${ZIP_PATH_TO_EXTRACT} -d ${DESTINATION_PATH} && 46 | 47 | echo "Remove zipfile ${ZIP_FILE}" && 48 | rm ${ZIP_FILE} && 49 | 50 | REMOVE_FOLDER=${ZIP_PATH_TO_EXTRACT} && 51 | 52 | echo "Remove intermediate folder ${REMOVE_FOLDER}" && 53 | 54 | mv ${DESTINATION_PATH}/${REMOVE_FOLDER} ${DESTINATION_PATH} && 55 | rm -rf "${DESTINATION_PATH}/${REMOVE_FOLDER}" && 56 | 57 | echo "XSD extracted to $DESTINATION_PATH" 58 | } || 59 | { 60 | (>&2 echo "Error extracting zip file $ZIP_FILE from $WGET_URL. See my previous output for details") 61 | exit 1 62 | } 63 | else 64 | (>&2 echo "Error downloading zip from $WGET_URL") 65 | exit 1 66 | fi 67 | 68 | -------------------------------------------------------------------------------- /bin/version_updater.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Replaces the netex version in the bindings file. 4 | 5 | NETEX_VERSION=$1 6 | : ${BINDINGS_FILE:="./bindings.xjb"} 7 | 8 | if [ -z $NETEX_VERSION ]; then 9 | echo "USAGE: $0 " 10 | exit 1 11 | fi 12 | 13 | echo "Updating bindings file with version ${NETEX_VERSION}" 14 | 15 | sed -i -E "s/resources\/xsd\/[0-9]\.[0-9]+(\.[0-9])*\//resources\/xsd\/${NETEX_VERSION}\//" ${BINDINGS_FILE} -------------------------------------------------------------------------------- /bindings.xjb: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 4.0.0 18 | org.entur 19 | netex-java-model 20 | 2.0.16-SNAPSHOT 21 | 22 | netex-java-model 23 | Generates Java model from NeTEx XSDs using JAXB. 24 | https://github.com/entur/netex-java-model 25 | 26 | Entur AS 27 | https://www.entur.org/ 28 | 29 | 30 | 31 | EUPL-1.2 with modifications 32 | https://joinup.ec.europa.eu/software/page/eupl 33 | repo 34 | 35 | 36 | 37 | 38 | Erlend Nossum 39 | erlend.nossum@entur.org 40 | Entur 41 | https://www.entur.org 42 | 43 | 44 | Cristoffer Solem 45 | cristoffer.solem@entur.org 46 | Entur 47 | https://www.entur.org 48 | 49 | 50 | 51 | scm:git:ssh://git@github.com/entur/netex-java-model.git 52 | scm:git:ssh://git@github.com/entur/netex-java-model.git 53 | https://github.com/entur/netex-java-model/tree/master 54 | HEAD 55 | 56 | 57 | 58 | snapshots 59 | entur2-snapshots 60 | https://entur2.jfrog.io/entur2/libs-snapshot-local 61 | 62 | 63 | 64 | 65 | 66 | UTF-8 67 | 68 | 2023-11-01T10:21:59Z 69 | 11 70 | 71 | NeTEx 72 | update_dsj 73 | https://github.com/entur/${netexRepoName} 74 | 1.16 75 | 76 | 77 | 4.0.2 78 | 4.0.5 79 | 2.1.8 80 | 2.2.0 81 | 82 | 4.1.0 83 | 4.1.0 84 | 85 | 86 | 2.0.17 87 | 3.17.0 88 | 89 | 90 | 3.27.3 91 | 5.13.0 92 | 93 | 94 | 1.6.13 95 | 3.5.1 96 | 3.5.3 97 | 3.3.1 98 | 3.11.2 99 | 3.1.1 100 | 1.6 101 | 3.1.2 102 | 3.14.0 103 | 104 | 3.4.2 105 | 3.5.0 106 | 3.1.4 107 | 3.21.0 108 | 3.3.1 109 | 2.8.2 110 | 3.5.0 111 | 9.0.2 112 | 0.8.13 113 | 5.1.0.4751 114 | 115 | 116 | 117 | 118 | 119 | gpg 120 | ${env.GPG_KEY_NAME} 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | jakarta.xml.bind 129 | jakarta.xml.bind-api 130 | ${jakarta-xml-bind.version} 131 | 132 | 133 | io.github.threeten-jaxb 134 | threeten-jaxb-core 135 | ${threeten-jaxb-core.version} 136 | 137 | 138 | org.glassfish.jaxb 139 | jaxb-runtime 140 | ${glassfish-jaxb.version} 141 | runtime 142 | 143 | 144 | org.apache.cxf.xjc-utils 145 | cxf-xjc-runtime 146 | ${cxf-xjc.version} 147 | runtime 148 | 149 | 150 | 151 | 152 | org.slf4j 153 | slf4j-api 154 | ${slf4j.version} 155 | 156 | 157 | org.apache.commons 158 | commons-lang3 159 | ${commons-lang3.version} 160 | 161 | 162 | 163 | 164 | org.junit.jupiter 165 | junit-jupiter-api 166 | ${junit.version} 167 | test 168 | 169 | 170 | org.junit.jupiter 171 | junit-jupiter-engine 172 | ${junit.version} 173 | test 174 | 175 | 176 | org.assertj 177 | assertj-core 178 | ${assertj.core.version} 179 | test 180 | 181 | 182 | org.slf4j 183 | slf4j-simple 184 | ${slf4j.version} 185 | test 186 | 187 | 188 | 189 | 190 | 191 | 193 | 194 | org.apache.maven.wagon 195 | wagon-ssh-external 196 | 2.12 197 | 198 | 199 | 200 | 201 | 202 | maven-jar-plugin 203 | ${maven-jar-plugin.version} 204 | 205 | 206 | maven-clean-plugin 207 | ${maven-clean-plugin.version} 208 | 209 | 210 | maven-install-plugin 211 | ${maven-install-plugin.version} 212 | 213 | 214 | maven-site-plugin 215 | ${maven-site-plugin.version} 216 | 217 | 218 | maven-resources-plugin 219 | ${maven-resources-plugin.version} 220 | 221 | 222 | maven-deploy-plugin 223 | ${maven-deploy-plugin.version} 224 | 225 | 226 | 227 | 228 | 229 | org.codehaus.mojo 230 | exec-maven-plugin 231 | ${maven-exec-plugin.version} 232 | 233 | 234 | 235 | 236 | download-extract-current-version 237 | generate-sources 238 | 239 | exec 240 | 241 | 242 | 243 | ${netexGithubUrl}/archive/${netexBranch}.zip 244 | src/main/resources/xsd/${netexVersion} 245 | NeTEx-${netexBranch}/xsd/* 246 | 247 | ./bin/netex-download-extract.sh 248 | 249 | 250 | 251 | replace-hard-coded-id-in-bindings-file 252 | generate-sources 253 | 254 | exec 255 | 256 | 257 | 258 | ${netexVersion} 259 | 260 | 261 | ./bin/version_updater.sh 262 | 263 | 264 | 265 | 266 | 267 | download-extract-legacy-1.15 268 | generate-resources 269 | 270 | exec 271 | 272 | 273 | 274 | ${netexGithubUrl}/archive/tags/v1.0.15.zip 275 | src/main/resources/xsd/1.15 276 | NeTEx-tags-v1.0.15/xsd/* 277 | 278 | ./bin/netex-download-extract.sh 279 | 280 | 281 | 282 | 283 | download-extract-legacy-1.14 284 | generate-resources 285 | 286 | exec 287 | 288 | 289 | 290 | ${netexGithubUrl}/archive/tags/v1.0.14.zip 291 | src/main/resources/xsd/1.14 292 | NeTEx-tags-v1.0.14/xsd/* 293 | 294 | ./bin/netex-download-extract.sh 295 | 296 | 297 | 298 | 299 | download-extract-legacy-1.13 300 | generate-resources 301 | 302 | exec 303 | 304 | 305 | 306 | ${netexGithubUrl}/archive/tags/v1.0.13.zip 307 | src/main/resources/xsd/1.13 308 | NeTEx-tags-v1.0.13/xsd/* 309 | 310 | ./bin/netex-download-extract.sh 311 | 312 | 313 | 314 | 315 | download-extract-legacy-1.12 316 | generate-resources 317 | 318 | exec 319 | 320 | 321 | 322 | ${netexGithubUrl}/archive/tags/v1.0.12.zip 323 | src/main/resources/xsd/1.12 324 | NeTEx-tags-v1.0.12/xsd/* 325 | 326 | ./bin/netex-download-extract.sh 327 | 328 | 329 | 330 | 331 | download-extract-legacy-1.11 332 | generate-resources 333 | 334 | exec 335 | 336 | 337 | 338 | ${netexGithubUrl}/archive/tags/v1.0.11.zip 339 | src/main/resources/xsd/1.11 340 | NeTEx-tags-v1.0.11/xsd/* 341 | 342 | ./bin/netex-download-extract.sh 343 | 344 | 345 | 346 | 347 | download-extract-legacy-1.10 348 | generate-resources 349 | 350 | exec 351 | 352 | 353 | 354 | ${netexGithubUrl}/archive/tags/v1.0.10-entur.zip 355 | src/main/resources/xsd/1.10 356 | NeTEx-tags-v1.0.10-entur/xsd/* 357 | 358 | ./bin/netex-download-extract.sh 359 | 360 | 361 | 362 | 363 | download-extract-legacy-1.09 364 | generate-resources 365 | 366 | exec 367 | 368 | 369 | 370 | ${netexGithubUrl}/archive/tags/v1.0.9.zip 371 | src/main/resources/xsd/1.09 372 | NeTEx-tags-v1.0.9/xsd/* 373 | 374 | ./bin/netex-download-extract.sh 375 | 376 | 377 | 378 | 379 | download-extract-legacy-1.08 380 | generate-resources 381 | 382 | exec 383 | 384 | 385 | 386 | ${netexGithubUrl}/archive/tags/v1.0.8.zip 387 | src/main/resources/xsd/1.08 388 | NeTEx-tags-v1.0.8/xsd/* 389 | 390 | ./bin/netex-download-extract.sh 391 | 392 | 393 | 394 | 395 | download-extract-legacy-1.07 396 | generate-resources 397 | 398 | exec 399 | 400 | 401 | 402 | https://raw.githubusercontent.com/entur/NeTEx/master/archive/1.07.zip 403 | 404 | src/main/resources/xsd/1.07 405 | NeTEx-XML-deprecated-1.07/schema/xsd/* 406 | 407 | ./bin/netex-download-extract.sh 408 | 409 | 410 | 411 | 412 | download-extract-legacy-1.04beta 413 | generate-resources 414 | 415 | exec 416 | 417 | 418 | 419 | https://raw.githubusercontent.com/entur/NeTEx/master/archive/1.04beta.zip 420 | 421 | src/main/resources/xsd/1.04beta 422 | NeTEx-XML-deprecated-1.04beta/schema/xsd/* 423 | 424 | ./bin/netex-download-extract.sh 425 | 426 | 427 | 428 | annotation-removal 429 | generate-sources 430 | 431 | exec 432 | 433 | 434 | 435 | ${netexVersion} 436 | 437 | ./bin/annotation-replacer.sh 438 | 439 | 440 | 441 | 442 | 443 | org.apache.cxf 444 | cxf-xjc-plugin 445 | ${cxf.xjc.plugin.version} 446 | 447 | 448 | net.java.dev.jaxb2-commons:jaxb-fluent-api:${jaxb.fluent.api.version} 449 | org.apache.cxf.xjcplugins:cxf-xjc-ts:${cxf-xjc.version} 450 | 451 | 452 | 453 | 454 | generate-sources-for-netex 455 | generate-sources 456 | 457 | xsdtojava 458 | 459 | 460 | 466 | ${project.build.directory}/generated-sources/xjc 467 | 468 | 469 | 470 | ${basedir}/src/main/resources/xsd/${netexVersion}/NeTEx_publication.xsd 471 | 472 | true 473 | bindings.xjb 474 | 475 | -no-header 476 | -Xbug986 477 | -Xfluent-api 478 | -Xts:style:org.rutebanken.netex.OmitNullsToStringStyle.INSTANCE 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | org.apache.cxf.xjcplugins 489 | cxf-xjc-bug986 490 | ${cxf.xjc.plugin.version} 491 | 492 | 493 | 494 | 495 | org.apache.maven.plugins 496 | maven-compiler-plugin 497 | ${maven-compiler-plugin.version} 498 | 499 | ${jdk.version} 500 | ${jdk.version} 501 | UTF-8 502 | 503 | 504 | -Xlint:all 505 | 506 | 507 | 508 | 509 | org.codehaus.plexus 510 | plexus-compiler-javac 511 | 2.15.0 512 | 513 | 514 | 515 | 516 | 517 | org.apache.maven.plugins 518 | maven-release-plugin 519 | ${maven-release-plugin.version} 520 | 521 | true 522 | false 523 | release,sign,!noPublicDeploy 524 | deploy 525 | 526 | 527 | 528 | org.apache.maven.scm 529 | maven-scm-provider-gitexe 530 | 2.1.0 531 | 532 | 533 | 534 | 535 | org.apache.maven.plugins 536 | maven-enforcer-plugin 537 | ${maven-enforcer-plugin.version} 538 | 539 | 540 | 541 | enforce 542 | 543 | 544 | 545 | 546 | ${jdk.version} 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | org.apache.maven.plugins 556 | maven-surefire-plugin 557 | ${maven-surefire-plugin.version} 558 | 559 | @{argLine} -Xms500m -Xmx500m -Xss512k 560 | 561 | 562 | 563 | org.jacoco 564 | jacoco-maven-plugin 565 | ${jacoco-maven-plugin.version} 566 | 567 | 568 | default-prepare-agent 569 | 570 | prepare-agent 571 | 572 | 573 | 574 | default-report 575 | prepare-package 576 | 577 | report 578 | 579 | 580 | 581 | default-check 582 | 583 | check 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | org.apache.maven.plugins 593 | maven-jar-plugin 594 | 595 | 596 | 597 | org.entur.netex.java.model 598 | ${git.commit.id} 599 | ${git.commit.time} 600 | 601 | 602 | 603 | 604 | 605 | io.github.git-commit-id 606 | git-commit-id-maven-plugin 607 | ${git-commit-id-maven-plugin.version} 608 | 609 | 610 | 611 | revision 612 | 613 | 614 | 615 | 616 | false 617 | yyyy-MM-dd'T'HH:mm:ssXXX 618 | 619 | git.commit.id 620 | git.commit.time 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | sign 631 | 632 | false 633 | 634 | 635 | 636 | 637 | 638 | org.apache.maven.plugins 639 | maven-surefire-plugin 640 | ${maven-surefire-plugin.version} 641 | 642 | false 643 | 644 | 645 | 646 | 647 | 648 | 649 | org.apache.maven.plugins 650 | maven-surefire-plugin 651 | ${maven-surefire-plugin.version} 652 | 653 | 654 | org.apache.maven.plugins 655 | maven-gpg-plugin 656 | ${maven-gpg-plugin.version} 657 | 658 | 659 | sign-artifacts 660 | verify 661 | 662 | sign 663 | 664 | 665 | 666 | 667 | 668 | org.apache.maven.plugins 669 | maven-source-plugin 670 | ${maven-source-plugin.version} 671 | 672 | 673 | attach-sources 674 | 675 | jar 676 | 677 | 678 | 679 | 680 | 681 | org.apache.maven.plugins 682 | maven-javadoc-plugin 683 | ${maven-javadoc-plugin.version} 684 | 685 | none 686 | 687 | 688 | 689 | attach-javadocs 690 | 691 | jar 692 | 693 | 694 | 695 | 696 | 697 | org.sonatype.plugins 698 | nexus-staging-maven-plugin 699 | ${nexus-staging-maven-plugin.version} 700 | true 701 | 702 | ossrh 703 | https://oss.sonatype.org/ 704 | 705 | false 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | release 714 | 715 | false 716 | 717 | 718 | 722 | 723 | ossrh 724 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 725 | 726 | 727 | 728 | 729 | 730 | sonar 731 | 732 | false 733 | 734 | 735 | 736 | 17 737 | 738 | 739 | 740 | 741 | 742 | 743 | org.sonarsource.scanner.maven 744 | sonar-maven-plugin 745 | ${sonar-maven-plugin.version} 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "github>entur/ror-renovate-config", 4 | "github>entur/ror-renovate-config:groupNonMajorWeekly" 5 | ], 6 | "separateMinorPatch": true 7 | } -------------------------------------------------------------------------------- /src/main/java/org/rutebanken/netex/OmitNullsToStringStyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex; 17 | 18 | import org.apache.commons.lang3.builder.ToStringStyle; 19 | 20 | public class OmitNullsToStringStyle extends ToStringStyle { 21 | 22 | /** 23 | * 24 | */ 25 | private static final long serialVersionUID = 7043613680114711384L; 26 | public static final ToStringStyle INSTANCE = new OmitNullsToStringStyle(); 27 | 28 | public OmitNullsToStringStyle() { 29 | this.setUseClassName(false); 30 | this.setUseIdentityHashCode(false); 31 | this.setUseFieldNames(true); 32 | this.setContentStart("["); 33 | this.setContentEnd("]"); 34 | } 35 | 36 | @Override 37 | public void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) { 38 | if (value != null) { 39 | super.append(buffer, fieldName, value, fullDetail); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/rutebanken/netex/client/PublicationDeliveryClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.client; 17 | 18 | import jakarta.xml.bind.JAXBContext; 19 | import jakarta.xml.bind.JAXBElement; 20 | import jakarta.xml.bind.JAXBException; 21 | import jakarta.xml.bind.Marshaller; 22 | import jakarta.xml.bind.Unmarshaller; 23 | import org.rutebanken.netex.model.ObjectFactory; 24 | import org.rutebanken.netex.model.PublicationDeliveryStructure; 25 | import org.rutebanken.netex.validation.NeTExValidator; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | import org.xml.sax.SAXException; 29 | 30 | import java.io.IOException; 31 | import java.io.InputStream; 32 | import java.net.HttpURLConnection; 33 | import java.net.URL; 34 | 35 | public class PublicationDeliveryClient { 36 | 37 | private static final Logger LOGGER = LoggerFactory.getLogger(PublicationDeliveryClient.class); 38 | 39 | private final ObjectFactory objectFactory = new ObjectFactory(); 40 | 41 | private final String publicationDeliveryUrl; 42 | 43 | private final JAXBContext jaxbContext; 44 | private final boolean validateAgainstSchema; 45 | 46 | private NeTExValidator neTExValidator; 47 | 48 | /** 49 | * 50 | * @param publicationDeliveryUrl Url to where to POST the publication delivery XML 51 | * @param validateAgainstSchema If serialized XML should be validated against the NeTEx schema. 52 | */ 53 | public PublicationDeliveryClient(String publicationDeliveryUrl, boolean validateAgainstSchema) throws JAXBException, IOException, SAXException { 54 | this.publicationDeliveryUrl = publicationDeliveryUrl; 55 | this.jaxbContext = JAXBContext.newInstance(PublicationDeliveryStructure.class); 56 | this.validateAgainstSchema = validateAgainstSchema; 57 | if(validateAgainstSchema) { 58 | neTExValidator = new NeTExValidator(); 59 | } 60 | } 61 | 62 | public PublicationDeliveryClient(String publicationDeliveryUrl) throws JAXBException, IOException, SAXException { 63 | this(publicationDeliveryUrl, false); 64 | } 65 | 66 | public PublicationDeliveryStructure sendPublicationDelivery(PublicationDeliveryStructure publicationDelivery) throws JAXBException, IOException { 67 | 68 | Marshaller marshaller = jaxbContext.createMarshaller(); 69 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 70 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 71 | 72 | if(validateAgainstSchema) { 73 | marshaller.setSchema(neTExValidator.getSchema()); 74 | } 75 | 76 | URL url = new URL(publicationDeliveryUrl); 77 | HttpURLConnection connection = null; 78 | try { 79 | connection = (HttpURLConnection) url.openConnection(); 80 | connection.setRequestMethod("POST"); 81 | connection.setRequestProperty("Content-type", "application/xml"); 82 | connection.setDoOutput(true); 83 | 84 | LOGGER.info("About to start marshalling publication delivery to output stream {}", publicationDelivery); 85 | marshaller.marshal(objectFactory.createPublicationDelivery(publicationDelivery), connection.getOutputStream()); 86 | LOGGER.info("Done marshalling publication delivery to output stream. (Schema validation was set to {}) {}", validateAgainstSchema, publicationDelivery); 87 | 88 | int responseCode = connection.getResponseCode(); 89 | LOGGER.info("Got response code {} after posting publication delivery to URL : {}", responseCode, url); 90 | 91 | InputStream inputStream = connection.getInputStream(); 92 | JAXBElement element = (JAXBElement) unmarshaller.unmarshal(inputStream); 93 | 94 | return element.getValue(); 95 | } catch (Exception e) { 96 | throw new IOException("Error posting XML to " + publicationDeliveryUrl, e); 97 | } finally { 98 | if(connection != null) { 99 | connection.disconnect(); 100 | } 101 | } 102 | 103 | 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/org/rutebanken/netex/validation/NeTExValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.validation; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.xml.sax.SAXException; 21 | 22 | import javax.xml.XMLConstants; 23 | import javax.xml.transform.Source; 24 | import javax.xml.validation.Schema; 25 | import javax.xml.validation.SchemaFactory; 26 | import javax.xml.validation.Validator; 27 | import java.io.IOException; 28 | import java.net.URL; 29 | import java.util.EnumMap; 30 | import java.util.Map; 31 | 32 | public class NeTExValidator { 33 | 34 | private static final Logger LOGGER = LoggerFactory.getLogger(NeTExValidator.class); 35 | 36 | public enum NetexVersion { 37 | V1_0_4beta ("1.04beta"), 38 | V1_0_7 ("1.07"), 39 | v1_0_8 ("1.08"), 40 | v1_0_9 ("1.09"), 41 | v1_10 ("1.10"), 42 | v1_11 ("1.11"), 43 | v1_12 ("1.12"), 44 | v1_13 ("1.13"), 45 | v1_14 ("1.14"), 46 | v1_15 ("1.15"), 47 | v1_16 ("1.16"); 48 | 49 | private final String folderName; 50 | 51 | NetexVersion(String folderName) { 52 | this.folderName = folderName; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return folderName; 58 | } 59 | } 60 | private final Schema neTExSchema; 61 | 62 | public static final NetexVersion LATEST = NetexVersion.v1_16; 63 | 64 | private static final Map VALIDATORS_PER_VERSION = new EnumMap<>(NetexVersion.class); 65 | 66 | private static synchronized NeTExValidator createValidator(NeTExValidator.NetexVersion version) throws IOException, SAXException { 67 | NeTExValidator validator = VALIDATORS_PER_VERSION.get(version); 68 | if (validator == null) { 69 | validator = new NeTExValidator(version); 70 | VALIDATORS_PER_VERSION.put(version, validator); 71 | } 72 | return validator; 73 | } 74 | 75 | public static NeTExValidator getNeTExValidator(NeTExValidator.NetexVersion version) throws IOException, SAXException { 76 | if (version == null) { 77 | version = NeTExValidator.LATEST; 78 | } 79 | NeTExValidator validator = VALIDATORS_PER_VERSION.get(version); 80 | if (validator == null) { 81 | validator = createValidator(version); 82 | 83 | } 84 | return validator; 85 | } 86 | 87 | public static NeTExValidator getNeTExValidator() throws IOException, SAXException { 88 | return getNeTExValidator(null); 89 | } 90 | 91 | 92 | /** 93 | * Use static getNeTExValidator to avoid initializing more schemas than needed. 94 | */ 95 | public NeTExValidator() throws IOException, SAXException { 96 | this(LATEST); 97 | } 98 | 99 | /** 100 | * Use static getNeTExValidator to avoid initializing more schemas than needed. 101 | */ 102 | public NeTExValidator(NetexVersion version) throws IOException, SAXException { 103 | SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 104 | 105 | String resourceName = "xsd/"+ version +"/NeTEx_publication.xsd"; 106 | LOGGER.info("Loading resource: {}", resourceName); 107 | URL resource = getClass().getClassLoader().getResource(resourceName); 108 | if(resource == null) { 109 | throw new IOException("Cannot load resource " + resourceName); 110 | } 111 | neTExSchema = factory.newSchema(resource); 112 | } 113 | 114 | public Schema getSchema() { 115 | return neTExSchema; 116 | } 117 | 118 | public void validate(Source source) throws IOException, SAXException { 119 | Validator validator = neTExSchema.newValidator(); 120 | validator.validate(source); 121 | } 122 | 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/org/rutebanken/netex/validation/PredefinedSchemaListClasspathResourceResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.validation; 17 | 18 | import org.w3c.dom.ls.LSInput; 19 | import org.w3c.dom.ls.LSResourceResolver; 20 | 21 | import java.io.BufferedReader; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.io.InputStreamReader; 25 | import java.io.Reader; 26 | import java.nio.charset.StandardCharsets; 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | public class PredefinedSchemaListClasspathResourceResolver implements LSResourceResolver { 31 | 32 | private final Map resourceToPathMap = new HashMap<>(); 33 | 34 | public PredefinedSchemaListClasspathResourceResolver(String schemaList) throws IOException { 35 | 36 | InputStream resourceAsStream = getClass().getResourceAsStream(schemaList); 37 | if (resourceAsStream == null) { 38 | throw new IOException("Unable to load " + schemaList + " as resource stream"); 39 | } 40 | BufferedReader r = new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8)); 41 | String resource; 42 | while ((resource = r.readLine()) != null) { 43 | String name = resource.substring(resource.lastIndexOf('/') + 1); 44 | String existing = resourceToPathMap.put(name, resource); 45 | if (existing != null) { 46 | throw new RuntimeException("Duplicate resource file on classpath " + name); 47 | } 48 | } 49 | } 50 | 51 | @Override 52 | public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { 53 | try { 54 | 55 | String[] parts = systemId.split("/"); 56 | String filename = parts[parts.length - 1]; 57 | 58 | LSInput lsInput = createInput(systemId, baseURI); 59 | String path = resourceToPathMap.get(filename); 60 | if (path != null) { 61 | InputStream stream = getClass().getResourceAsStream(path); 62 | lsInput.setByteStream(stream); 63 | } 64 | return lsInput; 65 | } catch (Exception e) { 66 | throw new RuntimeException(e); 67 | } 68 | } 69 | 70 | protected LSInput createInput(final String systemId, final String baseUri) { 71 | 72 | return new LSInput() { 73 | 74 | private InputStream is; 75 | 76 | @Override 77 | public void setSystemId(String systemId) { 78 | } 79 | 80 | @Override 81 | public void setStringData(String stringData) { 82 | } 83 | 84 | @Override 85 | public void setPublicId(String publicId) { 86 | } 87 | 88 | @Override 89 | public void setEncoding(String encoding) { 90 | } 91 | 92 | @Override 93 | public void setCharacterStream(Reader characterStream) { 94 | } 95 | 96 | @Override 97 | public void setCertifiedText(boolean certifiedText) { 98 | } 99 | 100 | @Override 101 | public void setByteStream(InputStream byteStream) { 102 | is = byteStream; 103 | } 104 | 105 | @Override 106 | public void setBaseURI(String baseURI) { 107 | } 108 | 109 | @Override 110 | public String getSystemId() { 111 | return systemId; 112 | } 113 | 114 | @Override 115 | public String getStringData() { 116 | return null; 117 | } 118 | 119 | @Override 120 | public String getPublicId() { 121 | return null; 122 | } 123 | 124 | @Override 125 | public String getEncoding() { 126 | return null; 127 | } 128 | 129 | @Override 130 | public Reader getCharacterStream() { 131 | return null; 132 | } 133 | 134 | @Override 135 | public boolean getCertifiedText() { 136 | return false; 137 | } 138 | 139 | @Override 140 | public InputStream getByteStream() { 141 | return is; 142 | } 143 | 144 | @Override 145 | public String getBaseURI() { 146 | return baseUri; 147 | } 148 | }; 149 | 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/org/rutebanken/util/LocalDateTimeISO8601XmlAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.util; 17 | 18 | import jakarta.xml.bind.annotation.adapters.XmlAdapter; 19 | import java.time.LocalDateTime; 20 | import java.time.OffsetDateTime; 21 | import java.time.format.DateTimeFormatter; 22 | import java.time.format.DateTimeFormatterBuilder; 23 | import java.time.temporal.ChronoField; 24 | 25 | public class LocalDateTimeISO8601XmlAdapter extends XmlAdapter { 26 | 27 | private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd'T'HH:mm:ss") 28 | .optionalStart().appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true).optionalEnd() 29 | .optionalStart().appendPattern("XXXXX") 30 | .optionalEnd() 31 | 32 | // 33 | .parseDefaulting(ChronoField.OFFSET_SECONDS,OffsetDateTime.now().getLong(ChronoField.OFFSET_SECONDS) ).toFormatter(); 34 | 35 | @Override 36 | public LocalDateTime unmarshal(String inputDate) { 37 | return LocalDateTime.parse(inputDate, formatter); 38 | 39 | } 40 | 41 | @Override 42 | public String marshal(LocalDateTime inputDate) { 43 | if(inputDate != null) { 44 | return formatter.format(inputDate); 45 | } else { 46 | return null; 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/rutebanken/util/LocalDateXmlAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.util; 17 | 18 | import jakarta.xml.bind.annotation.adapters.XmlAdapter; 19 | import java.time.LocalDateTime; 20 | import java.time.OffsetDateTime; 21 | import java.time.format.DateTimeFormatter; 22 | import java.time.format.DateTimeFormatterBuilder; 23 | import java.time.temporal.ChronoField; 24 | 25 | public class LocalDateXmlAdapter extends XmlAdapter { 26 | private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd") 27 | .optionalStart().appendPattern("XXXXX").optionalEnd() 28 | .parseDefaulting(ChronoField.HOUR_OF_DAY, 0) 29 | .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0) 30 | .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0) 31 | .parseDefaulting(ChronoField.OFFSET_SECONDS,OffsetDateTime.now().getLong(ChronoField.OFFSET_SECONDS) ) 32 | .toFormatter(); 33 | 34 | @Override 35 | public LocalDateTime unmarshal(String inputDate) { 36 | return LocalDateTime.parse(inputDate, formatter); 37 | } 38 | 39 | @Override 40 | public String marshal(LocalDateTime inputDate) { 41 | if(inputDate != null) { 42 | return formatter.format(inputDate); 43 | } else { 44 | return null; 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/rutebanken/util/LocalTimeISO8601XmlAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.util; 17 | 18 | import jakarta.xml.bind.annotation.adapters.XmlAdapter; 19 | import java.time.LocalTime; 20 | import java.time.OffsetDateTime; 21 | import java.time.format.DateTimeFormatter; 22 | import java.time.format.DateTimeFormatterBuilder; 23 | import java.time.temporal.ChronoField; 24 | 25 | public class LocalTimeISO8601XmlAdapter extends XmlAdapter { 26 | 27 | private static final DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("HH:mm:ss") 28 | .optionalStart().appendFraction(ChronoField.MILLI_OF_SECOND, 0, 3, true).optionalEnd() 29 | .optionalStart().appendPattern("XXXXX") 30 | .optionalEnd() 31 | 32 | // 33 | .parseDefaulting(ChronoField.OFFSET_SECONDS,OffsetDateTime.now().getLong(ChronoField.OFFSET_SECONDS) ).toFormatter(); 34 | 35 | @Override 36 | public LocalTime unmarshal(String inputDate) { 37 | return LocalTime.parse(inputDate, formatter); 38 | 39 | } 40 | 41 | @Override 42 | public String marshal(LocalTime inputDate) { 43 | if(inputDate != null) { 44 | return formatter.format(inputDate); 45 | } else { 46 | return null; 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/AbstractUnmarshalFrameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import jakarta.xml.bind.JAXBContext; 19 | import jakarta.xml.bind.JAXBException; 20 | import org.junit.jupiter.api.BeforeAll; 21 | 22 | abstract class AbstractUnmarshalFrameTest { 23 | 24 | protected static JAXBContext jaxbContext; 25 | 26 | 27 | @BeforeAll 28 | public static void initContext() throws JAXBException { 29 | jaxbContext = JAXBContext.newInstance(PublicationDeliveryStructure.class); 30 | 31 | } 32 | 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/MarshalUnmarshalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import org.junit.jupiter.api.BeforeAll; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import jakarta.xml.bind.JAXBContext; 22 | import jakarta.xml.bind.JAXBElement; 23 | import jakarta.xml.bind.JAXBException; 24 | import jakarta.xml.bind.Marshaller; 25 | import jakarta.xml.bind.Unmarshaller; 26 | import javax.xml.stream.XMLOutputFactory; 27 | import javax.xml.stream.XMLStreamWriter; 28 | import java.io.ByteArrayInputStream; 29 | import java.io.ByteArrayOutputStream; 30 | import java.io.File; 31 | import java.io.FileInputStream; 32 | import java.io.FileNotFoundException; 33 | import java.io.IOException; 34 | import java.io.StringWriter; 35 | import java.nio.charset.StandardCharsets; 36 | import java.nio.file.Files; 37 | import java.nio.file.Paths; 38 | import java.time.LocalDateTime; 39 | import java.time.LocalTime; 40 | import java.time.temporal.ChronoField; 41 | import java.util.Arrays; 42 | import java.util.List; 43 | 44 | import static org.assertj.core.api.Assertions.assertThat; 45 | import static org.junit.jupiter.api.Assertions.assertFalse; 46 | 47 | class MarshalUnmarshalTest { 48 | 49 | private static JAXBContext jaxbContext; 50 | 51 | private static final ObjectFactory factory = new ObjectFactory(); 52 | 53 | @BeforeAll 54 | public static void initContext() throws JAXBException { 55 | jaxbContext = JAXBContext.newInstance(PublicationDeliveryStructure.class); 56 | 57 | } 58 | 59 | @Test 60 | void publicationDeliveryWithOffsetDateTime() throws JAXBException { 61 | Marshaller marshaller = jaxbContext.createMarshaller(); 62 | 63 | PublicationDeliveryStructure publicationDelivery = new PublicationDeliveryStructure() 64 | .withDescription(new MultilingualString().withValue("value").withLang("no").withTextIdType("")).withPublicationTimestamp(LocalDateTime.now().withNano(0)) 65 | .withParticipantRef("participantRef"); 66 | 67 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 68 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 69 | marshaller.marshal(factory.createPublicationDelivery(publicationDelivery), byteArrayOutputStream); 70 | 71 | String xml = byteArrayOutputStream.toString(); 72 | System.out.println(xml); 73 | 74 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 75 | 76 | @SuppressWarnings("unchecked") 77 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 78 | .unmarshal(new ByteArrayInputStream(xml.getBytes())); 79 | PublicationDeliveryStructure actual = jaxbElement.getValue(); 80 | 81 | System.out.println(actual.getPublicationTimestamp()); 82 | assertThat(actual.getPublicationTimestamp()).isEqualTo(publicationDelivery.getPublicationTimestamp()); 83 | assertThat(actual.getDescription()).isNotNull(); 84 | assertThat(actual.getDescription().getValue()).isEqualTo(publicationDelivery.getDescription().getValue()); 85 | assertThat(actual.getParticipantRef()).isEqualTo(publicationDelivery.getParticipantRef()); 86 | } 87 | 88 | @Test 89 | void unmarshalPublicationDeliveryAndVerifyDateTime() throws JAXBException { 90 | 91 | String xml = "" 92 | + "" 93 | + " 2016-05-18T15:00:00.0+01:00" 94 | + " NHR" 95 | + " " 96 | + " " 97 | + " " 98 | + " " 99 | + " " 100 | + " " 101 | + " 10.8577903" 102 | + " 59.910579" 103 | + " " 104 | + " " 105 | + " Krokstien " 106 | + " bus" 107 | + " onstreetBus" 108 | + " " 109 | + " " 110 | + " " 111 | + " " 112 | + " 10.8577903" 113 | + " 59.910579" 114 | + " " 115 | + " " 116 | + " outdoors" 117 | + " wellLit" 118 | + " busStop" 119 | + " " 120 | + " " 121 | + " " 122 | + " " 123 | + " " 124 | + " " 125 | + ""; 126 | 127 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 128 | 129 | @SuppressWarnings("unchecked") 130 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 131 | .unmarshal(new ByteArrayInputStream(xml.getBytes())); 132 | PublicationDeliveryStructure actual = jaxbElement.getValue(); 133 | 134 | System.out.println(actual.getPublicationTimestamp()); 135 | assertThat(actual.getPublicationTimestamp().getHour()).isEqualTo(15); 136 | } 137 | 138 | @Test 139 | void timetableWithVehicleModes() throws JAXBException { 140 | Marshaller marshaller = jaxbContext.createMarshaller(); 141 | 142 | TimetableFrame timetableFrame = factory.createTimetableFrame().withVersion("any").withId("TimetableFrame") 143 | .withName(factory.createMultilingualString().withValue("TimetableFrame")).withVehicleModes(VehicleModeEnumeration.AIR); 144 | 145 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 146 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 147 | marshaller.marshal(factory.createTimetableFrame(timetableFrame), byteArrayOutputStream); 148 | 149 | String xml = byteArrayOutputStream.toString(); 150 | System.out.println(xml); 151 | 152 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 153 | 154 | @SuppressWarnings("unchecked") 155 | JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes())); 156 | TimetableFrame actual = jaxbElement.getValue(); 157 | 158 | assertThat(actual.getVersion()).isNotNull().isNotEmpty().isEqualTo(timetableFrame.getVersion()); 159 | assertThat(actual.getId()).isNotNull().isNotEmpty().isEqualTo(timetableFrame.getId()); 160 | assertThat(actual.getName().getValue()).isNotNull().isNotEmpty().isEqualTo(timetableFrame.getName().getValue()); 161 | assertThat(actual.getVehicleModes()).isNotNull().isNotEmpty().hasSize(1); 162 | assertThat(actual.getVehicleModes().get(0)).isNotNull().isEqualTo(VehicleModeEnumeration.AIR); 163 | } 164 | 165 | @Test 166 | void dayTypeWithPropertiesOfDay() throws JAXBException { 167 | Marshaller marshaller = jaxbContext.createMarshaller(); 168 | 169 | List daysOfWeek = Arrays.asList(DayOfWeekEnumeration.MONDAY, DayOfWeekEnumeration.TUESDAY, DayOfWeekEnumeration.WEDNESDAY, 170 | DayOfWeekEnumeration.THURSDAY, DayOfWeekEnumeration.FRIDAY); 171 | PropertyOfDay propertyOfDay = factory.createPropertyOfDay().withDescription(factory.createMultilingualString().withValue("PropertyOfDay")) 172 | .withName(factory.createMultilingualString().withValue("PropertyOfDay")).withDaysOfWeek(daysOfWeek); 173 | PropertiesOfDay_RelStructure propertiesOfDay = factory.createPropertiesOfDay_RelStructure().withPropertyOfDay(propertyOfDay); 174 | DayType dayType = factory.createDayType().withVersion("any").withId(String.format("%s:dt:weekday", "SK4488")) 175 | .withName(factory.createMultilingualString().withValue("Ukedager (mandag til fredag)")).withProperties(propertiesOfDay); 176 | 177 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 178 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 179 | marshaller.marshal(factory.createDayType(dayType), byteArrayOutputStream); 180 | 181 | String xml = byteArrayOutputStream.toString(); 182 | System.out.println(xml); 183 | 184 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 185 | 186 | @SuppressWarnings("unchecked") 187 | JAXBElement jaxbElement = (JAXBElement) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes())); 188 | DayType actual = jaxbElement.getValue(); 189 | 190 | assertThat(actual.getVersion()).isNotNull().isNotEmpty().isEqualTo(dayType.getVersion()); 191 | assertThat(actual.getId()).isNotNull().isNotEmpty().isEqualTo(dayType.getId()); 192 | assertThat(actual.getName().getValue()).isNotNull().isNotEmpty().isEqualTo(dayType.getName().getValue()); 193 | assertThat(actual.getProperties().getPropertyOfDay().get(0).getDaysOfWeek()).isNotNull().isNotEmpty().hasSize(5) 194 | .hasOnlyElementsOfType(DayOfWeekEnumeration.class).hasSameElementsAs(daysOfWeek); 195 | } 196 | 197 | @Test 198 | void datedCallWithLocalDate() throws JAXBException { 199 | Marshaller marshaller = jaxbContext.createMarshaller(); 200 | 201 | DatedCall datedCall = new DatedCall().withArrivalDate(LocalDateTime.now().with(ChronoField.MILLI_OF_DAY, 0)); 202 | 203 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 204 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 205 | 206 | marshaller.marshal(factory.createDatedCall(datedCall), byteArrayOutputStream); 207 | 208 | String xml = byteArrayOutputStream.toString(); 209 | System.out.println(xml); 210 | 211 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 212 | 213 | JAXBElement actual = (JAXBElement) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes())); 214 | 215 | assertThat(actual.getValue().getArrivalDate()).isEqualTo(datedCall.getArrivalDate()); 216 | 217 | } 218 | 219 | 220 | @Test 221 | void marshalledNamespacePrefixes() throws JAXBException { 222 | Marshaller marshaller = jaxbContext.createMarshaller(); 223 | 224 | PublicationDeliveryStructure publicationDeliveryStructure = new PublicationDeliveryStructure(); 225 | 226 | 227 | marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 228 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 229 | 230 | marshaller.marshal(factory.createPublicationDelivery(publicationDeliveryStructure), byteArrayOutputStream); 231 | 232 | String xml = byteArrayOutputStream.toString(); 233 | System.out.println(xml); 234 | 235 | assertThat(xml) 236 | .as("Namespace declaration without prefix for netex").contains("xmlns=\"http://www.netex.org.uk/netex\"") 237 | .as(" actual = (JAXBElement) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes())); 256 | 257 | assertThat(actual.getValue().getChanged().getHour()).isEqualTo(datedCall.getChanged().getHour()); 258 | assertThat(actual.getValue().getChanged()).isEqualToIgnoringNanos(datedCall.getChanged()); 259 | } 260 | 261 | @Test 262 | void unmarshalPublicationDeliveryAndVerifyValidBetween() throws JAXBException, IOException { 263 | 264 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 265 | 266 | @SuppressWarnings("unchecked") 267 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 268 | .unmarshal(Files.newInputStream(Paths.get("src/test/resources/date_time_examples.xml"))); 269 | PublicationDeliveryStructure actual = jaxbElement.getValue(); 270 | CompositeFrame compositeFrame = (CompositeFrame) actual.dataObjects.compositeFrameOrCommonFrame 271 | .get(0).getValue(); 272 | ValidityConditions_RelStructure validityConditions = compositeFrame.getValidityConditions(); 273 | ValidBetween validBetweenWithTimezone = (ValidBetween) validityConditions.getValidityConditionRefOrValidBetweenOrValidityCondition_().get(0); 274 | assertThat(validBetweenWithTimezone.getFromDate()).isNotNull(); 275 | assertThat(validBetweenWithTimezone.getToDate()).isNotNull(); 276 | assertThat(validBetweenWithTimezone.getToDate()).hasToString("2017-01-01T11:00"); 277 | 278 | ValidBetween validBetweenWithoutTimezone = (ValidBetween) validityConditions.getValidityConditionRefOrValidBetweenOrValidityCondition_().get(1); 279 | assertThat(validBetweenWithoutTimezone.getFromDate()).isNotNull(); 280 | assertThat(validBetweenWithoutTimezone.getToDate()).isNotNull(); 281 | 282 | assertThat(validBetweenWithoutTimezone.getToDate()).hasToString("2017-01-01T12:00"); 283 | 284 | Timetable_VersionFrameStructure timetableFrame = (Timetable_VersionFrameStructure) compositeFrame.getFrames().getCommonFrame().get(1).getValue(); 285 | ServiceJourney_VersionStructure serviceJourney = (ServiceJourney_VersionStructure) timetableFrame.getVehicleJourneys() 286 | .getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(0); 287 | assertThat(serviceJourney.getDepartureTime()).isNotNull(); 288 | // Specified as local time 289 | assertThat(serviceJourney.getDepartureTime()).hasToString("07:55"); 290 | 291 | LocalTime departureTimeZulu = serviceJourney.getPassingTimes().getTimetabledPassingTime().get(0).getDepartureTime(); 292 | assertThat(departureTimeZulu).isNotNull().hasToString("07:55"); 293 | 294 | LocalTime departureTimeOffset = serviceJourney.getPassingTimes().getTimetabledPassingTime().get(1).getArrivalTime(); 295 | assertThat(departureTimeOffset).isNotNull().hasToString("08:40"); 296 | } 297 | 298 | @Test 299 | void fragmentShouldNotContainNetexNamespace() throws Exception { 300 | JAXBContext netexJaxBContext = JAXBContext.newInstance("net.opengis.gml._3:org.rutebanken.netex.model:uk.org.siri.siri"); 301 | Marshaller marshaller = netexJaxBContext.createMarshaller(); 302 | 303 | marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name()); 304 | marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 305 | marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); 306 | 307 | StringWriter stringWriter = new StringWriter(); 308 | AvailabilityCondition availabilityCondition = new AvailabilityCondition().withFromDate(LocalDateTime.now()).withToDate(LocalDateTime.now()).withId("NSR:AvailabilityCondition:2").withVersion("v1"); 309 | 310 | 311 | String netexNamespace="http://www.netex.org.uk/netex"; 312 | 313 | XMLOutputFactory outputFactory = XMLOutputFactory.newFactory(); 314 | XMLStreamWriter xmlStreamWriter = outputFactory.createXMLStreamWriter(stringWriter); 315 | xmlStreamWriter.setDefaultNamespace(netexNamespace); 316 | 317 | marshaller.marshal(new ObjectFactory().createAvailabilityCondition(availabilityCondition), xmlStreamWriter); 318 | String xml = stringWriter.toString(); 319 | System.out.println(xml); 320 | assertFalse(xml.contains(netexNamespace)); 321 | } 322 | 323 | } 324 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/ToStringTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | class ToStringTest { 23 | @Test 24 | void toStringMethod() { 25 | StopPlace stopPlace = new StopPlace() 26 | .withName(new MultilingualString().withValue("berger")) 27 | .withDescription(new MultilingualString().withValue("description")); 28 | System.out.println(stopPlace.toString()); 29 | assertThat(stopPlace.toString()).contains("berger"); 30 | assertThat(stopPlace.toString()).contains("description"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/UnmarshalResourceFrameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import jakarta.xml.bind.JAXBElement; 19 | import jakarta.xml.bind.JAXBException; 20 | import jakarta.xml.bind.Unmarshaller; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.io.ByteArrayInputStream; 24 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | 27 | class UnmarshalResourceFrameTest extends AbstractUnmarshalFrameTest { 28 | 29 | @Test 30 | void unmarshalResourceFrame() throws JAXBException { 31 | 32 | String xml = "\n" + 33 | "\n" + 34 | " 2023-08-03T00:20:33.505\n" + 35 | " RB\n" + 36 | " Shared data used across line files\n" + 37 | " \n" + 38 | " \n" + 39 | " \n" + 40 | " \n" + 41 | " 2023-07-31T00:00:00\n" + 42 | " 2024-08-01T00:00:00\n" + 43 | " \n" + 44 | " \n" + 45 | " \n" + 46 | " \n" + 47 | " VYG\n" + 48 | " http://www.rutebanken.org/ns/vyg\n" + 49 | " \n" + 50 | " \n" + 51 | " PEN\n" + 52 | " http://www.rutebanken.org/ns/pen\n" + 53 | " \n" + 54 | " \n" + 55 | " NSR\n" + 56 | " http://www.rutebanken.org/ns/nsr\n" + 57 | " \n" + 58 | " \n" + 59 | " \n" + 60 | " \n" + 61 | " Europe/Oslo\n" + 62 | " no\n" + 63 | " \n" + 64 | " \n" + 65 | " \n" + 66 | " \n" + 67 | " \n" + 68 | " \n" + 69 | " Vy\n" + 70 | " \n" + 71 | " https://www.vy.no/\n" + 72 | " \n" + 73 | " authority\n" + 74 | " \n" + 75 | " \n" + 76 | " Vy Tåg\n" + 77 | " operator\n" + 78 | " \n" + 79 | " https://www.vy.no/\n" + 80 | " \n" + 81 | " \n" + 82 | " \n" + 83 | " Vy Tåg\n" + 84 | " \n" + 85 | " https://www.vy.no/\n" + 86 | " \n" + 87 | " authority\n" + 88 | " \n" + 89 | " \n" + 90 | " Vy\n" + 91 | " operator\n" + 92 | " \n" + 93 | " https://www.vy.no/\n" + 94 | " \n" + 95 | " \n" + 96 | " \n" + 97 | " \n" + 98 | " \n" + 99 | " \n" + 100 | " \n" + 101 | ""; 102 | 103 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 104 | 105 | @SuppressWarnings("unchecked") 106 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 107 | .unmarshal(new ByteArrayInputStream(xml.getBytes())); 108 | 109 | PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); 110 | CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); 111 | 112 | ResourceFrame resourceFrame = (ResourceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); 113 | Authority authority = (Authority) resourceFrame.getOrganisations().getOrganisation_().get(0).getValue(); 114 | assertEquals("Vy", authority.getName().getValue()); 115 | 116 | 117 | 118 | } 119 | 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/UnmarshalServiceCalendarFrameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import jakarta.xml.bind.JAXBElement; 19 | import jakarta.xml.bind.JAXBException; 20 | import jakarta.xml.bind.Unmarshaller; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.io.ByteArrayInputStream; 24 | import java.time.LocalDateTime; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | class UnmarshalServiceCalendarFrameTest extends AbstractUnmarshalFrameTest { 29 | 30 | @Test 31 | void unmarshalServiceCalendarFrame() throws JAXBException { 32 | 33 | String xml = "\n" + 34 | "\n" + 35 | " 2023-08-03T00:20:33.505\n" + 36 | " RB\n" + 37 | " Shared data used across line files\n" + 38 | " \n" + 39 | " \n" + 40 | " \n" + 41 | " \n" + 42 | " 2023-07-31T00:00:00\n" + 43 | " 2024-08-01T00:00:00\n" + 44 | " \n" + 45 | " \n" + 46 | " \n" + 47 | " \n" + 48 | " VYG\n" + 49 | " http://www.rutebanken.org/ns/vyg\n" + 50 | " \n" + 51 | " \n" + 52 | " PEN\n" + 53 | " http://www.rutebanken.org/ns/pen\n" + 54 | " \n" + 55 | " \n" + 56 | " NSR\n" + 57 | " http://www.rutebanken.org/ns/nsr\n" + 58 | " \n" + 59 | " \n" + 60 | " \n" + 61 | " \n" + 62 | " Europe/Oslo\n" + 63 | " no\n" + 64 | " \n" + 65 | " \n" + 66 | " \n" + 67 | " \n" + 68 | " \n" + 69 | " \n" + 70 | " \n" + 71 | " \n" + 72 | " Tuesday Thursday Friday\n" + 73 | " \n" + 74 | " \n" + 75 | " \n" + 76 | " \n" + 77 | " \n" + 78 | " \n" + 79 | " Tuesday Wednesday Thursday\n" + 80 | " \n" + 81 | " \n" + 82 | " \n" + 83 | " \n" + 84 | " \n" + 85 | " \n" + 86 | " 2023-10-29\n" + 87 | " \n" + 88 | " \n" + 89 | " 2023-10-30\n" + 90 | " \n" + 91 | " \n" + 92 | " \n" + 93 | " \n" + 94 | " 2023-08-17T00:00:00\n" + 95 | " 2024-06-24T00:00:00\n" + 96 | " \n" + 97 | " \n" + 98 | " 2023-08-16T00:00:00\n" + 99 | " 2024-06-23T00:00:00\n" + 100 | " " + 101 | " \n" + 102 | " \n" + 103 | " \n" + 104 | " 2024-05-01\n" + 105 | " \n" + 106 | " false\n" + 107 | " \n" + 108 | " \n" + 109 | " 2024-05-17\n" + 110 | " \n" + 111 | " false\n" + 112 | " \n" + 113 | " \n" + 114 | " \n" + 115 | " \n" + 116 | " \n" + 117 | " \n" + 118 | ""; 119 | 120 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 121 | 122 | @SuppressWarnings("unchecked") 123 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 124 | .unmarshal(new ByteArrayInputStream(xml.getBytes())); 125 | 126 | PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); 127 | CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); 128 | 129 | ServiceCalendarFrame serviceCalendarFrame = (ServiceCalendarFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); 130 | 131 | DayType dayType = (DayType) serviceCalendarFrame.getDayTypes().getDayType_().get(0).getValue(); 132 | assertEquals(DayOfWeekEnumeration.TUESDAY, dayType.getProperties().getPropertyOfDay().get(0).getDaysOfWeek().get(0)); 133 | 134 | OperatingDay operatingDay = serviceCalendarFrame.getOperatingDays().getOperatingDay().get(0); 135 | assertEquals(LocalDateTime.of(2023,10,29,0,0), operatingDay.getCalendarDate()); 136 | 137 | OperatingPeriod operatingPeriod = (OperatingPeriod) serviceCalendarFrame.getOperatingPeriods().getOperatingPeriodOrUicOperatingPeriod().get(0); 138 | assertEquals(LocalDateTime.of(2023,8,17,0,0), operatingPeriod.getFromDate()); 139 | 140 | DayTypeAssignment dayTypeAssignment = serviceCalendarFrame.getDayTypeAssignments().getDayTypeAssignment().get(0); 141 | assertEquals(LocalDateTime.of(2024,5,1,0,0), dayTypeAssignment.getDate()); 142 | 143 | 144 | } 145 | 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/UnmarshalServiceFrameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import jakarta.xml.bind.JAXBElement; 19 | import jakarta.xml.bind.JAXBException; 20 | import jakarta.xml.bind.Unmarshaller; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.io.ByteArrayInputStream; 24 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals; 26 | import static org.junit.jupiter.api.Assertions.assertFalse; 27 | 28 | class UnmarshalServiceFrameTest extends AbstractUnmarshalFrameTest{ 29 | 30 | @Test 31 | void unmarshalServiceFrame() throws JAXBException { 32 | 33 | String xml = "\n" + 34 | "\n" + 35 | " 2023-08-03T00:20:33.337\n" + 36 | " RB\n" + 37 | " Narvik-Riksgränsen (Sverige)\n" + 38 | " \n" + 39 | " \n" + 40 | " \n" + 41 | " \n" + 42 | " 2023-07-31T00:00:00\n" + 43 | " 2024-08-01T00:00:00\n" + 44 | " \n" + 45 | " \n" + 46 | " \n" + 47 | " \n" + 48 | " VYG\n" + 49 | " http://www.rutebanken.org/ns/vyg\n" + 50 | " \n" + 51 | " \n" + 52 | " PEN\n" + 53 | " http://www.rutebanken.org/ns/pen\n" + 54 | " \n" + 55 | " \n" + 56 | " NSR\n" + 57 | " http://www.rutebanken.org/ns/nsr\n" + 58 | " \n" + 59 | " \n" + 60 | " \n" + 61 | " \n" + 62 | " Europe/Oslo\n" + 63 | " no\n" + 64 | " \n" + 65 | " \n" + 66 | " \n" + 67 | " \n" + 68 | " \n" + 69 | " \n" + 70 | " Riksgränsen-Narvik Ofotbanen\n" + 71 | " KJ-NK\n" + 72 | " \n" + 73 | " \n" + 74 | " \n" + 75 | " \n" + 76 | " \n" + 77 | " \n" + 78 | " \n" + 79 | " \n" + 80 | " \n" + 81 | " \n" + 82 | " \n" + 83 | " \n" + 84 | " \n" + 85 | " \n" + 86 | " Narvik-Riksgränsen (Sverige)\n" + 87 | " rail\n" + 88 | " F8\n" + 89 | " F8\n" + 90 | " \n" + 91 | " \n" + 92 | " \n" + 93 | " 0054A6\n" + 94 | " FFFFFF\n" + 95 | " \n" + 96 | " \n" + 97 | " \n" + 98 | " \n" + 99 | " \n" + 100 | " KMB-NK\n" + 101 | " \n" + 102 | " \n" + 103 | " \n" + 104 | " \n" + 105 | " false\n" + 106 | " \n" + 107 | " \n" + 108 | " \n" + 109 | " \n" + 110 | " false\n" + 111 | " \n" + 112 | " \n" + 113 | " \n" + 114 | " \n" + 115 | " \n" + 116 | " \n" + 117 | " \n" + 118 | " \n" + 119 | " \n" + 120 | " \n" + 121 | " \n" + 122 | " \n" + 123 | " \n" + 124 | " \n" + 125 | " \n" + 126 | " \n" + 127 | " \n" + 128 | " \n" + 129 | " \n" + 130 | " \n" + 131 | " \n" + 132 | " \n" + 133 | " \n" + 134 | " \n" + 135 | " \n" + 136 | " \n" + 137 | ""; 138 | 139 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 140 | 141 | @SuppressWarnings("unchecked") 142 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 143 | .unmarshal(new ByteArrayInputStream(xml.getBytes())); 144 | 145 | PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); 146 | CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); 147 | 148 | ServiceFrame serviceFrame = (ServiceFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); 149 | Line line = (Line) serviceFrame.getLines().getLine_().get(0).getValue(); 150 | assertEquals("Narvik-Riksgränsen (Sverige)", line.getName().getValue()); 151 | assertEquals("F8", line.getPublicCode()); 152 | assertEquals("F8", line.getPrivateCode().getValue()); 153 | assertEquals("rail", line.getTransportMode().value()); 154 | 155 | Route route = (Route) serviceFrame.getRoutes().getRoute_().get(0).getValue(); 156 | assertEquals("Riksgränsen-Narvik Ofotbanen", route.getName().getValue()); 157 | assertEquals("KJ-NK", route.getShortName().getValue()); 158 | 159 | PointOnRoute pointOnRoute = route.getPointsInSequence().getPointOnRoute().get(0); 160 | assertEquals("VYG:RoutePoint:KJ", pointOnRoute.getPointRef().getValue().getRef()); 161 | 162 | JourneyPattern journeyPattern = (JourneyPattern) serviceFrame.getJourneyPatterns().getJourneyPattern_OrJourneyPatternView().get(0).getValue(); 163 | assertEquals("KMB-NK", journeyPattern.getName().getValue()); 164 | assertEquals("VYG:Route:F8-R", journeyPattern.getRouteRef().getRef()); 165 | 166 | StopPointInJourneyPattern stopPointInJourneyPattern = (StopPointInJourneyPattern) journeyPattern.getPointsInSequence().getPointInJourneyPatternOrStopPointInJourneyPatternOrTimingPointInJourneyPattern().get(0); 167 | assertEquals("VYG:ScheduledStopPoint:KMB-1", stopPointInJourneyPattern.getScheduledStopPointRef().getValue().getRef()); 168 | assertFalse(stopPointInJourneyPattern.isForAlighting()); 169 | assertEquals("VYG:DestinationDisplay:F8-NK", stopPointInJourneyPattern.getDestinationDisplayRef().getRef()); 170 | 171 | ServiceLinkInJourneyPattern_VersionedChildStructure serviceLinkInJourneyPattern = (ServiceLinkInJourneyPattern_VersionedChildStructure) journeyPattern.getLinksInSequence().getServiceLinkInJourneyPatternOrTimingLinkInJourneyPattern().get(0); 172 | assertEquals("VYG:ServiceLink:KMB-1_ABOe-1_NULL",serviceLinkInJourneyPattern.getServiceLinkRef().getRef()); 173 | 174 | PassengerStopAssignment passengerStopAssignment = (PassengerStopAssignment) serviceFrame.getStopAssignments().getStopAssignment().get(0).getValue(); 175 | assertEquals("NSR:Quay:111", passengerStopAssignment.getQuayRef().getValue().getRef()); 176 | assertEquals("VYG:ScheduledStopPoint:HAL-1", passengerStopAssignment.getScheduledStopPointRef().getValue().getRef()); 177 | 178 | 179 | } 180 | 181 | 182 | } 183 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/UnmarshalSiteFrameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import jakarta.xml.bind.JAXBElement; 19 | import jakarta.xml.bind.JAXBException; 20 | import jakarta.xml.bind.Unmarshaller; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.io.ByteArrayInputStream; 24 | import java.math.BigDecimal; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | class UnmarshalSiteFrameTest extends AbstractUnmarshalFrameTest { 29 | 30 | @Test 31 | void unmarshalSiteFrame() throws JAXBException { 32 | 33 | String xml = "" 34 | + "" 35 | + " 2016-05-18T15:00:00.0+01:00" 36 | + " NHR" 37 | + " " 38 | + " " + 39 | " \n" + 40 | " \n" + 41 | " Lillehammer\n" + 42 | " \n" + 43 | " \n" + 44 | " \n" + 45 | " \n" + 46 | " \n" + 47 | " \n" + 48 | " \n" + 49 | " \n" + 50 | " \n" + 51 | " 10.461604\n" + 52 | " 61.114889\n" + 53 | " \n" + 54 | " \n" + 55 | " \n" + 56 | " \n" + 57 | " Narvik\n" + 58 | " \n" + 59 | " \n" + 60 | " \n" + 61 | " \n" + 62 | " \n" + 63 | " \n" + 64 | " \n" + 65 | " \n" + 66 | " 17.434792\n" + 67 | " 68.440156\n" + 68 | " \n" + 69 | " \n" + 70 | " " + 71 | " \n" 72 | + " " 73 | + " " 74 | + " " 75 | + " " 76 | + " 10.8577903" 77 | + " 59.910579" 78 | + " " 79 | + " " 80 | + " Krokstien " 81 | + " bus" 82 | + " \n" + 83 | " \n" + 84 | " \n" + 85 | " " 86 | + " onstreetBus" 87 | + " " 88 | + " " 89 | + " " 90 | + " " 91 | + " 10.8577903" 92 | + " 59.910579" 93 | + " " 94 | + " " 95 | + " outdoors" 96 | + " wellLit" 97 | + " busStop" 98 | + " " 99 | + " " 100 | + " " 101 | + " " + 102 | " \n" + 103 | " \n" + 104 | " \n" + 105 | " 2020-12-11T10:05:19.737\n" + 106 | " \n" + 107 | " \n" + 108 | " \n" + 109 | " zone_type\n" + 110 | " external\n" + 111 | " \n" + 112 | " \n" + 113 | " imported-id\n" + 114 | " \n" + 115 | " \n" + 116 | " \n" + 117 | " 1\n" + 118 | " \n" + 119 | " \n" + 120 | " \n" + 121 | "59.82905206496 10.76591487408 59.84434061779 10.77278128624 59.85878172188 10.7820510006 59.87257035803 10.77767363548 59.88506137242 10.76522818565 59.89664364788 10.75205321789 59.90553214085 10.75819013357 59.9071460207 10.75720308065 59.90858768703 10.75040099859 59.91232066638 10.75396297216 59.91342867802 10.75784674644 59.91263263624 10.76381202221 59.90413339229 10.77188010693 59.88867858273 10.78677168846 59.86171241467 10.79784358978 59.82424195011 10.78273768902 59.82672258934 10.77484126568 59.82523422797 10.77406878948 59.82299077502 10.77501292706 59.82260246975 10.77170844555 59.8253205116 10.77042098522 59.82905206496 10.76591487408\n" + 122 | " \n" + 123 | " \n" + 124 | " \n" + 125 | " \n" + 126 | " \n" + 127 | " \n" + 128 | " 2022-02-01T12:14:14.239\n" + 129 | " \n" + 130 | " \n" + 131 | " \n" + 132 | " zone_type\n" + 133 | " external\n" + 134 | " \n" + 135 | " \n" + 136 | " Oslo\n" + 137 | " \n" + 138 | " \n" + 139 | " \n" + 140 | "59.91199795775 10.64158912182 59.91406329688 10.64070937872 59.91460113858 10.64007773233 59.9207425438 10.6681537199 59.92364614029 10.67858214855 59.92401176035 10.68300242901 59.92272131861 10.68866725445 59.91984989492 10.69587705374 59.91853778084 10.69527623892 59.91429994335 10.70132730246 59.91286928215 10.70604799032 59.91261111115 10.71173427343 59.91441826595 10.71802137136 59.91549390663 10.71857927084 59.91727939319 10.72229144812 59.92068876034 10.72806356192 59.91895723278 10.73186156988 59.91865608833 10.73209760427 59.91926912951 10.73379276037 59.91963479781 10.74001548529 59.91834418584 10.74057338476 59.91409556696 10.74834106207 59.91277246826 10.75859782934 59.91148158944 10.76353309393 59.9057688589 10.75793262005 59.90015198557 10.74398513317 59.90202438224 10.72875018597 59.9062853053 10.70458884716 59.90301434241 10.70518966198 59.89647147151 10.69398871422 59.8936515825 10.67596431255 59.89479249528 10.66935530663 59.90172308416 10.66115851879 59.90936229862 10.64764018536 59.91199795775 10.64158912182\n" + 141 | " \n" + 142 | " \n" + 143 | " \n" + 144 | " \n" + 145 | " \n" 146 | + " " 147 | + " " 148 | + ""; 149 | 150 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 151 | 152 | @SuppressWarnings("unchecked") 153 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 154 | .unmarshal(new ByteArrayInputStream(xml.getBytes())); 155 | 156 | PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); 157 | SiteFrame siteFrame = (SiteFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); 158 | 159 | StopPlace stopPlace = (StopPlace) siteFrame.getStopPlaces().getStopPlace_().get(0).getValue(); 160 | assertEquals("Krokstien", stopPlace.getName().getValue()); 161 | assertEquals(AllVehicleModesOfTransportEnumeration.BUS, stopPlace.getTransportMode()); 162 | assertEquals(StopTypeEnumeration.ONSTREET_BUS, stopPlace.getStopPlaceType()); 163 | assertEquals("BRA:TariffZone:311", stopPlace.getTariffZones().getTariffZoneRef_().get(0).getValue().getRef()); 164 | 165 | Quay quay = (Quay) stopPlace.getQuays().getQuayRefOrQuay().get(0).getValue(); 166 | assertEquals(BigDecimal.valueOf(59.910579), quay.getCentroid().getLocation().getLatitude()); 167 | TariffZone tariffZone = (TariffZone) siteFrame.getTariffZones().getTariffZone().get(0).getValue(); 168 | assertEquals("1", tariffZone.getName().getValue()); 169 | 170 | GroupOfStopPlaces groupOfStopPlaces = siteFrame.getGroupsOfStopPlaces().getGroupOfStopPlaces().get(0); 171 | assertEquals("Lillehammer", groupOfStopPlaces.getName().getValue()); 172 | assertEquals("NSR:StopPlace:420", groupOfStopPlaces.getMembers().getStopPlaceRef().get(0).getValue().getRef()); 173 | 174 | 175 | 176 | } 177 | 178 | 179 | } 180 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/model/UnmarshalTimetableFrameTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.model; 17 | 18 | import jakarta.xml.bind.JAXBElement; 19 | import jakarta.xml.bind.JAXBException; 20 | import jakarta.xml.bind.Unmarshaller; 21 | import org.junit.jupiter.api.Test; 22 | 23 | import java.io.ByteArrayInputStream; 24 | import java.time.LocalTime; 25 | 26 | import static org.junit.jupiter.api.Assertions.assertEquals; 27 | 28 | class UnmarshalTimetableFrameTest extends AbstractUnmarshalFrameTest { 29 | 30 | @Test 31 | void unmarshalTimetableFrame() throws JAXBException { 32 | 33 | String xml = "\n" + 34 | "\n" + 35 | " 2023-08-03T00:20:33.337\n" + 36 | " RB\n" + 37 | " Narvik-Riksgränsen (Sverige)\n" + 38 | " \n" + 39 | " \n" + 40 | " \n" + 41 | " \n" + 42 | " 2023-07-31T00:00:00\n" + 43 | " 2024-08-01T00:00:00\n" + 44 | " \n" + 45 | " \n" + 46 | " \n" + 47 | " \n" + 48 | " VYG\n" + 49 | " http://www.rutebanken.org/ns/vyg\n" + 50 | " \n" + 51 | " \n" + 52 | " PEN\n" + 53 | " http://www.rutebanken.org/ns/pen\n" + 54 | " \n" + 55 | " \n" + 56 | " NSR\n" + 57 | " http://www.rutebanken.org/ns/nsr\n" + 58 | " \n" + 59 | " \n" + 60 | " \n" + 61 | " \n" + 62 | " Europe/Oslo\n" + 63 | " no\n" + 64 | " \n" + 65 | " \n" + 66 | " \n" + 67 | " \n" + 68 | " \n" + 69 | " \n" + 70 | " \n" + 71 | " \n" + 72 | " ContentCheck\n" + 73 | " 8357BD63\n" + 74 | " \n" + 75 | " \n" + 76 | " 96\n" + 77 | " 96\n" + 78 | " rail\n" + 79 | " \n" + 80 | " regionalRail\n" + 81 | " \n" + 82 | " \n" + 83 | " \n" + 84 | " \n" + 85 | " \n" + 86 | " \n" + 87 | " \n" + 88 | " 14:55:00\n" + 89 | " \n" + 90 | " \n" + 91 | " \n" + 92 | " 17:43:00\n" + 93 | " \n" + 94 | " \n" + 95 | " \n" + 96 | " \n" + 97 | " \n" + 98 | " cancellation" + 99 | " \n" + 100 | " \n" + 101 | " " + 102 | " \n" + 103 | " \n" + 104 | " \n" + 105 | " \n" + 106 | " \n" + 107 | " \n" + 108 | " \n" + 109 | " \n" + 110 | ""; 111 | 112 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 113 | 114 | @SuppressWarnings("unchecked") 115 | JAXBElement jaxbElement = (JAXBElement) unmarshaller 116 | .unmarshal(new ByteArrayInputStream(xml.getBytes())); 117 | 118 | PublicationDeliveryStructure publicationDeliveryStructure = jaxbElement.getValue(); 119 | CompositeFrame compositeFrame = (CompositeFrame) publicationDeliveryStructure.getDataObjects().getCompositeFrameOrCommonFrame().get(0).getValue(); 120 | 121 | TimetableFrame timetableFrame = (TimetableFrame) compositeFrame.getFrames().getCommonFrame().get(0).getValue(); 122 | ServiceJourney serviceJourney = (ServiceJourney) timetableFrame.getVehicleJourneys().getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(0); 123 | assertEquals("96", serviceJourney.getName().getValue()); 124 | assertEquals("96", serviceJourney.getPrivateCode().getValue()); 125 | assertEquals("rail", serviceJourney.getTransportMode().value()); 126 | 127 | TimetabledPassingTime timetabledPassingTime = serviceJourney.getPassingTimes().getTimetabledPassingTime().get(0); 128 | assertEquals(LocalTime.of(14,55), timetabledPassingTime.getDepartureTime()); 129 | 130 | DatedServiceJourney dsj = (DatedServiceJourney) timetableFrame.getVehicleJourneys().getVehicleJourneyOrDatedVehicleJourneyOrNormalDatedVehicleJourney().get(1); 131 | assertEquals("VYG:OperatingDay:2023-12-09", dsj.getOperatingDayRef().getRef()); 132 | assertEquals("VYG:ServiceJourney:96-KMB_87815-R", dsj.getJourneyRef().getValue().getRef()); 133 | assertEquals("VYG:DatedServiceJourney:8916_KVG-DEG_23-10-19", dsj.getReplacedJourneys().getDatedVehicleJourneyRefOrNormalDatedVehicleJourneyRef().get(0).getValue().getRef()); 134 | assertEquals("cancellation", dsj.getServiceAlteration().value()); 135 | 136 | 137 | 138 | 139 | } 140 | 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/test/java/org/rutebanken/netex/validation/NeTExValidatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by 3 | * the European Commission - subsequent versions of the EUPL (the "Licence"); 4 | * You may not use this work except in compliance with the Licence. 5 | * You may obtain a copy of the Licence at: 6 | * 7 | * https://joinup.ec.europa.eu/software/page/eupl 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the Licence is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the Licence for the specific language governing permissions and 13 | * limitations under the Licence. 14 | */ 15 | 16 | package org.rutebanken.netex.validation; 17 | 18 | import org.junit.jupiter.api.Test; 19 | import org.xml.sax.SAXException; 20 | import org.xml.sax.SAXParseException; 21 | 22 | import javax.xml.transform.stream.StreamSource; 23 | import java.io.IOException; 24 | import java.io.StringReader; 25 | 26 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 27 | 28 | class NeTExValidatorTest { 29 | 30 | private final NeTExValidator neTExValidator = NeTExValidator.getNeTExValidator(); 31 | 32 | public NeTExValidatorTest() throws IOException, SAXException { } 33 | 34 | public static final String xml = "\n" + 35 | "\n" + 36 | " 2016-11-29T13:32:06.869+01:00\n" + 37 | " NSR\n" + 38 | ""; 39 | 40 | 41 | @Test 42 | void validationFailsForInvalidXml() { 43 | String xml = "\n" + 44 | ""; 45 | 46 | assertThatThrownBy(() -> neTExValidator.validate(new StreamSource(new StringReader(xml)))).isInstanceOf(SAXParseException.class); 47 | } 48 | 49 | @Test 50 | void validatePublicationDeliveryWithLatestVersion() throws IOException, SAXException { 51 | neTExValidator.validate(new StreamSource(new StringReader(xml))); 52 | 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/test/resources/date_time_examples.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 2017-02-22T09:20:00 19 | RUT 20 | 21 | 22 | 23 | 24 | 2017-01-01T10:00:00Z 25 | 2017-01-01T11:00:00.0Z 26 | 27 | 28 | 2017-01-01T11:00:00 29 | 2017-01-01T12:00:00 30 | 31 | 32 | 33 | 34 | 35 | 36 | RUT 37 | 38 | support@ruter.no 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 07:55:00 47 | 48 | 49 | 50 | 07:55:00Z 51 | 52 | 53 | 54 | 08:40:00+01:00 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.logFile=System.out 2 | --------------------------------------------------------------------------------