本文整理汇总了C#中iTextSharp.xmp.impl.XmpNode类的典型用法代码示例。如果您正苦于以下问题:C# XmpNode类的具体用法?C# XmpNode怎么用?C# XmpNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmpNode类属于iTextSharp.xmp.impl命名空间,在下文中一共展示了XmpNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeCompactRdfGeneralQualifier
/// <summary>
/// Serializes the general qualifier. </summary>
/// <param name="node"> the root node of the subtree </param>
/// <param name="indent"> the current indent level </param>
/// <exception cref="IOException"> Forwards all writer exceptions. </exception>
/// <exception cref="XmpException"> If qualifier and element fields are mixed. </exception>
private void SerializeCompactRdfGeneralQualifier(int indent, XmpNode node) {
// The node has general qualifiers, ones that can't be
// attributes on a property element.
// Emit using the qualified property pseudo-struct form. The
// value is output by a call
// to SerializePrettyRDFProperty with emitAsRDFValue set.
Write(" rdf:parseType=\"Resource\">");
WriteNewline();
SerializeCanonicalRdfProperty(node, false, true, indent + 1);
for (IEnumerator iq = node.IterateQualifier(); iq.MoveNext();) {
XmpNode qualifier = (XmpNode) iq.Current;
if (qualifier == null)
continue;
SerializeCanonicalRdfProperty(qualifier, false, false, indent + 1);
}
}
示例2: XmpMetaImpl
/// <summary>
/// Constructor for an empty metadata object.
/// </summary>
public XmpMetaImpl() {
// create root node
_tree = new XmpNode(null, null, null);
}
示例3: DoSetArrayItem
// -------------------------------------------------------------------------------------
// private
/// <summary>
/// Locate or create the item node and set the value. Note the index
/// parameter is one-based! The index can be in the range [1..size + 1] or
/// "last()", normalize it and check the insert flags. The order of the
/// normalization checks is important. If the array is empty we end up with
/// an index and location to set item size + 1.
/// </summary>
/// <param name="arrayNode"> an array node </param>
/// <param name="itemIndex"> the index where to insert the item </param>
/// <param name="itemValue"> the item value </param>
/// <param name="itemOptions"> the options for the new item </param>
/// <param name="insert"> insert oder overwrite at index position? </param>
/// <exception cref="XmpException"> </exception>
private void DoSetArrayItem(XmpNode arrayNode, int itemIndex, string itemValue, PropertyOptions itemOptions,
bool insert) {
XmpNode itemNode = new XmpNode(ARRAY_ITEM_NAME, null);
itemOptions = XmpNodeUtils.VerifySetOptions(itemOptions, itemValue);
// in insert mode the index after the last is allowed,
// even ARRAY_LAST_ITEM points to the index *after* the last.
int maxIndex = insert ? arrayNode.ChildrenLength + 1 : arrayNode.ChildrenLength;
if (itemIndex == ARRAY_LAST_ITEM) {
itemIndex = maxIndex;
}
if (1 <= itemIndex && itemIndex <= maxIndex) {
if (!insert) {
arrayNode.RemoveChild(itemIndex);
}
arrayNode.AddChild(itemIndex, itemNode);
SetNode(itemNode, itemValue, itemOptions, false);
}
else {
throw new XmpException("Array index out of bounds", XmpError.BADINDEX);
}
}
示例4: FixupQualifiedNode
/// <summary>
/// The parent is an RDF pseudo-struct containing an rdf:value field. Fix the
/// XMP data model. The rdf:value node must be the first child, the other
/// children are qualifiers. The form, value, and children of the rdf:value
/// node are the real ones. The rdf:value node's qualifiers must be added to
/// the others.
/// </summary>
/// <param name="xmpParent"> the parent xmp node </param>
/// <exception cref="XmpException"> thown on parsing errors </exception>
private static void FixupQualifiedNode(XmpNode xmpParent) {
Debug.Assert(xmpParent.Options.Struct && xmpParent.HasChildren());
XmpNode valueNode = xmpParent.GetChild(1);
Debug.Assert("rdf:value".Equals(valueNode.Name));
// Move the qualifiers on the value node to the parent.
// Make sure an xml:lang qualifier stays at the front.
// Check for duplicate names between the value node's qualifiers and the parent's children.
// The parent's children are about to become qualifiers. Check here, between the groups.
// Intra-group duplicates are caught by XMPNode#addChild(...).
if (valueNode.Options.HasLanguage) {
if (xmpParent.Options.HasLanguage) {
throw new XmpException("Redundant xml:lang for rdf:value element", XmpError.BADXMP);
}
XmpNode langQual = valueNode.GetQualifier(1);
valueNode.RemoveQualifier(langQual);
xmpParent.AddQualifier(langQual);
}
// Start the remaining copy after the xml:lang qualifier.
for (int i = 1; i <= valueNode.QualifierLength; i++) {
XmpNode qualifier = valueNode.GetQualifier(i);
xmpParent.AddQualifier(qualifier);
}
// Change the parent's other children into qualifiers.
// This loop starts at 1, child 0 is the rdf:value node.
for (int i = 2; i <= xmpParent.ChildrenLength; i++) {
XmpNode qualifier = xmpParent.GetChild(i);
xmpParent.AddQualifier(qualifier);
}
// Move the options and value last, other checks need the parent's original options.
// Move the value node's children to be the parent's children.
Debug.Assert(xmpParent.Options.Struct || xmpParent.HasValueChild);
xmpParent.HasValueChild = false;
xmpParent.Options.Struct = false;
xmpParent.Options.MergeWith(valueNode.Options);
xmpParent.Value = valueNode.Value;
xmpParent.RemoveChildren();
for (IEnumerator it = valueNode.IterateChildren(); it.MoveNext();) {
XmpNode child = (XmpNode) it.Current;
xmpParent.AddChild(child);
}
}
示例5: XmpPropertyImpl1
public XmpPropertyImpl1(XmpNode itemNode) {
_itemNode = itemNode;
}
示例6: RdfParseTypeResourcePropertyElement
/// <summary>
/// 7.2.18 parseTypeResourcePropertyElt
/// start-element ( URI == propertyElementURIs,
/// attributes == set ( idAttr?, parseResource ) )
/// propertyEltList
/// end-element()
///
/// Add a new struct node with a qualifier for the possible rdf:ID attribute.
/// Then process the XML child nodes to get the struct fields.
/// </summary>
/// <param name="xmp"> the xmp metadata object that is generated </param>
/// <param name="xmpParent"> the parent xmp node </param>
/// <param name="xmlNode"> the currently processed XML node </param>
/// <param name="isTopLevel"> Flag if the node is a top-level node </param>
/// <exception cref="XmpException"> thown on parsing errors </exception>
private static void RdfParseTypeResourcePropertyElement(XmpMetaImpl xmp, XmpNode xmpParent, XmlNode xmlNode,
bool isTopLevel) {
XmpNode newStruct = AddChildNode(xmp, xmpParent, xmlNode, "", isTopLevel);
newStruct.Options.Struct = true;
if (xmlNode.Attributes != null) {
for (int i = 0; i < xmlNode.Attributes.Count; i++) {
XmlNode attribute = xmlNode.Attributes[i];
if ("xmlns".Equals(attribute.Prefix) || (attribute.Prefix == null && "xmlns".Equals(attribute.Name))) {
continue;
}
string attrLocal = attribute.LocalName;
string attrNs = attribute.NamespaceURI;
if (XML_LANG.Equals(attribute.Name)) {
AddQualifierNode(newStruct, XML_LANG, attribute.Value);
}
else if (NS_RDF.Equals(attrNs) && ("ID".Equals(attrLocal) || "parseType".Equals(attrLocal))) {
continue; // The caller ensured the value is "Resource".
// Ignore all rdf:ID attributes.
}
throw new XmpException("Invalid attribute for ParseTypeResource property element",
XmpError.BADRDF);
}
}
RdfPropertyElementList(xmp, newStruct, xmlNode, false);
if (newStruct.HasValueChild) {
FixupQualifiedNode(newStruct);
}
}
示例7: AddChildNode
/// <summary>
/// Adds a child node.
/// </summary>
/// <param name="xmp"> the xmp metadata object that is generated </param>
/// <param name="xmpParent"> the parent xmp node </param>
/// <param name="xmlNode"> the currently processed XML node </param>
/// <param name="value"> Node value </param>
/// <param name="isTopLevel"> Flag if the node is a top-level node </param>
/// <returns> Returns the newly created child node. </returns>
/// <exception cref="XmpException"> thown on parsing errors </exception>
private static XmpNode AddChildNode(XmpMetaImpl xmp, XmpNode xmpParent, XmlNode xmlNode, string value,
bool isTopLevel) {
IXmpSchemaRegistry registry = XmpMetaFactory.SchemaRegistry;
string @namespace = xmlNode.NamespaceURI;
string childName;
if (@namespace != null) {
if (NS_DC_DEPRECATED.Equals(@namespace)) {
// Fix a legacy DC namespace
@namespace = NS_DC;
}
string prefix = registry.GetNamespacePrefix(@namespace);
if (prefix == null) {
prefix = xmlNode.Prefix ?? DEFAULT_PREFIX;
prefix = registry.RegisterNamespace(@namespace, prefix);
}
childName = prefix + xmlNode.LocalName;
}
else {
throw new XmpException("XML namespace required for all elements and attributes",
XmpError.BADRDF);
}
// create schema node if not already there
PropertyOptions childOptions = new PropertyOptions();
bool isAlias = false;
if (isTopLevel) {
// Lookup the schema node, adjust the XMP parent pointer.
// Incoming parent must be the tree root.
XmpNode schemaNode = XmpNodeUtils.FindSchemaNode(xmp.Root, @namespace, DEFAULT_PREFIX, true);
schemaNode.Implicit = false; // Clear the implicit node bit.
// need runtime check for proper 32 bit code.
xmpParent = schemaNode;
// If this is an alias set the alias flag in the node
// and the hasAliases flag in the tree.
if (registry.FindAlias(childName) != null) {
isAlias = true;
xmp.Root.HasAliases = true;
schemaNode.HasAliases = true;
}
}
// Make sure that this is not a duplicate of a named node.
bool isArrayItem = "rdf:li".Equals(childName);
bool isValueNode = "rdf:value".Equals(childName);
// Create XMP node and so some checks
XmpNode newChild = new XmpNode(childName, value, childOptions);
newChild.Alias = isAlias;
// Add the new child to the XMP parent node, a value node first.
if (!isValueNode) {
xmpParent.AddChild(newChild);
}
else {
xmpParent.AddChild(1, newChild);
}
if (isValueNode) {
if (isTopLevel || !xmpParent.Options.Struct) {
throw new XmpException("Misplaced rdf:value element", XmpError.BADRDF);
}
xmpParent.HasValueChild = true;
}
if (isArrayItem) {
if (!xmpParent.Options.Array) {
throw new XmpException("Misplaced rdf:li element", XmpError.BADRDF);
}
newChild.Name = ARRAY_ITEM_NAME;
}
return newChild;
}
示例8: AccumulatePath
/// <param name="currNode"> the node that will be added to the path. </param>
/// <param name="parentPath"> the path up to this node. </param>
/// <param name="currentIndex"> the current array index if an arrey is traversed </param>
/// <returns> Returns the updated path. </returns>
protected internal virtual string AccumulatePath(XmpNode currNode, string parentPath, int currentIndex) {
string separator;
string segmentName;
if (currNode.Parent == null || currNode.Options.SchemaNode) {
return null;
}
if (currNode.Parent.Options.Array) {
separator = "";
segmentName = "[" + Convert.ToString(currentIndex) + "]";
}
else {
separator = "/";
segmentName = currNode.Name;
}
if (String.IsNullOrEmpty(parentPath)) {
return segmentName;
}
if (_outerInstance.Options.JustLeafname) {
return !segmentName.StartsWith("?") ? segmentName : segmentName.Substring(1); // qualifier
}
return parentPath + separator + segmentName;
}
示例9: CreatePropertyInfo
/// <summary>
/// Creates a property info object from an <code>XMPNode</code>. </summary>
/// <param name="node"> an <code>XMPNode</code> </param>
/// <param name="baseNs"> the base namespace to report </param>
/// <param name="path"> the full property path </param>
/// <returns> Returns a <code>XMPProperty</code>-object that serves representation of the node. </returns>
protected internal virtual IXmpPropertyInfo CreatePropertyInfo(XmpNode node, string baseNs, string path) {
string value = node.Options.SchemaNode ? null : node.Value;
return new XmpPropertyInfoImpl(node, baseNs, path, value);
}
示例10: SerializeCanonicalRdfProperty
/// <summary>
/// Recursively handles the "value" for a node. It does not matter if it is a
/// top level property, a field of a struct, or an item of an array. The
/// indent is that for the property element. An xml:lang qualifier is written
/// as an attribute of the property start tag, not by itself forcing the
/// qualified property form. The patterns below mostly ignore attribute
/// qualifiers like xml:lang. Except for the one struct case, attribute
/// qualifiers don't affect the output form.
///
/// <blockquote>
///
/// <pre>
/// <ns:UnqualifiedSimpleProperty>value</ns:UnqualifiedSimpleProperty>
///
/// <ns:UnqualifiedStructProperty> (If no rdf:resource qualifier)
/// <rdf:Description>
/// ... Fields, same forms as top level properties
/// </rdf:Description>
/// </ns:UnqualifiedStructProperty>
///
/// <ns:ResourceStructProperty rdf:resource="URI"
/// ... Fields as attributes
/// >
///
/// <ns:UnqualifiedArrayProperty>
/// <rdf:Bag> or Seq or Alt
/// ... Array items as rdf:li elements, same forms as top level properties
/// </rdf:Bag>
/// </ns:UnqualifiedArrayProperty>
///
/// <ns:QualifiedProperty>
/// <rdf:Description>
/// <rdf:value> ... Property "value" following the unqualified
/// forms ... </rdf:value>
/// ... Qualifiers looking like named struct fields
/// </rdf:Description>
/// </ns:QualifiedProperty>
/// </pre>
///
/// </blockquote>
/// </summary>
/// <param name="node"> the property node </param>
/// <param name="emitAsRdfValue"> property shall be rendered as attribute rather than tag </param>
/// <param name="useCanonicalRdf"> use canonical form with inner description tag or
/// the compact form with rdf:ParseType="resource" attribute. </param>
/// <param name="indent"> the current indent level </param>
/// <exception cref="IOException"> Forwards all writer exceptions. </exception>
/// <exception cref="XmpException"> If "rdf:resource" and general qualifiers are mixed. </exception>
private void SerializeCanonicalRdfProperty(XmpNode node, bool useCanonicalRdf, bool emitAsRdfValue, int indent) {
bool emitEndTag = true;
bool indentEndTag = true;
// Determine the XML element name. Open the start tag with the name and
// attribute qualifiers.
string elemName = node.Name;
if (emitAsRdfValue) {
elemName = "rdf:value";
}
else if (XmpConst.ARRAY_ITEM_NAME.Equals(elemName)) {
elemName = "rdf:li";
}
WriteIndent(indent);
Write('<');
Write(elemName);
bool hasGeneralQualifiers = false;
bool hasRdfResourceQual = false;
for (IEnumerator it = node.IterateQualifier(); it.MoveNext();) {
XmpNode qualifier = (XmpNode) it.Current;
if (qualifier != null) {
if (!RDF_ATTR_QUALIFIER.Contains(qualifier.Name)) {
hasGeneralQualifiers = true;
}
else {
hasRdfResourceQual = "rdf:resource".Equals(qualifier.Name);
if (!emitAsRdfValue) {
Write(' ');
Write(qualifier.Name);
Write("=\"");
AppendNodeValue(qualifier.Value, true);
Write('"');
}
}
}
}
// Process the property according to the standard patterns.
if (hasGeneralQualifiers && !emitAsRdfValue) {
// This node has general, non-attribute, qualifiers. Emit using the
// qualified property form.
// ! The value is output by a recursive call ON THE SAME NODE with
// emitAsRDFValue set.
if (hasRdfResourceQual) {
throw new XmpException("Can't mix rdf:resource and general qualifiers", XmpError.BADRDF);
}
//.........这里部分代码省略.........
示例11: NodeIterator
/// <summary>
/// Constructor for the node iterator. </summary>
/// <param name="visitedNode"> the currently visited node </param>
/// <param name="parentPath"> the accumulated path of the node </param>
/// <param name="index"> the index within the parent node (only for arrays) </param>
public NodeIterator(XmpIteratorImpl outerInstance, XmpNode visitedNode, string parentPath, int index) {
_outerInstance = outerInstance;
_visitedNode = visitedNode;
_state = ITERATE_NODE;
if (visitedNode.Options.SchemaNode) {
outerInstance.BaseNs = visitedNode.Name;
}
// for all but the root node and schema nodes
_path = AccumulatePath(visitedNode, parentPath, index);
}
示例12: StartOuterRdfDescription
/// <summary>
/// Start the outer rdf:Description element, including all needed xmlns attributes.
/// Leave the element open so that the compact form can add property attributes.
/// </summary>
/// <exception cref="IOException"> If the writing to </exception>
private void StartOuterRdfDescription(XmpNode schemaNode, int level) {
WriteIndent(level + 1);
Write(RDF_SCHEMA_START);
WriteTreeName();
ISet usedPrefixes = new HashSet();
usedPrefixes.Add("xml");
usedPrefixes.Add("rdf");
DeclareUsedNamespaces(schemaNode, usedPrefixes, level + 3);
Write('>');
WriteNewline();
}
示例13: DeclareUsedNamespaces
/// <summary>
/// Writes all used namespaces of the subtree in node to the output.
/// The subtree is recursivly traversed. </summary>
/// <param name="node"> the root node of the subtree </param>
/// <param name="usedPrefixes"> a set containing currently used prefixes </param>
/// <param name="indent"> the current indent level </param>
/// <exception cref="IOException"> Forwards all writer exceptions. </exception>
private void DeclareUsedNamespaces(XmpNode node, ISet usedPrefixes, int indent) {
if (node.Options.SchemaNode) {
// The schema node name is the URI, the value is the prefix.
string prefix = node.Value.Substring(0, node.Value.Length - 1);
DeclareNamespace(prefix, node.Name, usedPrefixes, indent);
}
else if (node.Options.Struct) {
for (IEnumerator it = node.IterateChildren(); it.MoveNext();) {
XmpNode field = (XmpNode) it.Current;
if (field == null)
continue;
DeclareNamespace(field.Name, null, usedPrefixes, indent);
}
}
for (IEnumerator it = node.IterateChildren(); it.MoveNext();) {
XmpNode child = (XmpNode) it.Current;
if (child == null)
continue;
DeclareUsedNamespaces(child, usedPrefixes, indent);
}
for (IEnumerator it = node.IterateQualifier(); it.MoveNext();) {
XmpNode qualifier = (XmpNode) it.Current;
if (qualifier == null)
continue;
DeclareNamespace(qualifier.Name, null, usedPrefixes, indent);
DeclareUsedNamespaces(qualifier, usedPrefixes, indent);
}
}
示例14: SerializeCanonicalRdfSchema
/// <summary>
/// Serializes one schema with all contained properties in pretty-printed
/// manner.<br>
/// Each schema's properties are written to a single
/// rdf:Description element. All of the necessary namespaces are declared in
/// the rdf:Description element. The baseIndent is the base level for the
/// entire serialization, that of the x:xmpmeta element. An xml:lang
/// qualifier is written as an attribute of the property start tag, not by
/// itself forcing the qualified property form.
///
/// <blockquote>
///
/// <pre>
/// <rdf:Description rdf:about="TreeName" xmlns:ns="URI" ... >
///
/// ... The actual properties of the schema, see SerializePrettyRDFProperty
///
/// <!-- ns1:Alias is aliased to ns2:Actual --> ... If alias comments are wanted
///
/// </rdf:Description>
/// </pre>
///
/// </blockquote>
/// </summary>
/// <param name="schemaNode"> a schema node </param>
/// <param name="level"> </param>
/// <exception cref="IOException"> Forwarded writer exceptions </exception>
/// <exception cref="XmpException"> </exception>
private void SerializeCanonicalRdfSchema(XmpNode schemaNode, int level) {
// Write each of the schema's actual properties.
for (IEnumerator it = schemaNode.IterateChildren(); it.MoveNext();) {
XmpNode propNode = (XmpNode) it.Current;
if (propNode == null)
continue;
SerializeCanonicalRdfProperty(propNode, _options.UseCanonicalFormat, false, level + 2);
}
}
示例15: RdfResourcePropertyElement
/// <summary>
/// 7.2.15 resourcePropertyElt
/// start-element ( URI == propertyElementURIs, attributes == set ( idAttr? ) )
/// ws* nodeElement ws*
/// end-element()
///
/// This handles structs using an rdf:Description node,
/// arrays using rdf:Bag/Seq/Alt, and typedNodes. It also catches and cleans up qualified
/// properties written with rdf:Description and rdf:value.
/// </summary>
/// <param name="xmp"> the xmp metadata object that is generated </param>
/// <param name="xmpParent"> the parent xmp node </param>
/// <param name="xmlNode"> the currently processed XML node </param>
/// <param name="isTopLevel"> Flag if the node is a top-level node </param>
/// <exception cref="XmpException"> thown on parsing errors </exception>
private static void RdfResourcePropertyElement(XmpMetaImpl xmp, XmpNode xmpParent, XmlNode xmlNode,
bool isTopLevel) {
if (isTopLevel && "iX:changes".Equals(xmlNode.Name)) {
// Strip old "punchcard" chaff which has on the prefix "iX:".
return;
}
XmpNode newCompound = AddChildNode(xmp, xmpParent, xmlNode, "", isTopLevel);
// walk through the attributes
if (xmlNode.Attributes != null) {
for (int i = 0; i < xmlNode.Attributes.Count; i++) {
XmlNode attribute = xmlNode.Attributes[i];
if ("xmlns".Equals(attribute.Prefix) || (attribute.Prefix == null && "xmlns".Equals(attribute.Name))) {
continue;
}
string attrLocal = attribute.LocalName;
string attrNs = attribute.NamespaceURI;
if (XML_LANG.Equals(attribute.Name)) {
AddQualifierNode(newCompound, XML_LANG, attribute.Value);
}
else if ("ID".Equals(attrLocal) && NS_RDF.Equals(attrNs)) {
continue; // Ignore all rdf:ID attributes.
}
throw new XmpException("Invalid attribute for resource property element", XmpError.BADRDF);
}
}
// walk through the children
bool found = false;
for (int i = 0; i < xmlNode.ChildNodes.Count; i++) {
XmlNode currChild = xmlNode.ChildNodes[i];
if (!IsWhitespaceNode(currChild)) {
if (currChild.NodeType == XmlNodeType.Element && !found) {
bool isRdf = NS_RDF.Equals(currChild.NamespaceURI);
string childLocal = currChild.LocalName;
if (isRdf && "Bag".Equals(childLocal)) {
newCompound.Options.Array = true;
}
else if (isRdf && "Seq".Equals(childLocal)) {
newCompound.Options.Array = true;
newCompound.Options.ArrayOrdered = true;
}
else if (isRdf && "Alt".Equals(childLocal)) {
newCompound.Options.Array = true;
newCompound.Options.ArrayOrdered = true;
newCompound.Options.ArrayAlternate = true;
}
else {
newCompound.Options.Struct = true;
if (!isRdf && !"Description".Equals(childLocal)) {
string typeName = currChild.NamespaceURI;
if (typeName == null) {
throw new XmpException("All XML elements must be in a namespace",
XmpError.BADXMP);
}
typeName += ':' + childLocal;
AddQualifierNode(newCompound, "rdf:type", typeName);
}
}
RdfNodeElement(xmp, newCompound, currChild, false);
if (newCompound.HasValueChild) {
FixupQualifiedNode(newCompound);
}
else if (newCompound.Options.ArrayAlternate) {
XmpNodeUtils.DetectAltText(newCompound);
}
found = true;
}
else if (found) {
// found second child element
throw new XmpException("Invalid child of resource property element", XmpError.BADRDF);
}
else {
throw new XmpException("Children of resource property element must be XML elements",
XmpError.BADRDF);
}
}
}
//.........这里部分代码省略.........