本文整理汇总了Java中org.restlet.data.Preference类的典型用法代码示例。如果您正苦于以下问题:Java Preference类的具体用法?Java Preference怎么用?Java Preference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Preference类属于org.restlet.data包,在下文中一共展示了Preference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blockMimeType
import org.restlet.data.Preference; //导入依赖的package包/类
/**
* Blocks the use of specified mime types for this resource, as it is known that the converter for that mime type
* cannot produce the representation for the Resource's target class.
* @param types The mime types to block
*/
protected void blockMimeType(MediaType... types) {
List<Preference<MediaType>> acceptedMediaTypes = getClientInfo().getAcceptedMediaTypes();
if (acceptedMediaTypes.size() > types.length) {
return;
}
Set<MediaType> accepted = new HashSet<>(acceptedMediaTypes.size());
for (Preference<MediaType> p : acceptedMediaTypes) {
accepted.add(p.getMetadata());
}
accepted.removeAll(Arrays.asList(types));
if (accepted.isEmpty()) {
throw OntopiaRestErrors.UNSUPPORTED_MIME_TYPE.build(getClass().getName(), Arrays.toString(types));
}
}
开发者ID:ontopia,项目名称:ontopia,代码行数:23,代码来源:AbstractOntopiaResource.java示例2: setDefaultHttpHeader
import org.restlet.data.Preference; //导入依赖的package包/类
/**
*
* 设置标准http header
* @param request {@code void}
* @since eSDK Cloud V100R003C50
*/
private void setDefaultHttpHeader(Request request)
{
ClientInfo clientInfo = new ClientInfo();
List<Preference<MediaType>> acceptedMediaTypes = new ArrayList<Preference<MediaType>>();
Preference<MediaType> preferenceMediaType = new Preference<MediaType>();
MediaType mediaType = MediaType.register("application/json;version=1.2;charset=UTF-8;", "");
preferenceMediaType.setMetadata(mediaType);
acceptedMediaTypes.add(preferenceMediaType);
clientInfo.setAcceptedMediaTypes(acceptedMediaTypes);
List<Preference<Language>> acceptedLanguages = new ArrayList<Preference<Language>>();
Preference<Language> preferenceLanguage = new Preference<Language>();
Language language = new Language("zh_CN", "");
preferenceLanguage.setMetadata(language);
acceptedLanguages.add(preferenceLanguage);
clientInfo.setAcceptedLanguages(acceptedLanguages);
request.setClientInfo(clientInfo);
}
开发者ID:eSDK,项目名称:esdk_cloud_fc_cli,代码行数:29,代码来源:RestletClient.java示例3: executeRequest
import org.restlet.data.Preference; //导入依赖的package包/类
protected Response executeRequest(Request request, MediaType mediaType) {
List<Preference<MediaType>> accepts = request.getClientInfo().getAcceptedMediaTypes();
accepts.clear();
if (mediaType != null) {
accepts.add(new Preference<>(mediaType));
}
ServerResource resource = new ModuleResource();
Response response = new Response(request);
resource.init(null, request, response);
if (response.getStatus().isSuccess()) {
resource.handle();
}
return resource.getResponse();
}
开发者ID:slipstream,项目名称:SlipStreamServer,代码行数:19,代码来源:ModuleResourceTest.java示例4: setDefaultHttpHeader
import org.restlet.data.Preference; //导入依赖的package包/类
/**
* 设置标准http header
*
* @param request {@code void}
* @since eSDK Cloud V100R003C50
*/
private void setDefaultHttpHeader(Request request, String version)
{
ClientInfo clientInfo = new ClientInfo();
List<Preference<MediaType>> acceptedMediaTypes = new ArrayList<Preference<MediaType>>();
Preference<MediaType> preferenceMediaType = new Preference<MediaType>();
String acceptStr = "application/json;";
if (null == version)
{
acceptStr += "charset=UTF-8;";
}
else
{
acceptStr += version + "charset=UTF-8;";
}
MediaType mediaType = MediaType.register(acceptStr, "");
preferenceMediaType.setMetadata(mediaType);
acceptedMediaTypes.add(preferenceMediaType);
clientInfo.setAcceptedMediaTypes(acceptedMediaTypes);
List<Preference<Language>> acceptedLanguages = new ArrayList<Preference<Language>>();
Preference<Language> preferenceLanguage = new Preference<Language>();
Language language = new Language("zh_CN", "");
preferenceLanguage.setMetadata(language);
acceptedLanguages.add(preferenceLanguage);
clientInfo.setAcceptedLanguages(acceptedLanguages);
request.setClientInfo(clientInfo);
}
开发者ID:Huawei,项目名称:eSDK_FC_SDK_Java,代码行数:38,代码来源:RestletClient.java示例5: getLocale
import org.restlet.data.Preference; //导入依赖的package包/类
protected Locale getLocale()
{
Request request = Request.getCurrent();
List<Preference<Language>> preferenceList = request.getClientInfo().getAcceptedLanguages();
if( preferenceList.isEmpty() )
{
return Locale.getDefault();
}
Language language = preferenceList
.get( 0 ).getMetadata();
String[] localeStr = language.getName().split( "-" );
Locale locale;
switch( localeStr.length )
{
case 1:
locale = new Locale( localeStr[ 0 ] );
break;
case 2:
locale = new Locale( localeStr[ 0 ], localeStr[ 1 ] );
break;
case 3:
locale = new Locale( localeStr[ 0 ], localeStr[ 1 ], localeStr[ 2 ] );
break;
default:
locale = Locale.getDefault();
}
return locale;
}
开发者ID:apache,项目名称:polygene-java,代码行数:33,代码来源:ContextResource.java示例6: beforeHandle
import org.restlet.data.Preference; //导入依赖的package包/类
@Override
protected int beforeHandle( Request request, Response response )
{
List<String> segments = request.getResourceRef().getSegments();
if( segments.get( segments.size() - 1 ).equals( "" ) )
{
return Filter.CONTINUE;
}
String extensions = request.getResourceRef().getExtensions();
if( extensions != null )
{
int idx = extensions.lastIndexOf( "." );
if( idx != -1 )
{
extensions = extensions.substring( idx + 1 );
}
MetadataService metadataService = getApplication().getMetadataService();
Metadata metadata = metadataService.getMetadata( extensions );
if( metadata != null && metadata instanceof MediaType )
{
request.getClientInfo()
.setAcceptedMediaTypes( Collections.singletonList( new Preference<MediaType>( (MediaType) metadata ) ) );
String path = request.getResourceRef().getPath();
path = path.substring( 0, path.length() - extensions.length() - 1 );
request.getResourceRef().setPath( path );
}
}
return Filter.CONTINUE;
}
开发者ID:apache,项目名称:polygene-java,代码行数:33,代码来源:ExtensionMediaTypeFilter.java示例7: beforeHandle
import org.restlet.data.Preference; //导入依赖的package包/类
@Override
protected int beforeHandle( Request request, Response response )
{
List<String> segments = request.getResourceRef().getSegments();
if (segments.get( segments.size()-1 ).equals(""))
return Filter.CONTINUE;
String extensions = request.getResourceRef().getExtensions();
if( extensions != null )
{
int idx = extensions.lastIndexOf( "." );
if( idx != -1 )
{
extensions = extensions.substring( idx + 1 );
}
MetadataService metadataService = getApplication().getMetadataService();
Metadata metadata = metadataService.getMetadata( extensions );
if( metadata != null && metadata instanceof MediaType )
{
request.getClientInfo()
.setAcceptedMediaTypes( Collections.singletonList( new Preference<>( (MediaType) metadata ) ) );
String path = request.getResourceRef().getPath();
path = path.substring( 0, path.length() - extensions.length() - 1 );
request.getResourceRef().setPath( path );
}
}
return Filter.CONTINUE;
}
开发者ID:apache,项目名称:polygene-java,代码行数:31,代码来源:ExtensionMediaTypeFilter.java示例8: setAcceptedLanguages
import org.restlet.data.Preference; //导入依赖的package包/类
public void setAcceptedLanguages(Language... acceptedLanguages)
{
List<Preference<Language>> languages = new ArrayList<>();
for( Language acceptedLanguage : acceptedLanguages )
{
languages.add( new Preference<>());
}
info.setAcceptedLanguages( languages );
}
开发者ID:apache,项目名称:polygene-java,代码行数:12,代码来源:ContextResourceClientFactory.java示例9: setAcceptedMediaTypes
import org.restlet.data.Preference; //导入依赖的package包/类
public void setAcceptedMediaTypes(MediaType... acceptedMediaTypes)
{
List<Preference<MediaType>> mediatypes = new ArrayList<>();
for( MediaType mediaType : acceptedMediaTypes )
{
mediatypes.add( new Preference<>( mediaType ) );
}
info.setAcceptedMediaTypes( mediatypes );
}
开发者ID:apache,项目名称:polygene-java,代码行数:11,代码来源:ContextResourceClientFactory.java示例10: updatePreferences
import org.restlet.data.Preference; //导入依赖的package包/类
@Override
public <T> void updatePreferences( List<Preference<MediaType>> preferences,
Class<T> entity
)
{
updatePreferences( preferences, MediaType.APPLICATION_JSON, 1.0F );
}
开发者ID:apache,项目名称:polygene-java,代码行数:8,代码来源:PolygeneConverter.java示例11: doError
import org.restlet.data.Preference; //导入依赖的package包/类
@Override
protected void doError(Status status) {
if (status.equals(Status.CLIENT_ERROR_NOT_ACCEPTABLE) && (status.getThrowable() == null)) {
// we have an ontopia error for this
List<Preference<MediaType>> acceptedMediaTypes = getClientInfo().getAcceptedMediaTypes();
List<MediaType> accepted = new ArrayList<>(acceptedMediaTypes.size());
for (Preference<MediaType> mt : acceptedMediaTypes) {
accepted.add(mt.getMetadata());
}
super.doError(OntopiaRestErrors.UNSUPPORTED_MIME_TYPE.build(getClass().getName(), Arrays.toString(accepted.toArray())).getStatus());
} else {
super.doError(status);
}
}
开发者ID:ontopia,项目名称:ontopia,代码行数:16,代码来源:AbstractOntopiaResource.java示例12: setDefaultHttpHeader
import org.restlet.data.Preference; //导入依赖的package包/类
/**
*
* 设置标准http header
* @param request {@code void}
* @since eSDK Cloud V100R003C50
*/
private void setDefaultHttpHeader(Request request, String version)
{
ClientInfo clientInfo = new ClientInfo();
List<Preference<MediaType>> acceptedMediaTypes = new ArrayList<Preference<MediaType>>();
Preference<MediaType> preferenceMediaType = new Preference<MediaType>();
String acceptStr = "application/json;";
if (null == version)
{
acceptStr += "charset=UTF-8;";
}
else
{
acceptStr += version + "charset=UTF-8;";
}
MediaType mediaType = MediaType.register(acceptStr, "");
preferenceMediaType.setMetadata(mediaType);
acceptedMediaTypes.add(preferenceMediaType);
clientInfo.setAcceptedMediaTypes(acceptedMediaTypes);
List<Preference<Language>> acceptedLanguages = new ArrayList<Preference<Language>>();
Preference<Language> preferenceLanguage = new Preference<Language>();
Language language = new Language("zh_CN", "");
preferenceLanguage.setMetadata(language);
acceptedLanguages.add(preferenceLanguage);
clientInfo.setAcceptedLanguages(acceptedLanguages);
request.setClientInfo(clientInfo);
}
开发者ID:eSDK,项目名称:esdk_cloud_fc_cli,代码行数:38,代码来源:RestletClient.java示例13: testSnomedCTServerApplication
import org.restlet.data.Preference; //导入依赖的package包/类
@Test
public final void testSnomedCTServerApplication() throws ResourceException,
IOException {
BufferedReader testCaseReader = new BufferedReader(new FileReader(
"src/test/resources/test_cases.txt"));
String strLine = null;
while ((strLine = testCaseReader.readLine()) != null) {
log.debug("Test case: " + strLine);
MediaType mimeType = MediaType.TEXT_CSV;
ClientResource uriResource = new ClientResource(strLine);
for (int i = 0; i < 2; i++) {
uriResource.getClientInfo().getAcceptedMediaTypes()
.add(new Preference<MediaType>(mimeType));
String result = null;
uriResource.get();
if (uriResource.getStatus().isSuccess()
&& uriResource.getResponseEntity().isAvailable()) {
result = uriResource.getResponseEntity().getText();
}
assertNotNull(result);
log.debug("Result (" + mimeType.toString() + ") : " + result);
if (mimeType == MediaType.TEXT_CSV)
mimeType = MediaType.APPLICATION_JSON;
else
mimeType = MediaType.TEXT_CSV;
}
}
testCaseReader.close();
}
开发者ID:LiU-IMT,项目名称:SnomedCTRESTServer,代码行数:38,代码来源:TestSnomedCTServerApplication.java示例14: beforeHandle
import org.restlet.data.Preference; //导入依赖的package包/类
@Override
protected int beforeHandle(Request request, Response response) {
ClientInfo clientInfo = request.getClientInfo();
String agent = clientInfo.getAgent();
for (String browserName : affectedBrowserNames) {
if (agent != null && agent.contains(browserName)) {
List<Preference<MediaType>> preferences;
preferences = clientInfo.getAcceptedMediaTypes();
LinkedList<Preference<MediaType>> trimmedPreferences;
trimmedPreferences = new LinkedList<Preference<MediaType>>();
for (Preference<MediaType> preference : preferences) {
MediaType mediaType = preference.getMetadata();
if (MediaType.TEXT_HTML.equals(mediaType)
|| MediaType.APPLICATION_XHTML.equals(mediaType)) {
trimmedPreferences.add(preference);
clientInfo.setAcceptedMediaTypes(trimmedPreferences);
}
}
}
}
return CONTINUE;
}
开发者ID:slipstream,项目名称:SlipStreamServer,代码行数:29,代码来源:TrimmedMediaTypesFilter.java示例15: isHtml
import org.restlet.data.Preference; //导入依赖的package包/类
protected boolean isHtml(Request request) {
for (Preference<MediaType> mt : request.getClientInfo().getAcceptedMediaTypes()) {
if (mt.getMetadata().includes(MediaType.APPLICATION_XHTML)
|| mt.getMetadata().includes(MediaType.TEXT_HTML)) {
return true;
}
}
return false;
}
开发者ID:slipstream,项目名称:SlipStreamServer,代码行数:10,代码来源:ReportDecorator.java本文标签属性:
示例:示例英文
代码:代码转换器
java:java游戏