Ejemplo n.º 1
0
  // javadoc inherited
  public String perform(Map params) throws IllegalArgumentException, Exception {
    String direction = WidgetServiceHelper.getParameter(params, P_DIR);
    Integer x = WidgetServiceHelper.getIntParameter(params, P_X);
    Integer y = WidgetServiceHelper.getIntParameter(params, P_Y);
    String t = WidgetServiceHelper.getParameter(params, P_T);
    Integer offx = WidgetServiceHelper.getIntParameter(params, P_OFFX);
    Integer offy = WidgetServiceHelper.getIntParameter(params, P_OFFY);
    Integer zoom = WidgetServiceHelper.getIntParameter(params, P_ZOOM);

    if (null == direction) {
      throw new IllegalArgumentException(exceptionLocalizer.format("widget-missing-dir-parameter"));
    }
    if (null == zoom) {
      throw new IllegalArgumentException(
          exceptionLocalizer.format("widget-missing-zoom-parameter"));
    }

    if (null != t && null != offx && null != offy && DIR_IN.equals(direction)) {
      return zoomInPhoto(zoom.intValue(), t, offx.intValue(), offy.intValue());
    }
    if (null != t && null != offx && null != offy && DIR_OUT.equals(direction)) {
      return zoomOutPhoto(zoom.intValue(), t, offx.intValue(), offy.intValue());
    } else if ((null != x) && (null != y) && DIR_IN.equals(direction)) {
      return zoomInMap(zoom.intValue(), x.intValue(), y.intValue());
    } else if ((null != x) && (null != y) && DIR_OUT.equals(direction)) {
      return zoomOutMap(zoom.intValue(), x.intValue(), y.intValue());
    }
    throw new IllegalArgumentException(
        exceptionLocalizer.format("widet-invalid-zoom-operation-params"));
  }
  public LocalRepository createJDBCRepository(JDBCRepositoryConfiguration configuration)
      throws RepositoryException {

    JDBCDriverVendor vendor = configuration.getDriverVendor();

    DataSource dataSource = configuration.getDataSource();
    if (vendor == null) {
      vendor = getVendorFromDatabase(dataSource);
    }

    VendorFactory factory = (VendorFactory) VENDOR_2_FACTORY.get(vendor);
    if (factory == null) {
      throw new JDBCRepositoryException(EXCEPTION_LOCALIZER.format("jdbc-unknown-vendor", vendor));
    }

    InternalJDBCRepository repository =
        factory.createRepository((InternalJDBCRepositoryConfiguration) configuration);

    JDBCRepositoryConnection connection = null;
    try {
      connection = (JDBCRepositoryConnection) repository.connect();
      connection.getConnection();

    } finally {
      connection.disconnect();
    }

    return repository;
  }
  public DataSource createMCSDriverDataSource(MCSDriverConfiguration configuration)
      throws JDBCRepositoryException, RepositoryException {

    // Get the vendor string.
    JDBCDriverVendor vendor = configuration.getDriverVendor();
    if (vendor == null) {
      throw new JDBCRepositoryException(EXCEPTION_LOCALIZER.format("jdbc-missing-vendor"));
    }

    VendorFactory factory = (VendorFactory) VENDOR_2_FACTORY.get(vendor);
    if (factory == null) {
      throw new JDBCRepositoryException(EXCEPTION_LOCALIZER.format("jdbc-unknown-vendor", vendor));
    }

    DataSource dataSource = factory.createDriverDataSource(configuration);

    return createMCSConnectionPool(configuration.getConnectionPoolConfiguration(), dataSource);
  }
  private JDBCDriverVendor getVendorFromDatabase(DataSource dataSource)
      throws JDBCRepositoryException {

    JDBCDriverVendor vendor;
    if (dataSource instanceof VendorDataSource) {
      VendorDataSource vendorDataSource = (VendorDataSource) dataSource;
      vendor = vendorDataSource.getVendor();
    } else {
      String databaseProduct = null;
      Connection con = null;
      try {
        con = dataSource.getConnection();
        DatabaseMetaData metaData = con.getMetaData();
        databaseProduct = metaData.getDatabaseProductName();
        con.close();
      } catch (SQLException sqle) {
        throw new JDBCRepositoryException(EXCEPTION_LOCALIZER.format("sql-exception"), sqle);
      }

      if (PRODUCT_ORACLE.equalsIgnoreCase(databaseProduct)) {
        vendor = JDBCDriverVendor.ORACLE8;
      } else if (databaseProduct != null
          && databaseProduct.regionMatches(true, 0, PRODUCT_DB2, 0, PRODUCT_DB2.length())) {
        vendor = JDBCDriverVendor.DB2;
      } else if (PRODUCT_MSSQL.equalsIgnoreCase(databaseProduct)) {
        vendor = JDBCDriverVendor.MSSQL_JSQL;
      } else if (PRODUCT_SYBASE.equalsIgnoreCase(databaseProduct)) {
        vendor = JDBCDriverVendor.SYBASE;
      } else if (PRODUCT_POSTGRES.equalsIgnoreCase(databaseProduct)) {
        vendor = JDBCDriverVendor.POSTGRESQL;
      } else if (PRODUCT_HYPERSONIC.equalsIgnoreCase(databaseProduct)) {
        vendor = JDBCDriverVendor.HYPERSONIC;
      } else if (PRODUCT_MYSQL.equalsIgnoreCase(databaseProduct)) {
        vendor = JDBCDriverVendor.MYSQL;
      } else if (PRODUCT_DERBY.equalsIgnoreCase(databaseProduct)) {
        vendor = JDBCDriverVendor.DERBY_SERVER;
      } else {
        throw new JDBCRepositoryException(
            EXCEPTION_LOCALIZER.format("jdbc-unknown-vendor", databaseProduct));
      }
    }
    return vendor;
  }
 /**
  * Accepts a localization key a substitution parameter (or an array of substitution parameters,
  * and a cause exception
  *
  * @param key the message localization key
  * @param param the substitution parameter or array of substitution params
  * @param cause the cause excception
  */
 public ResourceRetrieverException(String key, Object param, Throwable cause) {
   super(EXCEPTION_LOCALIZER.format(key, param), cause);
 }
