/**
  * Test function getNextElement()
  */
 public function test_getNextElement_1()
 {
     $xmlCode = '</peng><unknown peng="5"><b>Hallo</b></unknown><anotherOne></anotherOne>';
     $found = XMLUtil::getNextElement($element, $xmlCode, $end);
     $this->assertNotNull($found);
     $this->assertEquals('<unknown peng="5"><b>Hallo</b></unknown>', $found);
     $this->assertEquals(strlen($xmlCode) - strlen('<anotherOne></anotherOne>'), $end);
     $this->assertEquals('unknown', $element);
 }
예제 #2
0
 protected function importFromODT($styles_xml_content, $root_element)
 {
     if (empty($styles_xml_content) || empty($root_element)) {
         return false;
     }
     // Only import known style elements
     switch ($root_element) {
         case 'office:styles':
         case 'office:automatic-styles':
             $style_elements = XMLUtil::getElementContent($root_element, $styles_xml_content, $end);
             break;
         default:
             return false;
     }
     $pos = 0;
     $max = strlen($style_elements);
     while ($pos < $max) {
         $xml_code = XMLUtil::getNextElement($element, substr($style_elements, $pos), $end);
         if ($xml_code == NULL) {
             break;
         }
         $pos += $end + 1;
         // Create new ODTStyle
         $object = ODTStyle::importODTStyle($xml_code);
         if ($object != NULL) {
             // Success, add it
             switch ($root_element) {
                 case 'office:styles':
                     $this->addStyle($object);
                     break;
                 case 'office:automatic-styles':
                     $this->addAutomaticStyle($object);
                     break;
             }
         }
     }
     return true;
 }
 /**
  * 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;
 }