MediaWiki  REL1_19
XMPReader Class Reference

Class for reading xmp data containing properties relevant to images, and spitting out an array that FormatExif accepts. More...

List of all members.

Public Member Functions

 __construct ()
 Constructor.
 __destruct ()
 Destroy the xml parser.
 char ($parser, $data)
 Character data handler Called whenever character data is found in the xmp document.
 endElement ($parser, $elm)
 Handler for hitting a closing element.
 getResults ()
 Get the result array.
 parse ($content, $allOfIt=true, $reset=false)
 Main function to call to parse XMP.
 parseExtended ($content)
 Entry point for XMPExtended blocks in jpeg files.
 startElement ($parser, $elm, $attribs)
 Hits an opening element.

Public Attributes

const MODE_ALT = 15
const MODE_BAG = 13
const MODE_BAGSTRUCT = 16
const MODE_IGNORE = 1
const MODE_INITIAL = 0
 These are various mode constants.
const MODE_LANG = 14
const MODE_LI = 2
const MODE_LI_LANG = 3
const MODE_QDESC = 4
const MODE_SEQ = 12
const MODE_SIMPLE = 10
const MODE_STRUCT = 11
const NS_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
const NS_XML = 'http://www.w3.org/XML/1998/namespace'

Protected Attributes

 $items

Private Member Functions

 doAttribs ($attribs)
 Process attributes.
 endElementModeIgnore ($elm)
 When we hit a closing element in MODE_IGNORE Check to see if this is the element we started to ignore, in which case we get out of MODE_IGNORE.
 endElementModeLi ($elm)
 Hit a closing element in MODE_LI (either rdf:Seq, or rdf:Bag ) Add information about what type of element this is.
 endElementModeQDesc ($elm)
 End element while in MODE_QDESC mostly when ending an element when we have a simple value that has qualifiers.
 endElementModeSimple ($elm)
 Hit a closing element when in MODE_SIMPLE.
 endElementNested ($elm)
 Hit a closing element in MODE_STRUCT, MODE_SEQ, MODE_BAG generally means we've finished processing a nested structure.
 resetXMLParser ()
 Main use is if a single item has multiple xmp documents describing it.
 saveValue ($ns, $tag, $val)
 Given an extracted value, save it to results array.
 startElementModeBag ($elm)
 Start element in MODE_BAG (unordered array) this should always be <rdf:Bag>
 startElementModeIgnore ($elm)
 Hit an opening element while in MODE_IGNORE.
 startElementModeInitial ($ns, $tag, $attribs)
 Starting an element when in MODE_INITIAL This usually happens when we hit an element inside the outer rdf:Description.
 startElementModeLang ($elm)
 Start element in MODE_LANG (language alternative) this should always be <rdf:Alt>
 startElementModeLi ($elm, $attribs)
 opening element in MODE_LI process elements of arrays.
 startElementModeLiLang ($elm, $attribs)
 Opening element in MODE_LI_LANG.
 startElementModeQDesc ($elm)
 Start an element when in MODE_QDESC.
 startElementModeSeq ($elm)
 Start element in MODE_SEQ (ordered array) this should always be <rdf:Seq>
 startElementModeSimple ($elm, $attribs)
 Handle an opening element when in MODE_SIMPLE.
 startElementModeStruct ($ns, $tag, $attribs)
 Hit an opening element when in a Struct (MODE_STRUCT) This is generally for fields of a compound property.

Private Attributes

 $ancestorStruct = false
 $charContent = false
 $charset = false
 $curItem = array()
 $extendedXMPOffset = 0
 $itemLang = false
 $mode = array()
 $processingArray = false
 $results = array()
 $xmlParser

Detailed Description

Class for reading xmp data containing properties relevant to images, and spitting out an array that FormatExif accepts.

Note, this is not meant to recognize every possible thing you can encode in XMP. It should recognize all the properties we want. For example it doesn't have support for structures with multiple nesting levels, as none of the properties we're supporting use that feature. If it comes across properties it doesn't recognize, it should ignore them.

