Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
XSLTransformationFilter.inc.php
1 <?php
2 
16 import('lib.pkp.classes.filter.PersistableFilter');
17 import('lib.pkp.classes.xslt.XSLTransformer');
18 
30  function XSLTransformationFilter($filterGroup, $displayName = 'XSL Transformation') {
31  // Check that we only get xml input, the output type is arbitrary.
32  if (!substr($filterGroup->getInputType(), 0, 5) == 'xml::') fatalError('XSL filters need XML as input.');
33 
34  // Instantiate the settings of this filter
35  import('lib.pkp.classes.filter.FilterSetting');
36  $this->addSetting(new FilterSetting('xsl', null, null));
37  $this->addSetting(new FilterSetting('xslType', null, null));
38  $this->addSetting(new FilterSetting('resultType', null, null, FORM_VALIDATOR_OPTIONAL_VALUE));
39 
40  $this->setDisplayName($displayName);
41 
42  parent::PersistableFilter($filterGroup);
43  }
44 
45 
46  //
47  // Getters and Setters
48  //
53  function &getXSL() {
54  return $this->getData('xsl');
55  }
56 
61  function getXSLType() {
62  return $this->getData('xslType');
63  }
64 
69  function setXSL(&$xsl) {
70  // Determine the xsl type
71  if (is_string($xsl)) {
72  $this->setData('xslType', XSL_TRANSFORMER_DOCTYPE_STRING);
73  } elseif (is_a($xsl, 'DOMDocument')) {
74  $this->setData('xslType', XSL_TRANSFORMER_DOCTYPE_DOM);
75  } else assert(false);
76 
77  $this->setData('xsl', $xsl);
78  }
79 
84  function setXSLFilename($xslFile) {
85  $this->setData('xslType', XSL_TRANSFORMER_DOCTYPE_FILE);
86  $this->setData('xsl', $xslFile);
87  }
88 
93  function getResultType() {
94  return $this->getData('resultType');
95  }
96 
101  function setResultType($resultType) {
102  $this->setData('resultType', $resultType);
103  }
104 
105 
106  //
107  // Implement template methods from PersistableFilter
108  //
112  function getClassName() {
113  return 'lib.pkp.classes.xslt.XSLTransformationFilter';
114  }
115 
116 
117  //
118  // Implement template methods from Filter
119  //
126  function &process(&$xml) {
127  // Determine the input type
128  if (is_string($xml)) {
129  $xmlType = XSL_TRANSFORMER_DOCTYPE_STRING;
130  } elseif (is_a($xml, 'DOMDocument')) {
131  $xmlType = XSL_TRANSFORMER_DOCTYPE_DOM;
132  } else assert(false);
133 
134  // Determine the result type based on
135  // the input type if it has not been
136  // set explicitly.
137  if (is_null($this->getResultType())) {
138  $this->setResultType($xmlType);
139  }
140 
141  // Transform the input
142  $xslTransformer = new XSLTransformer();
143  $result =& $xslTransformer->transform($xml, $xmlType, $this->getXsl(), $this->getXslType(), $this->getResultType());
144  return $result;
145  }
146 }
147 ?>
Class that describes a configurable filter setting.
setDisplayName($displayName)
Definition: Filter.inc.php:140
& getData($key, $locale=null)
A filter that can be persisted to the database.
XSLTransformationFilter($filterGroup, $displayName= 'XSL Transformation')
Wrapper class for running XSL transformations using PHP 4.x or 5.x.
setData($key, $value, $locale=null)
Class that transforms XML via XSL.