String u = target.feed.toString();
if (u.charAt(u.length()-1)!='/') {
u += "/";
}
final String feedBase = u;
final MetadataService metadataService = new MetadataService();
target.dir.listFiles(new FileFilter() {
public boolean accept(File file) {
if (file.isDirectory()) {
URI subFeed = URI.create(feedBase+file.getName()+"/");
targets.add(new Target(file,subFeed));
} else {
if (!excludeDot || file.getName().charAt(0)!='.') {
// Sync content
Entry entry = entries.get(file.getName());
Status status = null;
if (entry!=null) {
log.info("Updating "+file);
// update existing media
try {
FileInputStream is = new FileInputStream(file);
EntryClient client = feedClient.getEntryClient(entry);
status = client.updateMedia(new InputRepresentation(is,entry.getMediaContent().getMediaType()));
is.close();
} catch (IOException ex) {
log.log(Level.SEVERE,"Cannot update "+file+" due to I/O exception.",ex);
}
entries.remove(file.getName());
} else {
log.info("Creating "+file);
// create new media
try {
FileInputStream is = new FileInputStream(file);
int extPos = file.getName().lastIndexOf('.');
String ext = extPos<0 ? null : file.getName().substring(extPos+1);
Metadata metadata = ext==null ? null : metadataService.getMetadata(ext);
MediaType type = metadata==null ? MediaType.APPLICATION_OCTET_STREAM : MediaType.valueOf(metadata.getName());
Entry mediaEntry = feedClient.createMedia(file.getName(),new InputRepresentation(is,type));
is.close();
} catch (StatusException ex) {
log.log(Level.SEVERE,"Cannot create media entry from "+file+" due to status "+ex.getStatus().getCode(),ex);