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.http.yangschema;
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;
39 public static Date parseRevision(String sRevision) throws ParseException {
40 final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
41 return fmt.parse(sRevision);
44 public YangFilename(String fn) throws ParseException {
46 matcher = pattern.matcher(this.filename);
47 if (!matcher.find()) {
48 throw new ParseException("unknown filename format", 0);
50 this.module = matcher.group(1);
51 this.revision = parseRevision(matcher.group(2));
55 public static String createFilename(String module, String rev) {
56 return String.format("%s@%s.yang", module, rev);
59 public YangFilename(String module, String rev) throws ParseException {
60 this(createFilename(module, rev));
63 public String getFilename() {
67 public Date getRevision() {
71 public String getModule() {