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