replaced log4j with POILogger in openxml4j, also converted non-ascii characters into unicode to keep javadoc quiet
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@746241 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
441d05aa7d
commit
bd27fe48ad
@ -85,7 +85,8 @@ public class ContentTypes {
|
|||||||
/**
|
/**
|
||||||
* TIFF image format.
|
* TIFF image format.
|
||||||
*
|
*
|
||||||
* @see http://partners.adobe.com/public/developer/tiff/index.html#spec
|
* @see <a href="http://partners.adobe.com/public/developer/tiff/index.html#spec">
|
||||||
|
* http://partners.adobe.com/public/developer/tiff/index.html#spec</a>
|
||||||
*/
|
*/
|
||||||
public static final String IMAGE_TIFF = "image/tiff";
|
public static final String IMAGE_TIFF = "image/tiff";
|
||||||
|
|
||||||
@ -94,7 +95,8 @@ public class ContentTypes {
|
|||||||
/**
|
/**
|
||||||
* Pict image format.
|
* Pict image format.
|
||||||
*
|
*
|
||||||
* @see http://developer.apple.com/documentation/mac/QuickDraw/QuickDraw-2.html
|
* @see <a href="http://developer.apple.com/documentation/mac/QuickDraw/QuickDraw-2.html">
|
||||||
|
* http://developer.apple.com/documentation/mac/QuickDraw/QuickDraw-2.html</a>
|
||||||
*/
|
*/
|
||||||
public static final String IMAGE_PICT = "image/pict";
|
public static final String IMAGE_PICT = "image/pict";
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ import java.util.Date;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
@ -48,6 +47,8 @@ import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMar
|
|||||||
import org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller;
|
import org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller;
|
||||||
import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext;
|
import org.apache.poi.openxml4j.opc.internal.unmarshallers.UnmarshallContext;
|
||||||
import org.apache.poi.openxml4j.util.Nullable;
|
import org.apache.poi.openxml4j.util.Nullable;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a container that can store multiple data objects.
|
* Represents a container that can store multiple data objects.
|
||||||
@ -60,7 +61,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
/**
|
/**
|
||||||
* Logger.
|
* Logger.
|
||||||
*/
|
*/
|
||||||
protected static Logger logger = Logger.getLogger("org.openxml4j.opc");
|
private static POILogger logger = POILogFactory.getLogger(Package.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default package access.
|
* Default package access.
|
||||||
@ -340,7 +341,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
if (this.packageAccess == PackageAccess.READ) {
|
if (this.packageAccess == PackageAccess.READ) {
|
||||||
logger
|
logger
|
||||||
.warn("The close() method is intended to SAVE a package. This package is open in READ ONLY mode, use the revert() method instead !");
|
.log(POILogger.WARN, "The close() method is intended to SAVE a package. This package is open in READ ONLY mode, use the revert() method instead !");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,7 +540,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
}
|
}
|
||||||
} catch (OpenXML4JException e) {
|
} catch (OpenXML4JException e) {
|
||||||
logger
|
logger
|
||||||
.warn("Can't retrieve parts by relationship type: an exception has been thrown by getRelationshipsByType method");
|
.log(POILogger.WARN, "Can't retrieve parts by relationship type: an exception has been thrown by getRelationshipsByType method");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return retArr;
|
return retArr;
|
||||||
@ -619,7 +620,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
if (unmarshallPart instanceof PackagePropertiesPart)
|
if (unmarshallPart instanceof PackagePropertiesPart)
|
||||||
this.packageProperties = (PackagePropertiesPart) unmarshallPart;
|
this.packageProperties = (PackagePropertiesPart) unmarshallPart;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
logger.warn("Unmarshall operation : IOException for "
|
logger.log(POILogger.WARN, "Unmarshall operation : IOException for "
|
||||||
+ part.partName);
|
+ part.partName);
|
||||||
continue;
|
continue;
|
||||||
} catch (InvalidOperationException invoe) {
|
} catch (InvalidOperationException invoe) {
|
||||||
@ -650,7 +651,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
* If rule M1.12 is not verified : Packages shall not contain
|
* If rule M1.12 is not verified : Packages shall not contain
|
||||||
* equivalent part names and package implementers shall neither
|
* equivalent part names and package implementers shall neither
|
||||||
* create nor recognize packages with equivalent part names.
|
* create nor recognize packages with equivalent part names.
|
||||||
* @see {@link#createPartImpl(URI, String)}
|
* @see #createPartImpl(PackagePartName, String, boolean)
|
||||||
*/
|
*/
|
||||||
public PackagePart createPart(PackagePartName partName, String contentType) {
|
public PackagePart createPart(PackagePartName partName, String contentType) {
|
||||||
return this.createPart(partName, contentType, true);
|
return this.createPart(partName, contentType, true);
|
||||||
@ -732,7 +733,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
* disk
|
* disk
|
||||||
*
|
*
|
||||||
* @return The new part.
|
* @return The new part.
|
||||||
* @see {@link #createPart(PackagePartName, String)}
|
* @see #createPart(PackagePartName, String)
|
||||||
*/
|
*/
|
||||||
public PackagePart createPart(PackagePartName partName, String contentType,
|
public PackagePart createPart(PackagePartName partName, String contentType,
|
||||||
ByteArrayOutputStream content) {
|
ByteArrayOutputStream content) {
|
||||||
@ -846,7 +847,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
sourcePartName = PackagingURIHelper.createPartName(sourceURI);
|
sourcePartName = PackagingURIHelper.createPartName(sourceURI);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
logger
|
logger
|
||||||
.error("Part name URI '"
|
.log(POILogger.ERROR, "Part name URI '"
|
||||||
+ sourceURI
|
+ sourceURI
|
||||||
+ "' is not valid ! This message is not intended to be displayed !");
|
+ "' is not valid ! This message is not intended to be displayed !");
|
||||||
return;
|
return;
|
||||||
@ -947,7 +948,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
this.deletePartRecursive(targetPartName);
|
this.deletePartRecursive(targetPartName);
|
||||||
}
|
}
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
logger.warn("An exception occurs while deleting part '"
|
logger.log(POILogger.WARN, "An exception occurs while deleting part '"
|
||||||
+ partName.getName()
|
+ partName.getName()
|
||||||
+ "'. Some parts may remain in the package. - "
|
+ "'. Some parts may remain in the package. - "
|
||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
@ -1126,7 +1127,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
*
|
*
|
||||||
* @return All package relationships of this package.
|
* @return All package relationships of this package.
|
||||||
* @throws OpenXML4JException
|
* @throws OpenXML4JException
|
||||||
* @see {@link #getRelationshipsHelper(String)}
|
* @see #getRelationshipsHelper(String)
|
||||||
*/
|
*/
|
||||||
public PackageRelationshipCollection getRelationships()
|
public PackageRelationshipCollection getRelationships()
|
||||||
throws OpenXML4JException {
|
throws OpenXML4JException {
|
||||||
@ -1230,7 +1231,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
try {
|
try {
|
||||||
partMarshallers.put(new ContentType(contentType), marshaller);
|
partMarshallers.put(new ContentType(contentType), marshaller);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
logger.warn("The specified content type is not valid: '"
|
logger.log(POILogger.WARN, "The specified content type is not valid: '"
|
||||||
+ e.getMessage() + "'. The marshaller will not be added !");
|
+ e.getMessage() + "'. The marshaller will not be added !");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1248,7 +1249,7 @@ public abstract class Package implements RelationshipSource {
|
|||||||
try {
|
try {
|
||||||
partUnmarshallers.put(new ContentType(contentType), unmarshaller);
|
partUnmarshallers.put(new ContentType(contentType), unmarshaller);
|
||||||
} catch (InvalidFormatException e) {
|
} catch (InvalidFormatException e) {
|
||||||
logger.warn("The specified content type is not valid: '"
|
logger.log(POILogger.WARN, "The specified content type is not valid: '"
|
||||||
+ e.getMessage()
|
+ e.getMessage()
|
||||||
+ "'. The unmarshaller will not be added !");
|
+ "'. The unmarshaller will not be added !");
|
||||||
}
|
}
|
||||||
|
@ -211,12 +211,12 @@ public abstract class PackagePart implements RelationshipSource {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a relationship to a part (except relationships part).
|
* Add a relationship to a part (except relationships part).
|
||||||
*
|
* <p>
|
||||||
* Check rule M1.25: The Relationships part shall not have relationships to
|
* Check rule M1.25: The Relationships part shall not have relationships to
|
||||||
* any other part. Package implementers shall enforce this requirement upon
|
* any other part. Package implementers shall enforce this requirement upon
|
||||||
* the attempt to create such a relationship and shall treat any such
|
* the attempt to create such a relationship and shall treat any such
|
||||||
* relationship as invalid.
|
* relationship as invalid.
|
||||||
*
|
* </p>
|
||||||
* @param targetPartName
|
* @param targetPartName
|
||||||
* Name of the target part. This one must be relative to the
|
* Name of the target part. This one must be relative to the
|
||||||
* source root directory of the part.
|
* source root directory of the part.
|
||||||
@ -281,12 +281,12 @@ public abstract class PackagePart implements RelationshipSource {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a relationship to a part (except relationships part).
|
* Add a relationship to a part (except relationships part).
|
||||||
*
|
* <p>
|
||||||
* Check rule M1.25: The Relationships part shall not have relationships to
|
* Check rule M1.25: The Relationships part shall not have relationships to
|
||||||
* any other part. Package implementers shall enforce this requirement upon
|
* any other part. Package implementers shall enforce this requirement upon
|
||||||
* the attempt to create such a relationship and shall treat any such
|
* the attempt to create such a relationship and shall treat any such
|
||||||
* relationship as invalid.
|
* relationship as invalid.
|
||||||
*
|
* </p>
|
||||||
* @param targetURI
|
* @param targetURI
|
||||||
* URI of the target part. Must be relative to the source root
|
* URI of the target part. Must be relative to the source root
|
||||||
* directory of the part.
|
* directory of the part.
|
||||||
@ -572,14 +572,14 @@ public abstract class PackagePart implements RelationshipSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return true if this part is a relationship
|
||||||
*/
|
*/
|
||||||
public boolean isRelationshipPart() {
|
public boolean isRelationshipPart() {
|
||||||
return this.isRelationshipPart;
|
return this.isRelationshipPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return true if this part has been logically deleted
|
||||||
*/
|
*/
|
||||||
public boolean isDeleted() {
|
public boolean isDeleted() {
|
||||||
return isDeleted;
|
return isDeleted;
|
||||||
|
@ -29,7 +29,7 @@ import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
|
|||||||
* @author Julien Chable
|
* @author Julien Chable
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*
|
*
|
||||||
* @see http://www.ietf.org/rfc/rfc3986.txt
|
* @see <a href="http://www.ietf.org/rfc/rfc3986.txt">http://www.ietf.org/rfc/rfc3986.txt</a>
|
||||||
*/
|
*/
|
||||||
public final class PackagePartName implements Comparable<PackagePartName> {
|
public final class PackagePartName implements Comparable<PackagePartName> {
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public final class PackageRelationship {
|
|||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* R<EFBFBD>f<EFBFBD>rence vers le package.
|
* Reference to the package.
|
||||||
*/
|
*/
|
||||||
private Package container;
|
private Package container;
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ public final class PackageRelationship {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param packageParent
|
* @param pkg
|
||||||
* @param sourcePart
|
* @param sourcePart
|
||||||
* @param targetUri
|
* @param targetUri
|
||||||
* @param targetMode
|
* @param targetMode
|
||||||
@ -170,7 +170,7 @@ public final class PackageRelationship {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return URL of the source part of this relationship
|
||||||
*/
|
*/
|
||||||
public URI getSourceURI() {
|
public URI getSourceURI() {
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
|
@ -22,13 +22,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.dom4j.Attribute;
|
import org.dom4j.Attribute;
|
||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.dom4j.io.SAXReader;
|
import org.dom4j.io.SAXReader;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a collection of PackageRelationship elements that are owned by a
|
* Represents a collection of PackageRelationship elements that are owned by a
|
||||||
@ -40,7 +41,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
|||||||
public final class PackageRelationshipCollection implements
|
public final class PackageRelationshipCollection implements
|
||||||
Iterable<PackageRelationship> {
|
Iterable<PackageRelationship> {
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger("org.openxml4j.opc");
|
private static POILogger logger = POILogFactory.getLogger(PackageRelationshipCollection.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Package relationships ordered by ID.
|
* Package relationships ordered by ID.
|
||||||
@ -300,7 +301,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
try {
|
try {
|
||||||
SAXReader reader = new SAXReader();
|
SAXReader reader = new SAXReader();
|
||||||
logger.debug("Parsing relationship: " + relPart.getPartName());
|
logger.log(POILogger.DEBUG, "Parsing relationship: " + relPart.getPartName());
|
||||||
Document xmlRelationshipsDoc = reader
|
Document xmlRelationshipsDoc = reader
|
||||||
.read(relPart.getInputStream());
|
.read(relPart.getInputStream());
|
||||||
|
|
||||||
@ -352,7 +353,7 @@ public final class PackageRelationshipCollection implements
|
|||||||
|
|
||||||
if (value.indexOf("\\") != -1) {
|
if (value.indexOf("\\") != -1) {
|
||||||
logger
|
logger
|
||||||
.info("target contains \\ therefore not a valid URI"
|
.log(POILogger.INFO, "target contains \\ therefore not a valid URI"
|
||||||
+ value + " replaced by /");
|
+ value + " replaced by /");
|
||||||
value = value.replaceAll("\\\\", "/");
|
value = value.replaceAll("\\\\", "/");
|
||||||
// word can save external relationship with a \ instead
|
// word can save external relationship with a \ instead
|
||||||
@ -361,14 +362,14 @@ public final class PackageRelationshipCollection implements
|
|||||||
|
|
||||||
target = new URI(value);
|
target = new URI(value);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
logger.error("Cannot convert " + value
|
logger.log(POILogger.ERROR, "Cannot convert " + value
|
||||||
+ " in a valid relationship URI-> ignored", e);
|
+ " in a valid relationship URI-> ignored", e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
addRelationship(target, targetMode, type, id);
|
addRelationship(target, targetMode, type, id);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e);
|
logger.log(POILogger.ERROR, e);
|
||||||
throw new InvalidFormatException(e.getMessage());
|
throw new InvalidFormatException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,13 +218,12 @@ public final class PackagingURIHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combine les deux URI.
|
* Combine two URIs.
|
||||||
*
|
*
|
||||||
* @param prefix
|
* @param prefix the prefix URI
|
||||||
* L'URI de pr<EFBFBD>fixe.
|
* @param suffix the suffix URI
|
||||||
* @param suffix
|
*
|
||||||
* L'URI de suffixe.
|
* @return the combined URI
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static URI combine(URI prefix, URI suffix) {
|
public static URI combine(URI prefix, URI suffix) {
|
||||||
URI retUri = null;
|
URI retUri = null;
|
||||||
@ -406,11 +405,11 @@ public final class PackagingURIHelper {
|
|||||||
URI relationshipPartUri) {
|
URI relationshipPartUri) {
|
||||||
if (relationshipPartUri == null)
|
if (relationshipPartUri == null)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Le param<61>tre relationshipPartUri ne doit pas <20>tre null !");
|
"Must not be null");
|
||||||
|
|
||||||
if (!isRelationshipPartURI(relationshipPartUri))
|
if (!isRelationshipPartURI(relationshipPartUri))
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"L'URI ne doit pas <20>tre celle d'une partie de type relation.");
|
"Must be a relationship part");
|
||||||
|
|
||||||
if (relationshipPartUri.compareTo(PACKAGE_RELATIONSHIPS_ROOT_URI) == 0)
|
if (relationshipPartUri.compareTo(PACKAGE_RELATIONSHIPS_ROOT_URI) == 0)
|
||||||
return PACKAGE_ROOT_URI;
|
return PACKAGE_ROOT_URI;
|
||||||
|
@ -40,12 +40,12 @@ public interface RelationshipSource {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a relationship to a part (except relationships part).
|
* Add a relationship to a part (except relationships part).
|
||||||
*
|
* <p>
|
||||||
* Check rule M1.25: The Relationships part shall not have relationships to
|
* Check rule M1.25: The Relationships part shall not have relationships to
|
||||||
* any other part. Package implementers shall enforce this requirement upon
|
* any other part. Package implementers shall enforce this requirement upon
|
||||||
* the attempt to create such a relationship and shall treat any such
|
* the attempt to create such a relationship and shall treat any such
|
||||||
* relationship as invalid.
|
* relationship as invalid.
|
||||||
*
|
* </p>
|
||||||
* @param targetPartName
|
* @param targetPartName
|
||||||
* Name of the target part. This one must be relative to the
|
* Name of the target part. This one must be relative to the
|
||||||
* source root directory of the part.
|
* source root directory of the part.
|
||||||
|
@ -28,7 +28,6 @@ import java.util.zip.ZipFile;
|
|||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
|
||||||
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
|
||||||
@ -43,6 +42,8 @@ import org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller;
|
|||||||
import org.apache.poi.openxml4j.util.ZipEntrySource;
|
import org.apache.poi.openxml4j.util.ZipEntrySource;
|
||||||
import org.apache.poi.openxml4j.util.ZipFileZipEntrySource;
|
import org.apache.poi.openxml4j.util.ZipFileZipEntrySource;
|
||||||
import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource;
|
import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Physical zip package.
|
* Physical zip package.
|
||||||
@ -52,7 +53,7 @@ import org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource;
|
|||||||
*/
|
*/
|
||||||
public final class ZipPackage extends Package {
|
public final class ZipPackage extends Package {
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger("org.openxml4j");
|
private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zip archive, as either a file on disk,
|
* Zip archive, as either a file on disk,
|
||||||
@ -220,7 +221,7 @@ public final class ZipPackage extends Package {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// We assume we can continue, even in degraded mode ...
|
// We assume we can continue, even in degraded mode ...
|
||||||
logger.warn("Entry "
|
logger.log(POILogger.WARN,"Entry "
|
||||||
+ entry.getName()
|
+ entry.getName()
|
||||||
+ " is not valid, so this part won't be add to the package.");
|
+ " is not valid, so this part won't be add to the package.");
|
||||||
return null;
|
return null;
|
||||||
@ -308,7 +309,7 @@ public final class ZipPackage extends Package {
|
|||||||
// temporary file
|
// temporary file
|
||||||
if (!tempFile.delete()) {
|
if (!tempFile.delete()) {
|
||||||
logger
|
logger
|
||||||
.warn("The temporary file: '"
|
.log(POILogger.WARN,"The temporary file: '"
|
||||||
+ targetFile.getAbsolutePath()
|
+ targetFile.getAbsolutePath()
|
||||||
+ "' cannot be deleted ! Make sure that no other application use it.");
|
+ "' cannot be deleted ! Make sure that no other application use it.");
|
||||||
}
|
}
|
||||||
@ -353,7 +354,7 @@ public final class ZipPackage extends Package {
|
|||||||
* current package
|
* current package
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @see #getPart(URI)
|
* @see #getPart(PackageRelationship)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected PackagePart getPartImpl(PackagePartName partName) {
|
protected PackagePart getPartImpl(PackagePartName partName) {
|
||||||
@ -371,7 +372,6 @@ public final class ZipPackage extends Package {
|
|||||||
* The stream use to save this package.
|
* The stream use to save this package.
|
||||||
*
|
*
|
||||||
* @see #save(OutputStream)
|
* @see #save(OutputStream)
|
||||||
* @see #saveInZip(ZipOutputStream)
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void saveImpl(OutputStream outputStream) {
|
public void saveImpl(OutputStream outputStream) {
|
||||||
@ -389,7 +389,7 @@ public final class ZipPackage extends Package {
|
|||||||
// we save it as well
|
// we save it as well
|
||||||
if (this.getPartsByRelationshipType(
|
if (this.getPartsByRelationshipType(
|
||||||
PackageRelationshipTypes.CORE_PROPERTIES).size() == 0) {
|
PackageRelationshipTypes.CORE_PROPERTIES).size() == 0) {
|
||||||
logger.debug("Save core properties part");
|
logger.log(POILogger.DEBUG,"Save core properties part");
|
||||||
|
|
||||||
// We have to save the core properties part ...
|
// We have to save the core properties part ...
|
||||||
new ZipPackagePropertiesMarshaller().marshall(
|
new ZipPackagePropertiesMarshaller().marshall(
|
||||||
@ -408,13 +408,13 @@ public final class ZipPackage extends Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save package relationships part.
|
// Save package relationships part.
|
||||||
logger.debug("Save package relationships");
|
logger.log(POILogger.DEBUG,"Save package relationships");
|
||||||
ZipPartMarshaller.marshallRelationshipPart(this.getRelationships(),
|
ZipPartMarshaller.marshallRelationshipPart(this.getRelationships(),
|
||||||
PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_PART_NAME,
|
PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_PART_NAME,
|
||||||
zos);
|
zos);
|
||||||
|
|
||||||
// Save content type part.
|
// Save content type part.
|
||||||
logger.debug("Save content types part");
|
logger.log(POILogger.DEBUG,"Save content types part");
|
||||||
this.contentTypeManager.save(zos);
|
this.contentTypeManager.save(zos);
|
||||||
|
|
||||||
// Save parts.
|
// Save parts.
|
||||||
@ -424,7 +424,7 @@ public final class ZipPackage extends Package {
|
|||||||
if (part.isRelationshipPart())
|
if (part.isRelationshipPart())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
logger.debug("Save part '"
|
logger.log(POILogger.DEBUG,"Save part '"
|
||||||
+ ZipHelper.getZipItemNameFromOPCName(part
|
+ ZipHelper.getZipItemNameFromOPCName(part
|
||||||
.getPartName().getName()) + "'");
|
.getPartName().getName()) + "'");
|
||||||
PartMarshaller marshaller = partMarshallers
|
PartMarshaller marshaller = partMarshallers
|
||||||
@ -449,7 +449,7 @@ public final class ZipPackage extends Package {
|
|||||||
zos.close();
|
zos.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger
|
logger
|
||||||
.error("Fail to save: an error occurs while saving the package : "
|
.log(POILogger.ERROR,"Fail to save: an error occurs while saving the package : "
|
||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,28 +25,28 @@ import java.util.regex.Pattern;
|
|||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a immutable MIME ContentType value (RFC 2616 <EFBFBD>3.7)
|
* Represents a immutable MIME ContentType value (RFC 2616 §3.7)
|
||||||
*
|
* <p>
|
||||||
* media-type = type "/" subtype *( ";" parameter ) type = token<br>
|
* media-type = type "/" subtype *( ";" parameter ) type = token<br>
|
||||||
* subtype = token<br>
|
* subtype = token<br>
|
||||||
*
|
* </p><p>
|
||||||
* Rule M1.13 : Package implementers shall only create and only recognize parts
|
* Rule M1.13 : Package implementers shall only create and only recognize parts
|
||||||
* with a content type; format designers shall specify a content type for each
|
* with a content type; format designers shall specify a content type for each
|
||||||
* part included in the format. Content types for package parts shall fit the
|
* part included in the format. Content types for package parts shall fit the
|
||||||
* definition and syntax for media types as specified in RFC 2616,<EFBFBD><EFBFBD>3.7.
|
* definition and syntax for media types as specified in RFC 2616, \§3.7.
|
||||||
*
|
* </p><p>
|
||||||
* Rule M1.14: Content types shall not use linear white space either between the
|
* Rule M1.14: Content types shall not use linear white space either between the
|
||||||
* type and subtype or between an attribute and its value. Content types also
|
* type and subtype or between an attribute and its value. Content types also
|
||||||
* shall not have leading or trailing white spaces. Package implementers shall
|
* shall not have leading or trailing white spaces. Package implementers shall
|
||||||
* create only such content types and shall require such content types when
|
* create only such content types and shall require such content types when
|
||||||
* retrieving a part from a package; format designers shall specify only such
|
* retrieving a part from a package; format designers shall specify only such
|
||||||
* content types for inclusion in the format.
|
* content types for inclusion in the format.
|
||||||
*
|
* </p>
|
||||||
* @author Julien Chable
|
* @author Julien Chable
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
*
|
*
|
||||||
* @see http://www.ietf.org/rfc/rfc2045.txt
|
* @see <a href="http://www.ietf.org/rfc/rfc2045.txt">http://www.ietf.org/rfc/rfc2045.txt</a>
|
||||||
* @see http://www.ietf.org/rfc/rfc2616.txt
|
* @see <a href="http://www.ietf.org/rfc/rfc2616.txt">http://www.ietf.org/rfc/rfc2616.txt</a>
|
||||||
*/
|
*/
|
||||||
public final class ContentType {
|
public final class ContentType {
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import java.util.TreeMap;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
@ -42,6 +41,8 @@ import org.apache.poi.openxml4j.opc.Package;
|
|||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage package content types ([Content_Types].xml part).
|
* Manage package content types ([Content_Types].xml part).
|
||||||
@ -51,7 +52,7 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
|||||||
*/
|
*/
|
||||||
public abstract class ContentTypeManager {
|
public abstract class ContentTypeManager {
|
||||||
|
|
||||||
protected static Logger logger = Logger.getLogger("org.openxml4j");
|
private static POILogger logger = POILogFactory.getLogger(ContentTypeManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the package using this content type manager.
|
* Reference to the package using this content type manager.
|
||||||
@ -95,7 +96,7 @@ public abstract class ContentTypeManager {
|
|||||||
/**
|
/**
|
||||||
* Constructor. Parses the content of the specified input stream.
|
* Constructor. Parses the content of the specified input stream.
|
||||||
*
|
*
|
||||||
* @param archive
|
* @param in
|
||||||
* If different of <i>null</i> then the content types part is
|
* If different of <i>null</i> then the content types part is
|
||||||
* retrieve and parse.
|
* retrieve and parse.
|
||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
@ -118,43 +119,39 @@ public abstract class ContentTypeManager {
|
|||||||
/**
|
/**
|
||||||
* Build association extention-> content type (will be stored in
|
* Build association extention-> content type (will be stored in
|
||||||
* [Content_Types].xml) for example ContentType="image/png" Extension="png"
|
* [Content_Types].xml) for example ContentType="image/png" Extension="png"
|
||||||
*
|
* <p>
|
||||||
* [M2.8]: When adding a new part to a package, the package implementer
|
* [M2.8]: When adding a new part to a package, the package implementer
|
||||||
* shall ensure that a content type for that part is specified in the
|
* shall ensure that a content type for that part is specified in the
|
||||||
* Content Types stream; the package implementer shall perform the steps
|
* Content Types stream; the package implementer shall perform the steps
|
||||||
* described in<EFBFBD><EFBFBD>9.1.2.3:
|
* described in §9.1.2.3:
|
||||||
*
|
* </p><p>
|
||||||
* 1. Get the extension from the part name by taking the substring to the
|
* 1. Get the extension from the part name by taking the substring to the
|
||||||
* right of the rightmost occurrence of the dot character (.) from the
|
* right of the rightmost occurrence of the dot character (.) from the
|
||||||
* rightmost segment.
|
* rightmost segment.
|
||||||
*
|
* </p><p>
|
||||||
* 2. If a part name has no extension, a corresponding Override element
|
* 2. If a part name has no extension, a corresponding Override element
|
||||||
* shall be added to the Content Types stream.
|
* shall be added to the Content Types stream.
|
||||||
*
|
* </p><p>
|
||||||
* 3. Compare the resulting extension with the values specified for the
|
* 3. Compare the resulting extension with the values specified for the
|
||||||
* Extension attributes of the Default elements in the Content Types stream.
|
* Extension attributes of the Default elements in the Content Types stream.
|
||||||
* The comparison shall be case-insensitive ASCII.
|
* The comparison shall be case-insensitive ASCII.
|
||||||
*
|
* </p><p>
|
||||||
* 4. If there is a Default element with a matching Extension attribute,
|
* 4. If there is a Default element with a matching Extension attribute,
|
||||||
* then the content type of the new part shall be compared with the value of
|
* then the content type of the new part shall be compared with the value of
|
||||||
* the ContentType attribute. The comparison might be case-sensitive and
|
* the ContentType attribute. The comparison might be case-sensitive and
|
||||||
* include every character regardless of the role it plays in the
|
* include every character regardless of the role it plays in the
|
||||||
* content-type grammar of RFC 2616, or it might follow the grammar of RFC
|
* content-type grammar of RFC 2616, or it might follow the grammar of RFC
|
||||||
* 2616.
|
* 2616.
|
||||||
*
|
* </p><p>
|
||||||
* a. If the content types match, no further action is required.
|
* a. If the content types match, no further action is required.
|
||||||
*
|
* </p><p>
|
||||||
* b. If the content types do not match, a new Override element shall be
|
* b. If the content types do not match, a new Override element shall be
|
||||||
* added to the Content Types stream. .
|
* added to the Content Types stream. .
|
||||||
*
|
* </p><p>
|
||||||
* 5. If there is no Default element with a matching Extension attribute, a
|
* 5. If there is no Default element with a matching Extension attribute, a
|
||||||
* new Default element or Override element shall be added to the Content
|
* new Default element or Override element shall be added to the Content
|
||||||
* Types stream.
|
* Types stream.
|
||||||
*
|
* </p>
|
||||||
*
|
|
||||||
* @param partUri
|
|
||||||
* the uri that will be stored
|
|
||||||
* @return <b>false</b> if an error occured.
|
|
||||||
*/
|
*/
|
||||||
public void addContentType(PackagePartName partName, String contentType) {
|
public void addContentType(PackagePartName partName, String contentType) {
|
||||||
boolean defaultCTExists = false;
|
boolean defaultCTExists = false;
|
||||||
@ -197,18 +194,19 @@ public abstract class ContentTypeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <p>
|
||||||
* Delete a content type based on the specified part name. If the specified
|
* Delete a content type based on the specified part name. If the specified
|
||||||
* part name is register with an override content type, then this content
|
* part name is register with an override content type, then this content
|
||||||
* type is remove, else the content type is remove in the default content
|
* type is remove, else the content type is remove in the default content
|
||||||
* type list if it exists and if no part is associated with it yet.
|
* type list if it exists and if no part is associated with it yet.
|
||||||
*
|
* </p><p>
|
||||||
* Check rule M2.4: The package implementer shall require that the Content
|
* Check rule M2.4: The package implementer shall require that the Content
|
||||||
* Types stream contain one of the following for every part in the package:
|
* Types stream contain one of the following for every part in the package:
|
||||||
* One matching Default element One matching Override element Both a
|
* One matching Default element One matching Override element Both a
|
||||||
* matching Default element and a matching Override element, in which case
|
* matching Default element and a matching Override element, in which case
|
||||||
* the Override element takes precedence.
|
* the Override element takes precedence.
|
||||||
*
|
* </p>
|
||||||
* @param partUri
|
* @param partName
|
||||||
* The part URI associated with the override content type to
|
* The part URI associated with the override content type to
|
||||||
* delete.
|
* delete.
|
||||||
* @exception InvalidOperationException
|
* @exception InvalidOperationException
|
||||||
@ -290,34 +288,34 @@ public abstract class ContentTypeManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the content type for the specified part, if any.
|
* Get the content type for the specified part, if any.
|
||||||
*
|
* <p>
|
||||||
* Rule [M2.9]: To get the content type of a part, the package implementer
|
* Rule [M2.9]: To get the content type of a part, the package implementer
|
||||||
* shall perform the steps described in<EFBFBD><EFBFBD>9.1.2.4:
|
* shall perform the steps described in §9.1.2.4:
|
||||||
*
|
* </p><p>
|
||||||
* 1. Compare the part name with the values specified for the PartName
|
* 1. Compare the part name with the values specified for the PartName
|
||||||
* attribute of the Override elements. The comparison shall be
|
* attribute of the Override elements. The comparison shall be
|
||||||
* case-insensitive ASCII.
|
* case-insensitive ASCII.
|
||||||
*
|
* </p><p>
|
||||||
* 2. If there is an Override element with a matching PartName attribute,
|
* 2. If there is an Override element with a matching PartName attribute,
|
||||||
* return the value of its ContentType attribute. No further action is
|
* return the value of its ContentType attribute. No further action is
|
||||||
* required.
|
* required.
|
||||||
*
|
* </p><p>
|
||||||
* 3. If there is no Override element with a matching PartName attribute,
|
* 3. If there is no Override element with a matching PartName attribute,
|
||||||
* then a. Get the extension from the part name by taking the substring to
|
* then a. Get the extension from the part name by taking the substring to
|
||||||
* the right of the rightmost occurrence of the dot character (.) from the
|
* the right of the rightmost occurrence of the dot character (.) from the
|
||||||
* rightmost segment. b. Check the Default elements of the Content Types
|
* rightmost segment. b. Check the Default elements of the Content Types
|
||||||
* stream, comparing the extension with the value of the Extension
|
* stream, comparing the extension with the value of the Extension
|
||||||
* attribute. The comparison shall be case-insensitive ASCII.
|
* attribute. The comparison shall be case-insensitive ASCII.
|
||||||
*
|
* </p><p>
|
||||||
* 4. If there is a Default element with a matching Extension attribute,
|
* 4. If there is a Default element with a matching Extension attribute,
|
||||||
* return the value of its ContentType attribute. No further action is
|
* return the value of its ContentType attribute. No further action is
|
||||||
* required.
|
* required.
|
||||||
*
|
* </p><p>
|
||||||
* 5. If neither Override nor Default elements with matching attributes are
|
* 5. If neither Override nor Default elements with matching attributes are
|
||||||
* found for the specified part name, the implementation shall not map this
|
* found for the specified part name, the implementation shall not map this
|
||||||
* part name to a part.
|
* part name to a part.
|
||||||
*
|
* </p>
|
||||||
* @param partUri
|
* @param partName
|
||||||
* The URI part to check.
|
* The URI part to check.
|
||||||
* @return The content type associated with the URI (in case of an override
|
* @return The content type associated with the URI (in case of an override
|
||||||
* content type) or the extension (in case of default content type),
|
* content type) or the extension (in case of default content type),
|
||||||
@ -460,7 +458,7 @@ public abstract class ContentTypeManager {
|
|||||||
* XML parent element use to append this override type element.
|
* XML parent element use to append this override type element.
|
||||||
* @param entry
|
* @param entry
|
||||||
* The values to append.
|
* The values to append.
|
||||||
* @see #save(ZipOutputStream)
|
* @see #save(java.io.OutputStream)
|
||||||
*/
|
*/
|
||||||
private void appendSpecificTypes(Element root,
|
private void appendSpecificTypes(Element root,
|
||||||
Entry<PackagePartName, String> entry) {
|
Entry<PackagePartName, String> entry) {
|
||||||
@ -477,7 +475,7 @@ public abstract class ContentTypeManager {
|
|||||||
* XML parent element use to append this default type element.
|
* XML parent element use to append this default type element.
|
||||||
* @param entry
|
* @param entry
|
||||||
* The values to append.
|
* The values to append.
|
||||||
* @see #save(ZipOutputStream)
|
* @see #save(java.io.OutputStream)
|
||||||
*/
|
*/
|
||||||
private void appendDefaultType(Element root, Entry<String, String> entry) {
|
private void appendDefaultType(Element root, Entry<String, String> entry) {
|
||||||
root.addElement(DEFAULT_TAG_NAME).addAttribute(
|
root.addElement(DEFAULT_TAG_NAME).addAttribute(
|
||||||
|
@ -29,6 +29,8 @@ import org.dom4j.Document;
|
|||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.Package;
|
import org.apache.poi.openxml4j.opc.Package;
|
||||||
import org.apache.poi.openxml4j.opc.StreamHelper;
|
import org.apache.poi.openxml4j.opc.StreamHelper;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zip implementation of the ContentTypeManager.
|
* Zip implementation of the ContentTypeManager.
|
||||||
@ -38,6 +40,7 @@ import org.apache.poi.openxml4j.opc.StreamHelper;
|
|||||||
* @see ContentTypeManager
|
* @see ContentTypeManager
|
||||||
*/
|
*/
|
||||||
public class ZipContentTypeManager extends ContentTypeManager {
|
public class ZipContentTypeManager extends ContentTypeManager {
|
||||||
|
private static POILogger logger = POILogFactory.getLogger(ZipContentTypeManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate constructor to the super constructor.
|
* Delegate constructor to the super constructor.
|
||||||
@ -81,7 +84,7 @@ public class ZipContentTypeManager extends ContentTypeManager {
|
|||||||
}
|
}
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
logger.error("Cannot write: " + CONTENT_TYPES_PART_NAME
|
logger.log(POILogger.ERROR, "Cannot write: " + CONTENT_TYPES_PART_NAME
|
||||||
+ " in Zip !", ioe);
|
+ " in Zip !", ioe);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import java.net.URI;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.dom4j.Document;
|
import org.dom4j.Document;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
@ -41,6 +40,8 @@ import org.apache.poi.openxml4j.opc.StreamHelper;
|
|||||||
import org.apache.poi.openxml4j.opc.TargetMode;
|
import org.apache.poi.openxml4j.opc.TargetMode;
|
||||||
import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
|
import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
|
||||||
import org.apache.poi.openxml4j.opc.internal.ZipHelper;
|
import org.apache.poi.openxml4j.opc.internal.ZipHelper;
|
||||||
|
import org.apache.poi.util.POILogger;
|
||||||
|
import org.apache.poi.util.POILogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zip part marshaller. This marshaller is use to save any part in a zip stream.
|
* Zip part marshaller. This marshaller is use to save any part in a zip stream.
|
||||||
@ -49,7 +50,7 @@ import org.apache.poi.openxml4j.opc.internal.ZipHelper;
|
|||||||
* @version 0.1
|
* @version 0.1
|
||||||
*/
|
*/
|
||||||
public class ZipPartMarshaller implements PartMarshaller {
|
public class ZipPartMarshaller implements PartMarshaller {
|
||||||
private static Logger logger = Logger.getLogger("org.openxml4j");
|
private static POILogger logger = POILogFactory.getLogger(ZipPartMarshaller.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the specified part.
|
* Save the specified part.
|
||||||
@ -60,7 +61,7 @@ public class ZipPartMarshaller implements PartMarshaller {
|
|||||||
public boolean marshall(PackagePart part, OutputStream os)
|
public boolean marshall(PackagePart part, OutputStream os)
|
||||||
throws OpenXML4JException {
|
throws OpenXML4JException {
|
||||||
if (!(os instanceof ZipOutputStream)) {
|
if (!(os instanceof ZipOutputStream)) {
|
||||||
logger.error("Unexpected class " + os.getClass().getName());
|
logger.log(POILogger.ERROR,"Unexpected class " + os.getClass().getName());
|
||||||
throw new OpenXML4JException("ZipOutputStream expected !");
|
throw new OpenXML4JException("ZipOutputStream expected !");
|
||||||
// Normally should happen only in developpement phase, so just throw
|
// Normally should happen only in developpement phase, so just throw
|
||||||
// exception
|
// exception
|
||||||
@ -88,7 +89,7 @@ public class ZipPartMarshaller implements PartMarshaller {
|
|||||||
}
|
}
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
logger.error("Cannot write: " + part.getPartName() + ": in ZIP",
|
logger.log(POILogger.ERROR,"Cannot write: " + part.getPartName() + ": in ZIP",
|
||||||
ioe);
|
ioe);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ public class ZipPartMarshaller implements PartMarshaller {
|
|||||||
*
|
*
|
||||||
* @param rels
|
* @param rels
|
||||||
* The relationships collection to marshall.
|
* The relationships collection to marshall.
|
||||||
* @param relPartURI
|
* @param relPartName
|
||||||
* Part name of the relationship part to marshall.
|
* Part name of the relationship part to marshall.
|
||||||
* @param zos
|
* @param zos
|
||||||
* Zip output stream in which to save the XML content of the
|
* Zip output stream in which to save the XML content of the
|
||||||
@ -137,19 +138,19 @@ public class ZipPartMarshaller implements PartMarshaller {
|
|||||||
.getSourcePartUriFromRelationshipPartUri(relPartName.getURI());
|
.getSourcePartUriFromRelationshipPartUri(relPartName.getURI());
|
||||||
|
|
||||||
for (PackageRelationship rel : rels) {
|
for (PackageRelationship rel : rels) {
|
||||||
// L'<EFBFBD>l<EFBFBD>ment de la relation
|
// the relationship element
|
||||||
Element relElem = root
|
Element relElem = root
|
||||||
.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME);
|
.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME);
|
||||||
|
|
||||||
// L'attribut ID
|
// the relationship ID
|
||||||
relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel
|
relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel
|
||||||
.getId());
|
.getId());
|
||||||
|
|
||||||
// L'attribut Type
|
// the relationship Type
|
||||||
relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel
|
relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel
|
||||||
.getRelationshipType());
|
.getRelationshipType());
|
||||||
|
|
||||||
// L'attribut Target
|
// the relationship Target
|
||||||
String targetValue;
|
String targetValue;
|
||||||
URI uri = rel.getTargetURI();
|
URI uri = rel.getTargetURI();
|
||||||
if (rel.getTargetMode() == TargetMode.EXTERNAL) {
|
if (rel.getTargetMode() == TargetMode.EXTERNAL) {
|
||||||
@ -157,7 +158,7 @@ public class ZipPartMarshaller implements PartMarshaller {
|
|||||||
// alter it etc
|
// alter it etc
|
||||||
targetValue = uri.toString();
|
targetValue = uri.toString();
|
||||||
|
|
||||||
// add TargetMode attribut (as it is external link external)
|
// add TargetMode attribute (as it is external link external)
|
||||||
relElem.addAttribute(
|
relElem.addAttribute(
|
||||||
PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
|
PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
|
||||||
"External");
|
"External");
|
||||||
@ -178,14 +179,13 @@ public class ZipPartMarshaller implements PartMarshaller {
|
|||||||
ZipEntry ctEntry = new ZipEntry(ZipHelper.getZipURIFromOPCName(
|
ZipEntry ctEntry = new ZipEntry(ZipHelper.getZipURIFromOPCName(
|
||||||
relPartName.getURI().toASCIIString()).getPath());
|
relPartName.getURI().toASCIIString()).getPath());
|
||||||
try {
|
try {
|
||||||
// Cr<EFBFBD>ation de l'entr<EFBFBD>e dans le fichier ZIP
|
|
||||||
zos.putNextEntry(ctEntry);
|
zos.putNextEntry(ctEntry);
|
||||||
if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) {
|
if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Cannot create zip entry " + relPartName, e);
|
logger.log(POILogger.ERROR,"Cannot create zip entry " + relPartName, e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true; // success
|
return true; // success
|
||||||
|
@ -75,5 +75,4 @@ public final class DigitalCertificatePart extends PackagePart {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Introduire le concept de partie typ<EFBFBD>e d<EFBFBD>s cette partie
|
|
||||||
}
|
}
|
||||||
|
@ -310,25 +310,26 @@ public class PackagePropertiesUnmarshaller implements PartUnmarshaller {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the element for the following OPC compliance rules:
|
* Check the element for the following OPC compliance rules:
|
||||||
*
|
* <p>
|
||||||
* Rule M4.2: A format consumer shall consider the use of the Markup
|
* Rule M4.2: A format consumer shall consider the use of the Markup
|
||||||
* Compatibility namespace to be an error.
|
* Compatibility namespace to be an error.
|
||||||
*
|
* </p><p>
|
||||||
* Rule M4.3: Producers shall not create a document element that contains
|
* Rule M4.3: Producers shall not create a document element that contains
|
||||||
* refinements to the Dublin Core elements, except for the two specified in
|
* refinements to the Dublin Core elements, except for the two specified in
|
||||||
* the schema: <dcterms:created> and <dcterms:modified> Consumers shall
|
* the schema: <dcterms:created> and <dcterms:modified> Consumers shall
|
||||||
* consider a document element that violates this constraint to be an error.
|
* consider a document element that violates this constraint to be an error.
|
||||||
*
|
* </p><p>
|
||||||
* Rule M4.4: Producers shall not create a document element that contains
|
* Rule M4.4: Producers shall not create a document element that contains
|
||||||
* the xml:lang attribute. Consumers shall consider a document element that
|
* the xml:lang attribute. Consumers shall consider a document element that
|
||||||
* violates this constraint to be an error.
|
* violates this constraint to be an error.
|
||||||
*
|
* </p><p>
|
||||||
* Rule M4.5: Producers shall not create a document element that contains
|
* Rule M4.5: Producers shall not create a document element that contains
|
||||||
* the xsi:type attribute, except for a <dcterms:created> or
|
* the xsi:type attribute, except for a <dcterms:created> or
|
||||||
* <dcterms:modified> element where the xsi:type attribute shall be present
|
* <dcterms:modified> element where the xsi:type attribute shall be present
|
||||||
* and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
|
* and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
|
||||||
* prefix of the Dublin Core namespace. Consumers shall consider a document
|
* prefix of the Dublin Core namespace. Consumers shall consider a document
|
||||||
* element that violates this constraint to be an error.
|
* element that violates this constraint to be an error.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void checkElementForOPCCompliance(Element el)
|
public void checkElementForOPCCompliance(Element el)
|
||||||
throws InvalidFormatException {
|
throws InvalidFormatException {
|
||||||
|
@ -46,7 +46,7 @@ public final class Nullable<E> {
|
|||||||
/**
|
/**
|
||||||
* Get the store value if any.
|
* Get the store value if any.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the store value
|
||||||
*/
|
*/
|
||||||
public E getValue() {
|
public E getValue() {
|
||||||
return value;
|
return value;
|
||||||
|
@ -34,7 +34,7 @@ public class TestContentType extends TestCase {
|
|||||||
* recognize parts with a content type; format designers shall specify a
|
* recognize parts with a content type; format designers shall specify a
|
||||||
* content type for each part included in the format. Content types for
|
* content type for each part included in the format. Content types for
|
||||||
* package parts shall fit the definition and syntax for media types as
|
* package parts shall fit the definition and syntax for media types as
|
||||||
* specified in RFC 2616, §3.7.
|
* specified in RFC 2616, \u00A73.7.
|
||||||
*/
|
*/
|
||||||
public void testContentTypeValidation() throws InvalidFormatException {
|
public void testContentTypeValidation() throws InvalidFormatException {
|
||||||
String[] contentTypesToTest = new String[] { "text/xml",
|
String[] contentTypesToTest = new String[] { "text/xml",
|
||||||
@ -50,7 +50,7 @@ public class TestContentType extends TestCase {
|
|||||||
* recognize parts with a content type; format designers shall specify a
|
* recognize parts with a content type; format designers shall specify a
|
||||||
* content type for each part included in the format. Content types for
|
* content type for each part included in the format. Content types for
|
||||||
* package parts shall fit the definition and syntax for media types as
|
* package parts shall fit the definition and syntax for media types as
|
||||||
* specified in RFC 2616, §3.7.
|
* specified in RFC 2616, \u00A3.7.
|
||||||
*
|
*
|
||||||
* Check rule M1.14: Content types shall not use linear white space either
|
* Check rule M1.14: Content types shall not use linear white space either
|
||||||
* between the type and subtype or between an attribute and its value.
|
* between the type and subtype or between an attribute and its value.
|
||||||
|
Loading…
Reference in New Issue
Block a user