/** * Test function getNextElement() */ public function test_getNextElementContent_1() { $xmlCode = '</peng><unknown peng="5"><b>Hallo</b></unknown><anotherOne></anotherOne>'; $found = XMLUtil::getNextElementContent($element, $xmlCode, $end); $this->assertNotNull($found); $this->assertEquals('<b>Hallo</b>', $found); $this->assertEquals(strlen($xmlCode) - strlen('<anotherOne></anotherOne>'), $end); $this->assertEquals('unknown', $element); }
/** * Create new style by importing ODT style definition. * * @param $xmlCode Style definition in ODT XML format * @return ODTStyle New specific style */ public static function importODTStyle($xmlCode) { $style = new ODTTextListStyle(); $attrs = 0; $open = XMLUtil::getElementOpenTag('text:list-style', $xmlCode); if (!empty($open)) { // This properties are stored in the properties of ODTStyle $attrs += $style->importODTStyleInternal(self::$list_fields, $open); $content = XMLUtil::getElementContent('text:list-style', $xmlCode); } $pos = 0; $end = 0; $max = strlen($content); $text_fields = ODTTextStyle::getTextProperties(); while ($pos < $max) { // Get XML code for next level. $level = XMLUtil::getNextElement($element, substr($content, $pos), $end); $level_content = XMLUtil::getNextElementContent($element, $level, $ignore); if (!empty($level)) { $list_style_properties = array(); $list_level_properties = array(); $label_properties = array(); $text_properties = array(); $properties = array(); switch ($element) { case 'text:list-level-style-number': $attrs += $style->importODTStyleInternal(self::$style_number_fields, $level, $list_style_properties); $list_level_style = 'number'; break; case 'text:list-level-style-bullet': $attrs += $style->importODTStyleInternal(self::$style_bullet_fields, $level, $list_style_properties); $list_level_style = 'bullet'; break; case 'text:list-level-style-image': $attrs += $style->importODTStyleInternal(self::$style_image_fields, $level, $list_style_properties); $list_level_style = 'image'; break; } $temp_content = XMLUtil::getElement('style:text-properties', $level_content); $attrs += $style->importODTStyleInternal($text_fields, $temp_content, $text_properties); $temp_content = XMLUtil::getElementOpenTag('style:list-level-properties', $level_content); $attrs += $style->importODTStyleInternal(self::$list_level_props_fields, $temp_content, $list_level_properties); $temp_content = XMLUtil::getElement('style:list-level-label-alignment', $level_content); $attrs += $style->importODTStyleInternal(self::$label_align_fields, $temp_content, $label_properties); // Assign properties array to our level array $level_number = $style->getPropertyInternal('level', $list_style_properties); $properties['list-style'] = $list_style_properties; $properties['list-level'] = $list_level_properties; $properties['label'] = $label_properties; $properties['text'] = $text_properties; $style->list_level_styles[$level_number] = $properties; // Set special property 'list-level-style' to remember element to encode // on call to toString()! $style->setPropertyForLevel($level_number, 'list-level-style', $list_level_style); } $pos += $end; } // If style has no meaningfull content then throw it away if ($attrs == 0) { return NULL; } return $style; }