⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 importcontextimpl.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
字号:
/* * 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. */package org.apache.jackrabbit.server.io;import org.apache.jackrabbit.webdav.io.InputContext;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import javax.jcr.Item;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Date;/** * <code>ImportContextImpl</code>... */public class ImportContextImpl implements ImportContext {    private static Logger log = LoggerFactory.getLogger(ImportContextImpl.class);    private final IOListener ioListener;    private final Item importRoot;    private final String systemId;    private final File inputFile;    private InputContext inputCtx;    private boolean completed;    /**     * Creates a new item import context with the given root item and the     * specified <code>InputContext</code>. If the input context provides an     * input stream, the stream is written to a temporary file in order to avoid     * problems with multiple IOHandlers that try to run the import but fail.     * The temporary file is deleted as soon as this context is informed that     * the import has been completed and it will not be used any more.     *     * @param importRoot the import root node     * @param inputCtx wrapped by this <code>ImportContext</code>     */    public ImportContextImpl(Item importRoot, String systemId, InputContext inputCtx) throws IOException {        this(importRoot, systemId, (inputCtx != null) ? inputCtx.getInputStream() : null, null);        this.inputCtx = inputCtx;    }    /**     * Creates a new item import context. The specified InputStream is written     * to a temporary file in order to avoid problems with multiple IOHandlers     * that try to run the import but fail. The temporary file is deleted as soon     * as this context is informed that the import has been completed and it     * will not be used any more.     *     * @param importRoot     * @param systemId     * @param in     * @param ioListener     * @throws IOException     * @see ImportContext#informCompleted(boolean)     */    public ImportContextImpl(Item importRoot, String systemId, InputStream in, IOListener ioListener) throws IOException {        this.importRoot = importRoot;        this.systemId = systemId;        this.inputFile = IOUtil.getTempFile(in);        this.ioListener = (ioListener != null) ? ioListener : new DefaultIOListener(log);    }    /**     * @see ImportContext#getIOListener()     */    public IOListener getIOListener() {        return ioListener;    }    /**     * @see ImportContext#getImportRoot()     */    public Item getImportRoot() {        return importRoot;    }    /**     * @see ImportContext#hasStream()     */    public boolean hasStream() {        return inputFile != null;    }    /**     * Returns a new <code>InputStream</code> to the temporary file created     * during instanciation or <code>null</code>, if this context does not     * provide a stream.     *     * @see ImportContext#getInputStream()     * @see #hasStream()     */    public InputStream getInputStream() {        checkCompleted();        InputStream in = null;        if (inputFile != null) {            try {                in = new FileInputStream(inputFile);            } catch (IOException e) {                // unexpected error... ignore and return null            }        }        return in;    }    /**     * @see ImportContext#getSystemId()     */    public String getSystemId() {        return systemId;    }    /**     * @see ImportContext#getModificationTime()     */    public long getModificationTime() {        return (inputCtx != null) ? inputCtx.getModificationTime() : new Date().getTime();    }    /**     * @see ImportContext#getContentLanguage()     */    public String getContentLanguage() {        return (inputCtx != null) ? inputCtx.getContentLanguage() : null;    }    /**     * @see ImportContext#getContentLength()     */    public long getContentLength() {        if (inputCtx != null) {            return inputCtx.getContentLength();        } else if (inputFile != null) {            return inputFile.length();        } else {            log.debug("Unable to determine content length -> default value = " + IOUtil.UNDEFINED_LENGTH);            return IOUtil.UNDEFINED_LENGTH;        }    }    /**     * @return the content type present on the <code>InputContext</code> or     * <code>null</code>     * @see InputContext#getContentType()     */    private String getContentType() {        return (inputCtx != null) ? inputCtx.getContentType() : null;    }    /**     * @see ImportContext#getMimeType()     */    public String getMimeType() {        String contentType = getContentType();        String mimeType = null;        if (contentType != null) {            mimeType = IOUtil.getMimeType(contentType);        } else if (getSystemId() != null) {            mimeType = IOUtil.MIME_RESOLVER.getMimeType(getSystemId());        }        return mimeType;    }    /**     * @see ImportContext#getEncoding()     */    public String getEncoding() {        String contentType = getContentType();        return (contentType != null) ? IOUtil.getEncoding(contentType) : null;    }    /**     * @see ImportContext#getProperty(Object)     */    public Object getProperty(Object propertyName) {        return (inputCtx != null) ? inputCtx.getProperty(propertyName.toString()) : null;    }    /**     * @see ImportContext#informCompleted(boolean)     */    public void informCompleted(boolean success) {        checkCompleted();        completed = true;        if (inputFile != null) {            inputFile.delete();        }    }    /**     * @see ImportContext#isCompleted()     */    public boolean isCompleted() {        return completed;    }    /**     * @throws IllegalStateException if the context is already completed.     * @see #isCompleted()     * @see #informCompleted(boolean)     */    private void checkCompleted() {        if (completed) {            throw new IllegalStateException("ImportContext has already been consumed.");        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -