com.adobe.xmp.XMPException Java Examples

The following examples show how to use com.adobe.xmp.XMPException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add namespaces to the registry.
 */
private static void prepareRegistry() {
	if (!mIsPrepared) {
		XMPSchemaRegistry registry = XMPMetaFactory.getSchemaRegistry();
		try {
			registry.registerNamespace(NS_JE, "je:");
			registry.registerNamespace(NS_MP1, "MicrosoftPhoto:");
			registry.registerNamespace(NS_MP2, "MP:");
			registry.registerNamespace(NS_MPRI, "MPRI:");
			registry.registerNamespace(NS_MPREG, "MPReg:");
			registry.registerNamespace(NS_DC, "dc:");
			registry.registerNamespace(NS_EXIF, "exif:");
			mIsPrepared = true;
		}
		catch (XMPException e) {
			Logger.error("Exception while preparing XMP registry", e);
		}
	}
}
 
Example #2
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add namespaces to the registry.
 */
private static void prepareRegistry() {
	if (!mIsPrepared) {
		XMPSchemaRegistry registry = XMPMetaFactory.getSchemaRegistry();
		try {
			registry.registerNamespace(NS_JE, "je:");
			registry.registerNamespace(NS_MP1, "MicrosoftPhoto:");
			registry.registerNamespace(NS_MP2, "MP:");
			registry.registerNamespace(NS_MPRI, "MPRI:");
			registry.registerNamespace(NS_MPREG, "MPReg:");
			registry.registerNamespace(NS_DC, "dc:");
			registry.registerNamespace(NS_EXIF, "exif:");
			mIsPrepared = true;
		}
		catch (XMPException e) {
			Log.e(Application.TAG, "Exception while preparing XMP registry", e);
		}
	}
}
 
Example #3
Source File: JpegMetadataUtil.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Change metadata of the image (EXIF and XMP as far as applicable).
 *
 * @param jpegImageFileName the file for which metadata should be changed.
 * @param metadata          the new metadata.
 * @throws ImageReadException  thrown if the metadata cannot be read.
 * @throws ImageWriteException thrown if the metadata cannot be written.
 * @throws IOException         thrown in case of other errors while reading metadata.
 * @throws XMPException        thrown in case of issues with XML handling.
 */
public static void changeMetadata(@NonNull final String jpegImageFileName, @NonNull final JpegMetadata metadata) throws IOException,
		ImageReadException, ImageWriteException, XMPException {
	if (changeJpegAllowed()) {
		checkJpeg(jpegImageFileName);
		changeXmpMetadata(jpegImageFileName, metadata);

		if (changeExifAllowed()) {
			try {
				changeExifMetadata(jpegImageFileName, metadata);
			}
			catch (Exception e) {
				throw new ExifStorageException(e);
			}
		}
	}
}
 
Example #4
Source File: XmpSample.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
private static void xmpSample(InputStream imageStream) throws XMPException, ImageProcessingException, IOException
{
    // Extract metadata from the image
    Metadata metadata = ImageMetadataReader.readMetadata(imageStream);

    // Iterate through any XMP directories we may have received
    for (XmpDirectory xmpDirectory : metadata.getDirectoriesOfType(XmpDirectory.class)) {

        // Usually with metadata-extractor, you iterate a directory's tags. However XMP has
        // a complex structure with many potentially unknown properties. This doesn't map
        // well to metadata-extractor's directory-and-tag model.
        //
        // If you need to use XMP data, access the XMPMeta object directly.
        XMPMeta xmpMeta = xmpDirectory.getXMPMeta();

        XMPIterator itr = xmpMeta.iterator();

        // Iterate XMP properties
        while (itr.hasNext()) {

            XMPPropertyInfo property = (XMPPropertyInfo) itr.next();

            // Print details of the property
            System.out.println(property.getPath() + ": " + property.getValue());
        }
    }
}
 
