X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=server%2Fruntime%2Forg.argeo.server.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fmvc%2FSerializingView.java;h=b42a9a0d279300e6bad4e61bfcaa1ebaf662decc;hb=3a3d316af102ba410d1d9e6de349d0c8f7ac044f;hp=05befd68d6d3a6919e604ce6d91e390b992bf172;hpb=ff2edf71a6223a88a10d2f6c51db2797bfb0c4b9;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/mvc/SerializingView.java b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/mvc/SerializingView.java index 05befd68d..b42a9a0d2 100644 --- a/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/mvc/SerializingView.java +++ b/server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/mvc/SerializingView.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.server.mvc; import java.util.Locale; @@ -10,13 +25,23 @@ import org.argeo.ArgeoException; import org.argeo.server.ServerAnswer; import org.argeo.server.ServerSerializer; import org.springframework.validation.BindingResult; +import org.springframework.web.servlet.View; import org.springframework.web.servlet.view.AbstractView; +/** + * Can be used as a standalone {@link View} or using + * {@link SerializingViewResolver} + */ public class SerializingView extends AbstractView implements MvcConstants { private final String viewName; private final Locale locale; - private final ServerSerializer serializer; + private ServerSerializer serializer; + + public SerializingView() { + this.viewName = null; + this.locale = Locale.getDefault(); + } public SerializingView(String viewName, Locale locale, ServerSerializer serializer) { @@ -25,7 +50,7 @@ public class SerializingView extends AbstractView implements MvcConstants { this.serializer = serializer; } - @SuppressWarnings({ "unchecked", "restriction" }) + @SuppressWarnings({ "rawtypes" }) @Override protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) @@ -46,7 +71,7 @@ public class SerializingView extends AbstractView implements MvcConstants { } } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") protected Object findAnswerInModel(Map model) { if (model.size() == 1) { return model.values().iterator().next(); @@ -68,7 +93,7 @@ public class SerializingView extends AbstractView implements MvcConstants { return model.get(ANSWER_MODEL_KEY); } else if (model.containsKey(ANSWER_MODEL_KEY_AS_HTML)) { return model.get(ANSWER_MODEL_KEY_AS_HTML); - } else if (model.containsKey(viewName)) { + } else if (viewName != null && model.containsKey(viewName)) { return model.get(viewName); } else { if (model.size() == 0) @@ -87,4 +112,8 @@ public class SerializingView extends AbstractView implements MvcConstants { return locale; } + public void setSerializer(ServerSerializer serializer) { + this.serializer = serializer; + } + }