Package com.esri.gpt.framework.jsf

Examples of com.esri.gpt.framework.jsf.MessageBroker


  HttpClientRequest httpClient = HttpClientRequest.newRequest();
  httpClient.setCredentialProvider(info.newCredentialProvider());
  ProcessingContext processingContext = new ProcessingContext(requestContext, publisher, httpClient, null, false);

  FacesContextBroker contextBroker = new FacesContextBroker();
  MessageBroker msgBroker = contextBroker.extractMessageBroker();
  processingContext.setMessageBroker(msgBroker);

  return processingContext;
}
View Full Code Here


   * @param query query
   * @return records
   * @throws Exception if searching fails
   */
  protected IFeedRecords doSearch(HttpServletRequest request, HttpServletResponse response, RequestContext context, RestQuery query) throws Exception {
    MessageBroker msgBroker = new FacesContextBroker(request, response).extractMessageBroker();
    final Map<DiscoveredRecord, Map<String, List<String>>> mapping = new HashMap<DiscoveredRecord, Map<String, List<String>>>();

    List<IFeedRecords.FieldMeta> fields = new ArrayList<IFeedRecords.FieldMeta>();
    loadStdFieldMeta(fields);

    int startRecord = query.getFilter().getStartRecord();
    boolean returnIdsOnly = Val.chkBool(Val.chkStr(request.getParameter("returnIdsOnly")), false);
    if (returnIdsOnly) {
      startRecord = 1;
      query.getFilter().setMaxRecords(1);
      LuceneQueryAdapter tmp = new LuceneQueryAdapter();
      tmp.execute(context, query);
      query.getFilter().setMaxRecords(query.getResult().getNumberOfHits());
    }

    query.getFilter().setStartRecord(startRecord);
    LuceneQueryAdapter lqa = new LuceneQueryAdapter() {
      @Override
      protected void onRecord(DiscoveredRecord record, Document document) {
        Map<String, List<String>> fieldMap = new HashMap<String, List<String>>();
        for (Fieldable field : document.getFields()) {
          String name = field.name();
          List<String> fieldValues = fieldMap.get(name);
          if (fieldValues == null) {
            fieldValues = new ArrayList<String>();
            fieldMap.put(name, fieldValues);
          }
          fieldValues.add(field.stringValue());
        }
        mapping.put(record, fieldMap);
      }
    };
    lqa.execute(context, query);
    startRecord += query.getFilter().getMaxRecords();

    loadLuceneMeta(context, fields);

    OpenSearchProperties osProps = new OpenSearchProperties();
    osProps.setShortName(msgBroker.retrieveMessage("catalog.openSearch.shortName"));
    osProps.setNumberOfHits(query.getResult().getNumberOfHits());
    osProps.setStartRecord(query.getFilter().getStartRecord());
    osProps.setRecordsPerPage(query.getFilter().getMaxRecords());

    ResourceIdentifier resourceIdentifier = ResourceIdentifier.newIdentifier(context);
View Full Code Here

      }
      String json = Val.chkStr(request.getParameter("errorsAsJson"));
      if (json.length()>0) {
        json = Val.escapeXmlForBrowser(json);
        FacesContextBroker fcb = new FacesContextBroker(request, response);
        MessageBroker msgBroker = fcb.extractMessageBroker();
       
        ArrayList<String> validationMessages = new ArrayList<String>();
        e.getValidationErrors().buildMessages(msgBroker, validationMessages, true);
       
        StringBuilder sb = new StringBuilder();
View Full Code Here

  private String readXml(HttpServletRequest request, RequestContext context)
    throws Exception {
   
    // initialize values for substitution
    CatalogConfiguration catCfg = context.getCatalogConfiguration();
    MessageBroker msgBroker = new MessageBroker();
    msgBroker.setBundleBaseName("gpt.resources.gpt");
   
    String basePath = RequestContext.resolveBaseContextPath(request);
    String restPath = basePath+"/rest/find/document";
    String imagePath = basePath+"/catalog/images";
    String shortName = Val.escapeXml(msgBroker.retrieveMessage("catalog.openSearch.shortName"));
    String description = Val.escapeXml(msgBroker.retrieveMessage("catalog.openSearch.description"));
       
    // read the XML, substitute values
    ResourcePath rp = new ResourcePath();
    rp.makeUrl(XML_LOCATION);
    String xml = XmlIoUtil.readXml(rp.makeUrl(XML_LOCATION).toExternalForm());
View Full Code Here

  if (context == null) {
    context = RequestContext.extract(servletRequest);
  }
 
  if (messageBroker == null) {
    messageBroker = new MessageBroker();
    messageBroker.setBundleBaseName("gpt.resources.gpt");
  }
  CatalogConfiguration catCfg = context.getCatalogConfiguration();

  // look for a configured class name for the resource link builder
View Full Code Here

    AsnOperation operation = context.getOperation();
    AsnProperty property = operation.getUIResources();
    context.getAuthorizer().authorizeQuery(context);
     
    // get the message broker
    MessageBroker msgBroker = context.getMessageBroker();
    if (msgBroker == null) {
      msgBroker = new MessageBroker();
      msgBroker.setBundleBaseName(MessageBroker.DEFAULT_BUNDLE_BASE_NAME);
    }

    // update each resource, generate the response
    for (AsnProperty child: property.getChildren()) {
      if (child instanceof AsnUIResource) {
        AsnUIResource uiResource = (AsnUIResource)child;
        String resourceKey = Val.chkStr(uiResource.getResourceKey());
        if (resourceKey.length() > 0) {
          String resourceValue = msgBroker.retrieveMessage(resourceKey);
          uiResource.setResourceValue(resourceValue);
          //System.err.println(resourceKey+" = "+uiResource.getDefaultValue());
        }
      }
    }
View Full Code Here

   * @return records
   * @throws Exception if searching fails
   */
  @Override
  public IFeedRecords doSearch(HttpServletRequest request, HttpServletResponse response, RequestContext context, RestQuery query) throws Exception {
    MessageBroker msgBroker = new FacesContextBroker(request, response).extractMessageBroker();
    final Map<DiscoveredRecord, Map<String, List<String>>> mapping = new HashMap<DiscoveredRecord, Map<String, List<String>>>();

    List<IFeedRecords.FieldMeta> fields = new ArrayList<IFeedRecords.FieldMeta>();
    loadStdFieldMeta(fields);

    int startRecord = query.getFilter().getStartRecord();
    boolean returnIdsOnly = Val.chkBool(Val.chkStr(request.getParameter("returnIdsOnly")), false);
    if (returnIdsOnly) {
      startRecord = 1;
      query.getFilter().setMaxRecords(1);
      LuceneQueryAdapter tmp = new LuceneQueryAdapter();
      tmp.execute(context, query);
      query.getFilter().setMaxRecords(query.getResult().getNumberOfHits());
    }

    query.getFilter().setStartRecord(startRecord);
    LuceneQueryAdapter lqa = new LuceneQueryAdapter() {
      @Override
      protected void onRecord(DiscoveredRecord record, Document document) {
        Map<String, List<String>> fieldMap = new HashMap<String, List<String>>();
        for (Fieldable field : document.getFields()) {
          String name = field.name();
          List<String> fieldValues = fieldMap.get(name);
          if (fieldValues == null) {
            fieldValues = new ArrayList<String>();
            fieldMap.put(name, fieldValues);
          }
          fieldValues.add(field.stringValue());
        }
        mapping.put(record, fieldMap);
      }
    };
    lqa.execute(context, query);
    startRecord += query.getFilter().getMaxRecords();

    loadLuceneMeta(context, fields);

    OpenSearchProperties osProps = new OpenSearchProperties();
    osProps.setShortName(msgBroker.retrieveMessage("catalog.openSearch.shortName"));
    osProps.setNumberOfHits(query.getResult().getNumberOfHits());
    osProps.setStartRecord(query.getFilter().getStartRecord());
    osProps.setRecordsPerPage(query.getFilter().getMaxRecords());

    ResourceIdentifier resourceIdentifier = ResourceIdentifier.newIdentifier(context);
View Full Code Here

*
* @return the string
*/
protected String readHeader() {
  StringBuffer row = new StringBuffer();
  MessageBroker mBrok = this.getMessageBroker();
  row
    .append(readEscapedCsvField(mBrok.retrieveMessage(
      "catalog.searchresult.csv.header.contentType")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
      "catalog.searchresult.csv.header.urlToMetadata")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
      "catalog.searchresult.csv.header.urlToliveData")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
      "catalog.searchresult.csv.header.urlToSiteOrDownLoad")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
        "catalog.searchresult.csv.header.title")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
        "catalog.searchresult.csv.header.abstract")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
        "catalog.searchresult.csv.header.west")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
        "catalog.searchresult.csv.header.east")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
        "catalog.searchresult.csv.header.north")))
    .append(DELIMETER)
    .append(readEscapedCsvField(mBrok.retrieveMessage(
        "catalog.searchresult.csv.header.south")))
    .append(DELIMETER)
    .append("\n");
  return row.toString();
}
View Full Code Here

