本文整理汇总了Java中com.adobe.xmp.XMPException类的典型用法代码示例。如果您正苦于以下问题:Java XMPException类的具体用法?Java XMPException怎么用?Java XMPException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMPException类属于com.adobe.xmp包,在下文中一共展示了XMPException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* Serializes the XmpDirectory component of <code>Metadata</code> into an <code>OutputStream</code>
* @param os Destination for the xmp data
* @param data populated metadata
* @return serialize success
*/
public static boolean write(OutputStream os, Metadata data)
{
XmpDirectory dir = data.getFirstDirectoryOfType(XmpDirectory.class);
if (dir == null)
return false;
XMPMeta meta = dir.getXMPMeta();
try
{
SerializeOptions so = new SerializeOptions().setOmitPacketWrapper(true);
XMPMetaFactory.serialize(meta, os, so);
}
catch (XMPException e)
{
e.printStackTrace();
return false;
}
return true;
}
示例2: extract
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* Performs the XMP data extraction, adding found values to the specified instance of {@link Metadata}.
* <p>
* The extraction is done with Adobe's XMPCore library.
*/
public void extract(@NotNull final byte[] xmpBytes, int offset, int length, @NotNull Metadata metadata, @Nullable Directory parentDirectory)
{
XmpDirectory directory = new XmpDirectory();
if (parentDirectory != null)
directory.setParent(parentDirectory);
try {
XMPMeta xmpMeta;
// If all xmpBytes are requested, no need to make a new ByteBuffer
if (offset == 0 && length == xmpBytes.length) {
xmpMeta = XMPMetaFactory.parseFromBuffer(xmpBytes);
} else {
ByteBuffer buffer = new ByteBuffer(xmpBytes, offset, length);
xmpMeta = XMPMetaFactory.parse(buffer.getByteStream());
}
directory.setXMPMeta(xmpMeta);
} catch (XMPException e) {
directory.addError("Error processing XMP data: " + e.getMessage());
}
if (!directory.isEmpty())
metadata.addDirectory(directory);
}
示例3: getInt
import com.adobe.xmp.XMPException; //导入依赖的package包/类
private static int getInt(XMPMeta xmp, String key) throws XMPException {
if (xmp.doesPropertyExist(GOOGLE_PANO_NAMESPACE, key)) {
return xmp.getPropertyInteger(GOOGLE_PANO_NAMESPACE, key);
} else {
return 0;
}
}
示例4: extractXMPMeta
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* Extracts XMPMeta from a JPEG image file stream.
*
* @param is the input stream containing the JPEG image file.
* @return Extracted XMPMeta or null.
*/
public static XMPMeta extractXMPMeta(InputStream is) {
List<Section> sections = parse(is, true);
if (sections == null) {
return null;
}
// Now we don't support extended xmp.
for (Section section : sections) {
if (hasXMPHeader(section.data)) {
int end = getXMPContentEnd(section.data);
byte[] buffer = new byte[end - XMP_HEADER_SIZE];
System.arraycopy(
section.data, XMP_HEADER_SIZE, buffer, 0, buffer.length);
try {
XMPMeta result = XMPMetaFactory.parseFromBuffer(buffer);
return result;
} catch (XMPException e) {
Log.d(TAG, "XMP parse error", e);
return null;
}
}
}
return null;
}
示例5: getXmpProperties
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* Gets a map of all XMP properties in this directory.
* <p>
* This is required because XMP properties are represented as strings, whereas the rest of this library
* uses integers for keys.
*/
@NotNull
public Map<String, String> getXmpProperties()
{
Map<String, String> propertyValueByPath = new HashMap<String, String>();
if (_xmpMeta != null)
{
try {
for (Iterator i = _xmpMeta.iterator(); i.hasNext(); ) {
XMPPropertyInfo prop = (XMPPropertyInfo)i.next();
String path = prop.getPath();
String value = prop.getValue();
if (path != null && value != null) {
propertyValueByPath.put(path, value);
}
}
} catch (XMPException ignored) {
}
}
return Collections.unmodifiableMap(propertyValueByPath);
}
示例6: setXMPMeta
import com.adobe.xmp.XMPException; //导入依赖的package包/类
public void setXMPMeta(@NotNull XMPMeta xmpMeta)
{
_xmpMeta = xmpMeta;
try {
int valueCount = 0;
for (Iterator i = _xmpMeta.iterator(); i.hasNext(); ) {
XMPPropertyInfo prop = (XMPPropertyInfo)i.next();
if (prop.getPath() != null) {
valueCount++;
}
}
setInt(TAG_XMP_VALUE_COUNT, valueCount);
} catch (XMPException ignored) {
}
}
示例7: prepareRegistry
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* 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);
}
}
}
示例8: changeMetadata
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* 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);
}
}
}
}
示例9: prepareRegistry
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* 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);
}
}
}
示例10: extract
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* Performs the XMP data extraction, adding found values to the specified instance of {@link Metadata}.
* <p/>
* The extraction is done with Adobe's XMPCore library.
*/
public void extract(@NotNull final String xmpString, @NotNull Metadata metadata)
{
XmpDirectory directory = metadata.getOrCreateDirectory(XmpDirectory.class);
try {
XMPMeta xmpMeta = XMPMetaFactory.parseFromString(xmpString);
processXmpTags(directory, xmpMeta);
} catch (XMPException e) {
directory.addError("Error processing XMP data: " + e.getMessage());
}
}
示例11: processXmpDateTag
import com.adobe.xmp.XMPException; //导入依赖的package包/类
@SuppressWarnings({ "SameParameterValue" })
void processXmpDateTag(@NotNull XMPMeta meta, @NotNull XmpDirectory directory, @NotNull String schemaNS, @NotNull String propName, int tagType) throws XMPException
{
Calendar cal = meta.getPropertyCalendar(schemaNS, propName);
if (cal == null)
return;
directory.setDate(tagType, cal.getTime());
}
示例12: createXmpMetadata
import com.adobe.xmp.XMPException; //导入依赖的package包/类
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);
}
}
示例13: getExtendedXMPGUID
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* Determine if there is an extended XMP section based on the standard XMP part.
* The xmpNote:HasExtendedXMP attribute contains the GUID of the Extended XMP chunks.
*/
@Nullable
private static String getExtendedXMPGUID(@NotNull Metadata metadata)
{
final Collection<XmpDirectory> xmpDirectories = metadata.getDirectoriesOfType(XmpDirectory.class);
for (XmpDirectory directory : xmpDirectories) {
final XMPMeta xmpMeta = directory.getXMPMeta();
try {
final XMPIterator itr = xmpMeta.iterator(SCHEMA_XMP_NOTES, null, null);
if (itr == null)
continue;
while (itr.hasNext()) {
final XMPPropertyInfo pi = (XMPPropertyInfo) itr.next();
if (ATTRIBUTE_EXTENDED_XMP.equals(pi.getPath())) {
return pi.getValue();
}
}
} catch (XMPException e) {
// Fail silently here: we had a reading issue, not a decoding issue.
}
}
return null;
}
示例14: xmpSample
import com.adobe.xmp.XMPException; //导入依赖的package包/类
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());
}
}
}
示例15: setDcItem
import com.adobe.xmp.XMPException; //导入依赖的package包/类
/**
* 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);
}
}
}