GPXEmail.java

  1. /*
  2.  * This file is part of Openrouteservice.
  3.  *
  4.  * Openrouteservice is free software; you can redistribute it and/or modify it under the terms of the
  5.  * GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1
  6.  * of the License, or (at your option) any later version.
  7.  *
  8.  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  9.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10.  * See the GNU Lesser General Public License for more details.
  11.  *
  12.  * You should have received a copy of the GNU Lesser General Public License along with this library;
  13.  * if not, see <https://www.gnu.org/licenses/>.
  14.  */

  15. package org.heigit.ors.api.responses.routing.gpx;

  16. import jakarta.xml.bind.annotation.XmlAttribute;
  17. import jakarta.xml.bind.annotation.XmlRootElement;
  18. import org.heigit.ors.exceptions.InternalServerException;
  19. import org.heigit.ors.routing.RoutingErrorCodes;

  20. @XmlRootElement(name = "email")
  21. public class GPXEmail {
  22.     @XmlAttribute(name = "id")
  23.     private String id;

  24.     @XmlAttribute(name = "domain")
  25.     private String domain;

  26.     // For JaxB compatibility
  27.     public GPXEmail() throws InternalServerException {
  28.         this("");
  29.     }

  30.     public GPXEmail(String email) throws InternalServerException {
  31.         try {
  32.             String[] parts = email.split("@");

  33.             if (parts.length == 2) {
  34.                 id = parts[0];
  35.                 domain = parts[1];
  36.             }
  37.         } catch (Exception e) {
  38.             throw new InternalServerException(RoutingErrorCodes.UNKNOWN, "Error creating GPX Email attribute, has it been set in the ors-config.json?");
  39.         }
  40.     }

  41.     public String getId() {
  42.         return id;
  43.     }

  44.     public String getDomain() {
  45.         return domain;
  46.     }
  47. }