* @param resource The resource to read.
* @return The string form of the resource.
*/
protected String readResource(String resource) throws IOException, EnunciateException {
HashMap<String, Object> model = new HashMap<String, Object>();
ResourceMethod exampleResource = getModelInternal().findExampleResourceMethod();
String label = getLabel() == null ? getEnunciate().getConfig() == null ? "enunciate" : getEnunciate().getConfig().getLabel() : getLabel();
model.put("label", label);
NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), label, getModelInternal().getNamespacesToPrefixes(), this.packageIdentifiers);
if (exampleResource != null) {
if (exampleResource.getEntityParameter() != null && exampleResource.getEntityParameter().getXmlElement() != null) {
ElementDeclaration el = exampleResource.getEntityParameter().getXmlElement();
TypeDefinition typeDefinition = null;
if (el instanceof RootElementDeclaration) {
typeDefinition = getModelInternal().findTypeDefinition((RootElementDeclaration) el);
}
else if (el instanceof LocalElementDeclaration && ((LocalElementDeclaration) el).getElementTypeDeclaration() instanceof ClassDeclaration) {
typeDefinition = getModelInternal().findTypeDefinition((ClassDeclaration) ((LocalElementDeclaration) el).getElementTypeDeclaration());
}
if (typeDefinition != null) {
model.put("input_element_name", nameForTypeDefinition.calculateName(typeDefinition));
}
}
if (exampleResource.getRepresentationMetadata() != null && exampleResource.getRepresentationMetadata().getXmlElement() != null) {
ElementDeclaration el = exampleResource.getRepresentationMetadata().getXmlElement();
TypeDefinition typeDefinition = null;
if (el instanceof RootElementDeclaration) {
typeDefinition = getModelInternal().findTypeDefinition((RootElementDeclaration) el);
}
else if (el instanceof LocalElementDeclaration && ((LocalElementDeclaration) el).getElementTypeDeclaration() instanceof ClassDeclaration) {
typeDefinition = getModelInternal().findTypeDefinition((ClassDeclaration) ((LocalElementDeclaration) el).getElementTypeDeclaration());
}
if (typeDefinition != null) {
model.put("output_element_name", nameForTypeDefinition.calculateName(typeDefinition));
}
}
model.put("resource_url", exampleResource.getFullpath());
model.put("resource_method", exampleResource.getHttpMethods().isEmpty() ? "GET" : exampleResource.getHttpMethods().iterator().next());
}
URL res = ObjCDeploymentModule.class.getResource(resource);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bytes);