1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
20 import java.text.ParseException;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
26 public class YangFilename {
28 private static final String regex = "([^\\/]*)@([0-9]{4}-[0-9]{2}-[0-9]{2}).yang";
29 private static final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
30 private final String filename;
31 private final Matcher matcher;
32 private Date revision;
33 private String module;
34 public static Date parseRevision(String sRevision) throws ParseException {
35 final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
36 return fmt.parse(sRevision);
38 public YangFilename(String fn) throws ParseException {
40 matcher = pattern.matcher(this.filename);
42 throw new ParseException("unknown filename format", 0);
44 this.module= matcher.group(1);
45 this.revision=parseRevision(matcher.group(2));
48 public static String createFilename(String module, String rev) {
49 return String.format("%s@%s.yang", module,rev);
51 public YangFilename(String module, String rev) throws ParseException {
52 this(createFilename(module, rev));
54 public String getFilename() {
57 public Date getRevision() {
60 public String getModule() {