public EngineApplication(Engine engine) { this.engine = engine; getMetadataService().addExtension("log", MediaType.TEXT_PLAIN ); getMetadataService().addExtension("cxml", MediaType.APPLICATION_XML ); setStatusService(new EngineStatusService()); }
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
/** * Constructor. By default, it creates the necessary services. * * @param enabled * True if the service has been enabled. * */ public StatusService(boolean enabled) { this(enabled, new ConverterService(), new MetadataService(), new ConnegService()); // this.homeRef = new Reference("/"); }
/** * Returns the character set associated to this extension. It returns null * if the extension was not declared of it is corresponds to another type of * medatata such as a media type. If several metadata are associated to the * same extension then only the first matching metadata is returned. * * * @param extension * The extension name without any delimiter. * @return The character set associated to this extension. */ public CharacterSet getCharacterSet(String extension) { return getMetadata(extension, CharacterSet.class); }
/** * Returns the virtual extension for the given language. * * @param language * the language to get the virtual file extension for. * @return the extension for the given language. Returns null, if no mapping * could be found. */ public String getByLanguage(Locale language) { return this.metadataService .getExtension(Converter.toLanguage(language)); }
Language language = (Language) metadata; defaultMetadata = language.equals(getMetadataService() .getDefaultLanguage()); } else if (metadata instanceof MediaType) { MediaType mediaType = (MediaType) metadata; defaultMetadata = mediaType.equals(getMetadataService() .getDefaultMediaType()); } else if (metadata instanceof CharacterSet) { CharacterSet characterSet = (CharacterSet) metadata; defaultMetadata = characterSet.equals(getMetadataService() .getDefaultCharacterSet()); } else if (metadata instanceof Encoding) { Encoding encoding = (Encoding) metadata; defaultMetadata = encoding.equals(getMetadataService() .getDefaultEncoding()); String extension = getMetadataService().getExtension(metadata);
current = metadataService.getMetadata(tokens[j]); current = metadataService.getMetadata(primaryPart); if (current instanceof Language) { variant.getLanguages().add((Language) current); .getDefaultLanguage(); .getDefaultMediaType(); .getDefaultEncoding(); .getDefaultCharacterSet();
this.getConnectorService().getClientProtocols().add(Protocol.CLAP); this.getMetadataService().setDefaultCharacterSet(CharacterSet.UTF_8); this.getMetadataService().addExtension("rdf", MediaType.APPLICATION_RDF_XML, true); this.getMetadataService().addExtension("rj", RestletUtilMediaType.APPLICATION_RDF_JSON, true); this.getMetadataService().addExtension("owl", MediaType.APPLICATION_RDF_XML, false); this.getMetadataService().addExtension("json", MediaType.APPLICATION_JSON, true); this.getMetadataService().addExtension("ttl", MediaType.APPLICATION_RDF_TURTLE, true); this.getMetadataService().addExtension("n3", MediaType.TEXT_RDF_N3, true); this.getMetadataService().addExtension("nt", MediaType.TEXT_RDF_NTRIPLES, true); this.getMetadataService().addExtension("nq", MediaType.register("text/nquads", "The NQuads extension to the NTriples RDF serialisation"), true); this.getMetadataService().addExtension("js", MediaType.TEXT_JAVASCRIPT, true); this.getMetadataService().addExtension("css", MediaType.TEXT_CSS, true); this.getMetadataService().addExtension("multipart", MediaType.MULTIPART_FORM_DATA, true); this.getMetadataService().addExtension("form", MediaType.APPLICATION_WWW_FORM, false);
.getEntity().getMediaType(); List<MediaType> amts = getMetadataService() .getAllMediaTypes( methodAnnotationInfo .getInput());
/** * Constructor. Sets the default language to {@link Language#ENGLISH_US}, * the default encoding to {@link Encoding#IDENTITY} (no encoding) and the * default media type to {@link MediaType#APPLICATION_OCTET_STREAM}. It also * calls the {@link #addCommonExtensions()} method. */ public MetadataService() { this.defaultEncoding = Encoding.IDENTITY; this.defaultLanguage = Language.ENGLISH_US; this.defaultMediaType = MediaType.APPLICATION_OCTET_STREAM; this.mappings = new CopyOnWriteArrayList<MetadataExtension>(); addCommonExtensions(); }
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
/** * Returns the application's metadata service or create a new one. * * @return The metadata service. */ public MetadataService getMetadataService() { MetadataService result = null; result = getApplication().getMetadataService(); if (result == null) { result = new MetadataService(); } return result; }
/** * Returns the encoding associated to this extension. It returns null if the * extension was not declared of it is corresponds to another type of * medatata such as a media type. If several metadata are associated to the * same extension then only the first matching metadata is returned. * * @param extension * The extension name without any delimiter. * @return The encoding associated to this extension. */ public Encoding getEncoding(String extension) { return getMetadata(extension, Encoding.class); }
/** * Returns the virtual extension for the given encoding. * * @param encoding * the encoding to get the virtual file extension for. * @return the extension for the given encoding. Returns null, if no mapping * could be found. */ public String getByEncoding(String encoding) { return this.metadataService.getExtension(Encoding.valueOf(encoding)); }
/** * Constructor. Sets the default language to {@link Language#ENGLISH_US}, * the default encoding to {@link Encoding#IDENTITY} (no encoding) and the * default media type to {@link MediaType#APPLICATION_OCTET_STREAM}. It also * calls the {@link #addCommonExtensions()} method. */ public MetadataService() { this.defaultCharacterSet = CharacterSet.DEFAULT; this.defaultEncoding = Encoding.IDENTITY; this.defaultLanguage = Language.DEFAULT; this.defaultMediaType = MediaType.APPLICATION_OCTET_STREAM; this.mappings = new CopyOnWriteArrayList<MetadataExtension>(); addCommonExtensions(); }
public static String convertSampleAccordingToMediaType( Object content, String mediaTypeAsString, String representationName) { MetadataService ms = new MetadataService(); MediaType mediaType = MediaType.valueOf(mediaTypeAsString); if (!supportedExtensions.contains(ms.getExtension(mediaType))) { return null; } String text; try { text = new JacksonRepresentation<>(mediaType, content).getText(); } catch (IOException e) { throw new RuntimeException(e); } if (ms.getAllMediaTypes("xml").contains(mediaType)) { text = text.replaceAll("HashMap", representationName); } return text; }
/** * Returns the metadata service. If the parent application doesn't exist, a * new instance is created. * * @return The metadata service. */ public MetadataService getMetadataService() { MetadataService result = null; if (getHelped() != null) { org.restlet.Application application = getHelped().getApplication(); if (application != null) { result = application.getMetadataService(); } } if (result == null) { result = new MetadataService(); } return result; }
/** * Returns the language associated to this extension. It returns null if the * extension was not declared of it is corresponds to another type of * medatata such as a media type. If several metadata are associated to the * same extension then only the first matching metadata is returned. * * @param extension * The extension name without any delimiter. * @return The language associated to this extension. */ public Language getLanguage(String extension) { return getMetadata(extension, Language.class); }
/** * Returns the virtual extension for the given {@link MediaType}. * * @param mediaType * the JAX-RS media type to get the virtual file extension for. * @return the extension for the given {@link MediaType}. Returns null, if * no mapping could be found. */ public String getByMediaType(MediaType mediaType) { org.restlet.data.MediaType restletMediaType; restletMediaType = Converter.toRestletMediaType(mediaType); return this.metadataService.getExtension(restletMediaType); } }
/** * Maps an extension to some metadata (media type, language or character * set) to an extension. * * @param extension * The extension name. * @param metadata * The metadata to map. */ public void addExtension(String extension, Metadata metadata) { addExtension(extension, metadata, false); }