use of com.revolsys.ui.model.PageInfo in project com.revolsys.open by revolsys.
the class PageInfoHttpMessageConverter method writeHtml.
@SuppressWarnings("unchecked")
private void writeHtml(final OutputStream out, final String url, final PageInfo pageInfo, final boolean showTitle) {
final XmlWriter writer = new XmlWriter(out);
writer.startTag(HtmlElem.DIV);
if (showTitle) {
writer.element(HtmlElem.H1, pageInfo.getTitle());
final DocInfo docInfo = pageInfo.getDefaultDocumentation();
if (docInfo != null) {
writer.startTag(HtmlElem.DIV);
writer.attribute(HtmlAttr.STYLE, "margin-bottom: 1em");
final String description = docInfo.getDescription();
if (description != null) {
if (docInfo.isHtml()) {
writer.write(description);
} else {
writer.element(HtmlElem.P, description);
}
}
writer.endTag(HtmlElem.DIV);
}
}
final HttpServletRequest request = HttpServletUtils.getRequest();
for (final String method : pageInfo.getMethods()) {
@SuppressWarnings("rawtypes") final Map parameterMap = request.getParameterMap();
writeMethod(writer, url, pageInfo, method, parameterMap);
}
final Map<String, PageInfo> pages = pageInfo.getPages();
final Element pagesElement = pageInfo.getPagesElement();
if (pagesElement != null) {
pagesElement.serialize(writer);
} else if (!pages.isEmpty()) {
writer.startTag(HtmlElem.DIV);
writer.attribute(HtmlAttr.CLASS, "resources");
writer.startTag(HtmlElem.DL);
for (final Entry<String, PageInfo> childPage : pages.entrySet()) {
final String childPath = childPage.getKey();
final PageInfo childPageInfo = childPage.getValue();
String childUri;
if (childPath.startsWith("/") || childPath.startsWith("http")) {
childUri = childPath;
} else if (url.charAt(url.length() - 1) != '/') {
childUri = url + "/" + childPath;
} else {
childUri = url + childPath;
}
writer.startTag(HtmlElem.DT);
final String childTitle = childPageInfo.getTitle();
HtmlUtil.serializeA(writer, null, childUri, childTitle);
writer.endTag(HtmlElem.DT);
final boolean isTemplate = childPath.matches(".*(\\{[^\\}]+\\}.*)+");
final String childDescription = childPageInfo.getDescription();
if (childDescription != null || isTemplate) {
writer.startTag(HtmlElem.DD);
if (childDescription != null) {
writer.element(HtmlElem.P, childDescription);
}
if (isTemplate) {
writer.startTag(HtmlElem.FORM);
writer.attribute(HtmlAttr.ACTION, childUri);
writer.attribute(HtmlAttr.METHOD, "get");
for (final String pathElement : childPath.split("/")) {
if (pathElement.matches("\\{[^\\}]+\\}")) {
final String name = pathElement.substring(1, pathElement.length() - 1);
HtmlUtil.serializeTextInput(writer, name, name, 20, 255);
}
}
HtmlUtil.serializeButtonInput(writer, "go", "doGet(this.form)");
writer.endTag(HtmlElem.FORM);
}
writer.endTag(HtmlElem.DD);
}
}
writer.endTag(HtmlElem.DL);
writer.endTag(HtmlElem.DIV);
}
writer.endTag(HtmlElem.DIV);
writer.endDocument();
writer.close();
}
use of com.revolsys.ui.model.PageInfo in project com.revolsys.open by revolsys.
the class PageInfoHttpMessageConverter method getMap.
private Map<String, Object> getMap(final String url, final PageInfo pageInfo) {
final MapEx pageMap = new NamedLinkedHashMapEx("resource");
pageMap.put("resourceUri", url);
pageMap.put("title", pageInfo.getTitle());
final String description = pageInfo.getDescription();
if (Property.hasValue(description)) {
pageMap.put("description", description);
}
for (final Entry<String, Object> attribute : pageInfo.getFields().entrySet()) {
final String key = attribute.getKey();
final Object value = attribute.getValue();
pageMap.put(key, value);
}
final List<Map<String, Object>> childPages = new ArrayList<>();
for (final Entry<String, PageInfo> childPage : pageInfo.getPages().entrySet()) {
final String childPath = childPage.getKey();
final PageInfo childPageInfo = childPage.getValue();
final String childUri = getUrl(url, childPath);
final Map<String, Object> childPageMap = getMap(childUri, childPageInfo);
childPages.add(childPageMap);
}
if (!childPages.isEmpty()) {
pageMap.put("resources", childPages);
}
return pageMap;
}
use of com.revolsys.ui.model.PageInfo in project com.revolsys.open by revolsys.
the class PageInfoHttpMessageConverter method writeWadlResource.
private void writeWadlResource(final XmlWriter writer, final String url, final PageInfo pageInfo, final boolean writeChildren) {
writer.startTag(RESOURCE);
writer.attribute(PATH, url);
writeWadlDoc(writer, pageInfo);
if (writeChildren) {
for (final Entry<String, PageInfo> childPage : pageInfo.getPages().entrySet()) {
final String childPath = childPage.getKey();
final PageInfo childPageInfo = childPage.getValue();
writeWadlResource(writer, childPath, childPageInfo, false);
}
}
writer.endTag(RESOURCE);
}
Aggregations