001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.tools.internal.ws.processor.modeler.wsdl;
026:
027: import java.util.HashMap;
028: import java.util.Map;
029:
030: import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
031:
032: /**
033: * @author Vivek Pandey
034: *
035: */
036: public class MimeHelper {
037: /**
038: * @param mimePart
039: * @return unique attachment ID
040: */
041: protected static String getAttachmentUniqueID(String mimePart) {
042: //return "uuid@" + mimePart;
043: return mimePart;
044: }
045:
046: /**
047: * @param mimeType
048: * @return true if mimeType is a binary type
049: */
050: protected static boolean isMimeTypeBinary(String mimeType) {
051: if (mimeType.equals(JPEG_IMAGE_MIME_TYPE)
052: || mimeType.equals(GIF_IMAGE_MIME_TYPE)) {
053: return true;
054: } else if (mimeType.equals(TEXT_XML_MIME_TYPE)
055: || mimeType.equals(TEXT_HTML_MIME_TYPE)
056: || mimeType.equals(TEXT_PLAIN_MIME_TYPE)
057: || mimeType.equals(APPLICATION_XML_MIME_TYPE)
058: || mimeType.equals(MULTIPART_MIME_TYPE)) {
059: return false;
060: }
061: //some unknown mime type, will be mapped to DataHandler java type so
062: // return true
063: return true;
064: }
065:
066: protected static void initMimeTypeToJavaType() {
067: mimeTypeToJavaType.put(JPEG_IMAGE_MIME_TYPE,
068: javaType.IMAGE_JAVATYPE);
069: //mimeTypeToJavaType.put(PNG_IMAGE_MIME_TYPE, javaType.IMAGE_JAVATYPE);
070: mimeTypeToJavaType.put(GIF_IMAGE_MIME_TYPE,
071: javaType.IMAGE_JAVATYPE);
072: mimeTypeToJavaType.put(TEXT_XML_MIME_TYPE,
073: javaType.SOURCE_JAVATYPE);
074: //mimeTypeToJavaType.put(TEXT_HTML_MIME_TYPE, javaType.SOURCE_JAVATYPE);
075: mimeTypeToJavaType.put(APPLICATION_XML_MIME_TYPE,
076: javaType.SOURCE_JAVATYPE);
077: mimeTypeToJavaType.put(TEXT_PLAIN_MIME_TYPE,
078: javaType.STRING_JAVATYPE);
079: mimeTypeToJavaType.put(MULTIPART_MIME_TYPE,
080: javaType.MIME_MULTIPART_JAVATYPE);
081:
082: }
083:
084: protected static Map mimeTypeToJavaType;
085: protected static JavaSimpleTypeCreator javaType;
086:
087: public static final String JPEG_IMAGE_MIME_TYPE = "image/jpeg";
088: //public static final String PNG_IMAGE_MIME_TYPE = "image/png";
089: public static final String GIF_IMAGE_MIME_TYPE = "image/gif";
090: public static final String TEXT_XML_MIME_TYPE = "text/xml";
091: public static final String TEXT_HTML_MIME_TYPE = "text/html";
092: public static final String TEXT_PLAIN_MIME_TYPE = "text/plain";
093: public static final String APPLICATION_XML_MIME_TYPE = "application/xml";
094: public static final String MULTIPART_MIME_TYPE = "multipart/*";
095:
096: /**
097: *
098: */
099: public MimeHelper() {
100: mimeTypeToJavaType = new HashMap();
101: javaType = new JavaSimpleTypeCreator();
102: initMimeTypeToJavaType();
103: }
104:
105: }
|