b00eb203f5f9e965da2e64aabfd986047a264bb9
[ccsdk/features.git] /
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
19
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;
25
26 public class YangFilename {
27
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);
37         }
38         public YangFilename(String fn) throws ParseException {
39                 this.filename = fn;
40                 matcher = pattern.matcher(this.filename);
41                 if(!matcher.find()) {
42                         throw new ParseException("unknown filename format", 0);
43                 }
44                 this.module= matcher.group(1);
45                 this.revision=parseRevision(matcher.group(2));
46                 
47         }
48         public static String createFilename(String module, String rev) {
49                 return String.format("%s@%s.yang", module,rev);
50         }
51         public YangFilename(String module, String rev) throws ParseException {
52                 this(createFilename(module, rev));
53         }
54         public String getFilename() {
55                 return this.filename;
56         }
57         public Date getRevision() {
58                 return this.revision;
59         }
60         public String getModule() {
61                 return this.module;
62         }
63 }