/******************************************************************************* * Copyright (c) 2012-2015 Codenvy, S.A. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ package org.eclipse.che.jdt; import org.eclipse.che.jdt.internal.core.JavaProject; import org.eclipse.jdt.core.JavaModelException; import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; /** * @author Evgen Vidolob */ @Path("javadoc/{ws-id}") public class JavadocService { @PathParam("ws-id") private String wsId; @Inject private JavaProjectService service; @Path("find") @GET @Produces("text/html") public String findJavadoc(@QueryParam("fqn") String fqn, @QueryParam("projectpath") String projectPath, @Context UriInfo uriInfo) throws JavaModelException { JavaProject project = service.getOrCreateJavaProject(wsId, projectPath); String urlPart = getUrlPart(projectPath, uriInfo.getBaseUriBuilder()); if(fqn.contains(";.")){ String name = fqn.substring(0, fqn.indexOf(";.")); String bodyDeclaration = fqn.substring(fqn.indexOf(";.")); fqn = name + bodyDeclaration.replaceAll("/","."); } return new JavadocFinder(urlPart).findJavadoc(project, fqn); } @Path("get") @Produces("text/html") @GET public String get(@QueryParam("handle") String handle, @QueryParam("projectpath") String projectPath, @Context UriInfo uriInfo) { JavaProject project = service.getOrCreateJavaProject(wsId, projectPath); String urlPart = getUrlPart(projectPath, uriInfo.getBaseUriBuilder()); return new JavadocFinder(urlPart).findJavadoc4Handle(project, handle); } private String getUrlPart(String projectPath, UriBuilder uriBuilder) { return uriBuilder.clone().path(JavadocService.class).path(JavadocService.class, "get").build(wsId).toString() + "?projectpath=" + projectPath + "&handle="; } }