BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
XMPReader Class Reference
Inheritance diagram for XMPReader:
Collaboration diagram for XMPReader:

Public Member Functions

 __construct (LoggerInterface $logger=null, $filename= 'unknown')
 
 setLogger (LoggerInterface $logger)
 
 getResults ()
 
 parse ($content, $allOfIt=true)
 
 parseExtended ($content)
 
 char ($parser, $data)
 
 endElement ($parser, $elm)
 
 startElement ($parser, $elm, $attribs)
 

Static Public Member Functions

static isSupported ()
 

Public Attributes

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

Protected Attributes

 $items
 

Detailed Description

Class for reading xmp data containing properties relevant to images, and spitting out an array that FormatMetadata 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.

Constructor & Destructor Documentation

XMPReader::__construct ( LoggerInterface  $logger = null,
  $filename = 'unknown' 
)

Primary job is to initialize the XMLParser

Parameters
LoggerInterface | null$logger
string$filename

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
resource$parserXMLParser reference to the xml parser
string$dataCharacter data
Exceptions
RuntimeExceptionOn invalid data
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
resource$parser
string$elmNamespace . ' ' . element name
Exceptions
RuntimeException
XMPReader::getResults ( )

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().
static XMPReader::isSupported ( )
static

Check if this instance supports using this class

Returns
bool
XMPReader::parse (   $content,
  $allOfIt = true 
)

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
string$contentXMP data
bool$allOfItIf this is all the data (true) or if its split up (false). Default true
Exceptions
RuntimeException
Returns
bool Success.
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
bool If it succeeded.
XMPReader::setLogger ( LoggerInterface  $logger)

Sets a logger instance on the object.

Parameters
LoggerInterface$logger
Returns
void

Implements Psr\Log\LoggerAwareInterface.

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
resource$parser
string$elmNamespace "<space>" element
array$attribsAttribute name => value
Exceptions
RuntimeException

Member Data Documentation

const XMPReader::MODE_INITIAL = 0

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.


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