本文整理汇总了Java中org.restlet.representation.Variant.getMediaType方法的典型用法代码示例。如果您正苦于以下问题:Java Variant.getMediaType方法的具体用法?Java Variant.getMediaType怎么用?Java Variant.getMediaType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.representation.Variant
的用法示例。
在下文中一共展示了Variant.getMediaType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
Resource resource) throws IOException {
if (source instanceof TemplateResolution) {
Locale locale = getLocale(resource);
TemplateRepresentation tr = new TemplateRepresentation(
((TemplateResolution) source).getTemplateResource().getBaseName(), locale,
target.getMediaType());
tr.setDataModel(resource.getRequest(), resource.getResponse());
return tr;
}
return null;
}
示例2: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
Resource resource) throws IOException {
Representation result = null;
if (source instanceof GsonRepresentation) {
result = (GsonRepresentation<?>) source;
} else {
if (target.getMediaType() == null) {
target.setMediaType(MediaType.APPLICATION_JSON);
}
if (VARIANT_JSON.isCompatible(target)) {
GsonRepresentation<Object> gsonRepresentation = create(source);
result = gsonRepresentation;
}
}
return result;
}
示例3: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
Resource resource) {
Representation result = null;
if (source instanceof JacksonRepresentation) {
result = (JacksonRepresentation<?>) source;
} else {
if (target.getMediaType() == null) {
target.setMediaType(MediaType.APPLICATION_JSON);
}
if (isCompatible(target)) {
result = create(target.getMediaType(), source);
}
}
return result;
}
示例4: getObjectClasses
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public List<Class<?>> getObjectClasses(Variant source) {
List<Class<?>> result = null;
result = addObjectClass(result, String.class);
result = addObjectClass(result, InputStream.class);
result = addObjectClass(result, Reader.class);
if (source.getMediaType() != null) {
MediaType mediaType = source.getMediaType();
if ((ObjectRepresentation.VARIANT_OBJECT_BINARY_SUPPORTED && MediaType.APPLICATION_JAVA_OBJECT
.equals(mediaType))
|| (ObjectRepresentation.VARIANT_OBJECT_XML_SUPPORTED && MediaType.APPLICATION_JAVA_OBJECT_XML
.equals(mediaType))) {
result = addObjectClass(result, Object.class);
} else if (MediaType.APPLICATION_WWW_FORM.equals(mediaType)) {
result = addObjectClass(result, Form.class);
}
}
return result;
}
示例5: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation( Object source, Variant target, Resource resource )
{
Representation result = null;
if( source instanceof JsonRepresentation )
{
result = (JsonRepresentation<?>) source;
}
else
{
if( target.getMediaType() == null )
{
target.setMediaType( MediaType.APPLICATION_JSON );
}
if( isCompatible( target ) )
{
result = create( target.getMediaType(), source );
}
}
return result;
}
示例6: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
Resource resource) throws IOException {
Representation result = null;
if (source instanceof XMLRepresentation) {
result = (XMLRepresentation<?>) source;
} else {
if (target.getMediaType() == null) {
target.setMediaType(MediaType.APPLICATION_ALL_XML);
}
if (VARIANT_APPLICATION_ALL_XML.isCompatible(target) || VARIANT_APPLICATION_XML.isCompatible(target) ||VARIANT_TEXT_XML.isCompatible(target) ) {
XMLRepresentation<Object> obixRepresentation = create(
target.getMediaType(), source, resource);
result = obixRepresentation;
}
}
return result;
}
示例7: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException {
Representation result = null;
if (source instanceof JSonRepresentation) {
result = (JSonRepresentation<?>) source;
} else {
if (target.getMediaType() == null) {
target.setMediaType(MediaType.APPLICATION_JSON);
}
if (VARIANT_JSON.isCompatible(target)) {
JSonRepresentation<Object> obixRepresentation = create(target.getMediaType(), source, resource);
result = obixRepresentation;
}
}
return result;
}
示例8: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Representation toRepresentation(Object source, Variant target, UniformResource resource) {
Representation result = null;
if (source instanceof XstreamRepresentation) {
result = (XstreamRepresentation) source;
} else {
if (target.getMediaType() == null) {
target.setMediaType(MediaType.TEXT_XML);
}
if (VARIANT_JSON.isCompatible(target)) {
XstreamRepresentation<Object> xstreamRepresentation = create(target.getMediaType(), source);
result = xstreamRepresentation;
} else if (VARIANT_APPLICATION_ALL_XML.isCompatible(target) || VARIANT_APPLICATION_XML.isCompatible(target)
|| VARIANT_TEXT_XML.isCompatible(target)) {
result = create(target.getMediaType(), source);
}
}
return result;
}
示例9: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Representation toRepresentation(Object source, Variant target, UniformResource resource) {
Representation result = null;
if (source instanceof OxmRepresentation) {
result = (OxmRepresentation) source;
} else {
if (target.getMediaType() == null) {
target.setMediaType(MediaType.TEXT_XML);
}
if (VARIANT_APPLICATION_ALL_XML.isCompatible(target) || VARIANT_APPLICATION_XML.isCompatible(target)
|| VARIANT_TEXT_XML.isCompatible(target)) {
result = create(target.getMediaType(), source);
}
}
return result;
}
示例10: getIndexRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
public Representation getIndexRepresentation(Variant variant, ReferenceList indexContent) {
MediaType mediaType = variant.getMediaType();
if (APPLICATION_JSON.isCompatible(mediaType)) {
return getJsonRepresentation(indexContent);
} else if (APPLICATION_XML.isCompatible(mediaType)) {
return getXmlRepresentation(indexContent);
} else if (TEXT_HTML.isCompatible(mediaType)) {
Representation jsonRepr = getJsonRepresentation(indexContent);
jsonRepr.setMediaType(TEXT_HTML);
return jsonRepr;
} else {
return super.getIndexRepresentation(variant, indexContent);
}
}
示例11: checkMetadataConsistency
import org.restlet.representation.Variant; //导入方法依赖的package包/类
/**
* Checks that the URI and the representation are compatible. The whole set
* of metadata of the representation must be included in the set of those of
* the URI
*
* @param fileName
* The name of the resource
* @param representation
* The provided representation.
* @return True if the metadata of the representation are compatible with
* the metadata extracted from the filename
*/
private boolean checkMetadataConsistency(String fileName, Representation representation) {
if (representation != null) {
Variant var = new Variant();
Entity.updateMetadata(fileName, var, false, getMetadataService());
// "var" contains the theoretical correct metadata
if (!var.getLanguages().isEmpty()
&& !representation.getLanguages().isEmpty()
&& !var.getLanguages().containsAll(representation.getLanguages())) {
return false;
}
if ((var.getMediaType() != null)
&& (representation.getMediaType() != null)
&& !(var.getMediaType().includes(representation.getMediaType()))) {
return false;
}
if (!var.getEncodings().isEmpty()
&& !representation.getEncodings().isEmpty()
&& !var.getEncodings().containsAll(representation.getEncodings())) {
return false;
}
}
return true;
}
示例12: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
Resource resource) throws IOException {
if (source instanceof Template) {
return new TemplateRepresentation((Template) source,
new ResolverHashModel(Resolver.createResolver(
resource.getRequest(), resource.getResponse())),
target.getMediaType());
}
return null;
}
示例13: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(final Object source, final Variant target, Resource resource) throws IOException {
return new OutputRepresentation(target.getMediaType()) {
@Override
public void write(OutputStream outputStream) throws IOException {
CharacterSet characterSet = target.getCharacterSet();
if (characterSet == null) {
characterSet = CharacterSet.UTF_8;
}
writeFragment(outputStream, source, characterSet);
}
};
}
示例14: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target, UniformResource resource) throws IOException {
if (source instanceof Template) {
TemplateRepresentation tr = new TemplateRepresentation((Template) source, target.getMediaType());
tr.setDataModel(resource.getRequest(), resource.getResponse());
return tr;
}
return null;
}
示例15: toRepresentation
import org.restlet.representation.Variant; //导入方法依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target, UniformResource resource) {
Representation result = null;
if (source instanceof JsonRepresentation) {
result = (JsonRepresentation) source;
} else {
if (target.getMediaType() == null)
target.setMediaType(MediaType.APPLICATION_JSON);
if (VARIANT_JSON.isCompatible(target)) {
JsonRepresentation representation = create(target.getMediaType(), source);
result = representation;
}
}
return result;
}