GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — better spring mvc support · astamuse/asta4d@351279b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc
    • Asta4dContextInitializeHandlerInterceptor.java
    • SpringWebApplicationTemplateResolver.java
    • SpringWebPageView.java
    • SpringWebPageViewResolver.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎…pring/mvc/Asta4dTemplateInitializer.java‎ ‎…ContextInitializeHandlerInterceptor.java‎asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/Asta4dTemplateInitializer.java renamed to asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/Asta4dContextInitializeHandlerInterceptor.java asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/Asta4dTemplateInitializer.java renamed to asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/Asta4dContextInitializeHandlerInterceptor.java

Copy file name to clipboardExpand all lines: asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/Asta4dContextInitializeHandlerInterceptor.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @author e-ryu
4646
*
4747
*/
48-
public class Asta4dTemplateInitializer extends HandlerInterceptorAdapter implements ServletContextAware, ApplicationContextAware,
48+
public class Asta4dContextInitializeHandlerInterceptor extends HandlerInterceptorAdapter implements ServletContextAware, ApplicationContextAware,
4949
InitializingBean, ServletConfigAware {
5050

5151
private ServletConfig servletConfig;
Collapse file

‎asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/SpringWebApplicationTemplateResolver.java‎

Copy file name to clipboardExpand all lines: asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/SpringWebApplicationTemplateResolver.java
-26Lines changed: 0 additions & 26 deletions
This file was deleted.
Collapse file

‎asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/SpringWebPageView.java‎

Copy file name to clipboardExpand all lines: asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/SpringWebPageView.java
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,22 @@
3333

3434
public class SpringWebPageView implements View {
3535

36-
private Asta4DPageProvider templateProvider;
36+
public static final String BODY_ONLY_FLAG = "BODY_ONLY#" + SpringWebPageView.class;
37+
38+
private static final UrlMappingRule NormalPageRule;
39+
40+
private static final UrlMappingRule BodyOnlyRule;
3741

38-
private UrlMappingRule dummyRule = new UrlMappingRule();
42+
static {
43+
NormalPageRule = new UrlMappingRule().asUnmodifiable();
44+
{
45+
UrlMappingRule rule = new UrlMappingRule();
46+
rule.getAttributeList().add(Asta4DPageProvider.AttrBodyOnly);
47+
BodyOnlyRule = rule.asUnmodifiable();
48+
}
49+
}
50+
51+
private Asta4DPageProvider templateProvider;
3952

4053
public SpringWebPageView(Asta4DPageProvider templateProvider) throws TemplateException {
4154
super();
@@ -53,7 +66,18 @@ public void render(Map<String, ?> model, HttpServletRequest request, HttpServlet
5366
for (Entry<String, ?> entry : model.entrySet()) {
5467
context.setData(entry.getKey(), entry.getValue());
5568
}
69+
UrlMappingRule dummyRule;
70+
if (context.getData(BODY_ONLY_FLAG) != null) {
71+
dummyRule = BodyOnlyRule;
72+
} else {
73+
dummyRule = NormalPageRule;
74+
}
5675
templateProvider.produce(dummyRule, response);
5776
}
5877

78+
public static void setCurrentRequestAsBodyOnly() {
79+
WebApplicationContext context = Context.getCurrentThreadContext();
80+
context.setData(BODY_ONLY_FLAG, "bodyonly");// the value is not matter
81+
}
82+
5983
}
Collapse file

‎asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/SpringWebPageViewResolver.java‎

Copy file name to clipboardExpand all lines: asta4d-spring/src/main/java/com/astamuse/asta4d/misc/spring/mvc/SpringWebPageViewResolver.java
+25-4Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,39 @@
2323
import org.springframework.web.servlet.ViewResolver;
2424

2525
import com.astamuse.asta4d.Page;
26-
import com.astamuse.asta4d.template.TemplateException;
26+
import com.astamuse.asta4d.template.TemplateNotFoundException;
2727
import com.astamuse.asta4d.web.dispatch.response.provider.Asta4DPageProvider;
2828

2929
public class SpringWebPageViewResolver implements ViewResolver {
3030

31+
private boolean exceptionOnTemplateNotFound = true;
32+
private String prefix = "";
33+
private String suffix = "";
34+
3135
@Override
3236
public View resolveViewName(String viewName, Locale locale) throws Exception {
3337
try {
34-
return new SpringWebPageView(new Asta4DPageProvider(Page.buildFromPath(viewName)));
35-
} catch (TemplateException e) {
36-
return null;
38+
String path = prefix + viewName + suffix;
39+
return new SpringWebPageView(new Asta4DPageProvider(Page.buildFromPath(path)));
40+
} catch (TemplateNotFoundException e) {
41+
if (exceptionOnTemplateNotFound) {
42+
throw e;
43+
} else {
44+
return null;
45+
}
3746
}
3847
}
3948

49+
public void setExceptionOnTemplateNotFound(boolean exceptionOnTemplateNotFound) {
50+
this.exceptionOnTemplateNotFound = exceptionOnTemplateNotFound;
51+
}
52+
53+
public void setPrefix(String prefix) {
54+
this.prefix = prefix;
55+
}
56+
57+
public void setSuffix(String suffix) {
58+
this.suffix = suffix;
59+
}
60+
4061
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.