Example #5
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the image person name.
 *
 * @param name the image person name.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setMicrosoftPerson(@Nullable final String name) throws XMPException {
	if (name != null) {
		String path = "RegionInfo"
				+ XMPPathFactory.composeArrayItemPath(XMPPathFactory.composeStructFieldPath(NS_MPRI, "Regions"), 1)
				+ XMPPathFactory.composeStructFieldPath(NS_MPREG, "PersonDisplayName");
		String path1 = "RegionInfo" + XMPPathFactory.composeStructFieldPath(NS_MPRI, "Regions");

		if (!mXmpMeta.doesArrayItemExist(NS_MP2, path1, 1)) {
			mXmpMeta.appendArrayItem(NS_MP2, path1, new PropertyOptions().setArray(true), null,
					new PropertyOptions().setStruct(true));
		}
		mXmpMeta.setProperty(NS_MP2, path, name);
	}
}
 
Example #6
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the User Comment.
 *
 * @param userComment the user comment.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setUserComment(@Nullable final String userComment) throws XMPException {
	if (userComment != null) {
		if (mXmpMeta.doesArrayItemExist(NS_EXIF, USER_COMMENT, 1)) {
			mXmpMeta.setArrayItem(NS_EXIF, USER_COMMENT, 1, userComment);
		}
		else {
			mXmpMeta.appendArrayItem(NS_EXIF, USER_COMMENT, new PropertyOptions().setArray(true), userComment, null);
		}
	}
}
 
Example #7
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set an entry in the DC namespace.
 *
 * @param item  the name of the entry.
 * @param value the value of the entry.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
private void setDcItem(final String item, @Nullable final String value) throws XMPException {
	if (value != null) {
		if (mXmpMeta.doesArrayItemExist(NS_DC, item, 1)) {
			mXmpMeta.setArrayItem(NS_DC, item, 1, value);
		}
		else {
			mXmpMeta.appendArrayItem(NS_DC, item, new PropertyOptions().setArray(true), value, null);
		}
	}
}
 
Example #8
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set a date entry in the custom namespace.
 *
 * @param item the name of the entry.
 * @param date the value of the entry.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setJeDate(final String item, @Nullable final Date date) throws XMPException {
	if (date != null) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		XMPDateTime xmpDate = XMPDateTimeFactory.createFromCalendar(calendar);
		mXmpMeta.setPropertyDate(NS_JE, item, xmpDate);
	}
}
 
Example #9
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set an entry in the custom namespace.
 *
 * @param item  the name of the entry.
 * @param value the value of the entry.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setJeItem(final String item, @Nullable final String value) throws XMPException {
	if (value != null) {
		mXmpMeta.setProperty(NS_JE, item, value);
	}
	else {
		removeJeItem(item);
	}
}
 
Example #10
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the image person name.
 *
 * @param name
 *            the image person name.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void setMicrosoftPerson(final String name) throws XMPException {
	if (name != null) {
		String path = "RegionInfo"
				+ XMPPathFactory.composeArrayItemPath(XMPPathFactory.composeStructFieldPath(NS_MPRI, "Regions"), 1)
				+ XMPPathFactory.composeStructFieldPath(NS_MPREG, "PersonDisplayName");
		String path1 = "RegionInfo" + XMPPathFactory.composeStructFieldPath(NS_MPRI, "Regions");

		if (!mXmpMeta.doesArrayItemExist(NS_MP2, path1, 1)) {
			mXmpMeta.appendArrayItem(NS_MP2, path1, new PropertyOptions().setArray(true), null,
					new PropertyOptions().setStruct(true));
		}
		mXmpMeta.setProperty(NS_MP2, path, name);
	}
}
 
Example #11
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the User Comment.
 *
 * @param userComment
 *            the user comment.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void setUserComment(final String userComment) throws XMPException {
	if (userComment != null) {
		if (mXmpMeta.doesArrayItemExist(NS_EXIF, USER_COMMENT, 1)) {
			mXmpMeta.setArrayItem(NS_EXIF, USER_COMMENT, 1, userComment);
		}
		else {
			mXmpMeta.appendArrayItem(NS_EXIF, USER_COMMENT, new PropertyOptions().setArray(true), userComment, null);
		}
	}
}
 
