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
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.jsfcl.std.reference;
042:
043: import java.io.BufferedReader;
044: import java.io.IOException;
045: import java.io.InputStream;
046: import java.io.InputStreamReader;
047: import java.util.List;
048:
049: /**
050: * @author eric
051: *
052: * TODO To change the template for this generated type comment go to
053: * Window - Preferences - Java - Code Generation - Code and Comments
054: */
055: public class MediaTypesReferenceDataDefiner extends
056: ReferenceDataDefiner {
057: protected static final String FILENAME = "media-types.txt"; //NOI18N
058:
059: public void addBaseItems(List list) {
060: InputStream in;
061: BufferedReader reader;
062: ReferenceDataItem item;
063:
064: list.add(newItem("", // NOI18N
065: null, true, false));
066: in = null;
067: try {
068: in = getClass().getResourceAsStream(FILENAME);
069: if (in == null) {
070: assert ReferenceDataManager.loggerUtil
071: .warning("Could not find mime-types file: "
072: + FILENAME); //NOI18N
073: return;
074: }
075: reader = new BufferedReader(new InputStreamReader(in));
076: String line, contentType;
077:
078: contentType = null;
079: while (true) {
080: line = reader.readLine();
081: if (line == null) {
082: break;
083: }
084: if (line.length() == 0 || line.startsWith("#")) { //NOI18N
085: continue;
086: }
087: // are we at the end marker line, a line with at least ---
088: if (line.startsWith("---")) { //NOI18N
089: break;
090: }
091: int index;
092: String contentSubType, combinedName;
093: boolean isSubTypeLine;
094:
095: isSubTypeLine = Character.isWhitespace(line.charAt(0));
096: line = line.trim();
097: if (!isSubTypeLine) {
098: // extract the content type
099: // these should really be up to first whitespace
100: index = line.indexOf(" "); //NOI18N
101: if (index == -1) {
102: contentType = line;
103: } else {
104: contentType = line.substring(0, index);
105: line = line.substring(index).trim();
106: }
107: }
108: // remove the portion pointing to the RFC for this subtype
109: index = line.indexOf("["); //NOI18N
110: if (index == -1) {
111: contentSubType = line;
112: } else {
113: contentSubType = line.substring(0, index).trim();
114: }
115: if (contentSubType.length() == 0) {
116: contentSubType = null;
117: }
118: combinedName = contentType;
119: if (contentType == null) {
120: throw new RuntimeException("Found an entry in "
121: + FILENAME
122: + " with no content type defined"); //NOI18N
123: }
124: if (contentSubType != null) {
125: combinedName += "/" + contentSubType; //NOI18N
126: }
127: item = newItem(combinedName, combinedName, false, false);
128: list.add(item);
129: }
130: } catch (IOException e) {
131: assert ReferenceDataManager.loggerUtil
132: .config("Problems parsing reference data ref file for: "
133: + FILENAME); //NOI18N
134: } finally {
135: if (in != null) {
136: try {
137: in.close();
138: } catch (IOException e) {
139: }
140: ;
141: }
142: }
143: }
144:
145: public boolean canAddRemoveItems() {
146:
147: return true;
148: }
149:
150: public boolean isValueAString() {
151:
152: return true;
153: }
154:
155: }
|