001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.client.rpc; 029 030import com.google.gwt.user.client.rpc.SerializationException; 031import com.google.gwt.user.client.rpc.SerializationStreamFactory; 032 033/** 034 * Utility class for deserializing prefetched RPC data.<p> 035 * 036 * @since 8.0 037 */ 038public final class CmsRpcPrefetcher { 039 040 /** 041 * Hidden constructor.<p> 042 */ 043 private CmsRpcPrefetcher() { 044 045 // empty 046 } 047 048 /** 049 * Deserializes the prefetched RPC data with the given dictionary name.<p> 050 * 051 * @param asyncService the RPC service instance 052 * @param dictionaryName the global variable name 053 * 054 * @return the prefetched RPC data 055 * 056 * @throws SerializationException if the deserialization fails 057 */ 058 public static Object getSerializedObjectFromDictionary(Object asyncService, String dictionaryName) 059 throws SerializationException { 060 061 return getSerializedObjectFromString(asyncService, getString(dictionaryName)); 062 } 063 064 /** 065 * Deserializes the prefetched RPC data.<p> 066 * 067 * @param asyncService the RPC service instance 068 * @param serializedData the serialized object data 069 * 070 * @return the prefetched RPC data 071 * 072 * @throws SerializationException if the deserialization fails 073 */ 074 public static Object getSerializedObjectFromString(Object asyncService, String serializedData) 075 throws SerializationException { 076 077 SerializationStreamFactory ssf = (SerializationStreamFactory)asyncService; 078 return ssf.createStreamReader(serializedData).readObject(); 079 } 080 081 /** 082 * Retrieves the given global variable as a string.<p> 083 * 084 * @param name the name of the variable to retrieve 085 * 086 * @return the variable's value 087 */ 088 private static native String getString(String name) /*-{ 089 var metas = $wnd.document.getElementsByTagName('META'); 090 var i; 091 for (i = 0; i < metas.length; i++) { 092 if (metas[i].getAttribute('NAME') == name) { 093 break; 094 } 095 } 096 return metas[i].getAttribute("CONTENT"); 097 }-*/; 098}