1 15 package org.apache.hivemind.schema.rules; 16 17 import java.util.Locale ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.HiveMind; 21 import org.apache.hivemind.Location; 22 import org.apache.hivemind.Resource; 23 import org.apache.hivemind.internal.Module; 24 import org.apache.hivemind.schema.Translator; 25 26 32 public class ResourceTranslator implements Translator 33 { 34 41 public Object translate( 42 Module contributingModule, 43 Class propertyType, 44 String inputValue, 45 Location location) 46 { 47 if (HiveMind.isBlank(inputValue)) 48 return null; 49 50 Locale locale = contributingModule.getLocale(); 51 52 Resource descriptor = contributingModule.getLocation().getResource(); 53 54 Resource baseResource = descriptor.getRelativeResource(inputValue); 55 56 Resource result = baseResource.getLocalization(locale); 57 58 if (result == null) 59 throw new ApplicationRuntimeException( 60 RulesMessages.resourceLocalizationError(inputValue, contributingModule)); 61 62 return result; 63 } 64 65 } 66 | Popular Tags |