public static Resource createResource(Resource res,short level,short type){
  boolean asDir=type == TYPE_DIR;
  if (level >= LEVEL_FILE && res.exists() && ((res.isDirectory() && asDir) || (res.isFile() && !asDir))) {
    return getCanonicalResourceEL(res);
  }
  Resource parent=res.getParentResource();
  if (level >= LEVEL_PARENT_FILE && parent != null && parent.exists() && canRW(parent)) {
    if (asDir) {
      if (res.mkdirs())       return getCanonicalResourceEL(res);
    }
 else {
      if (createNewResourceEL(res))       return getCanonicalResourceEL(res);
    }
    return getCanonicalResourceEL(res);
  }
  if (level >= LEVEL_GRAND_PARENT_FILE && parent != null) {
    Resource gparent=parent.getParentResource();
    if (gparent != null && gparent.exists() && canRW(gparent)) {
      if (asDir) {
        if (res.mkdirs())         return getCanonicalResourceEL(res);
      }
 else {
        if (parent.mkdirs() && createNewResourceEL(res))         return getCanonicalResourceEL(res);
      }
    }
  }
  return null;
}

public static Resource createResource ( Resource res , short level , short type ) { boolean asDir = type == TYPE_DIR ; if ( level >= LEVEL_FILE && res . exists ( ) && ( ( res . isDirectory ( ) && asDir ) || ( res . isFile ( ) && ! asDir ) ) ) { return getCanonicalResourceEL ( res ) ; } Resource parent = res . getParentResource ( ) ; if ( level >= LEVEL_PARENT_FILE && parent != null && parent . exists ( ) && canRW ( parent ) ) { if ( asDir ) { if ( res . mkdirs ( ) ) return getCanonicalResourceEL ( res ) ; } else { if ( createNewResourceEL ( res ) ) return getCanonicalResourceEL ( res ) ; } return getCanonicalResourceEL ( res ) ; } if ( level >= LEVEL_GRAND_PARENT_FILE && parent != null ) { Resource gparent = parent . getParentResource ( ) ; if ( gparent != null && gparent . exists ( ) && canRW ( gparent ) ) { if ( asDir ) { if ( res . mkdirs ( ) ) return getCanonicalResourceEL ( res ) ; } else { if ( parent . mkdirs ( ) && createNewResourceEL ( res ) ) return getCanonicalResourceEL ( res ) ; } } } return null ; }
create a file if possible , return file if ok , otherwise return null
