本文整理汇总了Java中org.restlet.data.Language类的典型用法代码示例。如果您正苦于以下问题:Java Language类的具体用法?Java Language怎么用?Java Language使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Language类属于org.restlet.data包,在下文中一共展示了Language类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getVariant
import org.restlet.data.Language; //导入依赖的package包/类
protected Variant getVariant( Request request,
List<Language> possibleLanguages,
List<MediaType> possibleMediaTypes
)
{
Language language = request.getClientInfo().getPreferredLanguage( possibleLanguages );
if( language == null )
{
language = possibleLanguages.get( 0 );
}
MediaType responseType = request.getClientInfo().getPreferredMediaType( possibleMediaTypes );
if( responseType == null && request.getClientInfo()
.getPreferredMediaType( Collections.singletonList( MediaType.ALL ) ) == MediaType.ALL )
{
responseType = possibleMediaTypes.get( 0 );
}
Variant variant = new Variant( responseType, language );
variant.setCharacterSet( CharacterSet.UTF_8 );
return variant;
}
开发者ID:apache,项目名称:polygene-java,代码行数:26,代码来源:AbstractResponseWriter.java
示例2: includes
import org.restlet.data.Language; //导入依赖的package包/类
/**
* Indicates if the current variant includes the given variant.
*
* @param other
* The other variant.
* @return True if the current variant includes the other.
*/
public boolean includes(Variant other) {
boolean result = other != null;
// Compare the character set
if (result) {
result = (getCharacterSet() == null)
|| getCharacterSet().includes(other.getCharacterSet());
}
// Compare the media type
if (result) {
result = (getMediaType() == null)
|| getMediaType().includes(other.getMediaType());
}
// Compare the languages
if (result) {
result = (getLanguages().isEmpty())
|| getLanguages().contains(Language.ALL)
|| getLanguages().containsAll(other.getLanguages());
}
return result;
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:32,代码来源:Variant.java
示例3: addVariant
import org.restlet.data.Language; //导入依赖的package包/类
private void addVariant( MediaType mediaType, Language language )
{
DelegatedResource resource = getResource();
List<Variant> variants = resource.getVariants();
if( resource.getAttributes().isNegotiateEncoding() )
{
for( Encoding encoding : CachingUtil.SUPPORTED_ENCODINGS )
{
Variant variant = new Variant( mediaType, language );
variant.getEncodings().add( encoding );
variants.add( variant );
}
}
else
variants.add( new Variant( mediaType, language ) );
}
开发者ID:tliron,项目名称:prudence,代码行数:17,代码来源:DelegatedResourceConversationService.java
示例4: setDefaultHttpHeader
import org.restlet.data.Language; //导入依赖的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
示例5: setDefaultHttpHeader
import org.restlet.data.Language; //导入依赖的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
示例6: getLocale
import org.restlet.data.Language; //导入依赖的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
示例7: entityHeaders
import org.restlet.data.Language; //导入依赖的package包/类
private Representation entityHeaders( Representation representation, EntityState entityState )
{
representation.setModificationDate( java.util.Date.from( entityState.lastModified() ) );
representation.setTag( new Tag( "" + entityState.version() ) );
representation.setCharacterSet( CharacterSet.UTF_8 );
representation.setLanguages( Collections.singletonList( Language.ENGLISH ) );
return representation;
}
开发者ID:apache,项目名称:polygene-java,代码行数:10,代码来源:EntityResource.java
示例8: setAcceptedLanguages
import org.restlet.data.Language; //导入依赖的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: Variant
import org.restlet.data.Language; //导入依赖的package包/类
/**
* Constructor.
*
* @param mediaType
* The media type.
* @param language
* The language.
*/
public Variant(MediaType mediaType, Language language) {
this.characterSet = null;
if (language != null) {
getLanguages().add(language);
} else {
this.languages = null;
}
this.mediaType = mediaType;
this.locationRef = null;
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:21,代码来源:Variant.java
示例10: setResponseText
import org.restlet.data.Language; //导入依赖的package包/类
@Override
public StringRepresentation setResponseText( String text, String mediaTypeName, String languageName, String characterSetName )
{
MediaType mediaType = mediaTypeName == null ? getMediaType() : MediaType.valueOf( mediaTypeName );
Language language = languageName == null ? getLanguage() : Language.valueOf( languageName );
CharacterSet characterSet = characterSetName == null ? getCharacterSet() : CharacterSet.valueOf( characterSetName );
StringRepresentation representation = new StringRepresentation( text, mediaType, language, characterSet );
getResponse().setEntity( representation );
return representation;
}
开发者ID:tliron,项目名称:prudence,代码行数:11,代码来源:ResourceConversationServiceBase.java
示例11: setDefaultHttpHeader
import org.restlet.data.Language; //导入依赖的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
示例12: getLanguages
import org.restlet.data.Language; //导入依赖的package包/类
/**
* Returns the modifiable list of languages. Creates a new instance if no
* one has been set. An "IllegalArgumentException" exception is thrown when
* adding a null language to this list.<br>
* <br>
* Note that when used with HTTP connectors, this property maps to the
* "Content-Language" header.
*
* @return The list of languages.
*/
public List<Language> getLanguages() {
if (this.languages == null) {
this.languages = new WrapperList<Language>() {
@Override
public void add(int index, Language element) {
if (element == null) {
throw new IllegalArgumentException(
"Cannot add a null language.");
}
super.add(index, element);
}
@Override
public boolean add(Language element) {
if (element == null) {
throw new IllegalArgumentException(
"Cannot add a null language.");
}
return super.add(element);
}
@Override
public boolean addAll(Collection<? extends Language> elements) {
boolean addNull = (elements == null);
if (!addNull) {
for (final Iterator<? extends Language> iterator = elements
.iterator(); !addNull && iterator.hasNext();) {
addNull = (iterator.next() == null);
}
}
if (addNull) {
throw new IllegalArgumentException(
"Cannot add a null language.");
}
return super.addAll(elements);
}
@Override
public boolean addAll(int index,
Collection<? extends Language> elements) {
boolean addNull = (elements == null);
if (!addNull) {
for (final Iterator<? extends Language> iterator = elements
.iterator(); !addNull && iterator.hasNext();) {
addNull = (iterator.next() == null);
}
}
if (addNull) {
throw new IllegalArgumentException(
"Cannot add a null language.");
}
return super.addAll(index, elements);
}
};
}
return this.languages;
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:74,代码来源:Variant.java
示例13: ResourceConversationServiceBase
import org.restlet.data.Language; //导入依赖的package包/类
/**
* Constructor.
*
* @param resource
* The resource
* @param entity
* The client entity or null
* @param preferences
* The negotiated client preferences or null
* @param defaultCharacterSet
* The character set to use if unspecified by variant
* @param supportedEncodings
* The supported encodings or null
* @param fileUploadSizeThreshold
* The size in bytes beyond which uploaded files will be stored to
* disk
* @param fileUploadDirectory
* The directory in which to place uploaded files
*/
public ResourceConversationServiceBase( R resource, Representation entity, Variant preferences, CharacterSet defaultCharacterSet, List<Encoding> supportedEncodings, int fileUploadSizeThreshold,
File fileUploadDirectory )
{
super( fileUploadSizeThreshold, fileUploadDirectory );
this.resource = resource;
this.entity = entity;
negotiated = preferences != null ? preferences : resource.getConnegService().getPreferredVariant( resource.getVariants(), resource.getRequest(), resource.getMetadataService() );
if( negotiated != null )
{
mediaType = negotiated.getMediaType();
characterSet = negotiated.getCharacterSet();
Iterator<Language> negotiatedLanguages = negotiated.getLanguages().iterator();
if( negotiatedLanguages.hasNext() )
language = negotiatedLanguages.next();
if( supportedEncodings != null )
{
List<Encoding> preferredEncodings = negotiated.getEncodings();
for( Encoding encoding : supportedEncodings )
{
if( preferredEncodings.contains( encoding ) )
{
if( Encoding.IDENTITY.equals( encoding ) )
encoding = null;
this.encoding = encoding;
break;
}
}
}
}
// For HTML forms, switch to HTML
// if( entity != null && ( entity.getMediaType().equals(
// MediaType.APPLICATION_WWW_FORM ) ) )
// mediaType = MediaType.TEXT_HTML;
if( characterSet == null )
characterSet = defaultCharacterSet;
}
开发者ID:tliron,项目名称:prudence,代码行数:62,代码来源:ResourceConversationServiceBase.java
示例14: CacheEntry
import org.restlet.data.Language; //导入依赖的package包/类
/**
* Constructor. Compresses string if encoding is provided.
*
* @param string
* The string
* @param mediaType
* The media type
* @param language
* The language
* @param characterSet
* The character set
* @param encoding
* The encoding
* @param headers
* The headers
* @param modificationDate
* The modification date or null
* @param tag
* The tag
* @param expirationDate
* The expiration date
* @param documentModificationDate
* The document modification date
* @throws IOException
* In case of a compression error
*/
public CacheEntry( String string, MediaType mediaType, Language language, CharacterSet characterSet, Encoding encoding, Series<Header> headers, Date modificationDate, Tag tag, Date expirationDate,
Date documentModificationDate ) throws IOException
{
this.mediaType = mediaType;
this.language = language;
this.characterSet = characterSet;
this.encoding = Encoding.IDENTITY.equals( encoding ) ? null : encoding;
this.headers = headers;
this.modificationDate = modificationDate != null ? modificationDate : new Date();
this.tag = tag;
this.expirationDate = expirationDate;
this.documentModificationDate = documentModificationDate;
if( IoUtil.SUPPORTED_COMPRESSION_ENCODINGS.contains( encoding ) )
bytes = IoUtil.compress( string, encoding, "text" );
else
this.string = string;
}
开发者ID:tliron,项目名称:prudence,代码行数:45,代码来源:CacheEntry.java
示例15: getLanguage
import org.restlet.data.Language; //导入依赖的package包/类
/**
* @return The language
*/
public Language getLanguage()
{
return language;
}
开发者ID:tliron,项目名称:prudence,代码行数:8,代码来源:CacheEntry.java
示例16: readExternal
import org.restlet.data.Language; //导入依赖的package包/类
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
{
int tagsLength = in.readInt();
tags = new String[tagsLength];
for( int i = 0; i < tagsLength; i++ )
{
String tag = IoUtil.readUtf8( in );
tags[i] = tag;
}
if( in.readBoolean() )
{
bytes = new byte[in.readInt()];
in.readFully( bytes );
}
else
string = IoUtil.readUtf8( in );
mediaType = MediaType.valueOf( in.readUTF() );
language = Language.valueOf( in.readUTF() );
characterSet = CharacterSet.valueOf( in.readUTF() );
encoding = Encoding.valueOf( in.readUTF() );
int headersLength = in.readInt();
if( headersLength > 0 )
{
headers = new Series<Header>( Header.class );
for( int i = 0; i < headersLength; i++ )
{
String name = IoUtil.readUtf8( in );
String value = IoUtil.readUtf8( in );
headers.add( new Header( name, value ) );
}
}
String tagValue = in.readUTF();
tag = tagValue != null ? Tag.parse( tagValue ) : null;
modificationDate = new Date( in.readLong() );
expirationDate = new Date( in.readLong() );
documentModificationDate = new Date( in.readLong() );
}
开发者ID:tliron,项目名称:prudence,代码行数:42,代码来源:CacheEntry.java
示例17: StringRepresentation
import org.restlet.data.Language; //导入依赖的package包/类
/**
* Constructor.
*
* @param text
* The string value.
* @param mediaType
* The media type.
* @param language
* The language.
* @param characterSet
* The character set.
*/
public StringRepresentation(CharSequence text, MediaType mediaType,
Language language, CharacterSet characterSet) {
super(mediaType);
setMediaType(mediaType);
if (language != null) {
getLanguages().add(language);
}
setCharacterSet(characterSet);
setText(text);
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:24,代码来源:StringRepresentation.java
示例18: setResponseText
import org.restlet.data.Language; //导入依赖的package包/类
/**
* A shortcut to set the response entity to a {@link StringRepresentation}.
*
* @param text
* The text
* @param mediaTypeName
* The media type or null to leave unchanged
* @param languageName
* The language or null to leave unchanged
* @param characterSetName
* The character set or null to leave unchanged
* @return The string representation
*/
public StringRepresentation setResponseText( String text, String mediaTypeName, String languageName, String characterSetName )
{
StringRepresentation representation = new StringRepresentation( text, MediaType.valueOf( mediaTypeName ), Language.valueOf( languageName ), CharacterSet.valueOf( characterSetName ) );
getResponse().setEntity( representation );
return representation;
}
开发者ID:tliron,项目名称:prudence,代码行数:20,代码来源:ConversationService.java
示例19: CompressedStringRepresentation
import org.restlet.data.Language; //导入依赖的package包/类
/**
* @param text
* The text
* @param mediaType
* The media type
* @param language
* The language
* @param characterSet
* The character set
* @param encoding
* The encoding
* @throws IOException
* In case of a compression error
*/
public CompressedStringRepresentation( CharSequence text, MediaType mediaType, Language language, CharacterSet characterSet, Encoding encoding ) throws IOException
{
super( IoUtil.compress( text, encoding, "text" ), mediaType );
if( language != null )
getLanguages().add( language );
setCharacterSet( characterSet );
getEncodings().add( encoding );
}
开发者ID:tliron,项目名称:prudence,代码行数:23,代码来源:CompressedStringRepresentation.java
示例20: setLanguages
import org.restlet.data.Language; //导入依赖的package包/类
/**
* Sets the list of languages.<br>
* <br>
* Note that when used with HTTP connectors, this property maps to the
* "Content-Language" header.
*
* @param languages
* The list of languages.
*/
public void setLanguages(List<Language> languages) {
this.languages = languages;
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:13,代码来源:Variant.java
注:本文中的org.restlet.data.Language类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论