Ejemplo n.º 6
0
  // Javadoc inherited.
  protected int exprElementEnd(MarinerRequestContext context, PAPIAttributes papiAttributes)
      throws PAPIException {
    IncludeAttributes attributes = (IncludeAttributes) papiAttributes;

    if (attributes.getHref() == null) {
      throw new PAPIException(exceptionLocalizer.format("include-href-missing"));
    } else {
      // @todo this is a bit duff since it relies on markup naming not to change; do this a
      // different way
      // Set up the markup that will be sent down the pipeline
      StringBuffer markup = new StringBuffer();
      InputSource inputSource;

      markup.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
      markup
          .append("<urid:fetch xmlns:urid=\"")
          .append(Namespace.URID.getURI())
          .append("\" href=\"")
          .append(attributes.getHref())
          .append("\"");

      if (attributes.getParse() != null) {
        markup.append(" parse=\"").append(attributes.getParse()).append("\"");
      }

      if (attributes.getEncoding() != null) {
        markup.append(" encoding=\"").append(attributes.getEncoding()).append("\"");
      }

      markup.append("/>");

      if (logger.isDebugEnabled()) {
        logger.debug("Set up inclusion command as: " + markup.toString());
      }

      inputSource = new InputSource(new StringReader(markup.toString()));

      // Set up and execute the pipeline to perform the required
      // inclusion
      MarinerPageContext pageContext = ContextInternals.getMarinerPageContext(context);
      XMLReader reader = MarlinSAXHelper.getXMLReader(context);
      reader.setContentHandler(MarlinSAXHelper.getContentHandler(context));
      // @todo this is nasty: we assume that the reader is actually an XMLPipelineFilter
      XMLPipelineFilter filter = (XMLPipelineFilter) reader;
      XMLPipelineContext pipelineContext = filter.getPipelineContext();

      // set the Base URI in the pipeline's context
      try {
        URL baseURI = pageContext.getAbsoluteURL(pageContext.getRequestURL(false));

        if (logger.isDebugEnabled()) {
          logger.debug("Setting Base URI " + baseURI);
        }

        pipelineContext.pushBaseURI(baseURI.toExternalForm());
      } catch (MalformedURLException e) {
        throw new PAPIException(e);
      }

      PipelineIntegrationUtilities.setUpIntegration(
          filter, pageContext.getCurrentElement(), context, pageContext.getCurrentOutputBuffer());

      if (logger.isDebugEnabled()) {
        logger.debug("Executing inclusion");
      }

      // Execute the inclusion
      try {
        reader.parse(inputSource);
      } catch (IOException e) {
        throw new PAPIException(e);
      } catch (SAXException e) {
        throw new PAPIException(e);
      } finally {
        PipelineIntegrationUtilities.tearDownIntegration(filter);
      }
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Successful execution of inclusion");
    }

    return CONTINUE_PROCESSING;
  }