1 17 package org.alfresco.repo.dictionary; 18 19 import java.io.InputStream ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import org.alfresco.i18n.I18NUtil; 24 import org.alfresco.service.cmr.dictionary.DictionaryException; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 29 35 public class DictionaryBootstrap 36 { 37 private List <String > models = new ArrayList <String >(); 39 40 private List <String > resourceBundles = new ArrayList <String >(); 42 43 private DictionaryDAO dictionaryDAO = null; 45 46 private static Log logger = LogFactory.getLog(DictionaryDAO.class); 48 49 50 55 public void setDictionaryDAO(DictionaryDAO dictionaryDAO) 56 { 57 this.dictionaryDAO = dictionaryDAO; 58 } 59 60 65 public void setModels(List <String > modelResources) 66 { 67 this.models = modelResources; 68 } 69 70 75 public void setLabels(List <String > labels) 76 { 77 this.resourceBundles = labels; 78 } 79 80 83 public void bootstrap() 84 { 85 for (String bootstrapModel : models) 87 { 88 InputStream modelStream = getClass().getClassLoader().getResourceAsStream(bootstrapModel); 89 if (modelStream == null) 90 { 91 throw new DictionaryException("Could not find bootstrap model " + bootstrapModel); 92 } 93 try 94 { 95 if (logger.isInfoEnabled()) 96 logger.info("Loading model from " + bootstrapModel); 97 98 M2Model model = M2Model.createModel(modelStream); 99 dictionaryDAO.putModel(model); 100 } 101 catch(DictionaryException e) 102 { 103 throw new DictionaryException("Could not import bootstrap model " + bootstrapModel, e); 104 } 105 } 106 107 for (String resourceBundle : resourceBundles) 109 { 110 I18NUtil.registerResourceBundle(resourceBundle); 111 } 112 } 113 114 } 115 | Popular Tags |