private static Resource[] merge(Resource[] first, Resource[] second) {
    if (ArrayUtil.isEmpty(second)) return first;
    if (ArrayUtil.isEmpty(first)) return second;

    Resource[] tmp = new Resource[first.length + second.length];
    for (int i = 0; i < first.length; i++) {
      tmp[i] = first[i];
    }
    for (int i = 0; i < second.length; i++) {
      tmp[first.length + i] = second[i];
    }
    return tmp;
  }
Exemple #2
0
 public void parse(
     IndexWriter writer, URL current, String[] extensions, boolean recurse, long timeout)
     throws IOException {
   translateExtension(extensions);
   if (ArrayUtil.isEmpty(extensions)) extensions = Index.EXTENSIONS;
   _parse(log, writer, null, current, new ArrayList(), extensions, recurse, 0, timeout);
 }
  public void checkFileLocation(Config config, Resource res, String serverPassword)
      throws SecurityException {
    if (res == null || !(res.getResourceProvider() instanceof FileResourceProvider)) {
      return;
    }

    // All
    if (getAccess(TYPE_FILE) == VALUE_ALL) return;
    // Local
    if (getAccess(TYPE_FILE) == VALUE_LOCAL) {
      res = ResourceUtil.getCanonicalResourceEL(res);

      // local
      if (rootDirectory != null) if (ResourceUtil.isChildOf(res, rootDirectory)) return;
      // custom
      if (!ArrayUtil.isEmpty(customFileAccess)) {
        for (int i = 0; i < customFileAccess.length; i++) {
          if (ResourceUtil.isChildOf(res, customFileAccess[i])) return;
        }
      }
      if (isValid(config, serverPassword) || isAdminContext()) return;
      throw new SecurityException(
          createExceptionMessage(res, true), "access is prohibited by security manager");
    }
    // None
    if (isValid(config, serverPassword)) return;

    // custom
    if (!ArrayUtil.isEmpty(customFileAccess)) {
      res = ResourceUtil.getCanonicalResourceEL(res);

      for (int i = 0; i < customFileAccess.length; i++) {
        if (ResourceUtil.isChildOf(res, customFileAccess[i])) return;
      }
    }

    if (isAdminContext()) return;
    throw new SecurityException(
        createExceptionMessage(res, false), "access is prohibited by security manager");
  }
 public Resource[] getCustomFileAccess() {
   if (ArrayUtil.isEmpty(customFileAccess)) return EMPTY_RESOURCE_ARRAY;
   return (Resource[]) ArrayUtil.clone(customFileAccess, new Resource[customFileAccess.length]);
 }
  private synchronized SessionFactory getSessionFactory(PageContext pc, boolean init)
      throws PageException {
    ApplicationContextPro appContext = ((ApplicationContextPro) pc.getApplicationContext());
    if (!appContext.isORMEnabled())
      throw new ORMException(this, "ORM is not enabled in application.cfc/cfapplication");

    this.hash = hash(appContext);

    // datasource
    String dsn = appContext.getORMDatasource();
    if (StringUtil.isEmpty(dsn))
      throw new ORMException(this, "missing datasource defintion in application.cfc/cfapplication");
    if (!dsn.equalsIgnoreCase(datasource)) {
      configuration = null;
      if (_factory != null) _factory.close();
      _factory = null;
      datasource = dsn.toLowerCase();
    }

    // config
    ormConf = appContext.getORMConfiguration();

    // List<Component> arr = null;
    arr = null;
    if (init) {
      if (ormConf.autogenmap()) {
        arr = HibernateSessionFactory.loadComponents(pc, this, ormConf);
        cfcs.clear();
      } else
        throw new HibernateException(this, "orm setting autogenmap=false is not supported yet");
    }

    // load entities
    if (!ArrayUtil.isEmpty(arr)) {
      loadNamingStrategy(ormConf);

      DatasourceConnectionPool pool =
          ((ConfigWebImpl) pc.getConfig()).getDatasourceConnectionPool();
      DatasourceConnection dc =
          pool.getDatasourceConnection(pc, pc.getConfig().getDataSource(dsn), null, null);
      // DataSourceManager manager = pc.getDataSourceManager();
      // DatasourceConnection dc=manager.getConnection(pc,dsn, null, null);
      this.ds = dc.getDatasource();
      try {
        Iterator<ComponentPro> it = arr.iterator();
        while (it.hasNext()) {
          createMapping(pc, it.next(), dc, ormConf);
        }
      } finally {
        pool.releaseDatasourceConnection(dc);
        // manager.releaseConnection(pc,dc);
      }
      if (arr.size() != cfcs.size()) {
        ComponentPro cfc;
        String name, lcName;
        Map<String, String> names = new HashMap<String, String>();
        Iterator<ComponentPro> it = arr.iterator();
        while (it.hasNext()) {
          cfc = it.next();
          name = HibernateCaster.getEntityName(cfc);
          lcName = name.toLowerCase();
          if (names.containsKey(lcName))
            throw new ORMException(
                this,
                "Entity Name ["
                    + name
                    + "] is ambigous, ["
                    + names.get(lcName)
                    + "] and ["
                    + cfc.getPageSource().getDisplayPath()
                    + "] use the same entity name.");
          names.put(lcName, cfc.getPageSource().getDisplayPath());
        }
      }
    }
    arr = null;
    if (configuration != null) return _factory;

    // MUST
    // cacheconfig
    // cacheprovider
    // ...

    String mappings = HibernateSessionFactory.createMappings(this, cfcs);

    DatasourceConnectionPool pool = ((ConfigWebImpl) pc.getConfig()).getDatasourceConnectionPool();
    DatasourceConnection dc =
        pool.getDatasourceConnection(pc, pc.getConfig().getDataSource(dsn), null, null);
    try {
      configuration = HibernateSessionFactory.createConfiguration(this, mappings, dc, ormConf);
    } catch (Exception e) {
      throw Caster.toPageException(e);
    } finally {
      pool.releaseDatasourceConnection(dc);
    }

    addEventListeners(pc, configuration, ormConf, cfcs);

    EntityTuplizerFactory tuplizerFactory = configuration.getEntityTuplizerFactory();
    // tuplizerFactory.registerDefaultTuplizerClass(EntityMode.MAP, CFCEntityTuplizer.class);
    // tuplizerFactory.registerDefaultTuplizerClass(EntityMode.MAP, MapEntityTuplizer.class);
    tuplizerFactory.registerDefaultTuplizerClass(EntityMode.MAP, AbstractEntityTuplizerImpl.class);
    tuplizerFactory.registerDefaultTuplizerClass(EntityMode.POJO, AbstractEntityTuplizerImpl.class);
    // tuplizerFactory.registerDefaultTuplizerClass(EntityMode.POJO,
    // AbstractEntityTuplizerImpl.class);

    // configuration.setEntityResolver(new CFCEntityResolver());
    // configuration.setEntityNotFoundDelegate(new EntityNotFoundDelegate());

    return _factory = configuration.buildSessionFactory();
  }