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