All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry Maven / Gradle / Ivy

Go to download

ODFDOM is an OpenDocument Format (ODF) framework. Its purpose is to provide an easy common way to create, access and manipulate ODF files, without requiring detailed knowledge of the ODF specification. It is designed to provide the ODF developer community with an easy lightwork programming API portable to any object-oriented language. The current reference implementation is written in Java.

There is a newer version: 1.0.0-BETA1
Show newest version
/**
 * **********************************************************************
 *
 * 

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * *

Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved. * *

Use is subject to license terms. * *

Licensed 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. You can also obtain a copy of the License at * http://odftoolkit.org/docs/license.txt * *

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.odftoolkit.odfdom.pkg.manifest; import java.net.URLConnection; import org.odftoolkit.odfdom.pkg.OdfElement; public class OdfFileEntry { private FileEntryElement mFileEntryElement; private static final String EMPTY_STRING = ""; private static final String DEFAULT_TYPE = "application/octet-stream"; /** @param fileEntryElement the OdfElement of the */ public OdfFileEntry(FileEntryElement fileEntryElement) { mFileEntryElement = fileEntryElement; } public OdfFileEntry getCopy() { return new OdfFileEntry((FileEntryElement) this.mFileEntryElement.cloneNode(true)); } public void setPath(String path) { mFileEntryElement.setFullPathAttribute(path); } public String getPath() { return mFileEntryElement.getFullPathAttribute(); } /** * @param mediaType of the file. Use null or an empty string to unset the mediaType * to an empty string. */ public void setMediaTypeString(String mediaType) { if (mediaType != null) { mFileEntryElement.setMediaTypeAttribute(mediaType); } else { mFileEntryElement.setMediaTypeAttribute(EMPTY_STRING); } } /** * @return the mediatype of the mandatory <manifest:file-entry> attribute. If no mediatype * exists an empty string is returned */ public String getMediaTypeString() { return mFileEntryElement.getMediaTypeAttribute(); } /** * Get the media type from the given file reference * * @param fileRef the reference to the file the media type is questioned * @return the mediaType string of the given file reference */ public static String getMediaTypeString(String fileRef) { String mediaType = null; mediaType = URLConnection.guessContentTypeFromName(fileRef); if (mediaType == null) { mediaType = DEFAULT_TYPE; } return mediaType; } public void setSize(Integer size) { if (size == null) { mFileEntryElement.removeAttributeNS( SizeAttribute.ATTRIBUTE_NAME.getUri(), SizeAttribute.ATTRIBUTE_NAME.getLocalName()); } else { mFileEntryElement.setSizeAttribute(size); } } /** Get the size. */ public Integer getSize() { return mFileEntryElement.getSizeAttribute(); } public void setEncryptionData(EncryptionDataElement encryptionData) { EncryptionDataElement encryptionDataEle = getEncryptionData(); if (encryptionData != null) { if (encryptionDataEle != null) { mFileEntryElement.replaceChild(encryptionData, encryptionDataEle); } else { mFileEntryElement.appendChild(encryptionData); } } else { if (encryptionDataEle != null) { mFileEntryElement.removeChild(encryptionDataEle); } } } /** @return null if no encryption data had been set */ public EncryptionDataElement getEncryptionData() { return OdfElement.findFirstChildNode(EncryptionDataElement.class, mFileEntryElement); } /** * Gets the OdfElement of this OdfFileEntry. * * @return the OdfElement of this OdfFileEntry. */ public FileEntryElement getOdfElement() { return mFileEntryElement; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy