本文整理匯總了Java中javax.activation.MimeType類的典型用法代碼示例。如果您正苦於以下問題:Java MimeType類的具體用法?Java MimeType怎麽用?Java MimeType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MimeType類屬於javax.activation包,在下文中一共展示了MimeType類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calcExpectedMediaType
import javax.activation.MimeType; //導入依賴的package包/類
static MimeType calcExpectedMediaType(AnnotationSource primarySource,
ModelBuilder builder ) {
XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class);
if(xmt==null)
return null;
try {
return new MimeType(xmt.value());
} catch (MimeTypeParseException e) {
builder.reportError(new IllegalAnnotationException(
Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()),
xmt
));
return null;
}
}
示例2: logoutByPost
import javax.activation.MimeType; //導入依賴的package包/類
@RequestMapping(value = "/api/logout", method = RequestMethod.POST)
public void logoutByPost(@RequestBody String requestBody, @RequestHeader(value = "Content-Type") MimeType contentType,
HttpServletResponse response) throws IOException, JSONException {
String sessionUUID;
if (contentType.match(JSONConverter.MIME_TYPE_JSON)) {
try {
JSONObject json = new JSONObject(requestBody);
sessionUUID = json.getString("session");
} catch (JSONException e) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
} else if (contentType.match(FORM_TYPE)) {
String[] fields = requestBody.split("=");
if (fields.length < 2) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
sessionUUID = URLEncodeUtils.decodeUtf8(fields[1]);
} else {
throw new IllegalStateException("Unsupported content type: " + contentType);
}
doLogout(sessionUUID, response);
}
示例3: classify
import javax.activation.MimeType; //導入依賴的package包/類
/**
* Classifies the given mime type into one of the following classifications: xml, json, yaml, csv, tsv, psv.
*
* @param type The MIME type to classify.
* @return The classification of the MIME type, or null if unclassifiable.
*/
public static String classify(MimeType type) {
if (type == null) return null;
String subType = type.getSubType();
String classification = null;
if (subType.equals("xml") || subType.endsWith("+xml")) {
classification = "xml";
} else if (subType.equals("json") || subType.endsWith("+json")) {
classification = "json";
} else if (subType.equals("csv") || subType.endsWith("+csv") || subType.equals("comma-separated-values") || subType.endsWith("+comma-separated-values")) {
classification = "csv";
} else if (subType.equals("yaml") || subType.endsWith("+yaml") || subType.equals("x-yaml") || subType.endsWith("+x-yaml")) {
classification = "yaml";
} else if (subType.equals("tsv") || subType.endsWith("+tsv") || subType.equals("tab-separated-values") || subType.endsWith("+tab-separated-values")) {
classification = "tsv";
} else if (subType.equals("psv") || subType.endsWith("+psv") || subType.equals("pipe-separated-values") || subType.endsWith("+pipe-separated-values")) {
classification = "psv";
}
return classification;
}
示例4: writeTypeRef
import javax.activation.MimeType; //導入依賴的package包/類
/**
* Writes a type attribute (if the referenced type is a global type)
* or writes out the definition of the anonymous type in place (if the referenced
* type is not a global type.)
*
* Also provides processing for ID/IDREF, MTOM @xmime, and swa:ref
*
* ComplexTypeHost and SimpleTypeHost don't share an api for creating
* and attribute in a type-safe way, so we will compromise for now and
* use _attribute().
*/
private void writeTypeRef(TypeHost th, NonElementRef<T, C> typeRef, String refAttName) {
// ID / IDREF handling
switch(typeRef.getSource().id()) {
case ID:
th._attribute(refAttName, new QName(WellKnownNamespace.XML_SCHEMA, "ID"));
return;
case IDREF:
th._attribute(refAttName, new QName(WellKnownNamespace.XML_SCHEMA, "IDREF"));
return;
case NONE:
// no ID/IDREF, so continue on and generate the type
break;
default:
throw new IllegalStateException();
}
// MTOM handling
MimeType mimeType = typeRef.getSource().getExpectedMimeType();
if( mimeType != null ) {
th._attribute(new QName(WellKnownNamespace.XML_MIME_URI, "expectedContentTypes", "xmime"), mimeType.toString());
}
// ref:swaRef handling
if(generateSwaRefAdapter(typeRef)) {
th._attribute(refAttName, new QName(WellKnownNamespace.SWA_URI, "swaRef", "ref"));
return;
}
// type name override
if(typeRef.getSource().getSchemaType()!=null) {
th._attribute(refAttName,typeRef.getSource().getSchemaType());
return;
}
// normal type generation
writeTypeRef(th, typeRef.getTarget(), refAttName);
}
示例5: print
import javax.activation.MimeType; //導入依賴的package包/類
@Override
public CharSequence print(V o) throws AccessorException {
XMLSerializer w = XMLSerializer.getInstance();
MimeType old = w.setExpectedMimeType(expectedMimeType);
try {
return core.print(o);
} finally {
w.setExpectedMimeType(old);
}
}
示例6: writeText
import javax.activation.MimeType; //導入依賴的package包/類
@Override
public void writeText(XMLSerializer w, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
MimeType old = w.setExpectedMimeType(expectedMimeType);
try {
core.writeText(w, o, fieldName);
} finally {
w.setExpectedMimeType(old);
}
}
示例7: writeLeafElement
import javax.activation.MimeType; //導入依賴的package包/類
@Override
public void writeLeafElement(XMLSerializer w, Name tagName, V o, String fieldName) throws IOException, SAXException, XMLStreamException, AccessorException {
MimeType old = w.setExpectedMimeType(expectedMimeType);
try {
core.writeLeafElement(w, tagName, o, fieldName);
} finally {
w.setExpectedMimeType(old);
}
}
示例8: DataSourceSource
import javax.activation.MimeType; //導入依賴的package包/類
public DataSourceSource(DataSource source) throws MimeTypeParseException {
this.source = source;
String ct = source.getContentType();
if(ct==null) {
charset = null;
} else {
MimeType mimeType = new MimeType(ct);
this.charset = mimeType.getParameter("charset");
}
}
示例9: getExpectedMimeType
import javax.activation.MimeType; //導入依賴的package包/類
public MimeType getExpectedMimeType() {
for( Ref t : refs ) {
MimeType mt = t.getExpectedMimeType();
if(mt!=null) return mt;
}
return null;
}
示例10: TypeUseImpl
import javax.activation.MimeType; //導入依賴的package包/類
public TypeUseImpl(CNonElement itemType, boolean collection, ID id, MimeType expectedMimeType, CAdapter adapter) {
this.coreType = itemType;
this.collection = collection;
this.id = id;
this.expectedMimeType = expectedMimeType;
this.adapter = adapter;
}
示例11: makeMimeTyped
import javax.activation.MimeType; //導入依賴的package包/類
public static TypeUse makeMimeTyped( TypeUse t, MimeType mt ) {
if(t.getExpectedMimeType()!=null)
// I don't think we let users tweak the idness, so
// this error must indicate an inconsistency within the RI/spec.
throw new IllegalStateException();
return new TypeUseImpl( t.getInfo(), t.isCollection(), t.idUse(), mt, t.getAdapterUse() );
}
示例12: CElementPropertyInfo
import javax.activation.MimeType; //導入依賴的package包/類
public CElementPropertyInfo(String name, CollectionMode collection, ID id, MimeType expectedMimeType, XSComponent source,
CCustomizations customizations, Locator locator, boolean required) {
super(name, collection.col, source, customizations, locator);
this.required = required;
this.id = id;
this.expectedMimeType = expectedMimeType;
this.isValueList = collection.val;
}