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.
/*
* eXist Open Source Native XML Database
* Copyright (C) 2001-2019 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.exist.xmldb;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import com.evolvedbinary.j8fu.lazy.LazyVal;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.exist.security.Permission;
import org.exist.storage.serializers.EXistOutputKeys;
import org.exist.util.EXistInputSource;
import org.exist.util.FileUtils;
import org.exist.util.Leasable;
import org.exist.util.io.ByteArrayContent;
import org.exist.util.io.ContentFile;
import org.exist.util.io.FastByteArrayInputStream;
import org.exist.util.io.FastByteArrayOutputStream;
import org.exist.util.io.TemporaryFileManager;
import org.exist.util.io.VirtualTempPath;
import org.xml.sax.InputSource;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.ErrorCodes;
import org.xmldb.api.base.Resource;
import org.xmldb.api.base.XMLDBException;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.exist.util.io.InputStreamUtil.copy;
public abstract class AbstractRemoteResource extends AbstractRemote
implements EXistResource, ExtendedResource, Resource {
protected final Leasable.Lease xmlRpcClientLease;
protected final XmldbURI path;
private String mimeType;
protected Path file = null;
private ContentFile contentFile = null;
protected InputSource inputSource = null;
private long contentLen = -1L;
private Permission permissions = null;
private boolean closed;
private LazyVal inMemoryBufferSize;
Date dateCreated = null;
Date dateModified = null;
protected AbstractRemoteResource(final Leasable.Lease xmlRpcClientLease, final RemoteCollection parent, final XmldbURI documentName, final String mimeType) {
super(parent);
this.xmlRpcClientLease = xmlRpcClientLease;
if (documentName.numSegments() > 1) {
this.path = documentName;
} else {
this.path = parent.getPathURI().append(documentName);
}
this.mimeType = mimeType;
}
@Override
public Properties getProperties() {
return collection.getProperties();
}
@Override
public Object getContent()
throws XMLDBException {
final Object res = getExtendedContent();
if (res != null) {
if (res instanceof byte[]) {
return res;
} else if (res instanceof Path) {
return readFile((Path) res);
} else if (res instanceof java.io.File) {
return readFile(((java.io.File) res).toPath());
} else if (res instanceof InputSource) {
return readFile((InputSource) res);
} else if (res instanceof ContentFile) {
return ((ContentFile) res).getBytes();
}
}
return res;
}
/**
* Get the data.
*
* @return the data
*
* @throws XMLDBException if an error occurs whilst retrieving the data.
*
* @deprecated instead use {@link org.xmldb.api.base.Resource#getContent()}
*/
@Deprecated
protected byte[] getData()
throws XMLDBException {
final Object res = getExtendedContent();
if (res != null) {
if (res instanceof Path) {
return readFile((Path) res);
} else if (res instanceof java.io.File) {
return readFile(((java.io.File) res).toPath());
} else if (res instanceof InputSource) {
return readFile((InputSource) res);
} else if (res instanceof String) {
return ((String) res).getBytes(UTF_8);
} else if (res instanceof ContentFile) {
return ((ContentFile) res).getBytes();
}
}
return (byte[]) res;
}
@Override
public long getContentLength()
throws XMLDBException {
return contentLen;
}
@Override
public Date getCreationTime()
throws XMLDBException {
return dateCreated;
}
@Override
public Date getLastModificationTime()
throws XMLDBException {
return dateModified;
}
@Override
public void setLastModificationTime(final Date dateModified) throws XMLDBException {
if (dateModified != null) {
if (dateModified.before(getCreationTime())) {
throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, "Modification time must be after creation time.");
}
final List