Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package org.apache.taverna.robundle.manifest;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import static com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS;
import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_EMPTY_JSON_ARRAYS;
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_NULL_MAP_VALUES;
import static java.nio.file.FileVisitResult.CONTINUE;
import static java.nio.file.FileVisitResult.SKIP_SUBTREE;
import static java.nio.file.Files.createDirectories;
import static java.nio.file.Files.getLastModifiedTime;
import static java.nio.file.Files.isDirectory;
import static java.nio.file.Files.newBufferedWriter;
import static java.nio.file.Files.walkFileTree;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.nio.file.StandardOpenOption.WRITE;
import static java.nio.file.attribute.FileTime.fromMillis;
import static org.apache.taverna.robundle.Bundles.uriToBundlePath;
import java.io.IOException;
import java.io.Writer;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.apache.taverna.robundle.Bundle;
import org.apache.taverna.robundle.manifest.combine.CombineManifest;
import org.apache.taverna.robundle.manifest.odf.ODFManifest;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.ObjectMapper;
@JsonPropertyOrder(value = { "@context", "id", "manifest", "createdOn",
"createdBy", "createdOn", "authoredOn", "authoredBy", "history",
"aggregates", "annotations", "@graph" })
public class Manifest {
public abstract class FileTimeMixin {
@Override
@JsonValue
public abstract String toString();
}
public abstract class PathMixin {
@Override
@JsonValue
public abstract String toString();
}
private static Logger logger = Logger.getLogger(Manifest.class
.getCanonicalName());
private static final String MANIFEST_JSON = "manifest.json";
private static final String META_INF = "/META-INF";
private static final String MIMETYPE = "/mimetype";
private static final String RO = "/.ro";
private static URI ROOT = URI.create("/");
public static FileTime now() {
return fromMillis(new GregorianCalendar().getTimeInMillis());
}
protected static Path withSlash(Path dir) {
if (dir == null)
return null;
if (isDirectory(dir)) {
Path fname = dir.getFileName();
if (fname == null)
return dir;
String fnameStr = fname.toString();
if (fnameStr.endsWith("/"))
return dir;
return dir.resolveSibling(fnameStr + "/");
}
return dir;
}
private Map aggregates = new LinkedHashMap<>();
private List annotations = new ArrayList<>();
private List authoredBy = new ArrayList<>();
private FileTime authoredOn;
private Bundle bundle;
private Agent createdBy = null;
private FileTime createdOn = now();
private List graph;
private List history = new ArrayList<>();
private URI id = URI.create("/");
private List manifest = new ArrayList<>();
public Manifest(Bundle bundle) {
this.bundle = bundle;
}
public List getAggregates() {
return new ArrayList<>(aggregates.values());
}
public PathMetadata getAggregation(Path file) {
URI fileUri = file.toUri();
return getAggregation(fileUri);
}
public PathMetadata getAggregation(URI uri) {
uri = relativeToBundleRoot(uri);
PathMetadata metadata = aggregates.get(uri);
if (metadata == null) {
metadata = new PathMetadata();
if (!uri.isAbsolute() && uri.getFragment() == null) {
Path path = uriToBundlePath(bundle, uri);
metadata.setFile(path);
metadata.setMediatype(guessMediaType(path));
} else {
metadata.setUri(uri);
}
aggregates.put(uri, metadata);
}
return metadata;
}
public List getAnnotations() {
return annotations;
}
public List getAuthoredBy() {
return authoredBy;
}
public FileTime getAuthoredOn() {
return authoredOn;
}
@JsonIgnore
public URI getBaseURI() {
return getBundle().getRoot().toUri();
}
@JsonIgnore
public Bundle getBundle() {
return bundle;
}
@JsonProperty(value = "@context")
public List