Example #1
0
  @SuppressWarnings("rawtypes")
  public static FileIDs searchFileIDs(FleximsDynamicEntityImpl de, String propName, String prefix) {
    FileIDs fileIDs = new FileIDs();
    XMLEntityMappings mappings = JpaMapHelper.getInternaEntityMappings();
    Class<?> clz = de.getClass();
    String firstName = null;
    String subName = null;
    if (propName != null) {
      int i = propName.indexOf('.');
      if (i != -1) {
        firstName = propName.substring(0, i);
        subName = propName.substring(i + 1);
      } else {
        firstName = propName;
      }
    }

    while (clz != FleximsDynamicEntityImpl.class && clz != Object.class) {
      ClassAccessor accessor = JpaMapHelper.findClassAccessor(mappings, clz.getSimpleName());
      if (accessor != null && accessor.getAttributes() != null) {

        // single file.
        for (BasicAccessor prop : accessor.getAttributes().getBasics()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Object value = de.get(prop.getName());
          if (value == null) {
            continue;
          }
          if (isFileUpload(prop)) {
            FileID fileID = FileID.valueOf((String) value);

            if (fileID != null) {
              fileIDs.getFileIDs().add(fileID);
              fileID.setPropName(prefix == null ? prop.getName() : prefix + "/" + prop.getName());
            }
          }
        }

        for (ElementCollectionAccessor prop : accessor.getAttributes().getElementCollections()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Collection values = de.get(prop.getName());
          if (values == null || values.isEmpty()) {
            continue;
          }
          if (isFileUpload(prop)) {
            for (Object value : values) {
              FileID fileID = FileID.valueOf((String) value);
              if (fileID != null) {
                fileIDs.getFileIDs().add(fileID);
                fileID.setPropName(prefix == null ? prop.getName() : prefix + "/" + prop.getName());
              }
            }
            continue;
          }
          Object firstObject = values.iterator().next();
          // collection of embedded
          if (firstObject instanceof FleximsDynamicEntityImpl) {
            for (Object obj : values) {
              FleximsDynamicEntityImpl embeded = (FleximsDynamicEntityImpl) obj;
              FileIDs iDs =
                  searchFileIDs(
                      embeded,
                      subName,
                      prefix == null ? prop.getName() : prefix + "/" + prop.getName());
              fileIDs.getFileIDs().addAll(iDs.getFileIDs());
            }
          }
        }
        for (EmbeddedAccessor prop : accessor.getAttributes().getEmbeddeds()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          FleximsDynamicEntityImpl embeded = de.get(prop.getName());
          if (embeded == null) {
            continue;
          }
          if (embeded != null) {
            FileIDs iDs =
                searchFileIDs(
                    embeded,
                    subName,
                    prefix == null ? prop.getName() : prefix + "/" + prop.getName());
            fileIDs.getFileIDs().addAll(iDs.getFileIDs());
          }
        }
      }
      clz = clz.getSuperclass();
    }
    return fileIDs;
  }
Example #2
0
  @SuppressWarnings("rawtypes")
  public static FileInfos searchServerFileInfos(
      FleximsDynamicEntityImpl de, String propName, Path prefix, Path start) {
    FileInfos fileInfos = new FileInfos();
    if (prefix == null) {
      prefix = serverFileTopDir();
    }
    if (start == null) {
      start = serverFileTopDir();
    }
    XMLEntityMappings mappings = JpaMapHelper.getInternaEntityMappings();
    Class<?> clz = de.getClass();
    String firstName = null;
    String subName = null;
    if (propName != null) {
      int i = propName.indexOf('.');
      if (i != -1) {
        firstName = propName.substring(0, i);
        subName = propName.substring(i + 1);
      } else {
        firstName = propName;
      }
    }

    while (clz != FleximsDynamicEntityImpl.class && clz != Object.class) {
      ClassAccessor accessor = JpaMapHelper.findClassAccessor(mappings, clz.getSimpleName());
      if (accessor != null) {

        // single file.
        for (BasicAccessor prop : accessor.getAttributes().getBasics()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Object value = de.get(prop.getName());
          if (value == null) {
            continue;
          }
          if (isServerFile(prop)) {
            Path filePath = prefix.resolve((String) value);
            if (!filePath.startsWith(prefix)) {
              // you can not navigate out.
              continue;
            }
            FileInfo fileInfo = pathToFileInfo(filePath, start);
            fileInfos.getFileInfos().add(fileInfo);
          }
        }

        for (ElementCollectionAccessor prop : accessor.getAttributes().getElementCollections()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          Collection values = de.get(prop.getName());
          if (values == null || values.isEmpty()) {
            continue;
          }
          if (isServerFile(prop)) {
            for (Object value : values) {
              Path filePath = prefix.resolve((String) value);
              if (!filePath.startsWith(prefix)) {
                // you can not navigate out.
                continue;
              }
              FileInfo fileInfo = pathToFileInfo(filePath, start);
              fileInfos.getFileInfos().add(fileInfo);
            }
            continue;
          }

          Object firstObject = values.iterator().next();
          // collection of embedded
          if (firstObject instanceof FleximsDynamicEntityImpl) {
            for (Object obj : values) {
              FleximsDynamicEntityImpl embeded = (FleximsDynamicEntityImpl) obj;
              FileInfos fileInfos2 = searchServerFileInfos(embeded, subName, prefix, start);
              fileInfos.getFileInfos().addAll(fileInfos2.getFileInfos());
            }
          }
        }
        for (EmbeddedAccessor prop : accessor.getAttributes().getEmbeddeds()) {
          if (firstName != null && !prop.getName().equals(firstName)) {
            continue;
          }
          FleximsDynamicEntityImpl embeded = de.get(prop.getName());
          if (embeded == null) {
            continue;
          }
          if (embeded != null) {
            FileInfos fileInfos2 = searchServerFileInfos(embeded, subName, prefix, start);
            fileInfos.getFileInfos().addAll(fileInfos2.getFileInfos());
          }
        }
      }
      clz = clz.getSuperclass();
    }
    return fileInfos;
  }