本文整理汇总了Java中org.restlet.data.CharacterSet类的典型用法代码示例。如果您正苦于以下问题:Java CharacterSet类的具体用法?Java CharacterSet怎么用?Java CharacterSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CharacterSet类属于org.restlet.data包,在下文中一共展示了CharacterSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVariant
import org.restlet.data.CharacterSet; //导入依赖的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;
}
示例2: representRdfXml
import org.restlet.data.CharacterSet; //导入依赖的package包/类
private Representation representRdfXml( final EntityState entity )
throws ResourceException
{
Representation representation = new WriterRepresentation( MediaType.APPLICATION_RDF_XML )
{
@Override
public void write( Writer writer )
throws IOException
{
try
{
Iterable<Statement> statements = entitySerializer.serialize( entity );
new RdfXmlSerializer().serialize( statements, writer );
}
catch( RDFHandlerException e )
{
throw new IOException( e );
}
}
};
representation.setCharacterSet( CharacterSet.UTF_8 );
return representation;
}
示例3: writeRequest
import org.restlet.data.CharacterSet; //导入依赖的package包/类
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
if (requestObject instanceof Form)
{
// Form as query parameters
if (request.getMethod().equals(Method.GET))
request.getResourceRef().setQuery(((Form)requestObject).getQueryString());
else
request.setEntity(((Form)requestObject).getWebRepresentation(CharacterSet.UTF_8));
return true;
}
return false;
}
示例4: writeFragment
import org.restlet.data.CharacterSet; //导入依赖的package包/类
@Override
protected void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException {
TMXMLWriter writer = new TMXMLWriter(new OutputStreamWriter(outputStream), characterSet.getName());
if (source instanceof TopicMapIF) {
writer.write((TopicMapIF) source);
}
if (source instanceof TopicIF) {
TopicIF topic = (TopicIF) source;
try {
writer.gatherPrefixes(topic);
writer.startTopicMap(topic.getTopicMap());
writer.writeTopic(topic);
writer.endTopicMap();
} catch (SAXException sax) {
throw new OntopiaServerException(sax);
}
}
}
示例5: finalizeZip
import org.restlet.data.CharacterSet; //导入依赖的package包/类
protected Representation finalizeZip(List<String> config, ZipOutputStream zip, ByteArrayOutputStream baos) throws Exception {
String file = "";
for (String s : config) {
file += s + '\n';
}
if (caCert == null) {
caCert = IOUtils.toByteArray(new FileInputStream(VPN.cfg.getProperty("ca.crt")));
}
ZipEntry configFile = new ZipEntry("neutrinet.ovpn");
configFile.setCreationTime(FileTime.from(Instant.now()));
zip.putNextEntry(configFile);
zip.write(file.getBytes());
zip.putNextEntry(new ZipEntry("ca.crt"));
zip.write(caCert);
zip.close();
ByteArrayRepresentation rep = new ByteArrayRepresentation(baos.toByteArray());
rep.setMediaType(MediaType.APPLICATION_ZIP);
rep.setSize(baos.size());
rep.setCharacterSet(CharacterSet.UTF_8);
rep.setDisposition(new Disposition(Disposition.TYPE_ATTACHMENT));
return rep;
}
示例6: doGet
import org.restlet.data.CharacterSet; //导入依赖的package包/类
@Get("html")
public Representation doGet() throws IOException {
ContextResource contextResource = getContextResource();
Request request = contextResource.getRequest();
OAuthCallbackState callbackState = new OAuthCallbackState(stateCrypter, contextResource.getParameter(CALLBACK_STATE_PARAM));
if (callbackState.getRealCallbackUrl() != null) {
// Copy the query parameters from this URL over to the real URL.
UriBuilder realUri = UriBuilder.parse(callbackState.getRealCallbackUrl());
Map<String, List<String>> params = UriBuilder.splitParameters(request.getResourceRef().getQuery());
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
realUri.putQueryParameter(entry.getKey(), entry.getValue());
}
realUri.removeQueryParameter(CALLBACK_STATE_PARAM);
ResourceUtil.setCachingHeaders(contextResource, ONE_HOUR_IN_SECONDS, true);
Response response = contextResource.getResponse();
response.setLocationRef(new Reference(realUri.toString()));
response.setStatus(Status.REDIRECTION_FOUND);
return contextResource.consolidate();
}
ResourceUtil.setCachingHeaders(contextResource, ONE_HOUR_IN_SECONDS, true);
contextResource.setCharacterSet(CharacterSet.UTF_8);
contextResource.setMediaType(MediaType.TEXT_HTML);
contextResource.append(RESP_BODY);
return contextResource.consolidate();
}
示例7: entityHeaders
import org.restlet.data.CharacterSet; //导入依赖的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;
}
示例8: representRdf
import org.restlet.data.CharacterSet; //导入依赖的package包/类
private Representation representRdf()
throws ResourceException
{
try
{
final Stream<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() );
WriterRepresentation representation = new WriterRepresentation( MediaType.APPLICATION_RDF_XML )
{
@Override
public void write( Writer writer )
throws IOException
{
PrintWriter out = new PrintWriter( writer );
out.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<rdf:RDF\n"
+ "\txmlns=\"urn:polygene:\"\n" + "\txmlns:polygene=\"http://polygene.apache.org/rdf/model/1.0/\"\n"
+ "\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
+ "\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">" );
query.forEach( qualifiedIdentity -> out.println( "<polygene:entity rdf:about=\""
+ getRequest().getResourceRef().getPath() + "/"
+ qualifiedIdentity.identity() + ".rdf\"/>" ) );
out.println( "</rdf:RDF>" );
}
};
representation.setCharacterSet( CharacterSet.UTF_8 );
return representation;
}
catch( EntityFinderException e )
{
throw new ResourceException( Status.SERVER_ERROR_INTERNAL, e );
}
}
示例9: representHtml
import org.restlet.data.CharacterSet; //导入依赖的package包/类
private Representation representHtml()
throws ResourceException
{
try
{
Stream<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() );
Representation representation = new WriterRepresentation( MediaType.TEXT_HTML )
{
@Override
public void write( Writer buf )
throws IOException
{
PrintWriter out = new PrintWriter( buf );
out.println( "<html><head><title>All entities</title></head><body><h1>All entities</h1><ul>" );
query.forEach( entity -> out.println( "<li><a href=\""
+ getRequest().getResourceRef().clone().addSegment( entity.identity() + ".html" )
+ "\">" + entity.identity() + "</a></li>" ) );
out.println( "</ul></body></html>" );
}
};
representation.setCharacterSet( CharacterSet.UTF_8 );
return representation;
}
catch( EntityFinderException e )
{
throw new ResourceException( e );
}
}
示例10: getStream
import org.restlet.data.CharacterSet; //导入依赖的package包/类
@Override
public InputStream getStream() throws IOException {
CharacterSet charset = getCharacterSet() == null ? CharacterSet.ISO_8859_1
: getCharacterSet();
ByteArrayInputStream result = new ByteArrayInputStream(getText()
.getBytes(charset.getName()));
return result;
}
示例11: init
import org.restlet.data.CharacterSet; //导入依赖的package包/类
/**
*
* @param jsonObject
*/
private void init(Object jsonObject) {
setCharacterSet(CharacterSet.UTF_8);
this.jsonValue = jsonObject;
this.indenting = false;
this.indentingSize = 3;
}
示例12: setResponseText
import org.restlet.data.CharacterSet; //导入依赖的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;
}
示例13: toRepresentation
import org.restlet.data.CharacterSet; //导入依赖的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: write
import org.restlet.data.CharacterSet; //导入依赖的package包/类
@Override
public void write(Writer writer) throws IOException {
if (representation != null) {
representation.write(writer);
} else if (object != null) {
CharacterSet charSet = (getCharacterSet() == null) ? CharacterSet.UTF_8 : getCharacterSet();
if (!MediaType.APPLICATION_JSON.isCompatible(getMediaType())) {
writer.append("<?xml version=\"1.0\" encoding=\"" + charSet.getName() + "\" ?>\n");
}
getXstream().toXML(object, writer);
}
}
示例15: fetch
import org.restlet.data.CharacterSet; //导入依赖的package包/类
/**
* Executes a request, returning the response as JSON to be handled by makeRequest.
*/
public void fetch(ContextResource contextResource) throws GadgetException, IOException {
HttpRequest rcr = buildHttpRequest(contextResource);
// Serialize the response
HttpResponse results = requestPipeline.execute(rcr);
// Rewrite the response
if (contentRewriterRegistry != null) {
try {
results = contentRewriterRegistry.rewriteHttpResponse(rcr, results);
} catch (RewritingException e) {
throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e, e.getHttpStatusCode());
}
}
// Serialize the response
String output = convertResponseToJson(contextResource, rcr.getSecurityToken(), results);
// Find and set the refresh interval
setResponseHeaders(contextResource, results);
contextResource.setStatus(Status.SUCCESS_OK);
contextResource.setMediaType(MediaType.APPLICATION_JSON);
contextResource.setCharacterSet(CharacterSet.UTF_8);
contextResource.setText(UNPARSEABLE_CRUFT + output);
}