001/* 002 * (C) Copyright 2012 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.styleguide.service.descriptors; 020 021import java.io.IOException; 022import java.util.ArrayList; 023import java.util.List; 024 025import org.apache.commons.logging.Log; 026import org.apache.commons.logging.LogFactory; 027import org.apache.xml.serialize.OutputFormat; 028import org.nuxeo.common.utils.FileUtils; 029import org.nuxeo.common.xmap.DOMSerializer; 030import org.nuxeo.common.xmap.annotation.XContent; 031import org.nuxeo.common.xmap.annotation.XNode; 032import org.nuxeo.common.xmap.annotation.XNodeList; 033import org.nuxeo.common.xmap.annotation.XObject; 034import org.w3c.dom.DocumentFragment; 035 036/** 037 * @since 5.7 038 */ 039@XObject("icon") 040public class IconDescriptor { 041 042 private static final Log log = LogFactory.getLog(IconDescriptor.class); 043 044 @XNode("@path") 045 protected String path; 046 047 @XNode("@enabled") 048 protected Boolean enabled = Boolean.TRUE; 049 050 @XNode("label") 051 protected String label; 052 053 // retrieve HTML tags => introspect DOM on setter 054 protected String description; 055 056 @XNode("sinceVersion") 057 protected String sinceVersion; 058 059 @XNodeList(value = "categories/category", type = ArrayList.class, componentType = String.class) 060 protected List<String> categories; 061 062 public String getPath() { 063 return path; 064 } 065 066 public String getFilename() { 067 return FileUtils.getFileName(path); 068 } 069 070 public String getLabel() { 071 return label; 072 } 073 074 public String getDescription() { 075 return description; 076 } 077 078 public String getSinceVersion() { 079 return sinceVersion; 080 } 081 082 public List<String> getCategories() { 083 return categories; 084 } 085 086 public void setPath(String path) { 087 this.path = path; 088 } 089 090 public void setLabel(String label) { 091 this.label = label; 092 } 093 094 public void setDescription(String description) { 095 this.description = description; 096 } 097 098 @XContent("description") 099 @SuppressWarnings("deprecation") 100 public void setDescription(DocumentFragment descriptionDOM) { 101 try { 102 OutputFormat of = new OutputFormat(); 103 of.setOmitXMLDeclaration(true); 104 this.description = DOMSerializer.toString(descriptionDOM, of).trim(); 105 } catch (IOException e) { 106 log.error(e, e); 107 } 108 } 109 110 public void setSinceVersion(String sinceVersion) { 111 this.sinceVersion = sinceVersion; 112 } 113 114 public void setCategories(List<String> categories) { 115 this.categories = categories; 116 } 117 118 public Boolean getEnabled() { 119 return enabled; 120 } 121 122 public void setEnabled(Boolean enabled) { 123 this.enabled = enabled; 124 } 125 126 public String toString() { 127 return getPath(); 128 } 129 130}