Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added initial format support to wrmldoc
  • Loading branch information
markmasse committed Mar 1, 2016
1 parent 4a0f09d commit 67603f1
Show file tree
Hide file tree
Showing 40 changed files with 3,149 additions and 1,325 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/org/wrml/model/rest/LinkTemplate.java
Expand Up @@ -61,7 +61,7 @@
* <p/>
* <p>
* A link ends with its pointy-end pointing to the end point. This end point is the resource that the referrer resource
* was referencing with its link.
* is referencing with its link.
* </p>
*
* @see Api
Expand All @@ -70,7 +70,6 @@
* @see URI
* @see Link
* @see LinkRelation
* @see org.wrml.runtime.schema.LinkSlot
* @see LinkValue
* @see Schema
* @see Document
Expand Down
Expand Up @@ -82,7 +82,7 @@ public enum SystemFormat {
vnd_wrml_swagger_api(new UniqueName("application/vnd.wrml.swagger.api+json"),
"The WRML System Format representing the \"application/vnd.wrml.swagger.api\" media type.",
URI.create("http://wrml.org"),
URI.create(""), "txt"),
URI.create(""), "json"),

vnd_wrml_wrmldoc(new UniqueName("application/vnd.wrml.wrmldoc+json"),
"The WRML System Format representing the \"application/vnd.wrml.wrmldoc\" media type.",
Expand Down
Expand Up @@ -25,9 +25,11 @@
package org.wrml.runtime.format.application.vnd.wrml.wrmldoc;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.StringUtils;
import org.wrml.model.Model;
import org.wrml.model.format.Format;
import org.wrml.model.rest.Api;
import org.wrml.model.rest.Document;
import org.wrml.model.rest.LinkRelation;
Expand All @@ -38,12 +40,16 @@
import org.wrml.model.schema.Schema;
import org.wrml.runtime.Context;
import org.wrml.runtime.Keys;
import org.wrml.runtime.format.FormatLoader;
import org.wrml.runtime.format.Formatter;
import org.wrml.runtime.format.application.vnd.wrml.complete.api.CompleteApiBuilder;
import org.wrml.runtime.format.application.vnd.wrml.complete.schema.CompleteSchemaBuilder;
import org.wrml.runtime.rest.ApiLoader;
import org.wrml.runtime.schema.SchemaLoader;

import java.io.IOException;
import java.net.URI;
import java.util.SortedSet;

public class WrmldocDataBuilder {

Expand Down Expand Up @@ -166,10 +172,44 @@ else if (model instanceof DocumentNotFoundErrorReport) {
final ObjectNode jstreeDataNode = _JstreeDataBuilder.buildJstreeData(objectMapper, context);
wrmlDataNode.put(PropertyName.jstree.name(), jstreeDataNode);

final ObjectNode formatsDataNode = buildFormatsData(objectMapper, model);
wrmlDataNode.put(PropertyName.formats.name(), formatsDataNode);

return wrmlDataNode;
}


public ObjectNode buildFormatsData(final ObjectMapper objectMapper, final Model model) {

final ObjectNode formatsNode = objectMapper.createObjectNode();

final Context context = model.getContext();
final FormatLoader formatLoader = context.getFormatLoader();
final SortedSet<URI> formatUris = formatLoader.getLoadedFormatUris();
final URI defaultFormatUri = formatLoader.getDefaultFormatUri();

for (final URI formatUri : formatUris) {
final Formatter formatter = formatLoader.getFormatter(formatUri);
if (formatter.isApplicableTo(model.getSchemaUri())) {

final Format format = formatLoader.loadFormat(formatUri);
final String mediaTypeString = String.valueOf(format.getMediaType());
final ObjectNode formatNode = objectMapper.createObjectNode();
formatsNode.put(mediaTypeString, formatNode);

formatNode.put("uri", String.valueOf(formatUri));
formatNode.put("title", format.getTitle());
formatNode.put("mediaType", mediaTypeString);
formatNode.put("fileExtension", format.getFileExtension());
formatNode.put("isDefault", formatUri.equals(defaultFormatUri));

}
}

return formatsNode;
}


public enum PropertyName {
docroot,
documentTitle,
Expand All @@ -179,7 +219,8 @@ public enum PropertyName {
schema,
api,
relation,
jstree;
jstree,
formats;
}
}

Expand Down
Expand Up @@ -79,6 +79,8 @@ public void writeModel(final OutputStream out, final Model model, final ModelWri

try {

final MessageFormat pageTemplate = getTemplate(SHELL_PAGE_TEMPLATE_RESOURCE);

final ObjectNode wrmldocData = _WrmldocDataBuilder.buildWrmldocData(objectMapper, model);

final String documentTitle = wrmldocData.get(WrmldocDataBuilder.PropertyName.documentTitle.name()).asText();
Expand All @@ -100,8 +102,23 @@ public void writeModel(final OutputStream out, final Model model, final ModelWri
final JsonNode jstreeDataNode = wrmldocData.get(WrmldocDataBuilder.PropertyName.jstree.name());
final String jstreeValue = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jstreeDataNode);

final MessageFormat pageTemplate = getTemplate(SHELL_PAGE_TEMPLATE_RESOURCE);
final String renderedPage = renderPage(pageTemplate, _WrmldocDataBuilder.getDocroot(), dotMin, documentTitle, documentIcon, schemaUriString, modelValue, schemaValue, apiValue, relationValue, jstreeValue);
final JsonNode formatsDataNode = wrmldocData.get(WrmldocDataBuilder.PropertyName.formats.name());
final String formatsValue = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(formatsDataNode);

final String renderedPage =
renderPage(
pageTemplate,
_WrmldocDataBuilder.getDocroot(),
dotMin,
documentTitle,
documentIcon,
schemaUriString,
modelValue,
schemaValue,
apiValue,
relationValue,
jstreeValue,
formatsValue);

IOUtils.write(renderedPage, out);

Expand Down
10 changes: 1 addition & 9 deletions core/src/main/java/org/wrml/runtime/rest/DefaultApiLoader.java
Expand Up @@ -518,18 +518,10 @@ private void loadSystemApis() {

apiBuilder.uri(apiUri).title(systemApi.getTitle()).description(systemApi.getDescription());

// NOTE: This call to docroot will automatically *Api* as a default response schema at the root
apiBuilder.docroot(systemApi.getDocrootId());
apiBuilder.resource(SYSTEM_API_PRIMARY_ENDPOINT_FULL_PATH, systemApi.getPrimaryEndpointId(), systemApi.getDefaultSchemaInterface(), true);

// TODO: Rework the SchemaNamespace
/*
* if (systemApi == SystemApi.Schema) { apiBuilder.link(SYSTEM_API_DOCROOT_FULL_PATH, SystemLinkRelation.self.getUri(), SYSTEM_API_DOCROOT_FULL_PATH,
* SchemaNamespace.class); apiBuilder.link(SYSTEM_API_DOCROOT_FULL_PATH, SystemLinkRelation.element.getUri(), SYSTEM_API_PRIMARY_ENDPOINT_FULL_PATH, Schema.class);
* apiBuilder.link(SYSTEM_API_DOCROOT_FULL_PATH, SystemLinkRelation.child.getUri(), SYSTEM_API_PRIMARY_ENDPOINT_FULL_PATH, SchemaNamespace.class);
* apiBuilder.link(SYSTEM_API_PRIMARY_ENDPOINT_FULL_PATH, SystemLinkRelation.element.getUri(), SYSTEM_API_PRIMARY_ENDPOINT_FULL_PATH, Schema.class);
* apiBuilder.link(SYSTEM_API_PRIMARY_ENDPOINT_FULL_PATH, SystemLinkRelation.child.getUri(), SYSTEM_API_PRIMARY_ENDPOINT_FULL_PATH, SchemaNamespace.class); }
*/

final Api api = apiBuilder.toApi();
loadApi(api);
}
Expand Down
Expand Up @@ -55,7 +55,9 @@

"relation" : {8},

"jstree" : {9}
"jstree" : {9},

"formats" : {10}

'}';

Expand All @@ -66,6 +68,13 @@

<script type="text/javascript" src="{0}jstree/jstree{1}.js"></script>

<script type="text/javascript" src="{0}ace/ace.js"></script>
<script type="text/javascript" src="{0}ace/mode-html.js"></script>
<script type="text/javascript" src="{0}ace/mode-java.js"></script>
<script type="text/javascript" src="{0}ace/mode-json.js"></script>
<script type="text/javascript" src="{0}ace/mode-xml.js"></script>
<script type="text/javascript" src="{0}ace/mode-yaml.js"></script>

<!-- Uses wrmldoc for app logic -->
<script type="text/javascript" src="{0}js/wrmldoc{1}.js"></script>

Expand Down
11 changes: 11 additions & 0 deletions wrmldoc/ace/ace.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions wrmldoc/ace/mode-html.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions wrmldoc/ace/mode-java.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions wrmldoc/ace/mode-json.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 67603f1

Please sign in to comment.