public void initialize()

in OpenCalaisAnnotator/src/main/java/org/apache/uima/annotator/calais/OpenCalaisAnnotator.java [242:306]


  public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    // initialize annotator logger
    this.logger = this.getContext().getLogger();

    // create SAX parser
    try {
      SAXParserFactory factory = SAXParserFactory.newInstance();
      this.saxParser = factory.newSAXParser();
    } catch (ParserConfigurationException ex) {
      throw new ResourceInitializationException(ex);
    } catch (SAXException ex) {
      throw new ResourceInitializationException(ex);
    }

    // get configuration parameters
    // get submitter
    String submitter = (String) this.getContext().getConfigParameterValue(
            CONFIG_PARAM_NAME_SUBMITTER);
    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
        CONFIG_PARAM_NAME_SUBMITTER, submitter });
    // get licenseID
    String licenseID = (String) this.getContext().getConfigParameterValue(
            CONFIG_PARAM_NAME_LICENSE_ID);
    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
        CONFIG_PARAM_NAME_LICENSE_ID, licenseID });
    // get allowSearch
    Boolean allowSearch = (Boolean) this.getContext().getConfigParameterValue(
            CONFIG_PARAM_NAME_ALLOW_SEARCH);
    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
        CONFIG_PARAM_NAME_ALLOW_SEARCH, allowSearch.toString() });
    // get allowDistribution
    Boolean allowDistribution = (Boolean) this.getContext().getConfigParameterValue(
            CONFIG_PARAM_NAME_ALLOW_DISTRIBUTION);
    this.logger.log(Level.CONFIG, "Parameter \"{0}\" set to \"{1}\"", new Object[] {
        CONFIG_PARAM_NAME_ALLOW_DISTRIBUTION, allowDistribution.toString() });

    // generate externalID for the calais service
    String externalID = "UIMACalaisAnnotWrapper-" + System.currentTimeMillis();
    this.logger.log(Level.CONFIG, "Generated external ID: \"{0}\"", externalID);

    // create configXML for calais service
    String configXML = getConfigXML(allowDistribution.toString(), allowSearch.toString(),
            externalID, submitter);

    // create service parameter string
    StringBuffer serviceParamsBuf = new StringBuffer();
    // param licenseID
    serviceParamsBuf.append("&licenseID=");
    serviceParamsBuf.append(licenseID);
    // param configXML
    serviceParamsBuf.append("&paramsXML=");
    serviceParamsBuf.append(configXML);
    // param content
    serviceParamsBuf.append("&content=");
    this.serviceParams = serviceParamsBuf.toString();

    // create calais service URL
    try {
      this.calaisService = new URL("http://api.opencalais.com/enlighten/calais.asmx/Enlighten");
    } catch (MalformedURLException ex) {
      throw new ResourceInitializationException(ex);
    }
  }