Search in sources :

Example 1 with Grammars

use of com.sun.research.ws.wadl.Grammars in project jersey by jersey.

the class WadlApplicationContextImpl method attachExternalGrammar.

/**
     * Update the application object to include the generated grammar objects.
     */
private void attachExternalGrammar(final Application application, final ApplicationDescription applicationDescription, URI requestURI) {
    try {
        final String requestURIPath = requestURI.getPath();
        if (requestURIPath.endsWith("application.wadl")) {
            requestURI = UriBuilder.fromUri(requestURI).replacePath(requestURIPath.substring(0, requestURIPath.lastIndexOf('/') + 1)).build();
        }
        final String root = application.getResources().get(0).getBase();
        final UriBuilder extendedPath = root != null ? UriBuilder.fromPath(root).path("/application.wadl/") : UriBuilder.fromPath("./application.wadl/");
        final URI rootURI = root != null ? UriBuilder.fromPath(root).build() : null;
        // Add a reference to this grammar
        //
        final Grammars grammars;
        if (application.getGrammars() != null) {
            LOGGER.info(LocalizationMessages.ERROR_WADL_GRAMMAR_ALREADY_CONTAINS());
            grammars = application.getGrammars();
        } else {
            grammars = new Grammars();
            application.setGrammars(grammars);
        }
        for (final String path : applicationDescription.getExternalMetadataKeys()) {
            final URI schemaURI = extendedPath.clone().path(path).build();
            final String schemaPath = rootURI != null ? requestURI.relativize(schemaURI).toString() : schemaURI.toString();
            final Include include = new Include();
            include.setHref(schemaPath);
            final Doc doc = new Doc();
            doc.setLang("en");
            doc.setTitle("Generated");
            include.getDoc().add(doc);
            // Finally add to list
            grammars.getInclude().add(include);
        }
    } catch (final Exception e) {
        throw new ProcessingException(LocalizationMessages.ERROR_WADL_EXTERNAL_GRAMMAR(), e);
    }
}
Also used : Include(com.sun.research.ws.wadl.Include) Doc(com.sun.research.ws.wadl.Doc) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Grammars(com.sun.research.ws.wadl.Grammars) JAXBException(javax.xml.bind.JAXBException) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

Doc (com.sun.research.ws.wadl.Doc)1 Grammars (com.sun.research.ws.wadl.Grammars)1 Include (com.sun.research.ws.wadl.Include)1 URI (java.net.URI)1 ProcessingException (javax.ws.rs.ProcessingException)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 JAXBException (javax.xml.bind.JAXBException)1