Example #12
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set an entry in the DC namespace.
 *
 * @param item
 *            the name of the entry.
 * @param value
 *            the value of the entry.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
private void setDcItem(final String item, final String value) throws XMPException {
	if (value != null) {
		if (mXmpMeta.doesArrayItemExist(NS_DC, item, 1)) {
			mXmpMeta.setArrayItem(NS_DC, item, 1, value);
		}
		else {
			mXmpMeta.appendArrayItem(NS_DC, item, new PropertyOptions().setArray(true), value, null);
		}
	}
}
 
Example #13
Source File: PdfXmpCreator.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
byte[] createXmpMetadata()
{
	try
	{
		XMPMeta xmp = XMPMetaFactory.create();
		xmp.setObjectName("");

		xmp.setProperty(XMPConst.NS_DC, DublinCoreSchema.FORMAT, FORMAT_PDF);
		xmp.setProperty(XMPConst.NS_PDF, PDF_PRODUCER, Document.getVersion());

		if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1A)
		{
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1);
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_A);
		}
		else if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1B)
		{
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1);
			xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_B);
		}

		xmp.setProperty(XMPConst.NS_XMP, XMP_CREATE_DATE, ((PdfDate) info.get(PdfName.CREATIONDATE)).getW3CDate());
		xmp.setProperty(XMPConst.NS_XMP, XMP_MODIFY_DATE, ((PdfDate) info.get(PdfName.MODDATE)).getW3CDate());

		String title = extractInfo(PdfName.TITLE);
		if (title != null)
		{
			xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.TITLE, 
					//FIXME use the tag language?
					XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, title);
		}

		String author = extractInfo(PdfName.AUTHOR);
		if (author != null)
		{
			//FIXME cache the options?
			PropertyOptions arrayOrdered = new PropertyOptions().setArrayOrdered(true);
			xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.CREATOR, arrayOrdered, author, null);
		}

		String subject = extractInfo(PdfName.SUBJECT);
		if (subject != null)
		{
			PropertyOptions array = new PropertyOptions().setArray(true);
			xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.SUBJECT, array, subject, null);
			xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.DESCRIPTION, 
					XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, subject);
		}

		String keywords = extractInfo(PdfName.KEYWORDS);
		if (keywords != null)
		{
			xmp.setProperty(XMPConst.NS_PDF, PDF_KEYWORDS, keywords);
		}

		String creator = extractInfo(PdfName.CREATOR);
		if (creator != null)
		{
			xmp.setProperty(XMPConst.NS_XMP, XMP_CREATOR_TOOL, creator);
		}

		SerializeOptions options = new SerializeOptions();
		options.setUseCanonicalFormat(true);

		ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
		XMPMetaFactory.serialize(xmp, out, options);
		return out.toByteArray();
	}
	catch (XMPException e)
	{
		throw new JRRuntimeException(e);
	}
}
 
Example #14
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Set a date entry in the custom namespace.
 *
 * @param item
 *            the name of the entry.
 * @param date
 *            the value of the entry.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void setJeDate(final String item, final Date date) throws XMPException {
	if (date != null) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		XMPDateTime xmpDate = XMPDateTimeFactory.createFromCalendar(calendar);
		mXmpMeta.setPropertyDate(NS_JE, item, xmpDate);
	}
}
 
Example #15
Source File: JpegMetadataUtil.java    From Augendiagnose with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Change metadata of the image (EXIF and XMP as far as applicable).
 *
 * @param jpegImageFileName
 *            the file for which metadata should be changed.
 * @param metadata
 *            the new metadata.
 * @throws ImageReadException
 *             thrown if the metadata cannot be read.
 * @throws ImageWriteException
 *             thrown if the metadata cannot be written.
 * @throws IOException
 *             thrown in case of other errors while reading metadata.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public static void changeMetadata(final String jpegImageFileName, final JpegMetadata metadata) throws IOException,
		ImageReadException, ImageWriteException, XMPException {
	if (changeJpegAllowed()) {
		checkJpeg(jpegImageFileName);
		changeXmpMetadata(jpegImageFileName, metadata);

		if (changeExifAllowed()) {
			changeExifMetadata(jpegImageFileName, metadata);
		}
	}
}
 
