Changeset 7309


Ignore:
Timestamp:
Mar 17, 2017, 3:07:38 PM (5 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #2063: Add API for setting metadata on remote files

Overloaded File.setUrl() method with a variant that also can set the metadata.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/File.java

    r7152 r7309  
    10411041    }
    10421042  }
     1043 
     1044  /**
     1045    Set the URL to an external file that should represent this file
     1046    object and update the metadata without going to the remote server.
     1047   
     1048    @param url The url to the file (null is not allowed)
     1049    @param metadata Metadata for the URL (or null to not update the metadata)
     1050    @since 3.11
     1051    @throws InvalidDataException If the URL is null, too long, or not a valid URL
     1052    @throws PermissionDeniedException If the logged in user doesn't have write permission
     1053  */
     1054  public void setUrl(String url, UriMetadata metadata)
     1055  {
     1056    checkPermission(Permission.WRITE);
     1057    FileData data = getData();
     1058   
     1059    // Validate the URL
     1060    URI uri = null;
     1061    try
     1062    {
     1063      uri = new URI(url).normalize();
     1064      data.setUrl(StringUtil.setNotNullString(uri.toString(), "url", MAX_URL_LENGTH));
     1065    }
     1066    catch (URISyntaxException ex)
     1067    {
     1068      throw new InvalidDataException("Invalid URL: " + url, ex);
     1069    }
     1070   
     1071    // Update properties so they make sense for external files
     1072    data.setLocation(Location.EXTERNAL.getValue());
     1073    data.setCompressed(false);
     1074    data.setMd5(null);
     1075    data.setAction(Action.NOTHING.getValue());
     1076   
     1077    if (metadata != null) setMetadataFromURI(metadata);
     1078  }
    10431079
    10441080  /**
     
    10681104    }
    10691105  }
     1106 
    10701107 
    10711108  /**
Note: See TracChangeset for help on using the changeset viewer.