001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thierry Delprat
016 */
017package org.nuxeo.apidoc.browse;
018
019import java.util.ArrayList;
020import java.util.List;
021import java.util.Map;
022
023import javax.ws.rs.GET;
024import javax.ws.rs.POST;
025import javax.ws.rs.Path;
026import javax.ws.rs.Produces;
027
028import org.nuxeo.apidoc.api.ExtensionInfo;
029import org.nuxeo.apidoc.api.ExtensionPointInfo;
030import org.nuxeo.apidoc.api.NuxeoArtifact;
031import org.nuxeo.ecm.webengine.forms.FormData;
032import org.nuxeo.ecm.webengine.model.WebObject;
033
034@WebObject(type = "contribution")
035public class ContributionWO extends NuxeoArtifactWebObject {
036
037    @Override
038    @GET
039    @Produces("text/html")
040    @Path("introspection")
041    public Object doGet() {
042        ExtensionInfo ei = getTargetExtensionInfo();
043        return getView("view").arg("contribution", ei);
044    }
045
046    public ExtensionInfo getTargetExtensionInfo() {
047        return getSnapshotManager().getSnapshot(getDistributionId(), ctx.getCoreSession()).getContribution(nxArtifactId);
048    }
049
050    @Override
051    public NuxeoArtifact getNxArtifact() {
052        return getTargetExtensionInfo();
053    }
054
055    @POST
056    @Produces("text/xml")
057    @Path("override")
058    public Object generateOverride() {
059
060        ExtensionInfo ei = getTargetExtensionInfo();
061        String epid = ei.getExtensionPoint();
062        ExtensionPointInfo ep = getSnapshotManager().getSnapshot(getDistributionId(), ctx.getCoreSession()).getExtensionPoint(
063                epid);
064
065        FormData formData = ctx.getForm();
066        Map<String, String[]> fields = formData.getFormFields();
067        List<String> selectedContribs = new ArrayList<String>(fields.keySet());
068        return getView("override").arg("contribution", ei).arg("selectedContribs", selectedContribs).arg("ep", ep);
069    }
070
071}