001/* 002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thierry Delprat 018 */ 019package org.nuxeo.apidoc.browse; 020 021import java.util.ArrayList; 022import java.util.List; 023import java.util.Map; 024 025import javax.ws.rs.GET; 026import javax.ws.rs.POST; 027import javax.ws.rs.Path; 028import javax.ws.rs.Produces; 029 030import org.nuxeo.apidoc.api.ExtensionInfo; 031import org.nuxeo.apidoc.api.ExtensionPointInfo; 032import org.nuxeo.apidoc.api.NuxeoArtifact; 033import org.nuxeo.ecm.webengine.forms.FormData; 034import org.nuxeo.ecm.webengine.model.WebObject; 035 036@WebObject(type = "contribution") 037public class ContributionWO extends NuxeoArtifactWebObject { 038 039 @Override 040 @GET 041 @Produces("text/html") 042 @Path("introspection") 043 public Object doGet() { 044 ExtensionInfo ei = getTargetExtensionInfo(); 045 return getView("view").arg("contribution", ei); 046 } 047 048 public ExtensionInfo getTargetExtensionInfo() { 049 return getSnapshotManager().getSnapshot(getDistributionId(), ctx.getCoreSession()).getContribution(nxArtifactId); 050 } 051 052 @Override 053 public NuxeoArtifact getNxArtifact() { 054 return getTargetExtensionInfo(); 055 } 056 057 @POST 058 @Produces("text/xml") 059 @Path("override") 060 public Object generateOverride() { 061 062 ExtensionInfo ei = getTargetExtensionInfo(); 063 String epid = ei.getExtensionPoint(); 064 ExtensionPointInfo ep = getSnapshotManager().getSnapshot(getDistributionId(), ctx.getCoreSession()).getExtensionPoint( 065 epid); 066 067 FormData formData = ctx.getForm(); 068 Map<String, String[]> fields = formData.getFormFields(); 069 List<String> selectedContribs = new ArrayList<String>(fields.keySet()); 070 return getView("override").arg("contribution", ei).arg("selectedContribs", selectedContribs).arg("ep", ep); 071 } 072 073}