001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.tools.ws.processor.modeler.wsdl;
037:
038: import com.sun.tools.ws.processor.modeler.JavaSimpleTypeCreator;
039:
040: import java.util.HashMap;
041: import java.util.Map;
042:
043: /**
044: * @author Vivek Pandey
045: *
046: */
047: public class MimeHelper {
048: /**
049: * @param mimePart
050: * @return unique attachment ID
051: */
052: protected static String getAttachmentUniqueID(String mimePart) {
053: //return "uuid@" + mimePart;
054: return mimePart;
055: }
056:
057: /**
058: * @param mimeType
059: * @return true if mimeType is a binary type
060: */
061: protected static boolean isMimeTypeBinary(String mimeType) {
062: if (mimeType.equals(JPEG_IMAGE_MIME_TYPE)
063: || mimeType.equals(GIF_IMAGE_MIME_TYPE)) {
064: return true;
065: } else if (mimeType.equals(TEXT_XML_MIME_TYPE)
066: || mimeType.equals(TEXT_HTML_MIME_TYPE)
067: || mimeType.equals(TEXT_PLAIN_MIME_TYPE)
068: || mimeType.equals(APPLICATION_XML_MIME_TYPE)
069: || mimeType.equals(MULTIPART_MIME_TYPE)) {
070: return false;
071: }
072: //some unknown mime type, will be mapped to DataHandler java type so
073: // return true
074: return true;
075: }
076:
077: protected static void initMimeTypeToJavaType() {
078: mimeTypeToJavaType.put(JPEG_IMAGE_MIME_TYPE,
079: javaType.IMAGE_JAVATYPE);
080: //mimeTypeToJavaType.put(PNG_IMAGE_MIME_TYPE, javaType.IMAGE_JAVATYPE);
081: mimeTypeToJavaType.put(GIF_IMAGE_MIME_TYPE,
082: javaType.IMAGE_JAVATYPE);
083: mimeTypeToJavaType.put(TEXT_XML_MIME_TYPE,
084: javaType.SOURCE_JAVATYPE);
085: //mimeTypeToJavaType.put(TEXT_HTML_MIME_TYPE, javaType.SOURCE_JAVATYPE);
086: mimeTypeToJavaType.put(APPLICATION_XML_MIME_TYPE,
087: javaType.SOURCE_JAVATYPE);
088: mimeTypeToJavaType.put(TEXT_PLAIN_MIME_TYPE,
089: javaType.STRING_JAVATYPE);
090: mimeTypeToJavaType.put(MULTIPART_MIME_TYPE,
091: javaType.MIME_MULTIPART_JAVATYPE);
092:
093: }
094:
095: protected static Map mimeTypeToJavaType;
096: protected static JavaSimpleTypeCreator javaType;
097:
098: public static final String JPEG_IMAGE_MIME_TYPE = "image/jpeg";
099: //public static final String PNG_IMAGE_MIME_TYPE = "image/png";
100: public static final String GIF_IMAGE_MIME_TYPE = "image/gif";
101: public static final String TEXT_XML_MIME_TYPE = "text/xml";
102: public static final String TEXT_HTML_MIME_TYPE = "text/html";
103: public static final String TEXT_PLAIN_MIME_TYPE = "text/plain";
104: public static final String APPLICATION_XML_MIME_TYPE = "application/xml";
105: public static final String MULTIPART_MIME_TYPE = "multipart/*";
106:
107: /**
108: *
109: */
110: public MimeHelper() {
111: mimeTypeToJavaType = new HashMap();
112: javaType = new JavaSimpleTypeCreator();
113: initMimeTypeToJavaType();
114: }
115:
116: }
|