* @param record the record
* @return the string
*/
protected String readRow(IFeedRecord record) {
  StringBuffer row = new StringBuffer();
  MessageBroker mBrok = this.getMessageBroker();
  String contentType = mBrok.retrieveMessage(
      "catalog.search.filterContentTypes." +
      record.getContentType());
  String resourceUrl = record.getResourceUrl();
  String webSite = record.getResourceLinks().findUrlByTag(ResourceLink.TAG_WEBSITE);
  if(!record.getContentType().toLowerCase().equals("livedata")) {
View Full Code Here

private void verifyFile(ActionEvent event, RequestContext context)
  throws Exception  {

  // extract the uploaded file information from the request,
  // ensure that a file with valid XML content was supplied
  MessageBroker msgBroker = extractMessageBroker();
  String sFileName = "";
  try {
    FileItem item = extractFileItem();
    if (item != null) {
      sFileName = Val.chkStr(item.getName());
      String sXml = Val.chkStr(item.getString("UTF-8"));

      // remove the UTF-8 byte order mark if present
      byte[] bom = new byte[3];
      bom[0] = (byte)0xEF;
      bom[1] = (byte)0xBB;
      bom[2] = (byte)0xBF;
      String sbom = new String(bom,"UTF-8");
      if (sXml.startsWith(sbom)) {
        sXml = Val.chkStr(sXml.substring(1));
      }

      if (sFileName.length() == 0) {
        msgBroker.addErrorMessage("publication.validateMetadata.err.file.required");
      } else if (sXml.length() == 0) {
        msgBroker.addErrorMessage("publication.validateMetadata.err.file.empty");
      } else {

        //String sOut = "C:/xfer/test19139.xml";
        //com.esri.gpt.framework.xml.XmlIoUtil.writeXmlFile(sXml,new java.io.File(sOut));

        // verifies the file, set the success message
        ValidationRequest request = new ValidationRequest(context,sFileName,sXml);
        request.verify();
        msgBroker.addSuccessMessage("catalog.publication.success.validated");
      }
    }

  } catch (ValidationException e) {
    FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_WARN,sFileName,null);
    msgBroker.addMessage(fm);

    String sKey = e.getKey();
    if (sKey.length() > 0) {
      String sMsg = sKey;
      Schema schema = context.getCatalogConfiguration().getConfiguredSchemas().get(sKey);
      if (schema != null) {
        if (schema.getLabel() != null) {
          String sResKey = schema.getLabel().getResourceKey();
          if (sResKey.length() > 0) {
            sMsg = extractMessageBroker().retrieveMessage(sResKey)+" ("+sKey+")";
          }
        }
      }
      fm = new FacesMessage(FacesMessage.SEVERITY_WARN," - "+sMsg,null);
      extractMessageBroker().addMessage(fm);
    }

    e.getValidationErrors().buildMessages(msgBroker,true);

  } catch (Exception e) {
    FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_WARN,sFileName,null);
    msgBroker.addMessage(fm);

    // there seems to be no good exception related to a file that is simply
    // not an XML file, a message containing "content is not allowed in prolog"
    // seems to be the best guess at the moment
    String sMsg = e.toString().toLowerCase();
    if (sMsg.indexOf("content is not allowed in prolog") != -1) {
      msgBroker.addErrorMessage("publication.validateMetadata.err.file.prolog");
    } else {
      throw e;
    }
  }
}
View Full Code Here

TOP

Related Classes of com.esri.gpt.framework.jsf.MessageBroker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.