diff options
author | Roberto E. Escobar | 2014-08-06 23:15:30 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2014-09-29 22:55:09 +0000 |
commit | 8187008050c506fa0b35a884f2760d2bb847c11f (patch) | |
tree | 2ebd7b5c3e67a6d285930ff8ddc5168cde751cf7 | |
parent | 56d079ef0a6cfb38b3c6082275ef59e21ae053f7 (diff) | |
download | org.eclipse.osee-8187008050c506fa0b35a884f2760d2bb847c11f.tar.gz org.eclipse.osee-8187008050c506fa0b35a884f2760d2bb847c11f.tar.xz org.eclipse.osee-8187008050c506fa0b35a884f2760d2bb847c11f.zip |
feature: Convert JAX-RS server to use MVC
Change-Id: Ic5053d2833967431cbfa2cabfbe612073812d236
14 files changed, 98 insertions, 179 deletions
diff --git a/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF index 651a6283804..a6a6f4c27c0 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF @@ -5,6 +5,7 @@ Bundle-SymbolicName: org.eclipse.osee.jaxrs.server Bundle-Version: 0.19.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Service-Component: OSGI-INF/*.xml +Osee-Template: OSEE-INF/templates/*.html Import-Package: com.google.common.cache, com.google.common.io, javax.annotation;version="1.2.0", @@ -63,7 +64,6 @@ Import-Package: com.google.common.cache, org.eclipse.osee.jaxrs.client, org.eclipse.osee.jaxrs.mvc, org.eclipse.osee.logger, - org.eclipse.osee.template.engine, org.osgi.framework, org.osgi.service.http Bundle-Vendor: Eclipse Open System Engineering Environment diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/html/authorization_code.html b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/authorization_code.html index ba48105ab64..ba48105ab64 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/html/authorization_code.html +++ b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/authorization_code.html diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/html/authorize_form.html b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/authorize_form.html index 5d0786152e6..5d0786152e6 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/html/authorize_form.html +++ b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/authorize_form.html diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/html/error_template.html b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/error_template.html index 0541e1c5e47..0541e1c5e47 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/html/error_template.html +++ b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/error_template.html diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/html/oauth_error.html b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/oauth_error.html index 0e685c0fb0b..0e685c0fb0b 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/html/oauth_error.html +++ b/plugins/org.eclipse.osee.jaxrs.server/OSEE-INF/templates/oauth_error.html diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/JaxRsUtils.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/JaxRsUtils.java index 03b4b003147..4ff56496f50 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/JaxRsUtils.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/JaxRsUtils.java @@ -21,10 +21,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.Response.StatusType; import org.apache.cxf.jaxrs.utils.JAXRSUtils; -import org.eclipse.osee.framework.jdk.core.type.ClassBasedResourceToken; -import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry; -import org.eclipse.osee.framework.jdk.core.type.ResourceRegistry; -import org.eclipse.osee.framework.jdk.core.type.ResourceToken; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.osgi.framework.ServiceReference; @@ -39,7 +35,7 @@ public final class JaxRsUtils { public static final String UTF_8_ENCODING = "UTF-8"; public static final List<MediaType> HTML_MEDIA_TYPES = Collections.unmodifiableList(Arrays.asList( - MediaType.APPLICATION_XHTML_XML_TYPE, MediaType.TEXT_HTML_TYPE)); + MediaType.TEXT_HTML_TYPE, MediaType.APPLICATION_XHTML_XML_TYPE)); public static boolean isHtmlSupported(List<MediaType> acceptableMediaTypes) { return !JAXRSUtils.intersectMimeTypes(acceptableMediaTypes, HTML_MEDIA_TYPES, false).isEmpty(); @@ -54,16 +50,6 @@ public final class JaxRsUtils { return toReturn; } - public static ResourceToken newTemplate(String resource, Class<?> clazz) { - return new ClassBasedResourceToken(resource, clazz); - } - - public static IResourceRegistry newSingleTemplateRegistry(ResourceToken token) { - IResourceRegistry registry = new ResourceRegistry(); - registry.registerResource(-1L, token); - return registry; - } - public static String getComponentName(ServiceReference<?> reference) { return (String) reference.getProperty("component.name"); } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/AbstractExceptionMapper.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/AbstractExceptionMapper.java index da827ba70e7..59644ec3fcc 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/AbstractExceptionMapper.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/AbstractExceptionMapper.java @@ -10,20 +10,16 @@ *******************************************************************************/ package org.eclipse.osee.jaxrs.server.internal.exceptions; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; import java.util.List; -import javax.ws.rs.WebApplicationException; +import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.UriInfo; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; +import javax.ws.rs.ext.Providers; import org.eclipse.osee.jaxrs.ErrorResponse; import org.eclipse.osee.jaxrs.OseeWebApplicationException; import org.eclipse.osee.jaxrs.server.internal.JaxRsUtils; @@ -43,6 +39,12 @@ public abstract class AbstractExceptionMapper<T extends Throwable> implements Ex } @Context + private ResourceInfo resourceInfo; + + @Context + private Providers providers; + + @Context private HttpHeaders headers; @Context @@ -73,18 +75,7 @@ public abstract class AbstractExceptionMapper<T extends Throwable> implements Ex Response toReturn = exception.getResponse(); List<MediaType> acceptableMediaTypes = headers.getAcceptableMediaTypes(); if (JaxRsUtils.isHtmlSupported(acceptableMediaTypes)) { - StreamingOutput output = new StreamingOutput() { - @Override - public void write(OutputStream output) throws IOException, WebApplicationException { - Writer writer = new OutputStreamWriter(output, JaxRsUtils.UTF_8_ENCODING); - try { - ErrorResponseMessageBodyWriter.writeErrorHtml(errorResponse, writer); - } finally { - writer.flush(); - } - } - }; - toReturn = Response.fromResponse(toReturn).entity(output).type(MediaType.TEXT_HTML_TYPE).build(); + toReturn = Response.fromResponse(toReturn).entity(errorResponse).type(MediaType.TEXT_HTML_TYPE).build(); } return toReturn; } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/ErrorResponseMessageBodyWriter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/ErrorResponseMessageBodyWriter.java index d15ed15336e..9ccb7f47b75 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/ErrorResponseMessageBodyWriter.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/exceptions/ErrorResponseMessageBodyWriter.java @@ -11,21 +11,10 @@ package org.eclipse.osee.jaxrs.server.internal.exceptions; import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.asTemplateValue; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newSingleTemplateRegistry; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newTemplate; -import java.io.Writer; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.Provider; -import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry; -import org.eclipse.osee.framework.jdk.core.type.ResourceToken; +import org.eclipse.osee.framework.jdk.core.type.ViewModel; import org.eclipse.osee.jaxrs.ErrorResponse; import org.eclipse.osee.jaxrs.server.internal.resources.AbstractHtmlWriter; -import org.eclipse.osee.template.engine.PageCreator; -import org.eclipse.osee.template.engine.PageFactory; /** * @author Roberto E. Escobar @@ -33,14 +22,12 @@ import org.eclipse.osee.template.engine.PageFactory; @Provider public class ErrorResponseMessageBodyWriter extends AbstractHtmlWriter<ErrorResponse> { - private static final ResourceToken ERROR_PAGE__TEMPLATE = newTemplate("error_template.html", - ErrorResponseMessageBodyWriter.class); + private static final String ERROR_PAGE__TEMPLATE = "error_template.html"; private static final String ERROR_PAGE__MESSAGE_TAG = "errorMessage"; private static final String ERROR_PAGE__CODE_TAG = "errorStatusCode"; private static final String ERROR_PAGE__REASON_TAG = "errorReason"; private static final String ERROR_PAGE__TYPE_TAG = "errorType"; private static final String ERROR_PAGE__EXCEPTION_TAG = "errorException"; - private static final IResourceRegistry REGISTRY = newSingleTemplateRegistry(ERROR_PAGE__TEMPLATE); @Override public Class<ErrorResponse> getSupportedClass() { @@ -48,19 +35,14 @@ public class ErrorResponseMessageBodyWriter extends AbstractHtmlWriter<ErrorResp } @Override - public void writeTo(ErrorResponse data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer writer) throws WebApplicationException { - writeErrorHtml(data, writer); - } - - public static void writeErrorHtml(ErrorResponse data, Writer writer) { - PageCreator creator = PageFactory.newPageCreator(REGISTRY, // - ERROR_PAGE__MESSAGE_TAG, asTemplateValue(data.getErrorMessage()), // - ERROR_PAGE__CODE_TAG, asTemplateValue(String.valueOf(data.getErrorCode())), // - ERROR_PAGE__REASON_TAG, asTemplateValue(data.getErrorReason()), // - ERROR_PAGE__TYPE_TAG, asTemplateValue(data.getErrorType()), // - ERROR_PAGE__EXCEPTION_TAG, asTemplateValue(data.getException()) // - ); - creator.realizePage(ERROR_PAGE__TEMPLATE, writer); + public ViewModel asViewModel(ErrorResponse data) { + ViewModel model = new ViewModel(ERROR_PAGE__TEMPLATE); + model.param(ERROR_PAGE__MESSAGE_TAG, asTemplateValue(data.getErrorMessage())); + model.param(ERROR_PAGE__CODE_TAG, asTemplateValue(String.valueOf(data.getErrorCode()))); + model.param(ERROR_PAGE__REASON_TAG, asTemplateValue(data.getErrorReason())); + model.param(ERROR_PAGE__TYPE_TAG, asTemplateValue(data.getErrorType())); + model.param(ERROR_PAGE__EXCEPTION_TAG, asTemplateValue(data.getException())); + return model; } } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/resources/AbstractHtmlWriter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/resources/AbstractHtmlWriter.java index e36d2f35392..18c2d5b90c7 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/resources/AbstractHtmlWriter.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/resources/AbstractHtmlWriter.java @@ -12,15 +12,17 @@ package org.eclipse.osee.jaxrs.server.internal.resources; import java.io.IOException; import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.util.Collection; import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; +import javax.ws.rs.ext.Providers; +import org.eclipse.osee.framework.jdk.core.type.ViewModel; import org.eclipse.osee.jaxrs.server.internal.JaxRsUtils; /** @@ -29,6 +31,9 @@ import org.eclipse.osee.jaxrs.server.internal.JaxRsUtils; @Provider public abstract class AbstractHtmlWriter<T> extends AbstractMessageBodyWriter<T> { + @Context + private Providers providers; + @Override public Collection<MediaType> getSupportedMediaTypes() { return JaxRsUtils.HTML_MEDIA_TYPES; @@ -36,14 +41,12 @@ public abstract class AbstractHtmlWriter<T> extends AbstractMessageBodyWriter<T> @Override public final void writeTo(T data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - Writer writer = new OutputStreamWriter(entityStream, JaxRsUtils.UTF_8_ENCODING); - try { - writeTo(data, type, genericType, annotations, mediaType, httpHeaders, writer); - } finally { - writer.flush(); - } + ViewModel model = asViewModel(data); + MessageBodyWriter<ViewModel> writer = + providers.getMessageBodyWriter(ViewModel.class, genericType, annotations, mediaType); + writer.writeTo(model, ViewModel.class, genericType, annotations, mediaType, httpHeaders, entityStream); } - public abstract void writeTo(T data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer writer) throws IOException, WebApplicationException; + public abstract ViewModel asViewModel(T data); } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/AuthorizationDataHtmlWriter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/AuthorizationDataHtmlWriter.java index 793b810c0da..69a1dca3851 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/AuthorizationDataHtmlWriter.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/AuthorizationDataHtmlWriter.java @@ -14,28 +14,17 @@ import static org.apache.cxf.rs.security.oauth2.utils.OAuthConstants.AUTHORIZATI import static org.apache.cxf.rs.security.oauth2.utils.OAuthConstants.AUTHORIZATION_DECISION_DENY; import static org.apache.cxf.rs.security.oauth2.utils.OAuthConstants.AUTHORIZATION_DECISION_KEY; import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.asTemplateValue; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newSingleTemplateRegistry; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newTemplate; -import java.io.Writer; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; import java.util.List; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.Provider; import org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData; import org.apache.cxf.rs.security.oauth2.common.OAuthPermission; import org.apache.cxf.rs.security.oauth2.common.Permission; import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants; -import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry; -import org.eclipse.osee.framework.jdk.core.type.ResourceToken; +import org.eclipse.osee.framework.jdk.core.type.ViewModel; import org.eclipse.osee.jaxrs.server.internal.resources.AbstractHtmlWriter; import org.eclipse.osee.jaxrs.server.internal.security.util.HiddenFormFields; import org.eclipse.osee.jaxrs.server.internal.security.util.InputFields; import org.eclipse.osee.jaxrs.server.internal.security.util.InputFields.InputType; -import org.eclipse.osee.template.engine.AppendableRule; -import org.eclipse.osee.template.engine.PageCreator; -import org.eclipse.osee.template.engine.PageFactory; /** * @author Roberto E. Escobar @@ -44,7 +33,7 @@ import org.eclipse.osee.template.engine.PageFactory; public class AuthorizationDataHtmlWriter extends AbstractHtmlWriter<OAuthAuthorizationData> { //@formatter:off - private static final ResourceToken AUTHORIZE_PAGE__TEMPLATE = newTemplate("authorize_form.html", AuthorizationDataHtmlWriter.class); + private static final String AUTHORIZE_PAGE__TEMPLATE = "authorize_form.html"; private static final String AUTHORIZE_PAGE__REPLY_TO_TAG = "replyTo"; private static final String AUTHORIZE_PAGE__DECISION_KEY_TAG = "authorizationDecisionKey"; private static final String AUTHORIZE_PAGE__DECISION_ALLOW_TAG = "authorizationDecisionAllow"; @@ -58,8 +47,6 @@ public class AuthorizationDataHtmlWriter extends AbstractHtmlWriter<OAuthAuthori private static final String AUTHORIZE_PAGE__HIDDEN_FIELDS_SECTION_TAG = "hiddenFieldsSection"; private static final String AUTHORIZE_PAGE__PERMISSIONS_SECTION_TAG = "permissionsSection"; - - private static final IResourceRegistry REGISTRY = newSingleTemplateRegistry(AUTHORIZE_PAGE__TEMPLATE); //@formatter:on @Override @@ -68,27 +55,28 @@ public class AuthorizationDataHtmlWriter extends AbstractHtmlWriter<OAuthAuthori } @Override - public void writeTo(OAuthAuthorizationData data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer writer) { - PageCreator creator = PageFactory.newPageCreator(REGISTRY, // - AUTHORIZE_PAGE__LOGGED_IN_AS_TAG, asTemplateValue(data.getEndUserName()), // - AUTHORIZE_PAGE__REPLY_TO_TAG, asTemplateValue(data.getReplyTo()), // - AUTHORIZE_PAGE__APPLICATION_NAME_TAG, asTemplateValue(data.getApplicationName()), // - AUTHORIZE_PAGE__APPLICATION_DESCRIPTION_TAG, asTemplateValue(data.getApplicationDescription()), // - AUTHORIZE_PAGE__APPLICATION_LOGO_URI_TAG, asTemplateValue(data.getApplicationLogoUri()), // - AUTHORIZE_PAGE__APPLICATION_WEB_URI_TAG, asTemplateValue(data.getApplicationWebUri()), // - AUTHORIZE_PAGE__DECISION_KEY_TAG, AUTHORIZATION_DECISION_KEY, // - AUTHORIZE_PAGE__DECISION_ALLOW_TAG, AUTHORIZATION_DECISION_ALLOW, // - AUTHORIZE_PAGE__DECISION_DENY_TAG, AUTHORIZATION_DECISION_DENY); - AppendableRule<?> hidden = HiddenFormFields.newForm(AUTHORIZE_PAGE__HIDDEN_FIELDS_SECTION_TAG) // + public ViewModel asViewModel(OAuthAuthorizationData data) { + ViewModel model = new ViewModel(AUTHORIZE_PAGE__TEMPLATE); + model.param(AUTHORIZE_PAGE__LOGGED_IN_AS_TAG, asTemplateValue(data.getEndUserName())); + model.param(AUTHORIZE_PAGE__REPLY_TO_TAG, asTemplateValue(data.getReplyTo())); + model.param(AUTHORIZE_PAGE__APPLICATION_NAME_TAG, asTemplateValue(data.getApplicationName())); + model.param(AUTHORIZE_PAGE__APPLICATION_DESCRIPTION_TAG, asTemplateValue(data.getApplicationDescription())); + model.param(AUTHORIZE_PAGE__APPLICATION_LOGO_URI_TAG, asTemplateValue(data.getApplicationLogoUri())); + model.param(AUTHORIZE_PAGE__APPLICATION_WEB_URI_TAG, asTemplateValue(data.getApplicationWebUri())); + model.param(AUTHORIZE_PAGE__DECISION_KEY_TAG, AUTHORIZATION_DECISION_KEY); + model.param(AUTHORIZE_PAGE__DECISION_ALLOW_TAG, AUTHORIZATION_DECISION_ALLOW); + model.param(AUTHORIZE_PAGE__DECISION_DENY_TAG, AUTHORIZATION_DECISION_DENY); + + model.param(AUTHORIZE_PAGE__HIDDEN_FIELDS_SECTION_TAG, HiddenFormFields.newForm() // .add(OAuthConstants.CLIENT_AUDIENCE, data.getAudience()) // .add(OAuthConstants.SESSION_AUTHENTICITY_TOKEN, data.getAuthenticityToken())// .add(OAuthConstants.CLIENT_ID, data.getClientId()) // .add(OAuthConstants.SCOPE, data.getProposedScope())// .add(OAuthConstants.REDIRECT_URI, data.getRedirectUri()) // - .add(OAuthConstants.STATE, data.getState()); // - creator.addSubstitution(hidden); + .add(OAuthConstants.STATE, data.getState())// + .build()); - InputFields input = InputFields.newListGroupContainer(AUTHORIZE_PAGE__PERMISSIONS_SECTION_TAG); + InputFields input = InputFields.newListGroupContainer(); List<? extends Permission> permissions = data.getPermissions(); if (permissions.isEmpty()) { Permission permission = new OAuthPermission("Full Data Access", "Application is able to read/write all data."); @@ -99,8 +87,8 @@ public class AuthorizationDataHtmlWriter extends AbstractHtmlWriter<OAuthAuthori addItem(input, permission); } } - creator.addSubstitution(input); - creator.realizePage(AUTHORIZE_PAGE__TEMPLATE, writer); + model.param(AUTHORIZE_PAGE__PERMISSIONS_SECTION_TAG, input.build()); + return model; } private void addItem(InputFields input, Permission perm) { @@ -108,4 +96,5 @@ public class AuthorizationDataHtmlWriter extends AbstractHtmlWriter<OAuthAuthori String key = String.format("%s_status", permissionName); input.add(key, InputType.checkbox, permissionName, perm.getDescription(), "", "allow", perm.isDefault()); } + } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OAuthErrorHtmlWriter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OAuthErrorHtmlWriter.java index 93ba8e9582a..b67463a059e 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OAuthErrorHtmlWriter.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OAuthErrorHtmlWriter.java @@ -11,20 +11,10 @@ package org.eclipse.osee.jaxrs.server.internal.security.oauth2.provider.writers; import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.asTemplateValue; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newSingleTemplateRegistry; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newTemplate; -import java.io.Writer; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.Provider; import org.apache.cxf.rs.security.oauth2.common.OAuthError; -import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry; -import org.eclipse.osee.framework.jdk.core.type.ResourceToken; +import org.eclipse.osee.framework.jdk.core.type.ViewModel; import org.eclipse.osee.jaxrs.server.internal.resources.AbstractHtmlWriter; -import org.eclipse.osee.template.engine.PageCreator; -import org.eclipse.osee.template.engine.PageFactory; /** * @author Roberto E. Escobar @@ -33,28 +23,25 @@ import org.eclipse.osee.template.engine.PageFactory; public class OAuthErrorHtmlWriter extends AbstractHtmlWriter<OAuthError> { //@formatter:off - private static final ResourceToken ERROR_PAGE__TEMPLATE = newTemplate("oauth_error.html", OAuthErrorHtmlWriter.class); + private static final String ERROR_PAGE__TEMPLATE = "oauth_error.html"; private static final String ERROR_PAGE__CODE_TAG = "errorCode"; private static final String ERROR_PAGE__DESCRIPTION_TAG = "errorDescription"; private static final String ERROR_PAGE__ERROR_URI = "errorUri"; private static final String ERROR_PAGE__ERROR_STATE = "errorState"; //@formatter:on - private static final IResourceRegistry registry = newSingleTemplateRegistry(ERROR_PAGE__TEMPLATE); - @Override public Class<OAuthError> getSupportedClass() { return OAuthError.class; } @Override - public void writeTo(OAuthError data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer writer) { - PageCreator creator = PageFactory.newPageCreator(registry, // - ERROR_PAGE__CODE_TAG, asTemplateValue(data.getError()), // - ERROR_PAGE__DESCRIPTION_TAG, asTemplateValue(data.getErrorDescription()), // - ERROR_PAGE__ERROR_URI, asTemplateValue(data.getErrorUri()), // - ERROR_PAGE__ERROR_STATE, asTemplateValue(data.getState())); - creator.realizePage(ERROR_PAGE__TEMPLATE, writer); + public ViewModel asViewModel(OAuthError data) { + ViewModel model = new ViewModel(ERROR_PAGE__TEMPLATE); + model.param(ERROR_PAGE__CODE_TAG, asTemplateValue(data.getError())); + model.param(ERROR_PAGE__DESCRIPTION_TAG, asTemplateValue(data.getErrorDescription())); + model.param(ERROR_PAGE__ERROR_URI, asTemplateValue(data.getErrorUri())); + model.param(ERROR_PAGE__ERROR_STATE, asTemplateValue(data.getState())); + return model; } - } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OOBAuthorizationResponseHtmlWriter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OOBAuthorizationResponseHtmlWriter.java index b3dbd694772..ef31720b92f 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OOBAuthorizationResponseHtmlWriter.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/provider/writers/OOBAuthorizationResponseHtmlWriter.java @@ -11,21 +11,11 @@ package org.eclipse.osee.jaxrs.server.internal.security.oauth2.provider.writers; import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.asTemplateValue; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newSingleTemplateRegistry; -import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.newTemplate; import static org.eclipse.osee.jaxrs.server.internal.security.oauth2.OAuthUtil.asExpirationValue; -import java.io.Writer; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.Provider; import org.apache.cxf.rs.security.oauth2.common.OOBAuthorizationResponse; -import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry; -import org.eclipse.osee.framework.jdk.core.type.ResourceToken; +import org.eclipse.osee.framework.jdk.core.type.ViewModel; import org.eclipse.osee.jaxrs.server.internal.resources.AbstractHtmlWriter; -import org.eclipse.osee.template.engine.PageCreator; -import org.eclipse.osee.template.engine.PageFactory; /** * @author Roberto E. Escobar @@ -34,27 +24,25 @@ import org.eclipse.osee.template.engine.PageFactory; public class OOBAuthorizationResponseHtmlWriter extends AbstractHtmlWriter<OOBAuthorizationResponse> { //@formatter:off - private static final ResourceToken AUTH_CODE_PAGE__TEMPLATE = newTemplate("authorization_code.html", OOBAuthorizationResponseHtmlWriter.class); + private static final String AUTH_CODE_PAGE__TEMPLATE = "authorization_code.html"; private static final String AUTH_CODE_PAGE__CODE_TAG = "authorizationCode"; private static final String AUTH_CODE_PAGE__CLIENT_ID_TAG = "clientId"; private static final String AUTH_CODE_PAGE__EXPIRES_IN_TAG = "expiresIn"; private static final String AUTH_CODE_PAGE__LOGGED_IN_AS_TAG = "loggedInAs"; //@formatter:on - private static final IResourceRegistry REGISTRY = newSingleTemplateRegistry(AUTH_CODE_PAGE__TEMPLATE); - @Override public Class<OOBAuthorizationResponse> getSupportedClass() { return OOBAuthorizationResponse.class; } @Override - public void writeTo(OOBAuthorizationResponse data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer writer) { - PageCreator creator = PageFactory.newPageCreator(REGISTRY, // - AUTH_CODE_PAGE__CODE_TAG, asTemplateValue(data.getAuthorizationCode()), // - AUTH_CODE_PAGE__CLIENT_ID_TAG, asTemplateValue(data.getClientId()), // - AUTH_CODE_PAGE__EXPIRES_IN_TAG, asExpirationValue(data.getExpiresIn()), // - AUTH_CODE_PAGE__LOGGED_IN_AS_TAG, asTemplateValue(data.getUserId())); - creator.realizePage(AUTH_CODE_PAGE__TEMPLATE, writer); + public ViewModel asViewModel(OOBAuthorizationResponse data) { + ViewModel model = new ViewModel(AUTH_CODE_PAGE__TEMPLATE); + model.param(AUTH_CODE_PAGE__CODE_TAG, asTemplateValue(data.getAuthorizationCode())); + model.param(AUTH_CODE_PAGE__CLIENT_ID_TAG, asTemplateValue(data.getClientId())); + model.param(AUTH_CODE_PAGE__EXPIRES_IN_TAG, asExpirationValue(data.getExpiresIn())); + model.param(AUTH_CODE_PAGE__LOGGED_IN_AS_TAG, asTemplateValue(data.getUserId())); + return model; } } diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/HiddenFormFields.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/HiddenFormFields.java index 68250e526ab..fd07f49e520 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/HiddenFormFields.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/HiddenFormFields.java @@ -11,26 +11,20 @@ package org.eclipse.osee.jaxrs.server.internal.security.util; import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.asTemplateValue; -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.template.engine.AppendableRule; /** * @author Roberto E. Escobar */ -public final class HiddenFormFields extends AppendableRule<Object> { +public final class HiddenFormFields { private final Map<String, String> data = new HashMap<String, String>(); - public static HiddenFormFields newForm(String tag) { - return new HiddenFormFields(tag); - } - - private HiddenFormFields(String ruleName) { - super(ruleName); + public static HiddenFormFields newForm() { + return new HiddenFormFields(); } public HiddenFormFields add(String key, String value) { @@ -38,19 +32,20 @@ public final class HiddenFormFields extends AppendableRule<Object> { return this; } - private void write(Appendable writer, String name, String value) throws IOException { + private void write(StringBuilder writer, String name, String value) { if (Strings.isValid(value)) { writer.append(String.format("<input type=\"hidden\" name=\"%s\" value=\"%s\">\n", name, asTemplateValue(value))); } } - @Override - public void applyTo(Appendable writer) throws IOException { - writer.append("<div class=\"form-group\">\n"); + public String build() { + StringBuilder builder = new StringBuilder(); + builder.append("<div class=\"form-group\">\n"); for (Entry<String, String> entry : data.entrySet()) { - write(writer, entry.getKey(), entry.getValue()); + write(builder, entry.getKey(), entry.getValue()); } - writer.append("</div>\n"); + builder.append("</div>\n"); + return builder.toString(); } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/InputFields.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/InputFields.java index 37e2917c4b5..825fdc60803 100644 --- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/InputFields.java +++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/util/InputFields.java @@ -11,17 +11,15 @@ package org.eclipse.osee.jaxrs.server.internal.security.util; import static org.eclipse.osee.jaxrs.server.internal.JaxRsUtils.asTemplateValue; -import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.template.engine.AppendableRule; /** * @author Roberto E. Escobar */ -public final class InputFields extends AppendableRule<Object> { +public final class InputFields { public static enum InputType { text, @@ -54,24 +52,23 @@ public final class InputFields extends AppendableRule<Object> { } } - public static InputFields newListGroup(String tag) { - return new InputFields(tag, ContainerType.LIST_GROUP, false); + public static InputFields newListGroup() { + return new InputFields(ContainerType.LIST_GROUP, false); } - public static InputFields newListGroupContainer(String tag) { - return new InputFields(tag, ContainerType.LIST_GROUP, true); + public static InputFields newListGroupContainer() { + return new InputFields(ContainerType.LIST_GROUP, true); } - public static InputFields newForm(String tag) { - return new InputFields(tag, ContainerType.FORM_GROUP, false); + public static InputFields newForm() { + return new InputFields(ContainerType.FORM_GROUP, false); } private final Map<String, Data> data = new LinkedHashMap<String, Data>(); private final ContainerType containerType; private final boolean wrapInContainer; - private InputFields(String ruleName, ContainerType containerType, boolean wrapInContainer) { - super(ruleName); + private InputFields(ContainerType containerType, boolean wrapInContainer) { this.containerType = containerType; this.wrapInContainer = wrapInContainer; } @@ -101,7 +98,7 @@ public final class InputFields extends AppendableRule<Object> { return this; } - private void write(Appendable writer, String msg, Object... data) throws IOException { + private void write(StringBuilder writer, String msg, Object... data) { writer.append(String.format(msg, data)); } @@ -121,7 +118,7 @@ public final class InputFields extends AppendableRule<Object> { return toReturn; } - private void write(Appendable writer, String key, Data data) throws IOException { + private void write(StringBuilder writer, String key, Data data) { write(writer, "<div class=\"%s%s\">\n", containerType.getStyle(), ifTrue(" has-error", data.hasError)); switch (data.type) { case checkbox: @@ -150,17 +147,18 @@ public final class InputFields extends AppendableRule<Object> { writer.append("</div>\n"); } - @Override - public void applyTo(Appendable writer) throws IOException { + public String build() { + StringBuilder builder = new StringBuilder(); if (wrapInContainer) { - writer.append("<div class=\"container\">\n"); + builder.append("<div class=\"container\">\n"); } for (Entry<String, Data> entry : data.entrySet()) { - write(writer, entry.getKey(), entry.getValue()); + write(builder, entry.getKey(), entry.getValue()); } if (wrapInContainer) { - writer.append("</div>\n"); + builder.append("</div>\n"); } + return builder.toString(); } private class Data { |