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.Serializable; 024import java.io.UnsupportedEncodingException; 025import java.net.URLEncoder; 026 027import org.jboss.seam.annotations.In; 028import org.jboss.seam.annotations.Name; 029import org.jboss.seam.annotations.Scope; 030 031import org.nuxeo.ecm.platform.contentview.jsf.ContentView; 032import org.nuxeo.ecm.platform.contentview.jsf.ContentViewService; 033import org.nuxeo.ecm.platform.contentview.jsf.ContentViewState; 034import org.nuxeo.ecm.platform.contentview.json.JSONContentViewState; 035import org.nuxeo.ecm.platform.forms.layout.io.Base64; 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 UnsupportedEncodingException { 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.encodeBytes(json.getBytes(), Base64.DONT_BREAK_LINES); 058 cv = URLEncoder.encode(encoded, "UTF-8"); 059 } 060 061 return VirtualHostHelper.getContextPathProperty() + "/spreadsheet/?cv=" + cv; 062 } 063}