The public methods one would call in this class are

  • parse( $content ) Reads in xmp content. Can potentially be called multiple times with partial data each time.
  • parseExtended( $content ) Reads XMPExtended blocks (jpeg files only).
  • getResults Outputs a results array.

Note XMP kind of looks like rdf. They are not the same thing - XMP is encoded as a specific subset of rdf. This class can read XMP. It cannot read rdf.

Definition at line 27 of file XMP.php.


Constructor & Destructor Documentation

Constructor.

Primary job is to initialize the XMLParser

Definition at line 77 of file XMP.php.

References XMPInfo\getItems(), and resetXMLParser().

Here is the call graph for this function:

Destroy the xml parser.

Not sure if this is actually needed.

Definition at line 115 of file XMP.php.


Member Function Documentation

XMPReader::char ( parser,
data 
)

Character data handler Called whenever character data is found in the xmp document.

does nothing if we're in MODE_IGNORE or if the data is whitespace throws an error if we're not in MODE_SIMPLE (as we're not allowed to have character data in the other modes).

As an example, this happens when we encounter XMP like: <exif:DigitalZoomRatio>0/10</exif:DigitalZoomRatio> and are processing the 0/10 bit.

Parameters:
$parserXMLParser reference to the xml parser
$dataString Character data
Exceptions:
MWExceptionon invalid data

Definition at line 360 of file XMP.php.

Referenced by doAttribs().

Here is the caller graph for this function:

XMPReader::doAttribs ( attribs) [private]

Process attributes.

Simple values can be stored as either a tag or attribute

Often the initial <rdf:Description> tag just has all the simple properties as attributes.

Example: <rdf:Description rdf:about="" xmlns:exif="http://ns.adobe.com/exif/1.0/" exif:DigitalZoomRatio="0/10">

Parameters:
$attribsArray attribute=>value array.

Definition at line 1082 of file XMP.php.

References char(), MODE_QDESC, saveValue(), and wfDebugLog().

Referenced by startElementModeInitial(), startElementModeLi(), and startElementModeStruct().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::endElement ( parser,
elm 
)

Handler for hitting a closing element.

generally just calls a helper function depending on what mode we're in.

Ignores the outer wrapping elements that are optional in xmp and have no meaning.

Parameters:
$parserXMLParser
$elmString namespace . ' ' . element name

Definition at line 581 of file XMP.php.

References endElementModeIgnore(), endElementModeLi(), endElementModeQDesc(), endElementModeSimple(), endElementNested(), and wfDebugLog().

Here is the call graph for this function:

XMPReader::endElementModeIgnore ( elm) [private]

When we hit a closing element in MODE_IGNORE Check to see if this is the element we started to ignore, in which case we get out of MODE_IGNORE.

Parameters:
$elmString Namespace of element followed by a space and then tag name of element.

Definition at line 394 of file XMP.php.

Referenced by endElement().

Here is the caller graph for this function:

XMPReader::endElementModeLi ( elm) [private]

Hit a closing element in MODE_LI (either rdf:Seq, or rdf:Bag ) Add information about what type of element this is.

Note we still have to hit the outer </property>

For example, when processing: <exif:ISOSpeedRatings> <rdf:Seq> <rdf:li>64</rdf:li> </rdf:Seq> </exif:ISOSpeedRatings>

This method is called when we hit the </rdf:Seq>. (For comparison, we call endElementModeSimple when we hit the </rdf:li>)

Parameters:
$elmString namespace . ' ' . element name

Definition at line 516 of file XMP.php.

References wfDebugLog().

Referenced by endElement().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::endElementModeQDesc ( elm) [private]

End element while in MODE_QDESC mostly when ending an element when we have a simple value that has qualifiers.

Qualifiers aren't all that common, and we don't do anything with them.

Parameters:
$elmString namespace and element

Definition at line 555 of file XMP.php.

References saveValue().

Referenced by endElement().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::endElementModeSimple ( elm) [private]

Hit a closing element when in MODE_SIMPLE.

This generally means that we finished processing a property value, and now have to save the result to the results array

For example, when processing: <exif:DigitalZoomRatio>0/10</exif:DigitalZoomRatio> this deals with when we hit </exif:DigitalZoomRatio>.

Or it could be if we hit the end element of a property of a compound data structure (like a member of an array).

Parameters:
$elmString namespace, space, and tag name.

Definition at line 419 of file XMP.php.

References saveValue().

Referenced by endElement().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::endElementNested ( elm) [private]

Hit a closing element in MODE_STRUCT, MODE_SEQ, MODE_BAG generally means we've finished processing a nested structure.

resets some internal variables to indicate that.

Note this means we hit the </closing> not the </rdf:Seq>.

For example, when processing: <exif:ISOSpeedRatings> <rdf:Seq> <rdf:li>64</rdf:li> </rdf:Seq> </exif:ISOSpeedRatings>

This method is called when we hit the </exif:ISOSpeedRatings> tag.

Parameters:
$elmString namespace . space . tag name.

Definition at line 452 of file XMP.php.

References wfDebugLog().

Referenced by endElement().

Here is the call graph for this function:

Here is the caller graph for this function:

Get the result array.

Do some post-processing before returning the array, and transform any metadata that is special-cased.

Returns:
Array array of results as an array of arrays suitable for FormatMetadata::getFormattedData().

Definition at line 126 of file XMP.php.

References wfRunHooks().

Here is the call graph for this function:

XMPReader::parse ( content,
allOfIt = true,
reset = false 
)

Main function to call to parse XMP.

Use getResults to get results.

Also catches any errors during processing, writes them to debug log, blanks result array and returns false.

Parameters:
$contentString: XMP data
$allOfItBoolean: If this is all the data (true) or if its split up (false). Default true
$resetBoolean: does xml parser need to be reset. Default false
Returns:
Boolean success.

Definition at line 218 of file XMP.php.

References $ok, resetXMLParser(), wfDebugLog(), wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by parseExtended(), and XMPTest\testXMPParse().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::parseExtended ( content)

Entry point for XMPExtended blocks in jpeg files.

Todo:
In serious need of testing
See also:
http://www.adobe.ge/devnet/xmp/pdfs/XMPSpecificationPart3.pdf XMP spec part 3 page 20
Parameters:
String$contentXMPExtended block minus the namespace signature
Returns:
Boolean If it succeeded.

Definition at line 292 of file XMP.php.

References parse(), resetXMLParser(), and wfDebugLog().

Here is the call graph for this function:

Main use is if a single item has multiple xmp documents describing it.

For example in jpeg's with extendedXMP

Definition at line 93 of file XMP.php.

Referenced by __construct(), parse(), and parseExtended().

Here is the caller graph for this function:

XMPReader::saveValue ( ns,
tag,
val 
) [private]

Given an extracted value, save it to results array.

note also uses $this->ancestorStruct and $this->processingArray to determine what name to save the value under. (in addition to $tag).

Parameters:
$nsString namespace of tag this is for
$tagString tag name
$valString value to save

Definition at line 1134 of file XMP.php.

References wfDebugLog().

Referenced by doAttribs(), endElementModeQDesc(), endElementModeSimple(), and startElementModeSimple().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::startElement ( parser,
elm,
attribs 
)

Hits an opening element.

Generally just calls a helper based on what MODE we're in. Also does some initial set up for the wrapper element

Parameters:
$parserXMLParser
$elmString namespace <space> element
$attribsArray attribute name => value

Definition at line 994 of file XMP.php.

References startElementModeBag(), startElementModeIgnore(), startElementModeInitial(), startElementModeLang(), startElementModeLi(), startElementModeLiLang(), startElementModeQDesc(), startElementModeSeq(), startElementModeSimple(), startElementModeStruct(), and wfDebugLog().

Here is the call graph for this function:

XMPReader::startElementModeBag ( elm) [private]

Start element in MODE_BAG (unordered array) this should always be <rdf:Bag>

Parameters:
$elmString namespace . ' ' . tag
Exceptions:
MWExceptionif we have an element that's not <rdf:Bag>

Definition at line 676 of file XMP.php.

Referenced by startElement().

Here is the caller graph for this function:

XMPReader::startElementModeIgnore ( elm) [private]

Hit an opening element while in MODE_IGNORE.

XMP is extensible, so ignore any tag we don't understand.

Mostly ignores, unless we encounter the element that we are ignoring. in which case we add it to the item stack, so we can ignore things that are nested, correctly.

Parameters:
$elmString namespace . ' ' . tag name

Definition at line 662 of file XMP.php.

Referenced by startElement().

Here is the caller graph for this function:

XMPReader::startElementModeInitial ( ns,
tag,
attribs 
) [private]

Starting an element when in MODE_INITIAL This usually happens when we hit an element inside the outer rdf:Description.

This is generally where most properties start.

Parameters:
$nsString Namespace
$tagString tag name (without namespace prefix)
$attribsArray array of attributes

Definition at line 805 of file XMP.php.

References $mode, doAttribs(), and wfDebugLog().

Referenced by startElement().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::startElementModeLang ( elm) [private]

Start element in MODE_LANG (language alternative) this should always be <rdf:Alt>

This tag tends to be used for metadata like describe this picture, which can be translated into multiple languages.

XMP supports non-linguistic alternative selections, which are really only used for thumbnails, which we don't care about.

Parameters:
$elmString namespace . ' ' . tag
Exceptions:
MWExceptionif we have an element that's not <rdf:Alt>

Definition at line 720 of file XMP.php.

Referenced by startElement().

Here is the caller graph for this function:

XMPReader::startElementModeLi ( elm,
attribs 
) [private]

opening element in MODE_LI process elements of arrays.

Example: <exif:ISOSpeedRatings> <rdf:Seq> <rdf:li>64</rdf:li> </rdf:Seq> </exif:ISOSpeedRatings> This method is called when we hit the <rdf:li> element.

Parameters:
$elmString: namespace . ' ' . tagname
$attribsArray: Attributes. (needed for BAGSTRUCTS)
Exceptions:
MWExceptionif gets a tag other than <rdf:li>

Definition at line 912 of file XMP.php.

References doAttribs().

Referenced by startElement().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::startElementModeLiLang ( elm,
attribs 
) [private]

Opening element in MODE_LI_LANG.

process elements of language alternatives

Example: <dc:title> <rdf:Alt> <rdf:li xml:lang="x-default">My house </rdf:li> </rdf:Alt> </dc:title>

This method is called when we hit the <rdf:li> element.

Parameters:
$elmString namespace . ' ' . tag
$attribsarray array of elements (most importantly xml:lang)
Exceptions:
MWExceptionif gets a tag other than <rdf:li> or if no xml:lang

Definition at line 964 of file XMP.php.

Referenced by startElement().

Here is the caller graph for this function:

XMPReader::startElementModeQDesc ( elm) [private]

Start an element when in MODE_QDESC.

This generally happens when a simple element has an inner rdf:Description to hold qualifier elements.

For example in: <exif:DigitalZoomRatio><rdf:Description><rdf:value>0/10</rdf:value> <foo:someQualifier>Bar</foo:someQualifier> </rdf:Description> </exif:DigitalZoomRatio> Called when processing the <rdf:value> or <foo:someQualifier>.

Parameters:
$elmString namespace and tag name separated by a space.

Definition at line 784 of file XMP.php.

Referenced by startElement().

Here is the caller graph for this function:

XMPReader::startElementModeSeq ( elm) [private]

Start element in MODE_SEQ (ordered array) this should always be <rdf:Seq>

Parameters:
$elmString namespace . ' ' . tag
Exceptions:
MWExceptionif we have an element that's not <rdf:Seq>

Definition at line 692 of file XMP.php.

References wfDebugLog().

Referenced by startElement().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::startElementModeSimple ( elm,
attribs 
) [private]

Handle an opening element when in MODE_SIMPLE.

This should not happen often. This is for if a simple element already opened has a child element. Could happen for a qualified element.

For example: <exif:DigitalZoomRatio><rdf:Description><rdf:value>0/10</rdf:value> <foo:someQualifier>Bar</foo:someQualifier> </rdf:Description> </exif:DigitalZoomRatio>

This method is called when processing the <rdf:Description> element

Parameters:
$elmString namespace and tag names separated by space.
$attribsArray Attributes of the element.

Definition at line 746 of file XMP.php.

References saveValue(), and wfDebugLog().

Referenced by startElement().

Here is the call graph for this function:

Here is the caller graph for this function:

XMPReader::startElementModeStruct ( ns,
tag,
attribs 
) [private]

Hit an opening element when in a Struct (MODE_STRUCT) This is generally for fields of a compound property.

Example of a struct (abbreviated; flash has more properties):

<exif:Flash> <rdf:Description> <exif:Fired>True</exif:Fired> <exif:Mode>1</exif:Mode></rdf:Description></exif:Flash>

or:

<exif:Flash rdf:parseType='Resource'> <exif:Fired>True</exif:Fired> <exif:Mode>1</exif:Mode></exif:Flash>

Parameters:
$nsString namespace
$tagString tag name (no ns)
$attribsArray array of attribs w/ values.

Definition at line 865 of file XMP.php.

References doAttribs().

Referenced by startElement().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

XMPReader::$ancestorStruct = false [private]

Definition at line 30 of file XMP.php.

XMPReader::$charContent = false [private]

Definition at line 31 of file XMP.php.

XMPReader::$charset = false [private]

Definition at line 38 of file XMP.php.

XMPReader::$curItem = array() [private]

Definition at line 29 of file XMP.php.

XMPReader::$extendedXMPOffset = 0 [private]

Definition at line 39 of file XMP.php.

XMPReader::$itemLang = false [private]

Definition at line 35 of file XMP.php.

XMPReader::$items [protected]

Definition at line 41 of file XMP.php.

XMPReader::$mode = array() [private]

Definition at line 32 of file XMP.php.

Referenced by startElementModeInitial().

XMPReader::$processingArray = false [private]

Definition at line 34 of file XMP.php.

XMPReader::$results = array() [private]

Definition at line 33 of file XMP.php.

XMPReader::$xmlParser [private]

Definition at line 37 of file XMP.php.

const XMPReader::MODE_ALT = 15

Definition at line 65 of file XMP.php.

const XMPReader::MODE_BAG = 13

Definition at line 63 of file XMP.php.

Definition at line 66 of file XMP.php.

Definition at line 53 of file XMP.php.

These are various mode constants.

they are used to figure out what to do with an element when its encountered.

For example, MODE_IGNORE is used when processing a property we're not interested in. So if a new element pops up when we're in that mode, we ignore it.

Definition at line 52 of file XMP.php.

Definition at line 64 of file XMP.php.

const XMPReader::MODE_LI = 2

Definition at line 54 of file XMP.php.

Definition at line 55 of file XMP.php.

Definition at line 56 of file XMP.php.

Referenced by doAttribs().

const XMPReader::MODE_SEQ = 12

Definition at line 62 of file XMP.php.

Definition at line 60 of file XMP.php.

Definition at line 61 of file XMP.php.

const XMPReader::NS_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'

Definition at line 68 of file XMP.php.

const XMPReader::NS_XML = 'http://www.w3.org/XML/1998/namespace'

Definition at line 69 of file XMP.php.


The documentation for this class was generated from the following file: