org.restlet.data.CharacterSet Java Examples
The following examples show how to use
org.restlet.data.CharacterSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TMXMLConverter.java From ontopia with Apache License 2.0 | 6 votes |
@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); } } }
Example #2
Source File: FormRequestWriter.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@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; }
Example #3
Source File: EntityResource.java From attic-polygene-java with Apache License 2.0 | 6 votes |
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; }
Example #4
Source File: AbstractResponseWriter.java From attic-polygene-java with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: AbstractConverter.java From ontopia with Apache License 2.0 | 5 votes |
@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); } }; }
Example #6
Source File: EntitiesResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
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 ); } }
Example #7
Source File: EntitiesResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
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 ); } }
Example #8
Source File: StringRepresentation.java From DeviceConnect-Android with MIT License | 5 votes |
@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; }
Example #9
Source File: EntityResource.java From attic-polygene-java with Apache License 2.0 | 5 votes |
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; }
Example #10
Source File: JsonRepresentation.java From DeviceConnect-Android with MIT License | 5 votes |
/** * * @param jsonObject */ private void init(Object jsonObject) { setCharacterSet(CharacterSet.UTF_8); this.jsonValue = jsonObject; this.indenting = false; this.indentingSize = 3; }
Example #11
Source File: LTMConverter.java From ontopia with Apache License 2.0 | 4 votes |
@Override protected void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException { new LTMTopicMapWriter(outputStream, characterSet.getName()).write((TopicMapIF) source); }
Example #12
Source File: CTMConverter.java From ontopia with Apache License 2.0 | 4 votes |
@Override protected void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException { //throw new OntopiaServerException("CTM writing is not yet implemented in Ontopia", new UnsupportedOperationException()); }
Example #13
Source File: JTMConverter.java From ontopia with Apache License 2.0 | 4 votes |
@Override protected void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException { JTMTopicMapWriter writer = new JTMTopicMapWriter(outputStream, characterSet.getName()); writer.write((TMObjectIF) source); }
Example #14
Source File: ValueCompositeRequestWriter.java From attic-polygene-java with Apache License 2.0 | 4 votes |
@Override public boolean writeRequest(Object requestObject, Request request) throws ResourceException { if (requestObject instanceof ValueComposite) { // Value as parameter final ValueComposite valueObject = (ValueComposite) requestObject; if (request.getMethod().equals(Method.GET)) { StateHolder holder = spi.stateOf( valueObject ); final ValueDescriptor descriptor = spi.valueDescriptorFor( valueObject ); final Reference ref = request.getResourceRef(); ref.setQuery( null ); descriptor.state().properties().forEach( propertyDescriptor -> { try { Object value = holder.propertyFor( propertyDescriptor.accessor() ).get(); String param; if( value == null ) { param = null; } else { param = serializer.serialize( value ); } ref.addQueryParameter( propertyDescriptor.qualifiedName().name(), param ); } catch( SerializationException e ) { throw new ResourceException( e ); } } ); } else { request.setEntity(new WriterRepresentation( MediaType.APPLICATION_JSON ) { @Override public void write( Writer writer ) throws IOException { setCharacterSet( CharacterSet.UTF_8 ); serializer.serialize( writer, valueObject ); } }); } return true; } return false; }
Example #15
Source File: StringRepresentation.java From DeviceConnect-Android with MIT License | 4 votes |
@Override public void setCharacterSet(CharacterSet characterSet) { super.setCharacterSet(characterSet); updateSize(); }
Example #16
Source File: FormUtils.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Reads the parameters with the given name.<br> * If multiple values are found, a list is returned created. * * @param query * The query string. * @param name * The parameter name to match. * @param characterSet * The supported character encoding. * @param separator * The separator character to append between parameters. * @param decode * Indicates if the parameters should be decoded using the given * character set. s * @return The parameter value or list of * values. * @throws IOException * If the parameters could not be read. */ public static Object getParameter(String query, String name, CharacterSet characterSet, char separator, boolean decode) throws IOException { return new FormReader(query, characterSet, separator, decode) .readParameter(name); }
Example #17
Source File: StringRepresentation.java From DeviceConnect-Android with MIT License | 3 votes |
/** * 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); }
Example #18
Source File: FormReader.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Constructor. * * @param parametersString * The parameters string. * @param characterSet * The supported character encoding. Set to null to leave the * data encoded. * @param separator * The separator character used between parameters. * @param decode * Indicates if the parameters should be decoded using the given * character set. */ public FormReader(String parametersString, CharacterSet characterSet, char separator, boolean decode) { this.decode = decode; this.stream = new ByteArrayInputStream(parametersString.getBytes()); this.characterSet = characterSet; this.separator = separator; }
Example #19
Source File: FormReader.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Constructor.<br> * In case the representation does not define a character set, the UTF-8 * character set is used. * * @param representation * The web form content. * @param decode * Indicates if the parameters should be decoded using the given * character set. * @throws IOException * if the stream of the representation could not be opened. */ public FormReader(Representation representation, boolean decode) throws IOException { this.decode = decode; this.stream = representation.getStream(); this.separator = '&'; if (representation.getCharacterSet() != null) { this.characterSet = representation.getCharacterSet(); } else { this.characterSet = CharacterSet.UTF_8; } }
Example #20
Source File: FormUtils.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Parses a parameters string into a given form. * * @param form * The target form. * @param parametersString * The parameters string. * @param characterSet * The supported character encoding. * @param decode * Indicates if the parameters should be decoded using the given * character set. * @param separator * The separator character to append between parameters. */ public static void parse(Form form, String parametersString, CharacterSet characterSet, boolean decode, char separator) { if ((parametersString != null) && !parametersString.equals("")) { FormReader fr = null; fr = new FormReader(parametersString, characterSet, separator, decode); fr.addParameters(form); } }
Example #21
Source File: FormUtils.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Reads the parameters whose name is a key in the given map.<br> * If a matching parameter is found, its value is put in the map.<br> * If multiple values are found, a list is created and set in the map. * * @param parametersString * The query string. * @param parameters * The parameters map controlling the reading. * @param characterSet * The supported character encoding. * @param separator * The separator character to append between parameters. * @param decode * Indicates if the parameters should be decoded using the given * character set. * @throws IOException * If the parameters could not be read. */ public static void getParameters(String parametersString, Map<String, Object> parameters, CharacterSet characterSet, char separator, boolean decode) throws IOException { new FormReader(parametersString, characterSet, separator, decode) .readParameters(parameters); }
Example #22
Source File: FormUtils.java From DeviceConnect-Android with MIT License | 3 votes |
/** * Reads the first parameter with the given name. * * @param query * The query string. * @param name * The parameter name to match. * @param characterSet * The supported character encoding. * @param separator * The separator character to append between parameters. * @param decode * Indicates if the parameters should be decoded using the given * character set. * @return The parameter. * @throws IOException */ public static Parameter getFirstParameter(String query, String name, CharacterSet characterSet, char separator, boolean decode) throws IOException { return new FormReader(query, characterSet, separator, decode) .readFirstParameter(name); }
Example #23
Source File: JsonRepresentation.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Constructor from a JSON string. * * @param jsonString * The JSON string. */ public JsonRepresentation(String jsonString) { super(MediaType.APPLICATION_JSON); setCharacterSet(CharacterSet.UTF_8); this.jsonRepresentation = new StringRepresentation(jsonString); }
Example #24
Source File: CharacterRepresentation.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Constructor. * * @param mediaType * The media type. */ public CharacterRepresentation(MediaType mediaType) { super(mediaType); setCharacterSet(CharacterSet.UTF_8); }
Example #25
Source File: StringRepresentation.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Constructor. The following metadata are used by default: UTF-8 character * set. * * @param text * The string value. * @param mediaType * The media type. * @param language * The language. */ public StringRepresentation(CharSequence text, MediaType mediaType, Language language) { this(text, mediaType, language, CharacterSet.UTF_8); }
Example #26
Source File: Variant.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Sets the character set or null if not applicable.<br> * <br> * Note that when used with HTTP connectors, this property maps to the * "Content-Type" header. * * @param characterSet * The character set or null if not applicable. */ public void setCharacterSet(CharacterSet characterSet) { this.characterSet = characterSet; }
Example #27
Source File: Variant.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Returns the character set or null if not applicable. Note that when used * with HTTP connectors, this property maps to the "Content-Type" header. * * @return The character set or null if not applicable. */ public CharacterSet getCharacterSet() { return this.characterSet; }
Example #28
Source File: FormReader.java From DeviceConnect-Android with MIT License | 2 votes |
/** * Constructor. * * @param parametersString * The parameters string. * @param characterSet * The supported character encoding. Set to null to leave the * data encoded. * @param separator * The separator character used between parameters. */ public FormReader(String parametersString, CharacterSet characterSet, char separator) { this(parametersString, characterSet, separator, true); }
Example #29
Source File: AbstractConverter.java From ontopia with Apache License 2.0 | votes |
protected abstract void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException;