001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.web.resources.api; 020 021import org.apache.commons.lang.StringUtils; 022 023/** 024 * @since 7.3 025 */ 026public enum ResourceType { 027 028 any, unknown, css, js, bundle, html, jsfjs, jsfcss, xhtml, xhtmlfirst; 029 030 public String getSuffix() { 031 return "." + name(); 032 } 033 034 /** 035 * @since 7.4 036 */ 037 public final boolean equals(String type) { 038 if (name().equalsIgnoreCase(type)) { 039 return true; 040 } 041 return false; 042 } 043 044 public final boolean matches(Resource r) { 045 if (ResourceType.any == this) { 046 return true; 047 } 048 if (r == null || r.getType() == null) { 049 return true; 050 } 051 if (this.name().toLowerCase().equals(r.getType().toLowerCase())) { 052 return true; 053 } 054 return false; 055 } 056 057 public static final ResourceType parse(String type) { 058 for (ResourceType item : values()) { 059 if (item.name().equals(type)) { 060 return item; 061 } 062 } 063 return ResourceType.unknown; 064 } 065 066 public static final boolean matches(String type, Resource r) { 067 if (StringUtils.isBlank(type) || ResourceType.any.name().equals(type.toLowerCase())) { 068 return true; 069 } 070 String rt = r.getType(); 071 if (StringUtils.isBlank(rt)) { 072 return true; 073 } 074 if (type.toLowerCase().equals(rt.toLowerCase())) { 075 return true; 076 } 077 return false; 078 } 079 080}