public virtual void XxeTestFromString() { XmlException ex = Assert.Throws <XmlException>(delegate { XmpMetaParser.Parse(XMP_WITH_XXE, null); }); // do not check the expected message as it differs depending on .net version }
public virtual void XxeTestFromByteBuffer() { XmpException ex = Assert.Throws <XmpException>(delegate { XmpMetaParser.Parse(System.Text.Encoding.UTF8.GetBytes(XMP_WITH_XXE), null); }); Assert.AreEqual("Unsupported Encoding", ex.Message); }
public virtual void XxeTestFromInputStream() { Stream inputStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(XMP_WITH_XXE)); XmpException ex = Assert.Throws <XmpException>(delegate { XmpMetaParser.Parse(inputStream, null); }); Assert.AreEqual("Unsupported Encoding", ex.Message); }
private void ReadPdfAInfo() { byte[] metadata = null; IXmpProperty pdfaidConformance = null; IXmpProperty pdfaidPart = null; try { metadata = reader.Metadata; xmpMeta = XmpMetaParser.Parse(metadata, null); pdfaidConformance = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:conformance"); pdfaidPart = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:part"); } catch (Exception e) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("only.pdfa.documents.can.be.opened.in.PdfAStamper")); } if (pdfaidConformance == null || pdfaidPart == null) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("only.pdfa.documents.can.be.opened.in.PdfAStamper")); } switch (((IPdfAConformance)pdfIsoConformance).ConformanceLevel) { case PdfAConformanceLevel.PDF_A_1A: case PdfAConformanceLevel.PDF_A_1B: if (!"1".Equals(pdfaidPart.Value)) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("only.pdfa.1.documents.can.be.opened.in.PdfAStamper", "1")); } break; case PdfAConformanceLevel.PDF_A_2A: case PdfAConformanceLevel.PDF_A_2B: case PdfAConformanceLevel.PDF_A_2U: if (!"2".Equals(pdfaidPart.Value)) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("only.pdfa.1.documents.can.be.opened.in.PdfAStamper", "2")); } break; case PdfAConformanceLevel.PDF_A_3A: case PdfAConformanceLevel.PDF_A_3B: case PdfAConformanceLevel.PDF_A_3U: if (!"3".Equals(pdfaidPart.Value)) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("only.pdfa.1.documents.can.be.opened.in.PdfAStamper", "3")); } break; } }
/// <summary> /// These functions support parsing serialized RDF into an XMP object, and serailizing an XMP /// object into RDF. The input for parsing may be any valid Unicode /// encoding. ISO Latin-1 is also recognized, but its use is strongly discouraged. Serialization /// is always as UTF-8. /// <p/> /// <code>parseFromBuffer()</code> parses RDF from an <code>InputStream</code>. The encoding /// is recognized automatically. /// </summary> /// <param name="in"> an <code>InputStream</code> </param> /// <param name="options"> Options controlling the parsing.<br> /// The available options are: /// <ul> /// <li> XMP_REQUIRE_XMPMETA - The <x:xmpmeta> XML element is required around /// <tt><rdf:RDF></tt>. /// <li> XMP_STRICT_ALIASING - Do not reconcile alias differences, throw an exception. /// </ul> /// <em>Note:</em>The XMP_STRICT_ALIASING option is not yet implemented. </param> /// <returns> Returns the <code>XMPMeta</code>-object created from the input. </returns> /// <exception cref="XmpException"> If the file is not well-formed XML or if the parsing fails. </exception> public static IXmpMeta Parse(Stream @in, ParseOptions options) { return(XmpMetaParser.Parse(@in, options)); }
/// <summary> /// Creates an <code>XMPMeta</code>-object from a byte-buffer. /// </summary> /// <param name="buffer"> a String contain an XMP-file. </param> /// <param name="options"> Options controlling the parsing. </param> /// <returns> Returns the <code>XMPMeta</code>-object created from the input. </returns> /// <exception cref="XmpException"> If the file is not well-formed XML or if the parsing fails. </exception> /// <seealso cref= XMPMetaFactory#parse(InputStream, ParseOptions) </seealso> public static IXmpMeta ParseFromBuffer(byte[] buffer, ParseOptions options) { return(XmpMetaParser.Parse(buffer, options)); }
/// <summary> /// Creates an <code>XMPMeta</code>-object from a string. /// </summary> /// <param name="packet"> a String contain an XMP-file. </param> /// <param name="options"> Options controlling the parsing. </param> /// <returns> Returns the <code>XMPMeta</code>-object created from the input. </returns> /// <exception cref="XmpException"> If the file is not well-formed XML or if the parsing fails. </exception> /// <seealso cref= XMPMetaFactory#parseFromString(String, ParseOptions) </seealso> public static IXmpMeta ParseFromString(string packet, ParseOptions options) { return(XmpMetaParser.Parse(packet, options)); }
/// <summary> /// These functions support parsing serialized RDF into an XMP object, and serializing an XMP /// object into RDF. /// </summary> /// <remarks> /// These functions support parsing serialized RDF into an XMP object, and serializing an XMP /// object into RDF. The input for parsing may be any valid Unicode /// encoding. ISO Latin-1 is also recognized, but its use is strongly discouraged. Serialization /// is always as UTF-8. /// <para /> /// <c>parseFromBuffer()</c> parses RDF from an <c>Stream</c>. The encoding /// is recognized automatically. /// </remarks> /// <param name="stream">an <c>Stream</c></param> /// <param name="options">Options controlling the parsing. /// The available options are: /// <list type="bullet"> /// <item>XMP_REQUIRE_XMPMETA - The <x:xmpmeta> XML element is required around <tt><rdf:RDF></tt>.</item> /// <item>XMP_STRICT_ALIASING - Do not reconcile alias differences, throw an exception.</item> /// </list> /// Note: The XMP_STRICT_ALIASING option is not yet implemented. /// </param> /// <returns>Returns the <c>XMPMeta</c>-object created from the input.</returns> /// <exception cref="XmpException">If the file is not well-formed XML or if the parsing fails.</exception> public static IXmpMeta Parse(Stream stream, ParseOptions options = null) { return(XmpMetaParser.Parse(stream, options)); }
private void CheckPdfAInfo(PdfReader reader) { byte[] metadata; IXmpMeta xmpMeta; IXmpProperty pdfaidConformance; IXmpProperty pdfaidPart; try { metadata = reader.Metadata; xmpMeta = XmpMetaParser.Parse(metadata, null); pdfaidConformance = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:conformance"); pdfaidPart = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:part"); } catch (Exception e) { throw new PdfAConformanceException( MessageLocalization.GetComposedMessage("only.pdfa.documents.can.be.added.in.PdfACopy")); } if (pdfaidConformance == null || pdfaidPart == null) { throw new PdfAConformanceException( MessageLocalization.GetComposedMessage("only.pdfa.documents.can.be.added.in.PdfACopy")); } switch (((IPdfAConformance)pdfIsoConformance).ConformanceLevel) { case PdfAConformanceLevel.PDF_A_1A: case PdfAConformanceLevel.PDF_A_1B: if (!"1".Equals(pdfaidPart.Value)) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("different.pdf.a.version", "1")); } break; case PdfAConformanceLevel.PDF_A_2A: case PdfAConformanceLevel.PDF_A_2B: case PdfAConformanceLevel.PDF_A_2U: if (!"2".Equals(pdfaidPart.Value)) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("different.pdf.a.version", "2")); } break; case PdfAConformanceLevel.PDF_A_3A: case PdfAConformanceLevel.PDF_A_3B: case PdfAConformanceLevel.PDF_A_3U: case PdfAConformanceLevel.ZUGFeRD: if (!"3".Equals(pdfaidPart.Value)) { throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("different.pdf.a.version", "3")); } break; } switch (((IPdfAConformance)pdfIsoConformance).ConformanceLevel) { case PdfAConformanceLevel.PDF_A_1A: case PdfAConformanceLevel.PDF_A_2A: case PdfAConformanceLevel.PDF_A_3A: if (!"A".Equals(pdfaidConformance.Value)) { throw new PdfAConformanceException( MessageLocalization.GetComposedMessage("incompatible.pdf.a.conformance.level", "a")); } break; case PdfAConformanceLevel.PDF_A_2U: case PdfAConformanceLevel.PDF_A_3U: if ("B".Equals(pdfaidConformance.Value)) { throw new PdfAConformanceException( MessageLocalization.GetComposedMessage("incompatible.pdf.a.conformance.level", "u")); } break; } }
public static XDocument ExtractXDocumentFromBuffer(byte[] buffer, ParseOptions options = null) => XmpMetaParser.Extract(buffer, options);
public static IXmpMeta ParseFromXDocument(XDocument root, ParseOptions options = null) => XmpMetaParser.Parse(root, options);
public static IXmpMeta ParseFromBuffer(byte[] buffer, int offset, int length, ParseOptions options = null) => XmpMetaParser.Parse(new ByteBuffer(buffer, offset, length), options);
/// <summary>Creates an <c>XMPMeta</c>-object from a byte-buffer.</summary> /// <seealso cref="Parse(Stream, ParseOptions)"/> /// <param name="buffer">a String contain an XMP-file.</param> /// <param name="options">Options controlling the parsing.</param> /// <returns>Returns the <c>XMPMeta</c>-object created from the input.</returns> /// <exception cref="XmpException">If the file is not well-formed XML or if the parsing fails.</exception> public static IXmpMeta ParseFromBuffer(byte[] buffer, ParseOptions options = null) => XmpMetaParser.Parse(buffer, options);
/// <summary>Creates an <c>XMPMeta</c>-object from a string.</summary> /// <seealso cref="ParseFromString(string, ParseOptions)"/> /// <param name="packet">a String contain an XMP-file.</param> /// <param name="options">Options controlling the parsing.</param> /// <returns>Returns the <c>XMPMeta</c>-object created from the input.</returns> /// <exception cref="XmpException">If the file is not well-formed XML or if the parsing fails.</exception> public static IXmpMeta ParseFromString(string packet, ParseOptions options = null) => XmpMetaParser.Parse(packet, options);
/// <summary> /// These functions support parsing serialized RDF into an XMP object, and serializing an XMP /// object into RDF. /// </summary> /// <remarks> /// These functions support parsing serialized RDF into an XMP object, and serializing an XMP /// object into RDF. The input for parsing may be any valid Unicode /// encoding. ISO Latin-1 is also recognized, but its use is strongly discouraged. Serialization /// is always as UTF-8. /// <para /> /// <c>parseFromBuffer()</c> parses RDF from an <c>Stream</c>. The encoding /// is recognized automatically. /// </remarks> /// <param name="stream">an <c>Stream</c></param> /// <param name="options">Options controlling the parsing. /// The available options are: /// <list type="bullet"> /// <item>XMP_REQUIRE_XMPMETA - The <x:xmpmeta> XML element is required around <tt><rdf:RDF></tt>.</item> /// <item>XMP_STRICT_ALIASING - Do not reconcile alias differences, throw an exception.</item> /// </list> /// Note: The XMP_STRICT_ALIASING option is not yet implemented. /// </param> /// <returns>Returns the <c>XMPMeta</c>-object created from the input.</returns> /// <exception cref="XmpException">If the file is not well-formed XML or if the parsing fails.</exception> public static IXmpMeta Parse(Stream stream, ParseOptions options = null) => XmpMetaParser.Parse(stream, options);