001/* 002 * (C) Copyright 2014 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 * Nelson Silva <[email protected]> 018 */ 019package org.nuxeo.ecm.platform.spreadsheet; 020 021import static java.nio.charset.StandardCharsets.UTF_8; 022import static org.jboss.seam.ScopeType.EVENT; 023 024import java.io.IOException; 025import java.io.Serializable; 026import java.net.URLEncoder; 027import java.util.Base64; 028 029import org.jboss.seam.annotations.In; 030import org.jboss.seam.annotations.Name; 031import org.jboss.seam.annotations.Scope; 032import org.nuxeo.ecm.platform.contentview.jsf.ContentView; 033import org.nuxeo.ecm.platform.contentview.jsf.ContentViewService; 034import org.nuxeo.ecm.platform.contentview.jsf.ContentViewState; 035import org.nuxeo.ecm.platform.contentview.json.JSONContentViewState; 036import org.nuxeo.ecm.platform.web.common.vh.VirtualHostHelper; 037 038/** 039 * Restful actions for Nuxeo Spreadsheet 040 * 041 * @since 6.0 042 */ 043@Name("spreadsheetActions") 044@Scope(EVENT) 045public class SpreadsheetActions implements Serializable { 046 047 @In(create = true) 048 protected ContentViewService contentViewService; 049 050 public String urlFor(ContentView contentView) throws IOException { 051 String cv = ""; 052 053 // Set the content view state 054 ContentViewState state = contentViewService.saveContentView(contentView); 055 if (state != null) { 056 String json = JSONContentViewState.toJSON(state, false); 057 String encoded = Base64.getEncoder().encodeToString(json.getBytes(UTF_8)); 058 cv = URLEncoder.encode(encoded, "UTF-8"); 059 } 060 061 return VirtualHostHelper.getContextPathProperty() + "/spreadsheet/?cv=" + cv; 062 } 063}