Example #1
0
 @SuppressWarnings("unchecked")
 public static void initResponseImplementations() throws InitializationFailedException {
   // Load the map of Response implementations
   logger.debug("-------------------------------------------------------");
   logger.debug("Loading available response implementations form responseImpl.properties");
   Properties aProperties = Property.getProps("responseImpl.properties");
   for (Object key : aProperties.keySet()) {
     String className = aProperties.getProperty(key.toString());
     try {
       if (Response.class.isAssignableFrom(Class.forName(className))) {
         Class.forName(className).getConstructor(InputStream.class, String.class, String.class);
         responseImpl.put(key.toString(), (Class<Response>) Class.forName(className));
         logger.debug("> Implementation loaded: " + responseImpl.get(key).getClass().toString());
       } else {
         logger.error("> Class: " + className + " is not a Response implementation.");
       }
     } catch (ClassNotFoundException e) {
       logger.error("Class not found: " + className + ". Check responseImpl.properties.");
     } catch (NoSuchMethodException e) {
       logger.error(
           "Response implementation: "
               + className
               + " does not have a constructor with signature (InputStream is, String charset, String observerId). Implementation skipped.");
     } catch (Exception e) {
       logger.error("Error trying to instanciate: " + className, e);
     }
   }
   if (responseImpl.size() == 0) {
     throw new InitializationFailedException(
         "There is no response implementation loaded. Check responseImpl.properties.");
   } else {
     logger.info("OK - " + responseImpl.size() + " implementation(s) successfully loaded.");
   }
 }
Example #2
0
  public static void initVelocity() throws InitializationFailedException {

    logger.debug("-------------------------------------------------------");
    logger.debug("Initializing Velocity");

    // Creating velocity engine
    velocityEngine = new VelocityEngine();
    Properties bProperties = Property.getProps("velocity.properties");
    bProperties.put(
        Velocity.FILE_RESOURCE_LOADER_PATH,
        Property.get("PATH_TO_TEMPLATES") + "," + Property.get("PATH_TO_TEMPLATES") + "includes/");
    logger.debug(
        "> Initializing velocity engine with FILE_RESOURCE_LOADER_PATH: "
            + Property.get("PATH_TO_TEMPLATES"));
    try {
      velocityEngine.init(bProperties);
      logger.debug("> Velocity engine successfully initialized");
    } catch (Exception e) {
      throw new InitializationFailedException(
          "Error instanciating velocity engine: " + e.getMessage());
    }

    // Creating velocity contexts
    for (ULocale locale : languageProperties.keySet()) {
      VelocityContext context = new VelocityContext();
      Properties langProps = languageProperties.get(locale);
      for (Object key : langProps.keySet()) {
        context.put((String) key, langProps.get(key));
      }
      context.put("esc", new EscapeTool());
      context.put("math", new MathTool());
      context.put("unicornTool", new UnicornVelocityTool());
      context.put("ucn", new Language());
      context.put("strUtils", new StringUtils());
      context.put("tasklist", mapOfTask);
      context.put("param_prefix", Property.get("UNICORN_PARAMETER_PREFIX"));
      context.put("languages", Language.getUiLocales());
      context.put("lang", locale.getName());
      context.put("currentLocale", locale);
      context.put("direction", Language.getLocaleDirection(locale));
      context.put("defaultLocale", Language.getDefaultLocale());
      context.put("year", (new SimpleDateFormat("yyyy")).format(new Date()));
      languageContexts.put(locale, context);
    }
    logger.debug("> " + languageContexts.size() + " velocity context(s) created");

    logger.info("OK - Velocity successfully initialized");
  }
Example #3
0
 public static void initObservers() throws InitializationFailedException {
   // Loading observers
   logger.debug("-------------------------------------------------------");
   logger.debug("Loading available observers from the observers.properties");
   Properties observers = Property.getProps("observers.properties");
   for (Object key : observers.keySet()) {
     String observerId = key.toString();
     String observerContract = observers.getProperty(key.toString());
     if (!observerContract.matches(".*\\.wadl$"))
       observerContract += "/" + Property.get("OBSERVER_DEFAULT_FILENAME");
     logger.debug("- Loading observer contract: " + observerContract);
     Observer obs = new Observer();
     WADLUnmarshaller unmarshaller;
     try {
       unmarshaller = new WADLUnmarshallerXPath();
       unmarshaller.addURL(new URL(observerContract));
       unmarshaller.unmarshal();
     } catch (MalformedURLException e) {
       logger.error(
           "Invalid observer contract URL \""
               + observerContract
               + "\". Check the observers list file.",
           e);
       logger.warn("> This observer will be skiped");
       continue;
     } catch (ParserConfigurationException e) {
       throw new InitializationFailedException("ParserConfigurationException: " + e.getMessage());
     } catch (IOException e) {
       logger.error("Unable to read observer contract: " + observerContract, e);
       logger.warn("> This observer will be skiped");
       continue;
     } catch (Exception e) {
       logger.error("Error unmarshalling contract: " + observerContract, e);
       logger.warn("> This observer will be skiped");
       continue;
     }
     try {
       obs.setResponseType(unmarshaller.getResponseType());
     } catch (UnknownParserException e) {
       logger.error(
           "Unknown implementation: "
               + unmarshaller.getResponseType()
               + ". Check observer contract or responseImpl.properties.",
           e);
       logger.warn("> This observer will be skiped");
       continue;
     }
     obs.setListOfCallMethod(unmarshaller.getListOfCallMethod());
     obs.setParamLangName(unmarshaller.getNameOfLangParameter());
     obs.setParamOutputName(unmarshaller.getNameOfOutputParameter());
     obs.setID(observerId);
     obs.setName(unmarshaller.getName());
     obs.setDescription(unmarshaller.getDescription());
     obs.setHelpLocation(unmarshaller.getHelpLocation());
     obs.setProvider(unmarshaller.getProvider());
     obs.setMapOfInputMethod(unmarshaller.getMapOfInputMethod());
     obs.setSupportedMimeTypes(unmarshaller.getSupportedMimeTypes());
     obs.setIndexURI(unmarshaller.getIndexUri());
     mapOfObserver.put(new String(obs.getID()), obs);
   }
   if (mapOfObserver.size() == 0) {
     throw new InitializationFailedException(
         "There is no observer loaded. Check the observers list file.");
   } else {
     logger.info("OK - " + mapOfObserver.size() + " observer(s) successfully loaded.");
   }
 }