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