1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import Logger from './Logger' 17 18class ResourceUtils { 19 constructor() { 20 } 21 22 static getStringByName(context, name) { 23 Logger.info("ResourceUtils getStringByName") 24 if (context == null) { 25 Logger.error("ResourceUtils context is null") 26 return 27 } 28 let value = null 29 try { 30 value = context.resourceManager.getStringByNameSync(name) 31 } catch (error) { 32 Logger.error("ResourceUtils Failed to get string. Cause: " + JSON.stringify(error)) 33 } 34 return value 35 } 36 37 static getStringByResource(context, resource) { 38 Logger.info("ResourceUtils getStringByResource") 39 if (context == null) { 40 Logger.error("ResourceUtils context is null") 41 return 42 } 43 let value = null 44 try { 45 value = context.resourceManager.getStringSync(resource) 46 } catch (error) { 47 Logger.error("ResourceUtils Failed to get string. Cause: " + JSON.stringify(error)) 48 } 49 return value 50 } 51} 52 53export default ResourceUtils