fcee3cbdb327d914bf3d135f3646250ec4ab17d5
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
23
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;
29
30 public class YangFilename {
31
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);
41         }
42         public YangFilename(String fn) throws ParseException {
43                 this.filename = fn;
44                 matcher = pattern.matcher(this.filename);
45                 if(!matcher.find()) {
46                         throw new ParseException("unknown filename format", 0);
47                 }
48                 this.module= matcher.group(1);
49                 this.revision=parseRevision(matcher.group(2));
50                 
51         }
52         public static String createFilename(String module, String rev) {
53                 return String.format("%s@%s.yang", module,rev);
54         }
55         public YangFilename(String module, String rev) throws ParseException {
56                 this(createFilename(module, rev));
57         }
58         public String getFilename() {
59                 return this.filename;
60         }
61         public Date getRevision() {
62                 return this.revision;
63         }
64         public String getModule() {
65                 return this.module;
66         }
67 }