Example #16
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Set an entry in the custom namespace.
 *
 * @param item
 *            the name of the entry.
 * @param value
 *            the value of the entry.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void setJeItem(final String item, final String value) throws XMPException {
	if (value != null) {
		mXmpMeta.setProperty(NS_JE, item, value);
	}
	else {
		removeJeItem(item);
	}
}
 
Example #17
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set an int entry in the custom namespace.
 *
 * @param item  the name of the entry.
 * @param value the value of the entry.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setJeInt(final String item, final int value) throws XMPException {
	mXmpMeta.setProperty(NS_JE, item, value);
}
 
Example #18
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the XMP String.
 *
 * @return the XMP String.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final String getXmpString() throws XMPException {
	return XMPMetaFactory.serializeToString(mXmpMeta, null);
}
 
Example #19
Source File: JpegMetadataUtil.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Log all XML data of the file.
 *
 * @param imageFile
 *            the file.
 * @throws ImageReadException
 *             thrown if the metadata cannot be read.
 * @throws IOException
 *             thrown in case of other errors while reading metadata.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public static void printAllXmpData(final File imageFile) throws ImageReadException, IOException, XMPException {
	final String xmpString = Imaging.getXmpXml(imageFile);
	Logger.info(new XmpHandler(xmpString).getXmpString());
}
 
Example #20
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the image subject.
 *
 * @param subject the image subject.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setDcSubject(final String subject) throws XMPException {
	setDcItem("subject", subject);
}
 
Example #21
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the image description.
 *
 * @param description the image description.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setDcDescription(final String description) throws XMPException {
	setDcItem("description", description);
}
 
Example #22
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the image title.
 *
 * @param title the image title.
 * @throws XMPException thrown in case of issues with XMP handling.
 */
public final void setDcTitle(final String title) throws XMPException {
	setDcItem("title", title);
}
 
Example #23
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the image description.
 *
 * @param description
 *            the image description.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void setDcDescription(final String description) throws XMPException {
	setDcItem("description", description);
}
 
Example #24
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set an int entry in the custom namespace.
 *
 * @param item
 *            the name of the entry.
 * @param value
 *            the value of the entry.
 * @throws XMPException
 *             thrown in case of issues with XMP handling.
 */
public final void setJeInt(final String item, final int value) throws XMPException {
	mXmpMeta.setProperty(NS_JE, item, value);
}
 
Example #25
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Delete an entry from the custom namespace.
 *
 * @param item
 *            the name of the entry.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void removeJeItem(final String item) throws XMPException {
	mXmpMeta.deleteProperty(NS_JE, item);
}
 
Example #26
Source File: JpegMetadataUtil.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Log all XML data of the file.
 *
 * @param imageFile the file.
 * @throws ImageReadException thrown if the metadata cannot be read.
 * @throws IOException        thrown in case of other errors while reading metadata.
 * @throws XMPException       thrown in case of issues with XML handling.
 */
public static void printAllXmpData(@NonNull final File imageFile) throws ImageReadException, IOException, XMPException {
	final String xmpString = Imaging.getXmpXml(imageFile);
	Log.i(Application.TAG, new XmpHandler(xmpString).getXmpString());
}
 
Example #27
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the XMP String.
 *
 * @return the XMP String.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final String getXmpString() throws XMPException {
	return XMPMetaFactory.serializeToString(mXmpMeta, null);
}
 
Example #28
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the image title.
 *
 * @param title
 *            the image title.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void setDcTitle(final String title) throws XMPException {
	setDcItem("title", title);
}
 
Example #29
Source File: XmpHandler.java    From Augendiagnose with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the image subject.
 *
 * @param subject
 *            the image subject.
 * @throws XMPException
 *             thrown in case of issues with XML handling.
 */
public final void setDcSubject(final String subject) throws XMPException {
	setDcItem("subject", subject);
}