001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.web.resources.api; 018 019import org.apache.commons.lang.StringUtils; 020 021/** 022 * @since 7.3 023 */ 024public enum ResourceType { 025 026 any, unknown, css, js, bundle, html, jsfjs, jsfcss, xhtml, xhtmlfirst; 027 028 public String getSuffix() { 029 return "." + name(); 030 } 031 032 /** 033 * @since 7.4 034 */ 035 public final boolean equals(String type) { 036 if (name().equalsIgnoreCase(type)) { 037 return true; 038 } 039 return false; 040 } 041 042 public final boolean matches(Resource r) { 043 if (ResourceType.any == this) { 044 return true; 045 } 046 if (r == null || r.getType() == null) { 047 return true; 048 } 049 if (this.name().toLowerCase().equals(r.getType().toLowerCase())) { 050 return true; 051 } 052 return false; 053 } 054 055 public static final ResourceType parse(String type) { 056 for (ResourceType item : values()) { 057 if (item.name().equals(type)) { 058 return item; 059 } 060 } 061 return ResourceType.unknown; 062 } 063 064 public static final boolean matches(String type, Resource r) { 065 if (StringUtils.isBlank(type) || ResourceType.any.name().equals(type.toLowerCase())) { 066 return true; 067 } 068 String rt = r.getType(); 069 if (StringUtils.isBlank(rt)) { 070 return true; 071 } 072 if (type.toLowerCase().equals(rt.toLowerCase())) { 073 return true; 074 } 075 return false; 076 } 077 078}