001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (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.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 * Nuxeo - initial API and implementation 016 * 017 * $Id: MimetypeDescriptor.java 20874 2007-06-19 20:26:15Z sfermigier $ 018 */ 019package org.nuxeo.ecm.platform.mimetype.service; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.nuxeo.common.xmap.annotation.XNode; 025import org.nuxeo.common.xmap.annotation.XObject; 026import org.nuxeo.ecm.platform.mimetype.MimetypeEntryImpl; 027import org.nuxeo.ecm.platform.mimetype.interfaces.MimetypeEntry; 028import org.w3c.dom.Element; 029import org.w3c.dom.NodeList; 030 031/** 032 * MimetypeEntry extension definition. 033 * 034 * @author <a href="mailto:ja@nuxeo.com">Julien Anguenot</a> 035 */ 036@XObject("mimetype") 037public class MimetypeDescriptor { 038 039 @XNode("@normalized") 040 protected String normalized; 041 042 @XNode("@binary") 043 protected boolean binary = true; 044 045 @XNode("@onlineEditable") 046 protected boolean onlineEditable = false; 047 048 @XNode("@oleSupported") 049 protected boolean oleSupported = false; 050 051 @XNode("@iconPath") 052 protected String iconPath; 053 054 @XNode("mimetypes") 055 protected Element mimetypes; 056 057 @XNode("extensions") 058 protected Element extensions; 059 060 public boolean isBinary() { 061 return binary; 062 } 063 064 public void setBinary(boolean binary) { 065 this.binary = binary; 066 } 067 068 public boolean isOnlineEditable() { 069 return onlineEditable; 070 } 071 072 public void setOnlineEditable(boolean onlineEditable) { 073 this.onlineEditable = onlineEditable; 074 } 075 076 public boolean isOleSupported() { 077 return oleSupported; 078 } 079 080 public void setOleSupported(boolean oleSupported) { 081 this.oleSupported = oleSupported; 082 } 083 084 public List<String> getExtensions() { 085 List<String> exts = new ArrayList<String>(); 086 NodeList elements = mimetypes.getElementsByTagName("extension"); 087 int len = elements.getLength(); 088 for (int i = 0; i < len; i++) { 089 exts.add(elements.item(i).getTextContent().trim()); 090 } 091 return exts; 092 } 093 094 public void setExtensions(Element extensions) { 095 this.extensions = extensions; 096 } 097 098 public String getIconPath() { 099 return iconPath; 100 } 101 102 public void setIconPath(String iconPath) { 103 this.iconPath = iconPath; 104 } 105 106 public List<String> getMimetypes() { 107 List<String> mtypes = new ArrayList<String>(); 108 NodeList elements = mimetypes.getElementsByTagName("mimetype"); 109 int len = elements.getLength(); 110 for (int i = 0; i < len; i++) { 111 mtypes.add(elements.item(i).getTextContent().trim()); 112 } 113 return mtypes; 114 } 115 116 public void setMimetypes(Element mimetypes) { 117 this.mimetypes = mimetypes; 118 } 119 120 public MimetypeEntry getMimetype() { 121 return new MimetypeEntryImpl(normalized, getMimetypes(), getExtensions(), iconPath, binary, onlineEditable, 122 oleSupported); 123 } 124 125 public String getNormalized() { 126 return normalized; 127 } 128 129 public void setNormalized(String normalized) { 130 this.normalized = normalized; 131 } 132 133}