summaryrefslogtreecommitdiffstats
path: root/warehouse/src/main/java/app/market/web/controller/BreadcrumbMapping.java
blob: 3a3d11329b70c190b28b47684690924eeda32f3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package app.market.web.controller;

import org.apache.commons.lang3.StringUtils;

import app.market.web.form.breadcrumb.BreadcrumbFrom;
import app.market.web.form.breadcrumb.BreadcrumbSubFrom;

public class BreadcrumbMapping {

	public static final String APP_DETAIL = "APP,APP_DETAIL";
	public static final String APP_DETAIL_MODIFY = "APP,APP_DETAIL,APP_DETAIL_MODIFY";
	public static final String APP_INSERT = "APP,APP_INSERT";
	public static final String APP_MODIFY = "APP,APP_MODIFY";
	public static final String USER_INSERT = "USER,USER_INSERT";
	public static final String USER_DETAIL = "USER,USER_DETAIL";
	public static final String USER_MODIFY = "USER,USER_MODIFY";
	public static BreadcrumbFrom getBreadcrumb(String name) {
		BreadcrumbFrom breadcrumb = new BreadcrumbFrom();
		String[] names = name.split(",");
		for (int i = 0; i < names.length; i++) {
			BreadcrumbSubFrom sub = BreadcrumbEnum.getBreadcrumbSubFrom(names[i]);
			breadcrumb.getBreadcrumb().add(sub);
			if (i == names.length - 1) {
				sub.setCurrent(true);
			}
		}
		return breadcrumb;
	}

	public enum BreadcrumbEnum {
		USER("USER", "User", "account"),
		USER_DETAIL("USER_DETAIL", "Detail", "url"),
		USER_INSERT("USER_INSERT", "Create", "url"),
		USER_MODIFY("USER_MODIFY", "Modify", "url"),
		APP("APP", "App", "app"),
		APP_DETAIL("APP_DETAIL", "Detail", "app/more"),
		APP_DETAIL_MODIFY("APP_DETAIL_MODIFY", "Modify", "url"),
		APP_MODIFY("APP_MODIFY", "Modify", "url"),
		APP_INSERT("APP_INSERT", "Create", "url");

		private String key;
		private String name;
		private String url;

		private BreadcrumbEnum(String key, String name, String value) {
			this.key = key;
			this.name = name;
			this.url = value;
		}

		public static BreadcrumbSubFrom getBreadcrumbSubFrom(String key) {
			for (BreadcrumbEnum c : BreadcrumbEnum.values()) {
				if (StringUtils.equalsIgnoreCase(c.getKey(), key)) {
					BreadcrumbSubFrom sub = new BreadcrumbSubFrom();
					sub.setName(c.getName());
					sub.setUrl(c.getUrl());
					return sub;
				}
			}
			return null;
		}

		public String getKey() {
			return key;
		}

		public void setKey(String key) {
			this.key = key;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

	}

}