use of com.webcohesion.enunciate.api.resources.ResourceGroup in project enunciate by stoicflame.
the class EnunciateJaxrsContext method getResourceGroupsByPath.
public List<ResourceGroup> getResourceGroupsByPath(ApiRegistrationContext registrationContext) {
Map<String, PathBasedResourceGroupImpl> resourcesByPath = new HashMap<String, PathBasedResourceGroupImpl>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (RootResource rootResource : rootResources) {
if (!facetFilter.accept(rootResource)) {
continue;
}
for (ResourceMethod method : rootResource.getResourceMethods(true)) {
if (facetFilter.accept(method)) {
com.webcohesion.enunciate.metadata.rs.ServiceContextRoot context = method.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = method.getParent();
while (context == null && resource != null) {
context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
resource = resource.getParent();
}
String path = method.getFullpath();
PathBasedResourceGroupImpl resourceGroup = resourcesByPath.get(path);
if (resourceGroup == null) {
String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
resourceGroup = new PathBasedResourceGroupImpl(contextPath, path, new ArrayList<Resource>());
resourcesByPath.put(path, resourceGroup);
}
resourceGroup.getResources().add(new ResourceImpl(method, resourceGroup, registrationContext));
}
}
}
ArrayList<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>(resourcesByPath.values());
Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
return resourceGroups;
}
use of com.webcohesion.enunciate.api.resources.ResourceGroup in project enunciate by stoicflame.
the class EnunciateSpringWebContext method getResourceGroupsByAnnotation.
public List<ResourceGroup> getResourceGroupsByAnnotation(ApiRegistrationContext registrationContext) {
Map<String, AnnotationBasedResourceGroupImpl> resourcesByAnnotation = new HashMap<String, AnnotationBasedResourceGroupImpl>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (SpringController springController : controllers) {
if (!facetFilter.accept(springController)) {
continue;
}
com.webcohesion.enunciate.metadata.rs.ResourceGroup controllerAnnotation = null;
boolean controllerAnnotationEvaluated = false;
for (RequestMapping method : springController.getRequestMappings()) {
if (facetFilter.accept(method)) {
com.webcohesion.enunciate.metadata.rs.ResourceGroup annotation = AnnotationUtils.getResourceGroup(method);
if (annotation == null) {
if (!controllerAnnotationEvaluated) {
controllerAnnotation = AnnotationUtils.getResourceGroup(springController);
controllerAnnotationEvaluated = true;
}
annotation = controllerAnnotation;
}
String label = annotation == null ? "Other" : annotation.value();
String description = annotation == null ? null : annotation.description();
if ("##default".equals(description)) {
description = null;
}
AnnotationBasedResourceGroupImpl resourceGroup = resourcesByAnnotation.get(label);
if (resourceGroup == null) {
resourceGroup = new AnnotationBasedResourceGroupImpl(relativeContextPath, label, new SortedList<Resource>(new ResourceComparator(this.pathSortStrategy)), this.pathSortStrategy);
resourcesByAnnotation.put(label, resourceGroup);
}
resourceGroup.setDescriptionIfNull(description);
resourceGroup.getResources().add(new ResourceImpl(method, resourceGroup, registrationContext));
}
}
}
ArrayList<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>(resourcesByAnnotation.values());
Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
return resourceGroups;
}
use of com.webcohesion.enunciate.api.resources.ResourceGroup in project enunciate by stoicflame.
the class EnunciateSpringWebContext method getResourceGroupsByPath.
public List<ResourceGroup> getResourceGroupsByPath(ApiRegistrationContext registrationContext) {
Map<String, PathBasedResourceGroupImpl> resourcesByPath = new HashMap<String, PathBasedResourceGroupImpl>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (SpringController springController : controllers) {
if (!facetFilter.accept(springController)) {
continue;
}
for (RequestMapping method : springController.getRequestMappings()) {
if (facetFilter.accept(method)) {
String path = method.getFullpath();
PathBasedResourceGroupImpl resourceGroup = resourcesByPath.get(path);
if (resourceGroup == null) {
resourceGroup = new PathBasedResourceGroupImpl(relativeContextPath, path, new ArrayList<Resource>());
resourcesByPath.put(path, resourceGroup);
}
resourceGroup.getResources().add(new ResourceImpl(method, resourceGroup, registrationContext));
}
}
}
ArrayList<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>(resourcesByPath.values());
Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
return resourceGroups;
}
use of com.webcohesion.enunciate.api.resources.ResourceGroup in project enunciate by stoicflame.
the class ApiDocsJavaDocTagHandler method onInlineTag.
@Override
public String onInlineTag(String tagName, String tagText, DecoratedElement context) {
if ("link".equals(tagName)) {
JavaDocLink link = JavaDocLink.parse(tagText);
String classRef = link.getClassName();
String subelementRef = link.getMemberName();
String value = link.getLabel();
// use the current context as the class ref.
if ("".equals(classRef)) {
DecoratedElement type = context;
while (!(type instanceof DecoratedTypeElement)) {
type = (DecoratedElement) type.getEnclosingElement();
if (type == null || type instanceof PackageElement) {
break;
}
}
if (type instanceof DecoratedTypeElement) {
classRef = ((DecoratedTypeElement) type).getQualifiedName().toString();
}
}
if (!"".equals(classRef)) {
if (classRef.indexOf('.') < 0) {
// if it's a local reference, assume it's in the current package.
DecoratedElement pckg = context;
while (!(pckg instanceof DecoratedPackageElement)) {
pckg = (DecoratedElement) pckg.getEnclosingElement();
if (pckg == null) {
break;
}
}
if (pckg != null) {
classRef = ((DecoratedPackageElement) pckg).getQualifiedName() + "." + classRef;
}
}
// now find the reference
Set<Syntax> syntaxes = this.registry.getSyntaxes(this.context);
for (Syntax syntax : syntaxes) {
List<DataType> dataTypes = syntax.findDataTypes(classRef);
if (dataTypes != null && !dataTypes.isEmpty()) {
DataType dataType = dataTypes.get(0);
Value dataTypeValue = dataType.findValue(subelementRef);
if (dataTypeValue != null) {
return "<a href=\"" + dataType.getSlug() + ".html#" + dataTypeValue.getValue() + "\">" + (value != null ? value : dataTypeValue.getValue()) + "</a>";
}
Property property = dataType.findProperty(subelementRef);
if (property != null) {
return "<a href=\"" + dataType.getSlug() + ".html#prop-" + property.getName() + "\">" + (value != null ? value : property.getName()) + "</a>";
}
return "<a href=\"" + dataType.getSlug() + ".html\">" + (value != null ? value : (subelementRef.isEmpty() ? dataType.getLabel() : subelementRef)) + "</a>";
}
}
List<ResourceApi> resourceApis = this.registry.getResourceApis(this.context);
for (ResourceApi resourceApi : resourceApis) {
Method method = resourceApi.findMethodFor(classRef, subelementRef);
if (method != null) {
if (value == null) {
value = method.getLabel() + " " + method.getResource().getGroup().getLabel();
}
return "<a href=\"" + method.getResource().getGroup().getSlug() + ".html#" + method.getSlug() + "\">" + value + "</a>";
} else {
ResourceGroup resourceGroup = resourceApi.findResourceGroupFor(classRef);
if (resourceGroup != null) {
if (value == null) {
value = resourceGroup.getLabel();
}
return "<a href=\"" + resourceGroup.getSlug() + ".html\">" + value + "</a>";
}
}
}
List<ServiceApi> serviceApis = this.registry.getServiceApis(this.context);
for (ServiceApi serviceApi : serviceApis) {
Operation operation = serviceApi.findOperationFor(classRef, subelementRef);
if (operation != null) {
if (value == null) {
value = operation.getName();
}
return "<a href=\"" + operation.getService().getSlug() + ".html#" + operation.getSlug() + "\">" + value + "</a>";
} else {
Service service = serviceApi.findServiceFor(classRef);
if (service != null) {
if (value == null) {
value = service.getLabel();
}
return "<a href=\"" + service.getSlug() + ".html\">" + value + "</a>";
}
}
}
}
return value != null ? value : tagText.trim();
} else if ("code".equals(tagName)) {
return "<code>" + tagText + "</code>";
}
return tagText;
}
use of com.webcohesion.enunciate.api.resources.ResourceGroup in project enunciate by stoicflame.
the class EnunciateJaxrsContext method getResourceGroupsByClass.
public List<ResourceGroup> getResourceGroupsByClass(ApiRegistrationContext registrationContext) {
List<ResourceGroup> resourceGroups = new ArrayList<ResourceGroup>();
Set<String> slugs = new TreeSet<String>();
FacetFilter facetFilter = registrationContext.getFacetFilter();
for (RootResource rootResource : rootResources) {
if (!facetFilter.accept(rootResource)) {
continue;
}
String slug = rootResource.getSimpleName().toString();
if (slugs.contains(slug)) {
slug = "";
String[] qualifiedNameTokens = rootResource.getQualifiedName().toString().split("\\.");
for (int i = qualifiedNameTokens.length - 1; i >= 0; i--) {
slug = slug.isEmpty() ? qualifiedNameTokens[i] : slug + "_" + qualifiedNameTokens[i];
if (!slugs.contains(slug)) {
break;
}
}
}
slugs.add(slug);
com.webcohesion.enunciate.metadata.rs.ServiceContextRoot context = rootResource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
com.webcohesion.enunciate.modules.jaxrs.model.Resource resource = rootResource.getParent();
while (context == null && resource != null) {
context = resource.getAnnotation(com.webcohesion.enunciate.metadata.rs.ServiceContextRoot.class);
resource = resource.getParent();
}
String contextPath = context != null ? JaxrsModule.sanitizeContextPath(context.value()) : this.relativeContextPath;
ResourceGroup group = new ResourceClassResourceGroupImpl(rootResource, slug, contextPath, registrationContext);
if (!group.getResources().isEmpty()) {
resourceGroups.add(group);
}
}
Collections.sort(resourceGroups, new ResourceGroupComparator(this.pathSortStrategy));
return resourceGroups;
}
Aggregations