package.xml0000664000175000017500000014146712653734733011331 0ustar janjan Horde_Kolab_Format pear.horde.org Kolab_Format A package for reading/writing Kolab data formats. This package allows converting Kolab data objects from XML to data arrays. Gunnar Wrobel wrobel p@rdus.de yes 2016-02-01 2.0.8 2.0.0 stable stable LGPL-2.1 * [jan] Mark PHP 7 as supported. 5.3.0 8.0.0alpha1 8.0.0alpha1 1.7.0 Horde_Exception pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Util pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 dom Horde_Support pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Test pear.horde.org 2.1.0 3.0.0alpha1 3.0.0alpha1 mbstring 1.0.0alpha1 1.0.0 alpha alpha 2011-03-10 LGPL-2.1 * First alpha release for Horde 4. 1.0.0beta1 1.0.0 beta beta 2011-03-16 LGPL-2.1 * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 LGPL-2.1 * First release candidate for Horde 4. * [gwr] Moved Horde specific functionality out of the tasks parser. * [gwr] Moved Horde specific functionality out of the note parser. 1.0.0RC2 1.0.0 beta beta 2011-03-29 LGPL-2.1 * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 LGPL-2.1 * First stable release for Horde 4. 1.0.1 1.0.0 stable stable 2011-08-11 LGPL-2.1 * [gwr] Removed stray kolab-format script which was moved to Horde_Kolab_Cli. * [gwr] Fixed detecting parse errors in subsequent parse attempts. 1.1.0 1.1.0 stable stable 2011-11-12 LGPL-2.1 * [gwr] Move Horde specific functionality out of the events parser. * [gwr] Move Horde specific functionality out of the contacts parser. * [gwr] Improve data validation. * [gwr] KEP2 support. * [gwr] Allow adding XML attributes on the fly. * [gwr] Avoid overwriting data from other Kolab clients. * [gwr] Add improved root node handler (version checking, avoids overwriting other data). 1.1.1 1.1.0 stable stable 2011-12-16 LGPL-2.1 * [gwr] Fixed datatype for birthday and anniversary contact attributes. * [gwr] Completed missing data API v1 support. 1.1.2 1.1.0 stable stable 2012-04-10 LGPL-2.1 * [jan] Fix parsing composite phone fields (alexander.haensch@ipc.uni-tuebingen.de, Bug #11047). 2.0.0alpha1 1.1.0 alpha stable 2012-07-05 LGPL-2.1 * First alpha release for Horde 5. 2.0.0beta1 1.1.0 beta stable 2012-07-19 LGPL-2.1 * First beta release for Horde 5. 2.0.0beta2 1.1.0 beta stable 2012-10-12 LGPL-2.1 * [jan] Categories attributes are returned and passed as an array now. 2.0.0RC1 1.1.0 beta stable 2012-10-26 LGPL-2.1 * [jan] Write custom Horde attributes to task objects. 2.0.0 2.0.0 stable stable 2012-10-30 LGPL-2.1 * First stable release for Horde 5. 2.0.1 2.0.0 stable stable 2012-11-19 LGPL-2.1 * [jan] Deprecate timezone parameters, always write UTC datetime values (Bug #11695). 2.0.2 2.0.0 stable stable 2013-01-09 LGPL-2.1 * [jan] Return date-only values as floating dates (Bug #11767). * [jan] Correctly format all-day events (Bug #11767). 2.0.3 2.0.0 stable stable 2013-03-05 LGPL-2.1 * [jan] Fix unit tests. 2.0.4 2.0.0 stable stable 2013-09-02 LGPL-2.1 * [jan] Fix saving all day events when the end date is on the next day (Thomas Jarosch <thomas.jarosch@intra2net.com>, Bug #12627). 2.0.5 2.0.0 stable stable 2013-11-19 LGPL-2.1 * [jan] Correctly translate display-name attribute of distribution lists. 2.0.6 2.0.0 stable stable 2015-01-09 LGPL-2.1 * [jan] Improve PSR-2 compatibility. 2.0.7 2.0.0 stable stable 2015-04-28 LGPL-2.1 * [jan] Fix issues with certain locales like Turkish. 2.0.8 2.0.0 stable stable 2016-02-01 LGPL-2.1 * [jan] Mark PHP 7 as supported. Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/examples/event.php0000664000175000017500000000171012653734732023057 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * The Autoloader allows us to omit "require/include" statements. */ require_once 'Horde/Autoloader/Default.php'; /** Create the factory */ $factory = new Horde_Kolab_Format_Factory(); /** Generate the format handler */ $format = $factory->create('Xml', 'Event', array('version' => 1)); /** Prepare a test object */ $object = array( 'uid' => 1, 'summary' => 'test event', 'start-date' => time(), 'end-date' => time() + 24 * 60 * 60, ); /** Save this test data array in Kolab XML format */ $xml = $format->save($object); var_dump($xml); /** Reload the object from the XML format */ $read_object = $format->load($xml); var_dump($read_object); Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/examples/event_v2.php0000664000175000017500000000202112653734732023462 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * The Autoloader allows us to omit "require/include" statements. */ require_once 'Horde/Autoloader/Default.php'; /** Create the factory */ $factory = new Horde_Kolab_Format_Factory(); /** Generate the format handler */ $format = $factory->create('Xml', 'Event'); $now = new DateTime(); /** Prepare a test object */ $object = array( 'uid' => 1, 'summary' => 'test event', 'start-date' => array( 'date' => $now, ), 'end-date' => array( 'date' => $now, ) ); /** Save this test data array in Kolab XML format */ $xml = $format->save($object); var_dump($xml); /** Reload the object from the XML format */ $read_object = $format->load($xml); var_dump($read_object); Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/examples/new_type.php0000664000175000017500000000375212653734732023600 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * The Autoloader allows us to omit "require/include" statements. */ require_once 'Horde/Autoloader/Default.php'; /** * Kolab XML handler for a string value * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_String extends Horde_Kolab_Format_Xml { /** * Specific data fields for the prefs object * * @var Kolab */ protected $_fields_specific; /** * Constructor */ public function __construct($parser, $params = array()) { $this->_root_name = 'string'; /** Specific preferences fields, in kolab format specification order */ $this->_fields_specific = array( 'string' => array( 'type' => self::TYPE_STRING, 'value' => self::VALUE_MAYBE_MISSING, ), ); parent::__construct($parser, $params); } } /** Create the factory */ $factory = new Horde_Kolab_Format_Factory(); /** Generate the format handler */ $format = $factory->create('Xml', 'String'); /** Prepare a test object */ $object = array( 'uid' => 1, 'string' => 'test string', ); /** Save this test data array in Kolab XML format */ $xml = $format->save($object); var_dump($xml); /** Reload the object from the XML format */ $read_object = $format->load($xml); var_dump($read_object); Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/examples/speed_check.php0000664000175000017500000000255412653734732024202 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * The Autoloader allows us to omit "require/include" statements. */ require_once 'Horde/Autoloader/Default.php'; /** Create the factory */ $factory = new Horde_Kolab_Format_Factory(); /** Generate the format handler */ $format = $factory->create('Xml', 'Event'); /** Prepare a test object */ if (!method_exists($format, 'getVersion')) { $object = array( 'uid' => 1, 'summary' => 'test event', 'start-date' => time(), 'end-date' => time() + 24 * 60 * 60, ); } else { $now = new DateTime(); $object = array( 'uid' => 1, 'summary' => 'test event', 'start-date' => array( 'date' => $now, ), 'end-date' => array( 'date' => $now, ) ); } $timer = new Horde_Support_Timer(); $timer->push(); for ($i = 0;$i < 1000;$i++) { /** Save this test data array in Kolab XML format */ $xml = $format->save($object); /** Reload the object from the XML format */ $read_object = $format->load($xml); } var_dump($timer->pop()); Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/COPYING0000664000175000017500000005750212653734732020454 0ustar janjan GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/DOCS_ORIGIN0000664000175000017500000000060412653734732021132 0ustar janjan====================== Documentation origin ====================== Some of the Horde component documentation is maintained in the Horde wiki. The following list indicates the source locations for some of the files in this directory. :`doc/Horde/Kolab/Format/README`_: README .. _doc/Horde/Kolab/Format/README: http://wiki.horde.org/Doc/Dev/HordeKolabFormat?actionID=export&format=rst Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/README0000664000175000017500000000021712653734732020270 0ustar janjan
Fatal error: Call to a member function token() on a non-object in /usr/share/php/Text/Wiki.php on line 1069
Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/TODO0000664000175000017500000000103512653734732020077 0ustar janjan==================================== Kolab_Format Development TODO List ==================================== - Check kolab/issue4672 (Kolab_Format has encoding problems) - Check kolab/issue4700 (Kolab_Format problems in e-mails fetching process) - Developer documentation - Test coverage - PHPdoc check - Additional KEPs - ... - Do not overwrite multiple entries - Extract Xml_* subtypes to Xml_Type_Composite_* types? - Improved error handling? Logging strict errors? - Think about storing the data in iCal format. Horde_Kolab_Format-2.0.8/doc/Horde/Kolab/Format/usage.txt0000664000175000017500000002451512653734732021264 0ustar janjanThe "Horde_Kolab_Format" package allows you to easily read and write the Kolab format within PHP. Installation of the package =========================== The package is being distributed as a standard PEAR package by the Horde project. As long as you have PEAR installed, installation should be straigt forward. pear channel-discover pear.horde.org pear install --force channel://pear.horde.org/Horde_Kolab_Format "pear" will probably complain about the library (and its dependencies) not being marked stable yet, but the "--force" option allows to ignore these warnings. Using the package ================= This section will present the construction of a short example script to demonstrate reading/writing an event in the Kolab XML format. The first required statement is the inclusion of the package: require_once 'Horde/Kolab/Format.php'; The API provided by the package is very simple. It only provides a "load()" and a "save()" function. In order to have access to these methods it is necessary to create the "Horde_Kolab_Format" object. The call looks like this: $format = Horde_Kolab_Format::factory('Xml', 'Event'); The function takes three arguments: # "Format type": Currently only "Xml" is supported here. # "Object type": The type of object you want to read/write. The package currently implements "Contact", "Distributionslist", "Event", "Note", "Task" and "Hprefs" The $format variable created above now provides the means to save and load events in Kolab XML format. In order to save an event we need to prepare an array with all relevant information about this event: $object = array( 'uid' => 1, 'summary' => 'test event', 'start-date' => time(), 'end-date' => time() + 24 * 60 * 60, ); This is an event that has the "UID" of "1" and carries the title "test event". It starts right now ("time()") and ends in a day ("time() + 24 * 60 * 60"). This event can now be saved using the "save()" function of the format handler: $xml = $format->save($object); The function returns the Kolab XML format as a result. This string can be fed back into the "load()" function: $read_object = $format->load($xml); If we dump the contents of the two variables $xml and $read_object this will be the result: var_dump($xml); string(438) " 1 2008-07-10T12:51:51Z 2008-07-10T12:51:51Z public Horde::Kolab test event 2008-07-10T12:51:51Z 2008-07-11T12:51:51Z " var_dump($read_object); array(11) { ["uid"]=> string(1) "1" ["body"]=> string(0) "" ["categories"]=> array(0) { } ["creation-date"]=> class DateTime#1 (3) { public $date => string(19) "2008-07-10 12:51:51" public $timezone_type => int(3) public $timezone => string(13) "UTC" } ["last-modification-date"]=> class DateTime#1 (3) { public $date => string(19) "2008-07-10 12:51:51" public $timezone_type => int(3) public $timezone => string(13) "UTC" } ["sensitivity"]=> string(6) "public" ["product-id"]=> string(12) "Horde::Kolab" ["summary"]=> string(10) "test event" ["start-date"]=> int(1215694311) ["attendee"]=> array(0) { } ["end-date"]=> int(1215780711) } We see that the format stores a lot more information than we originally provided. The resulting XML string does not only contain the "uid", "summary", "start-date", and "end-date". Several additional attributes have been added. These were either calculated or set to a default value. * "body": holds the event description. We did not specify an event description so this value has been set to an empty string. * "sensitivity": events may be "public" or "private" with "public" being the default * "sensitivity": events may be "public" or "private" with "public" being the default * "categories": Any Kolab object may be member of different categories. As we didn't specify a category this value is also empty. * "creation-date": The time stamp of the moment the object was created. * "last-modification-date": The time stamp of the moment the object was last modified. * "product-id": The ID of the product that last touched this object. If we use the "Horde_Kolab_Format" package it will always be "Horde::Kolab". If we read the XML data back into an array all these new informations are available within that array. Creating your own Kolab XML format ================================== Currently the "Horde_Kolab_Format" package provides handlers for the object types "Contact", "Distributionslist", "Event", "Note", and "Task" as they are defined within the Kolab Format specification. In addition the Horde specific "Hprefs" type is available. It is used for storing Horde user preferences in the IMAP store provided by the Kolab server. Depending on the web application you might wish to connect with the Kolab server these object types may not be enough. Do not hesitate to define your own new type in that case. If you want it to be adopted by more Kolab clients you should of course discuss it on the Kolab Format mailing list (http://kolab.org/pipermail/kolab-format/) to get some feedback on the new type. The "Horde_Kolab_Format" package makes the definition of a new object type rather straight forward. The following will explain the creation of a very simple new object that only saves a single string value. This time it will be necessary to load the XML format definition, too. Any new object type will extend this XML definition: require_once 'Horde/Kolab/Format.php'; require_once 'Horde/Kolab/Format/Xml.php'; A new object type is represented by a class that extends "Horde_Kolab_Format_Xml": class Horde_Kolab_Format_Xml_String extends Horde_Kolab_Format_Xml { protected $_fields_specific; public function __construct() { $this->_root_name = 'string'; /** Specific fields of this object type */ $this->_fields_specific = array( 'string' => array( 'type' => self::TYPE_STRING, 'value' => self::VALUE_MAYBE_MISSING, ), ); parent::__construct(); } } The class needs to end with the name of the object type. Here it is just "string". The declaration "var $_fields_specific;" indicates that the new object type has attributes beyond the basic set required for any Kolab object. So this part may not be missing for a declaration of a new type. The function creating the class ("__construct()") needs to do three things: * Declaring the XML root name which will be "string" here. It should always match the type name. * Declaring the specific attributes of the object. This part populates the "_fields_specific" variable with an array describing the possible object attributes. This will be described in more detail further below. * Calling the parent constructor using "parent::__construct()". The new format can now be used as demonstrated in the initial event example: $format = Horde_Kolab_Format::factory('Xml', 'String'); $object = array( 'uid' => 1, 'string' => 'test string', ); $xml = $format->save($object); $read_object = $format->load($xml); var_dump($xml); var_dump($read_object); The result looks like this: string(347) " 1 2008-07-10T13:28:36Z 2008-07-10T13:28:36Z public Horde::Kolab test string " array(8) { ["uid"]=> string(1) "1" ["body"]=> string(0) "" ["categories"]=> array(0) { } ["creation-date"]=> class DateTime#1 (3) { public $date => string(19) "2008-07-10 13:28:36" public $timezone_type => int(3) public $timezone => string(13) "UTC" } ["last-modification-date"]=> class DateTime#1 (3) { public $date => string(19) "2008-07-10 13:28:36" public $timezone_type => int(3) public $timezone => string(13) "UTC" } ["sensitivity"]=> string(6) "public" ["product-id"]=> string(12) "Horde::Kolab" ["string"]=> string(11) "test string" } Allowed fields ============== There are only a number of valid entries available to specify the attributes a new object type may contain. Each entry in the field list will look like this 'attribute_name' => array( 'type' => self::TYPE_*, 'value' => self::VALUE_*, ), "attribute_name" should be a short name describing the value that should be stored. "type" must be set to one of the following "self::TYPE_*" type values: * "self::TYPE_STRING": A string. * "self::TYPE_INTEGER": A number * "self::TYPE_BOOLEAN": True or false. * "self::TYPE_DATE": A date (e.g. 2008/08/08) * "self::TYPE_DATETIME": A time and a date. * "self::TYPE_DATE_OR_DATETIME": A date or a time and a date. * "self::TYPE_COLOR": A color (#00BBFF). * "self::TYPE_COMPOSITE": A composite element that combines several attributes. * "self::TYPE_MULTIPLE": Wrapper for an element that may occur several times. Examples for "self::TYPE_COMPOSITE" and "self::TYPE_MULTIPLE" can be found in the definitions currently provided by the "Horde_Kolab_Format" package. The following "value" settings are allowed: * "self::VALUE_DEFAULT": An attribute with a default value. * "self::VALUE_MAYBE_MISSING": An attribute that may be left undefined. * "self::VALUE_NOT_EMPTY": An attribute that will cause an error if it is left undefined. * "self::VALUE_CALCULATE": A complex attribute that gets its own function for calculating the correct value. Examples for "self::VALUE_CALCULATE" can again be found in the current object types implemented in "Horde_Kolab_Format". Detailed package documentation ============================== A detailed documentation based on the code comments and extracted via phpDocumentor can be found at http://dev.horde.org/api/framework/. Simply select the package "Horde_Kolab_Format" in the package selection box in the upper right corner. Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Decorator/Base.php0000664000175000017500000000252012653734732022715 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * A base decorator definition. * * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ abstract class Horde_Kolab_Format_Decorator_Base implements Horde_Kolab_Format { /** * The decorated Kolab format handler. * * @var Horde_Kolab_Format */ private $_handler; /** * Constructor. * * @param Horde_Kolab_Format $handler The handler to be decorated. */ public function __construct(Horde_Kolab_Format $handler) { $this->_handler = $handler; } /** * Return the decorated handler. * * @return Horde_Kolab_Format The handler. */ public function getHandler() { return $this->_handler; } }Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Decorator/Memory.php0000664000175000017500000000750112653734732023317 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Determines some memory parameters while loading/saving the Kolab objects. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Decorator_Memory extends Horde_Kolab_Format_Decorator_Base { /** * The memory tracker used for recording the memory parameters. * * @var Horde_Support_Memory */ private $_memory; /** * An optional logger. * * @var mixed */ private $_logger; /** * Constructor. * * @param Horde_Kolab_Format $handler The handler to be decorated. * @param Horde_Support_Memory $memory The memory tracker. * @param mixed $logger The logger. This must provide * a debug() method. */ public function __construct(Horde_Kolab_Format $handler, Horde_Support_Memory $memory, $logger = null) { parent::__construct($handler); $this->_memory = $memory; $this->_logger = $logger; } /** * Load an object based on the given XML stream. * * @param resource $xml The XML stream of the message. * @param array $options Additional options when parsing the XML. This * decorator provides no additional options. * * @return array The data array representing the object. * * @throws Horde_Kolab_Format_Exception */ public function load($xml, $options = array()) { $this->_memory->push(); $result = $this->getHandler()->load($xml); $this->_logger->debug( sprintf( 'Kolab Format data parsing complete. Memory usage: %s', $this->_formatUsage($this->_memory->pop()) ) ); return $result; } /** * Convert the data to a XML stream. * * @param array $object The data array representing the object. * @param array $options Additional options when writing the XML. This * decorator provides no additional options. * * @return resource The data as XML stream. * * @throws Horde_Kolab_Format_Exception */ public function save($object, $options = array()) { $this->_memory->push(); $result = $this->getHandler()->save($object); $this->_logger->debug( sprintf( 'Kolab Format data generation complete. Memory usage: %s', $this->_formatUsage($this->_memory->pop()) ) ); return $result; } /** * Format the memory usage information. * * @param array $usage The memory usage. * * @return string The formated memory usage. */ private function _formatUsage($usage) { return sprintf( '%.3f MB / %.3f MB / %.3f MB / %.3f MB [change in current usage (emalloc) / change in peak usage (emalloc) / change in current usage (real) / change in peak usage (real)]', $usage[0] / 1048576, $usage[1] / 1048576, $usage[2] / 1048576, $usage[3] / 1048576 ); } }Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Decorator/Timed.php0000664000175000017500000000717312653734732023116 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Determines how much time is spent while loading/saving the Kolab objects. * * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Decorator_Timed extends Horde_Kolab_Format_Decorator_Base { /** * The timer used for recording the amount of time spent. * * @var Horde_Support_Timer */ private $_timer; /** * An optional logger. * * @var mixed */ private $_logger; /** * Time spent handling objects. * * @var float */ private static $_spent = 0.0; /** * Constructor. * * @param Horde_Kolab_Format $handler The handler to be decorated. * @param Horde_Support_Timer $timer The timer. * @param mixed $logger The optional logger. If set this * needs to provide a debug() method. */ public function __construct(Horde_Kolab_Format $handler, Horde_Support_Timer $timer, $logger = null) { parent::__construct($handler); $this->_timer = $timer; $this->_logger = $logger; } /** * Load an object based on the given XML stream. * * @param resource $xml The XML stream of the message. * @param array $options Additional options when parsing the XML. This * decorator provides no additional options. * * @return array The data array representing the object. * * @throws Horde_Kolab_Format_Exception */ public function load($xml, $options = array()) { $this->_timer->push(); $result = $this->getHandler()->load($xml); $spent = $this->_timer->pop(); if (is_object($this->_logger)) { $this->_logger->debug(sprintf('Kolab Format data parsing complete. Time spent: %s ms', floor($spent * 1000))); } self::$_spent += $spent; return $result; } /** * Convert the data to a XML stream. * * @param array $object The data array representing the object. * @param array $options Additional options when writing the XML. This * decorator provides no additional options. * * @return resource The data as XML stream. * * @throws Horde_Kolab_Format_Exception */ public function save($object, $options = array()) { $this->_timer->push(); $result = $this->getHandler()->save($object); $spent = $this->_timer->pop(); if (is_object($this->_logger)) { $this->_logger->debug(sprintf('Kolab Format data generation complete. Time spent: %s ms', floor($spent * 1000))); } self::$_spent += $spent; return $result; } /** * Report the time spent for loading/saving objects. * * @return float The amount of time. */ public function timeSpent() { return self::$_spent; } }Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Exception/InvalidRoot.php0000664000175000017500000000160212653734732024311 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Indicates a problem when loading/saving the Kolab XML root node. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Exception_InvalidRoot extends Horde_Kolab_Format_Exception { } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Exception/MissingUid.php0000664000175000017500000000206212653734732024133 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Indicates a missing UID value when reading or writing a Kolab Format object. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Exception_MissingUid extends Horde_Kolab_Format_Exception { /** * Constructor. */ public function __construct() { parent::__construct('No UID in the Kolab XML object!'); } }Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Exception/MissingValue.php0000664000175000017500000000303212653734732024464 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Indicates a missing value when reading or writing a Kolab Format object. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Exception_MissingValue extends Horde_Kolab_Format_Exception { /** * The name of the value that was missing. * * @var string */ private $_value; /** * Constructor. * * @param string $value The value that was missing. */ public function __construct($value) { $this->_value = $value; parent::__construct( sprintf( "Data value for \"%s\" is empty in the Kolab XML object!", $value ) ); } /** * Return the name of the missing value. * * @return string The name */ public function getValue() { return $this->_value; } }Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Exception/ParseError.php0000664000175000017500000000337412653734733024154 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Indicates a parse error when reading a Kolab Format object. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Exception_ParseError extends Horde_Kolab_Format_Exception { /** * The input that failed to parse. * * @var resource */ private $_input; /** * Constructor. * * @param string $input The input that failed to parse. */ public function __construct($input) { if (strlen((string)$input) > 50) { $output = substr((string)$input, 0, 50) . '... [shortened to 50 characters]'; } else { $output = (string)$input; } $this->_input = $input; parent::__construct( sprintf( "Failed parsing Kolab object input data of type %s! Input was:\n%s", gettype($input), $output ) ); } /** * Return the complete input. * * @return resource The input that failed to parse. */ public function getInput() { return $this->_input; } }Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/AutomaticDate/V1.php0000664000175000017500000000632712653734733024626 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles api-version 1 of auto-generated date attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_AutomaticDate_V1 extends Horde_Kolab_Format_Xml_Type_Base { /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if ($result !== false) { return $result; } else { $attributes[$name] = time(); } } /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); if ($result !== null) { $date = Horde_Kolab_Format_Date::readUtcDateTime($result); if ($date === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf('Invalid date input "%s"!', $result) ); } return $date; } else { return $result; } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Boolean/True.php0000664000175000017500000000216112653734733024102 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a boolean attribute that defaults to true. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Boolean_True extends Horde_Kolab_Format_Xml_Type_Boolean { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = true; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Color/Background.php0000664000175000017500000000222012653734733024735 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the background color attribute that defaults to black. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Color_Background extends Horde_Kolab_Format_Xml_Type_Color { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = '#000000'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Color/Foreground.php0000664000175000017500000000221612653734733024775 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the background color attribute that defaults to blue. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Color_Foreground extends Horde_Kolab_Format_Xml_Type_Color { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = '#ffff00'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite/Recurrence/V1.php0000664000175000017500000000260512653734733026134 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles api version 1 of recurrence data. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite_Recurrence_V1 extends Horde_Kolab_Format_Xml_Type_Composite_Recurrence { protected $elements = array( 'interval' => 'Horde_Kolab_Format_Xml_Type_RecurrenceInterval', 'day' => 'Horde_Kolab_Format_Xml_Type_Multiple_String', 'daynumber' => 'Horde_Kolab_Format_Xml_Type_Integer', 'month' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'range' => 'Horde_Kolab_Format_Xml_Type_RecurrenceRange', 'exclusion' => 'Horde_Kolab_Format_Xml_Type_Multiple_Date', 'complete' => 'Horde_Kolab_Format_Xml_Type_Multiple_Date', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite/Address.php0000664000175000017500000000247712653734733025145 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles attributes of an address. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite_Address extends Horde_Kolab_Format_Xml_Type_Composite { protected $elements = array( 'type' => 'Horde_Kolab_Format_Xml_Type_AddressType', 'street' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'locality' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'region' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'postal-code' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'country' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite/Attendee.php0000664000175000017500000000236412653734733025304 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles attributes of an attendee. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite_Attendee extends Horde_Kolab_Format_Xml_Type_Composite { protected $elements = array( 'display-name' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'smtp-address' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'status' => 'Horde_Kolab_Format_Xml_Type_AttendeeStatus', 'request-response' => 'Horde_Kolab_Format_Xml_Type_Boolean_True', 'role' => 'Horde_Kolab_Format_Xml_Type_AttendeeRole', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite/Name.php0000664000175000017500000000260312653734733024427 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles name attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite_Name extends Horde_Kolab_Format_Xml_Type_Composite { protected $elements = array( 'given-name' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'middle-names' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'last-name' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'full-name' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'initials' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'prefix' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'suffix' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite/Phone.php0000664000175000017500000000175712653734733024631 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles phone attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite_Phone extends Horde_Kolab_Format_Xml_Type_Composite { protected $elements = array( 'type' => 'Horde_Kolab_Format_Xml_Type_PhoneType', 'number' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite/Recurrence.php0000664000175000017500000002276212653734733025654 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles recurrence data. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite_Recurrence extends Horde_Kolab_Format_Xml_Type_Composite { protected $elements = array( 'interval' => 'Horde_Kolab_Format_Xml_Type_RecurrenceInterval', 'day' => 'Horde_Kolab_Format_Xml_Type_Multiple_String', 'daynumber' => 'Horde_Kolab_Format_Xml_Type_Integer', 'month' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'range' => 'Horde_Kolab_Format_Xml_Type_RecurrenceRange', 'exclusion' => 'Horde_Kolab_Format_Xml_Type_Multiple_Date', 'complete' => 'Horde_Kolab_Format_Xml_Type_Multiple_Date', ); /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if ($node = $helper->findNodeRelativeTo('./' . $name, $parent_node)) { // Get the cycle type (must be present) $attributes['recurrence']['cycle'] = $node->getAttribute('cycle'); // Get the sub type (may be present) $attributes['recurrence']['type'] = $node->getAttribute('type'); } if (empty($attributes['recurrence'])) { return $result; } $recurrence = $attributes['recurrence']; if ($recurrence['interval'] < 0) { throw new Horde_Kolab_Format_Exception_ParseError( sprintf( 'Recurrence: interval cannot be below zero [Value: %s]!', $recurrence['interval'] ) ); } if (empty($recurrence['cycle'])) { throw new Horde_Kolab_Format_Exception_ParseError('Recurrence: "cycle" attribute missing!'); } if ($recurrence['cycle'] == 'weekly') { // Check for if (!isset($recurrence['day']) || count($recurrence['day']) == 0) { throw new Horde_Kolab_Format_Exception_ParseError( 'Recurrence: day tag missing for weekly recurrence!' ); } } // The code below is only for monthly or yearly recurrences if ($recurrence['cycle'] == 'monthly' || $recurrence['cycle'] == 'yearly') { if (!isset($recurrence['type'])) { throw new Horde_Kolab_Format_Exception_ParseError( 'Recurrence: type attribute missing!' ); } if (!isset($recurrence['daynumber'])) { throw new Horde_Kolab_Format_Exception_ParseError( 'Recurrence: daynumber tag missing!' ); } $daynumber = $recurrence['daynumber']; if ($daynumber < 0) { throw new Horde_Kolab_Format_Exception_ParseError( sprintf( 'Recurrence: daynumber cannot be below zero ["%s"]!', $daynumber ) ); } if ($recurrence['type'] == 'daynumber') { if ($recurrence['cycle'] == 'yearly' && $daynumber > 366) { throw new Horde_Kolab_Format_Exception_ParseError( sprintf( 'Recurrence: daynumber cannot be larger than 366 for yearly recurrences ["%s"]!', $daynumber ) ); } else if ($recurrence['cycle'] == 'monthly' && $daynumber > 31) { throw new Horde_Kolab_Format_Exception_ParseError( sprintf( 'Recurrence: daynumber cannot be larger than 31 for monthly recurrences ["%s"]!', $daynumber ) ); } } else if ($recurrence['type'] == 'weekday') { // daynumber is the week of the month if ($daynumber > 5) { throw new Horde_Kolab_Format_Exception_ParseError( sprintf( 'Recurrence: daynumber cannot be larger than 5 for type weekday ["%s"]!', $daynumber ) ); } // Check for if (!isset($recurrence['day']) || count($recurrence['day']) == 0) { throw new Horde_Kolab_Format_Exception_ParseError( 'Recurrence: day tag missing for type weekday!' ); } } if (($recurrence['type'] == 'monthday' || $recurrence['type'] == 'yearday') && $recurrence['cycle'] == 'monthly') { throw new Horde_Kolab_Format_Exception_ParseError( 'Recurrence: type monthday/yearday is only allowed for yearly recurrences' ); } if ($recurrence['cycle'] == 'yearly') { if ($recurrence['type'] == 'monthday') { // daynumber and month if (!isset($recurrence['month'])) { throw new Horde_Kolab_Format_Exception_ParseError( 'Recurrence: month tag missing for type monthday' ); } if ($daynumber > 31) { throw new Horde_Kolab_Format_Exception_ParseError( sprintf( 'Recurrence: daynumber cannot be larger than 31 for type monthday ["%s"]!', $daynumber ) ); } } else if ($recurrence['type'] == 'yearday') { if ($daynumber > 366) { throw new Horde_Kolab_Format_Exception_ParseError( sprintf( 'Recurrence: daynumber cannot be larger than 366 for type yearday ["%s"]!', $daynumber ) ); } } } } return $result; } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { $node = parent::saveNodeValue($name, $value, $parent_node, $helper, $params, $old_node); // Add attributes $node->setAttribute('cycle', $value['cycle']); if (isset($value['type'])) { $node->setAttribute('type', $value['type']); } return $node; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite/SimplePerson.php0000664000175000017500000000220412653734733026164 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles attributes to represent a person in a simple way. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite_SimplePerson extends Horde_Kolab_Format_Xml_Type_Composite { protected $elements = array( 'display-name' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'smtp-address' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'uid' => 'Horde_Kolab_Format_Xml_Type_String_Empty', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/CreationDate/V1.php0000664000175000017500000000775312653734733024450 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles api version 1 of the creation date attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_CreationDate_V1 extends Horde_Kolab_Format_Xml_Type_AutomaticDate_V1 { /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); if ($node !== false) { if (isset($attributes[$name]) && ($old = $this->loadNodeValue($node, $helper, $params)) != $attributes[$name]) { if (!$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf( 'Not attempting to overwrite old %s %s with new value %s!', $name, Horde_Kolab_Format_Date::writeDateTime($old), Horde_Kolab_Format_Date::writeDateTime($attributes[$name]) ) ); } } else { return $node; } } $result = $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); return ($node !== false) ? $node : $result; } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { if (isset($attributes[$name])) { return Horde_Kolab_Format_Date::writeUtcDateTime( $attributes[$name] ); } else { return Horde_Kolab_Format_Date::writeUtcDateTime(new DateTime()); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Date/V1.php0000664000175000017500000000600212653734733022745 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles api version 1 of date attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Date_V1 extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); return Horde_Kolab_Format_Date::readDate($result); } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { $date = Horde_Kolab_Format_Date::writeDate($value); $node = parent::saveNodeValue( $name, $date, $parent_node, $helper, $params, $old_node ); return $node; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/DateTime/V1.php0000664000175000017500000000603612653734733023573 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles api version 1 of date-time attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_DateTime_V1 extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); return Horde_Kolab_Format_Date::readDateOrDateTime($result); } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { $date = Horde_Kolab_Format_Date::writeDateTime($value); $node = parent::saveNodeValue( $name, $date, $parent_node, $helper, $params, $old_node ); return $node; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/EventDate/V1.php0000664000175000017500000000174512653734733023760 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles event start and end dates. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_EventDate_V1 extends Horde_Kolab_Format_Xml_Type_Date_V1 { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/EventDateTime/V1.php0000664000175000017500000000365512653734733024601 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles event start and end dates. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_EventDateTime_V1 extends Horde_Kolab_Format_Xml_Type_DateTime_V1 { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY; /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); if (strlen($result) == 10) { return array( 'date' => Horde_Kolab_Format_Date::readDate($result), 'date-only' => true ); } return array( 'date' => Horde_Kolab_Format_Date::readDateTime($result), 'date-only' => false ); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple/Address.php0000664000175000017500000000204312653734733024763 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the multiple address attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple_Address extends Horde_Kolab_Format_Xml_Type_Multiple { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element = 'Horde_Kolab_Format_Xml_Type_Composite_Address'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple/Attendee.php0000664000175000017500000000204712653734733025133 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the multiple attendee attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple_Attendee extends Horde_Kolab_Format_Xml_Type_Multiple { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element = 'Horde_Kolab_Format_Xml_Type_Composite_Attendee'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple/Boolean.php0000664000175000017500000000203112653734733024752 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the multiple boolean attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple_Boolean extends Horde_Kolab_Format_Xml_Type_Multiple { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element = 'Horde_Kolab_Format_Xml_Type_Boolean'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple/Date.php0000664000175000017500000000201512653734733024252 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the multiple date attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple_Date extends Horde_Kolab_Format_Xml_Type_Multiple { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element = 'Horde_Kolab_Format_Xml_Type_Date'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple/Phone.php0000664000175000017500000000203312653734733024446 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the multiple phone attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple_Phone extends Horde_Kolab_Format_Xml_Type_Multiple { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element = 'Horde_Kolab_Format_Xml_Type_Composite_Phone'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple/SimplePerson.php0000664000175000017500000000207112653734733026017 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the multiple simple person attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple_SimplePerson extends Horde_Kolab_Format_Xml_Type_Multiple { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element = 'Horde_Kolab_Format_Xml_Type_Composite_SimplePerson'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple/String.php0000664000175000017500000000204212653734733024643 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the multiple string attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple_String extends Horde_Kolab_Format_Xml_Type_Multiple { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element = 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing'; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/RecurrenceRange/V1.php0000664000175000017500000001156312653734733025152 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles api version 1 of the recurrence range attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_RecurrenceRange_V1 extends Horde_Kolab_Format_Xml_Type_String { /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if ($result !== false) { $type = $result->getAttribute('type'); if (!empty($type) && $type != 'none') { $attributes['range-type'] = $type; } } return $result; } /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); $type = $node->getAttribute('type'); if (empty($type) || $type == 'none') { return null; } if ($type == 'date') { return Horde_Kolab_Format_Date::readDate($result); } return $result; } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { if (isset($attributes['range-type']) && $attributes['range-type'] == 'date') { $attributes[$name] = Horde_Kolab_Format_Date::writeDate($attributes[$name]); } $node = parent::save( $name, $attributes, $parent_node, $helper, $params ); if (isset($attributes['range-type'])) { $type = $attributes['range-type']; } else { $type = 'none'; } $node->setAttribute('type', $type); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/String/Empty/List.php0000664000175000017500000000613412653734733025067 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a string attribute that defaults to an empty string. * * Copyright 2012-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Jan Schneider * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_String_Empty_List extends Horde_Kolab_Format_Xml_Type_String_Empty { /** * A default value if required. * * @var array */ protected $default = array(); /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::loadNodeValue($node, $helper, $params); $result = preg_split('/(? * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a string attribute that defaults to an empty string. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_String_Empty extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = ''; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/String/MaybeMissing.php0000664000175000017500000000767512653734733025460 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a string attribute that may also be missing. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_String_MaybeMissing extends Horde_Kolab_Format_Xml_Type_Base { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); if ($result === null) { $result = ''; } return $result; } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); if (!isset($attributes[$name])) { if ($node !== false) { /** Client indicates that the value should get removed */ $helper->removeNodes($parent_node, $name); } return false; } return $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { return $attributes[$name]; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/String/NotEmpty.php0000664000175000017500000000166712653734733024643 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a string attribute that must not be empty. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_String_NotEmpty extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/AddressType.php0000664000175000017500000000241512653734733024035 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the address type. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_AddressType extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = 'home'; /** * Address types * * @todo Check enum possibilities * * @var array */ private $_address_types = array( 'business', 'home', 'other', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/AttendeeRole.php0000664000175000017500000000217512653734733024164 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the attendee role. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_AttendeeRole extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = 'required'; /** * @todo Check enum possibilities */ } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/AttendeeStatus.php0000664000175000017500000000217712653734733024550 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the attendee status. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_AttendeeStatus extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = 'none'; /** * @todo Check enum possibilities */ } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/AutomaticDate.php0000664000175000017500000000630212653734733024331 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles auto-generated date attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_AutomaticDate extends Horde_Kolab_Format_Xml_Type_Base { /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load($name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if ($result !== false) { return $result; } else { $attributes[$name] = new DateTime(); } } /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); if ($result !== null) { $date = Horde_Kolab_Format_Date::readUtcDateTime($result); if ($date === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf('Invalid date input "%s"!', $result) ); } return $date; } else { return $result; } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Base.php0000664000175000017500000002421412653734733022461 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Utilities for the various XML handlers. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Base { /** * The factory for any additional objects required. * * @var Horde_Kolab_Format_Factory */ private $_factory; /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING; /** * A default value if required. * * @var string */ protected $default; /** * Collects xml types already created. * * @var array */ private static $_xml_types; /** * Constructor * * @param Horde_Kolab_Format_Factory $factory The factory for any additional * objects required. */ public function __construct($factory) { $this->_factory = $factory; } /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load($name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { if ($node = $helper->findNodeRelativeTo('./' . $name, $parent_node)) { if (($value = $this->loadNodeValue($node, $helper, $params)) !== null) { $attributes[$name] = $value; return $node; } } return false; } /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { return $helper->fetchNodeValue($node); } /** * Load a default value for a node. * * @param string $name The attribute name. * @param array $params The parameters for the current operation. * * @return mixed The default value. * * @throws Horde_Kolab_Format_Exception In case the attribute may not be * missing or the default value was * left undefined. */ protected function loadMissing($name, $params) { if ($this->value == Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception_MissingValue($name); } if ($this->value == Horde_Kolab_Format_Xml::VALUE_DEFAULT) { return $this->default; } } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); $result = $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); return ($node !== false) ? $node : $result; } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { if (isset($attributes[$name])) { return $attributes[$name]; } else { return ''; } } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if ($old_node === false) { return $helper->storeNewNodeValue( $parent_node, $name, $value ); } else { $helper->replaceFirstNodeTextValue($old_node, $value); return $old_node; } } /** * Validate that the parameter array contains all required parameters. * * @param string $key The parameter name. * @param array $params The parameters. * @param string $attribute The attribute name. * * @throws Horde_Kolab_Format_Exception In case required parameters are * missing. */ protected function checkMissing($key, $params, $attribute) { if (!isset($params[$key])) { throw new Horde_Kolab_Format_Exception( sprintf( 'Required parameter "%s" missing (attribute: %s)!', $key, $attribute ) ); } } /** * Return a parameter value. * * @param string $name The parameter name. * * @return mixed The parameter value. */ public function getParam($name) { return isset($this->_params[$name]) ? $this->_params[$name] : null; } /** * Returns if the XML handling should be relaxed. * * @param array $params The parameters. * * @return boolean True if the XML should not be strict. */ protected function isRelaxed($params) { return !empty($params['relaxed']); } /** * Create a handler for the sub type of this attribute. * * @param string $type The sub type. * @param array $params Additional parameters. * * @return Horde_Kolab_Format_Xml_Type The sub type handler. */ protected function createSubType($type, $params) { if (isset($params['api-version'])) { $class = $type . '_V' . $params['api-version']; } else { $class = $type; } if (!isset(self::$_xml_types[$class])) { self::$_xml_types[$class] = $this->_factory->createXmlType($type, $params); } return self::$_xml_types[$class]; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Boolean.php0000664000175000017500000000703012653734733023163 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a boolean attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Boolean extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node);; if ($result !== null) { if ($result == 'false') { $result = false; } else if ($result == 'true') { $result = true; } else { $result = (bool)$result; } } return $result; } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if (!is_string($value)) { if ($value) { $value = 'true'; } else { $value = 'false'; } } if (!in_array($value, array('true', 'false')) && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf('Invalid boolean input "%s"!', $value) ); } return parent::saveNodeValue( $name, $value, $parent_node, $helper, $params, $old_node ); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Color.php0000664000175000017500000000716412653734733022672 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a color attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Color extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node);; if ($result !== null) { $this->_checkColor($result, $params); } return $result; } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if (isset($value)) { $this->_checkColor($value, $params); } return parent::saveNodeValue( $name, $value, $parent_node, $helper, $params, $old_node ); } /** * Test if the input seems to be a real color. * * @param string $color The string to check. * @param array $params The parameters for this operation. * * @return NULL * * @throws Horde_Kolab_Format_Exception If the input is no color. */ private function _checkColor($color, $params) { if (!preg_match('/^#[0-9a-fA-F]{6}$/', $color) && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf('Invalid color input "%s"!', $color) ); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Composite.php0000664000175000017500000002313212653734733023547 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles composite attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Composite extends Horde_Kolab_Format_Xml_Type_Base { /** * The elements of the composite attribute. * * @var array */ protected $elements; /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING; /** * A default value if required. * * @var string */ protected $default; /** * Should the values be merged into the parent attributes? * * @var boolean */ protected $merge = false; /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { if ($node = $helper->findNodeRelativeTo('./' . $name, $parent_node)) { $result = $this->loadNodeValue($node, $helper, $params); } else { $result = $this->loadMissing($name, $params); } if (!$this->merge) { $attributes[$name] = $result; } else { $attributes = array_merge($attributes, $result); } return false; } /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = array(); foreach ($this->elements as $sub_name => $sub_type) { $this->createSubType($sub_type, $params) ->load($sub_name, $result, $node, $helper, $params); } return $result; } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); if (!$this->merge && !isset($attributes[$name])) { if ($node === false) { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING || ($this->value == Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY && $this->isRelaxed($params))) { return false; } } else { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) { /** Client indicates that the value should get removed */ $helper->removeNodes($parent_node, $name); return false; } else { return $node; } } } return $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if ($old_node === false) { $node = $helper->createNewNode($parent_node, $name); $this->_writeComposite($node, $name, $value, $helper, $params); return $node; } else { $this->_writeComposite($old_node, $name, $value, $helper, $params); return $old_node; } } /** * Write a composite value to a parent node. * * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param string $name The name of the the * attribute to be updated. * @param array $values The values to write. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * * @return array The list of new/updated child nodes. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ private function _writeComposite($parent_node, $name, $values, Horde_Kolab_Format_Xml_Helper $helper, $params) { foreach ($this->elements as $sub_name => $sub_type) { $this->createSubType($sub_type, $params) ->save($sub_name, $values, $parent_node, $helper, $params); } } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { if ($this->merge) { return $attributes; } if (isset($attributes[$name])) { return $attributes[$name]; } else { return $this->loadMissing($name, $params); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/CreationDate.php0000664000175000017500000000771112653734733024154 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the creation date attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_CreationDate extends Horde_Kolab_Format_Xml_Type_AutomaticDate { /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); if ($node !== false) { if (isset($attributes[$name]) && ($old = $this->loadNodeValue($node, $helper, $params)) != $attributes[$name]) { if (!$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf( 'Not attempting to overwrite old %s %s with new value %s!', $name, Horde_Kolab_Format_Date::writeUtcDateTime($old), Horde_Kolab_Format_Date::writeUtcDateTime($attributes[$name]) ) ); } } else { return $node; } } $result = $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); return ($node !== false) ? $node : $result; } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { if (isset($attributes[$name])) { return Horde_Kolab_Format_Date::writeUtcDateTime( $attributes[$name] ); } else { return Horde_Kolab_Format_Date::writeUtcDateTime(new DateTime()); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Date.php0000664000175000017500000000671512653734733022472 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles date attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Date extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); $date = Horde_Kolab_Format_Date::readDate($result); if ($date === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf('Invalid date input "%s"!', $result) ); } return $date; } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if (!isset($value) || !$value instanceof DateTime) { throw new Horde_Kolab_Format_Exception( sprintf( 'Missing or invalid date for the "%s" entry!', $name ) ); } $date = Horde_Kolab_Format_Date::writeDate($value); $node = parent::saveNodeValue( $name, $date, $parent_node, $helper, $params, $old_node ); return $node; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/DateTime.php0000664000175000017500000001007012653734733023276 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles date-time attributes. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_DateTime extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); if (strlen($result) == 10) { $date = array( 'date' => Horde_Kolab_Format_Date::readDate($result), 'date-only' => true ); } else { $date = array( 'date' => Horde_Kolab_Format_Date::readDateTime($result), 'date-only' => false ); } if ($date['date'] === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf('Invalid date input "%s"!', $result) ); } return $date; } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if ($value instanceof DateTime) { $value = array('date' => $value); } if (!isset($value['date']) || !$value['date'] instanceof DateTime) { throw new Horde_Kolab_Format_Exception( sprintf( 'Missing or invalid data in the "date" element of the "%s" entry!', $name ) ); } if (empty($value['date-only'])) { $date = Horde_Kolab_Format_Date::writeDateTime($value['date']); } else { $date = Horde_Kolab_Format_Date::writeDate($value['date']); } $node = parent::saveNodeValue( $name, $date, $parent_node, $helper, $params, $old_node ); return $node; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/EventDate.php0000664000175000017500000000173712653734733023473 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles event start and end dates. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_EventDate extends Horde_Kolab_Format_Xml_Type_Date { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/EventDateTime.php0000664000175000017500000000174712653734733024313 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles event start and end dates. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_EventDateTime extends Horde_Kolab_Format_Xml_Type_DateTime { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Integer.php0000664000175000017500000000732212653734733023205 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a integer attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Integer extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node);; if ($result !== null) { $this->_checkInteger($result, $params); $result = (int)$result; } return $result; } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if (!is_string($value)) { $value = (string)$value; } $this->_checkInteger($value, $params); return parent::saveNodeValue( $name, $value, $parent_node, $helper, $params, $old_node ); } /** * Test if the input seems to be a real integer. * * @param string $integer The string to check. * @param array $params The parameters for this operation. * * @return NULL * * @throws Horde_Kolab_Format_Exception If the input is no integer. */ private function _checkInteger($integer, $params) { if (((string)((int)$integer) !== $integer) && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf('Invalid integer input "%s"!', $integer) ); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/ModificationDate.php0000664000175000017500000000304012653734733025004 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the modification date attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_ModificationDate extends Horde_Kolab_Format_Xml_Type_AutomaticDate { /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { return Horde_Kolab_Format_Date::writeUtcDateTime( new DateTime('now', new DateTimeZone('UTC')) ); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Multiple.php0000664000175000017500000001647512653734733023414 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles attributes with multiple values. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Multiple extends Horde_Kolab_Format_Xml_Type_Base { /** * The class name representing the element that can occur multiple times. * * @var string */ protected $element; /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING; /** * A default value if required. * * @var string */ protected $default; /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $children = $helper->findNodesRelativeTo('./' . $name, $parent_node); if ($children->length > 0) { $sub_type = $this->createSubType($this->element, $params); $result = array(); foreach ($children as $child) { $result[] = $sub_type->loadNodeValue( $child, $helper, $params ); } $attributes[$name] = $result; } else { $attributes[$name] = $this->loadMissing($name, $params); } return false; } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $children = $helper->findNodesRelativeTo( './' . $name, $parent_node ); if (!isset($attributes[$name])) { if ($children->length == 0) { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING || ($this->value == Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY && $this->isRelaxed($params))) { return false; } } else { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) { /** Client indicates that the value should get removed */ $helper->removeNodes($parent_node, $name); return false; } else { return $children; } } } //@todo What is required to get around this overwriting of the old values? $helper->removeNodes($parent_node, $name); return $this->_writeMultiple( $parent_node, $name, $this->generateWriteValue($name, $attributes, $params), $helper, $params ); } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { if (isset($attributes[$name])) { return $attributes[$name]; } else { return $this->loadMissing($name, $params); } } /** * Write multiple values to one parent node. * * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param string $name The name of the the * attribute to be updated. * @param array $values The values to write. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * * @return array The list of new/updated child nodes. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ private function _writeMultiple( $parent_node, $name, $values, Horde_Kolab_Format_Xml_Helper $helper, $params ) { $sub_type = $this->createSubType($this->element, $params); $result = array(); foreach ($values as $value) { $result[] = $sub_type->saveNodeValue( $name, $value, $parent_node, $helper, $params ); } return $result; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/PhoneType.php0000664000175000017500000000302612653734733023520 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the phone type. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_PhoneType extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = ''; /** * Phone types * * @todo Check enum possibilities * * @var array */ private $_phone_types = array( 'business1', 'business2', 'businessfax', 'callback', 'car', 'company', 'home1', 'home2', 'homefax', 'isdn', 'mobile', 'pager', 'primary', 'radio', 'telex', 'ttytdd', 'assistant', 'other', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/PrefsApplication.php0000664000175000017500000001152312653734733025051 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the preferences "application" attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_PrefsApplication extends Horde_Kolab_Format_Xml_Type_Base { /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if ($result === false) { $result = parent::load('categories', $attributes, $parent_node, $helper, $params); } if ($result !== false && ($value = $this->loadNodeValue($result, $helper, $params)) !== null) { $attributes[$name] = $value; return $result; } else if (!$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception_MissingValue('Preferences XML object is missing an application setting.'); } else { return false; } } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); if (!isset($attributes[$name])) { if (!empty($attributes['categories'])) { $attributes[$name] = $attributes['categories']; unset($attributes['categories']); } } if (!isset($attributes[$name]) && $node === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception_MissingValue('Preferences data is missing an application setting.'); } if ($node === false) { $categories = $helper->findNodeRelativeTo( './categories', $parent_node ); /** Remove old categories entry */ $helper->removeNodes($parent_node, 'categories'); } return $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/ProductId.php0000664000175000017500000000560112653734733023503 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the product ID attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_ProductId extends Horde_Kolab_Format_Xml_Type_Base { /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if ($result !== false) { return $result; } else { $attributes[$name] = ''; } } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { return Horde_Kolab_Format_Xml::PRODUCT_ID . '-' . Horde_Kolab_Format::VERSION . ' (api version: ' . $params['api-version'] . ')'; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/RecurrenceInterval.php0000664000175000017500000000174712653734733025417 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the recurrence interval. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_RecurrenceInterval extends Horde_Kolab_Format_Xml_Type_Integer { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY; } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/RecurrenceRange.php0000664000175000017500000000672412653734733024667 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the recurrence range attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_RecurrenceRange extends Horde_Kolab_Format_Xml_Type_String { /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); $type = $node->getAttribute('type'); if (empty($type) || $type == 'none') { return null; } if ($type == 'date') { return Horde_Kolab_Format_Date::readDate($result); } return $result; } /** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue( $name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false ) { if (empty($value)) { $type = 'none'; $value = ''; } else if ($value instanceof DateTime) { $type = 'date'; $value = Horde_Kolab_Format_Date::writeDate($value); } else { $type = 'number'; } $node = parent::saveNodeValue( $name, $value, $parent_node, $helper, $params, $old_node ); $node->setAttribute('type', $type); return $node; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Root.php0000664000175000017500000001631012653734733022530 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the document root. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Root extends Horde_Kolab_Format_Xml_Type_Composite { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY; /** * Should the velues be merged into the parent attributes? * * @var boolean */ protected $merge = true; /** * Basic attributes in any Kolab object * * @var array */ private $_attributes_basic = array( 'uid' => 'Horde_Kolab_Format_Xml_Type_Uid', 'body' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'categories' => 'Horde_Kolab_Format_Xml_Type_String_Empty_List', 'creation-date' => 'Horde_Kolab_Format_Xml_Type_CreationDate', 'last-modification-date' => 'Horde_Kolab_Format_Xml_Type_ModificationDate', 'sensitivity' => 'Horde_Kolab_Format_Xml_Type_Sensitivity', 'inline-attachment' => 'Horde_Kolab_Format_Xml_Type_Multiple_String', 'link-attachment' => 'Horde_Kolab_Format_Xml_Type_Multiple_String', 'product-id' => 'Horde_Kolab_Format_Xml_Type_ProductId', ); /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { if (!($root = $helper->findNode('/' . $name))) { throw new Horde_Kolab_Format_Exception_InvalidRoot( sprintf('Missing root node "%s"!', $name) ); } $attributes['_format-version'] = $root->getAttribute('version'); $attributes['_api-version'] = $params['api-version']; if (!$this->isRelaxed($params)) { if (version_compare($params['expected-version'], $attributes['_format-version']) < 0) { throw new Horde_Kolab_Format_Exception_InvalidRoot( sprintf( 'Not attempting to read higher root version of %s with our version %s!', $attributes['_format-version'], $params['expected-version'] ) ); } } $this->_prepareCompositeParameters( $params, $attributes['_format-version'] ); parent::load($name, $attributes, $parent_node, $helper, $params); return $root; } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { if (!($root = $helper->findNode('/' . $name, $parent_node))) { $root = $helper->createNewNode($parent_node, $name); $root->setAttribute('version', $params['expected-version']); } else { if (!$this->isRelaxed($params)) { if (version_compare($params['expected-version'], $root->getAttribute('version')) < 0) { throw new Horde_Kolab_Format_Exception_InvalidRoot( sprintf( 'Not attempting to overwrite higher root version of %s with our version %s!', $root->getAttribute('version'), $params['expected-version'] ) ); } } if ($params['expected-version'] != $root->getAttribute('version')) { $root->setAttribute('version', $params['expected-version']); } } $this->_prepareCompositeParameters( $params, $params['expected-version'] ); parent::save($name, $attributes, $parent_node, $helper, $params); return $root; } /** * Prepare the parameters for the parent composite handler. * * @param array &$params The parameters for this operation. * @param string $version The format version of the document. * * @return NULL */ private function _prepareCompositeParameters(&$params, $version) { $params['format-version'] = $version; $this->elements = $this->_attributes_basic; if (isset($params['attributes-specific'])) { $this->elements = array_merge( $this->elements, $params['attributes-specific'] ); } if (isset($params['attributes-application'])) { $this->elements = array_merge( $this->elements, $params['attributes-application'] ); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Sensitivity.php0000664000175000017500000000216612653734733024143 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the sensitivity. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Sensitivity extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = 'public'; /** * @todo Check enum possibilities */ } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/String.php0000664000175000017500000001366512653734733023065 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles a string attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_String extends Horde_Kolab_Format_Xml_Type_Base { /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if ($result !== false) { return $result; } else { if ($this->value != Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) { $attributes[$name] = $this->loadMissing($name, $params); } return false; } } /** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue( $node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = $helper->fetchNodeValue($node); if ($result === null) { $result = ''; } return $result; } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); if (!isset($attributes[$name])) { if ($node === false) { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING || ($this->value == Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY && $this->isRelaxed($params))) { return false; } } else { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) { /** Client indicates that the value should get removed */ $helper->removeNodes($parent_node, $name); return false; } else { return $node; } } } return $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); } /** * Generate the value that should be written to the node. Override in the * extending classes. * * @param string $name The name of the the attribute * to be updated. * @param array $attributes The data array that holds all * attribute values. * @param array $params The parameters for this write operation. * * @return mixed The value to be written. */ protected function generateWriteValue($name, $attributes, $params) { if (isset($attributes[$name])) { return $attributes[$name]; } else { return $this->loadMissing($name, $params); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/TaskCompletion.php0000664000175000017500000000220412653734733024536 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the completion state of a task. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_TaskCompletion extends Horde_Kolab_Format_Xml_Type_Integer { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = 0; /** * @todo Range check */ } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/TaskPriority.php0000664000175000017500000000215012653734733024246 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the task priority. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_TaskPriority extends Horde_Kolab_Format_Xml_Type_Integer { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = 3; /** * @todo Range check */ } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/TaskStatus.php0000664000175000017500000000216412653734733023715 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the task status. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_TaskStatus extends Horde_Kolab_Format_Xml_Type_String { /** * Indicate which value type is expected. * * @var int */ protected $value = Horde_Kolab_Format_Xml::VALUE_DEFAULT; /** * A default value if required. * * @var string */ protected $default = 'not-started'; /** * @todo Enum possibilities */ } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/Uid.php0000664000175000017500000001132312653734733022325 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles the UID attribute. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_Uid extends Horde_Kolab_Format_Xml_Type_Base { /** * Load the node value from the Kolab object. * * @param string $name The name of the the * attribute to be fetched. * @param array &$attributes The data array that * holds all attribute * values. * @param DOMNode $parent_node The parent node of the * node to be loaded. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return DOMNode|boolean The named DOMNode or false if no node value was * found. */ public function load( $name, &$attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $result = parent::load($name, $attributes, $parent_node, $helper, $params); if (!$result && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception_MissingUid(); } return $result; } /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $node = $helper->findNodeRelativeTo( './' . $name, $parent_node ); if ($node === false) { if (!isset($attributes[$name])) { if ($this->isRelaxed($params)) { return false; } else { throw new Horde_Kolab_Format_Exception_MissingUid(); } } } else { if (isset($attributes[$name])) { if (($old = $this->loadNodeValue($node, $helper, $params)) != $attributes[$name]) { if (!$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception( sprintf( 'Not attempting to overwrite old %s %s with new value %s!', $name, $old, $attributes['uid'] ) ); } } else { return $node; } } } $result = $this->saveNodeValue( $name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node ); return ($node !== false) ? $node : $result; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Type/XmlAppend.php0000664000175000017500000000433312653734733023477 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles appending XML to the document. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Type_XmlAppend extends Horde_Kolab_Format_Xml_Type_Base { /** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { $value = $this->generateWriteValue($name, $attributes, $params); return empty($value) ? false : $helper->appendXml( $parent_node, $value ); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Annotation.php0000664000175000017500000000501412653734733022775 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML handler for IMAP folder annotations. * * Copyright 2008-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Annotation extends Horde_Kolab_Format_Xml { /** * The name of the root element. * * @var string */ protected $_root_name = 'annotations'; /** * Specific data fields for the prefs object * * @var Kolab */ protected $_fields_specific = array( 'annotation' => 'Horde_Kolab_Format_Xml_Type_Multiple_String', ); /** * Load the groupware object based on the specifc XML values. * * @param array &$children An array of XML nodes. * * @return array Array with the object data * * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. */ protected function _load(&$children) { $object = $this->_loadArray($children, $this->_fields_specific); $result = array(); foreach ($object['annotation'] as $annotation) { list($key, $value) = split('#', $annotation, 2); $result[base64_decode($key)] = base64_decode($value); } return $result; } /** * Save the specific XML values. * * @param array $root The XML document root. * @param array $object The resulting data array. * * @return boolean True on success. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ protected function _save(&$root, $object) { $annotations = array(); foreach ($object as $key => $value) { if ($key != 'uid') { $annotations['annotation'][] = base64_encode($key) . '#' . base64_encode($value); } } return $this->_saveArray($root, $annotations, $this->_fields_specific); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Contact.php0000664000175000017500000000625612653734733022267 0ustar janjan * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML handler for contact groupware objects * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Thomas Jarosch * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Contact extends Horde_Kolab_Format_Xml { /** * The name of the root element. * * @var string */ protected $_root_name = 'contact'; /** * Specific data fields for the contact object * * @var array */ protected $_fields_specific = array( 'name' => 'Horde_Kolab_Format_Xml_Type_Composite_Name', 'free-busy-url' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'organization' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'web-page' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'im-address' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'department' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'office-location' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'profession' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'job-title' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'manager-name' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'assistant' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'nick-name' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'spouse-name' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'birthday' => 'Horde_Kolab_Format_Xml_Type_Date', 'anniversary' => 'Horde_Kolab_Format_Xml_Type_Date', 'picture' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'children' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'gender' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'language' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'address' => 'Horde_Kolab_Format_Xml_Type_Multiple_Address', 'email' => 'Horde_Kolab_Format_Xml_Type_Multiple_SimplePerson', 'phone' => 'Horde_Kolab_Format_Xml_Type_Multiple_Phone', 'preferred-address' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'latitude' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'longitude' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Distributionlist.php0000664000175000017500000000600112653734733024233 0ustar janjan * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML handler for distributionlist groupware objects * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Thomas Jarosch * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Distributionlist extends Horde_Kolab_Format_Xml { /** * The name of the root element. * * @var string */ protected $_root_name = 'distribution-list'; /** * Specific data fields for the contact object * * @var array */ protected $_fields_specific = array( 'display-name' => 'Horde_Kolab_Format_Xml_Type_String_NotEmpty', 'member' => 'Horde_Kolab_Format_Xml_Type_Multiple_SimplePerson', ); /** * Load the groupware object based on the specifc XML values. * * @param array &$children An array of XML nodes. * * @return array Array with data. * * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. */ protected function _load(&$children) { $object = $this->_loadArray($children, $this->_fields_specific); // Map the display-name of a kolab dist list to horde's lastname attribute if (isset($object['display-name'])) { $object['last-name'] = $object['display-name']; unset($object['display-name']); } /** * The mapping from $object['member'] as stored in XML back to * Turba_Objects (contacts) must be performed in the * Kolab_IMAP storage driver as we need access to the search * facilities of the kolab storage driver. */ $object['__type'] = 'Group'; return $object; } /** * Save the specifc XML values. * * @param array $root The XML document root. * @param array $object The resulting data array. * * @return boolean True on success. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ protected function _save(&$root, $object) { // Map the display-name of a kolab dist list to horde's lastname attribute if (isset($object['last-name'])) { $object['display-name'] = $object['last-name']; unset($object['last-name']); } return $this->_saveArray($root, $object, $this->_fields_specific); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Envelope.php0000664000175000017500000000356512653734733022451 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * A Kolab XML envelope for arbitrary XML. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Envelope extends Horde_Kolab_Format_Xml { /** * Specific data fields for the prefs object * * @var Kolab */ protected $_fields_specific = array( 'xml' => 'Horde_Kolab_Format_Xml_Type_XmlAppend', ); /** * Convert the data to a XML stream. Strings contained in the data array may * only be provided as UTF-8 data. * * @param array $object The data array representing the object. * @param array $options Additional options when parsing the XML. *
     * - previous: The previous XML text (default: empty string)
     * - relaxed: Relaxed error checking (default: false)
     * 
* * @return resource The data as XML stream. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($object, $options = array()) { if (!isset($object['type'])) { throw new Horde_Kolab_Format_Exception('The "type" value is missing!'); } $this->_root_name = $object['type']; return parent::save($object, $options); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Event.php0000664000175000017500000001044412653734733021747 0ustar janjan * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML handler for event groupware objects. * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Thomas Jarosch * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Event extends Horde_Kolab_Format_Xml { /** * The name of the root element. * * @var string */ protected $_root_name = 'event'; /** * Specific data fields for the prefs object * * @var Kolab */ protected $_fields_specific = array( 'summary' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'location' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'organizer' => 'Horde_Kolab_Format_Xml_Type_Composite_SimplePerson', 'start-date' => 'Horde_Kolab_Format_Xml_Type_EventDateTime', 'alarm' => 'Horde_Kolab_Format_Xml_Type_Integer', 'horde-alarm-methods' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'recurrence' => 'Horde_Kolab_Format_Xml_Type_Composite_Recurrence', 'attendee' => 'Horde_Kolab_Format_Xml_Type_Multiple_Attendee', 'show-time-as' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'color-label' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'end-date' => 'Horde_Kolab_Format_Xml_Type_EventDateTime', ); /** * Load an object based on the given XML stream. The stream may only contain * UTF-8 data. * * @param resource $xml The XML stream of the message. * @param array $options Additional options when parsing the XML. *
     * - relaxed: Relaxed error checking (default: false)
     * 
* * @return array The data array representing the object. * * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. * * @todo Check encoding of the returned array. It seems to be ISO-8859-1 at * the moment and UTF-8 would seem more appropriate. */ public function load($xml, $options = array()) { $object = parent::load($xml, $options); if ($object['end-date']['date-only']) { $object['end-date']['date'] ->add(new DateInterval('P1D')); } $object['start-date'] = $object['start-date']['date']; $object['end-date'] = $object['end-date']['date']; return $object; } /** * Convert the data to a XML stream. Strings contained in the data array may * only be provided as UTF-8 data. * * @param array $object The data array representing the object. * @param array $options Additional options when writing the XML. *
     * - previous: The previous XML text (default: empty string)
     * - relaxed: Relaxed error checking (default: false)
     * 
* * @return resource The data as XML stream. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($object, $options = array()) { if (!empty($object['_is_all_day'])) { $this->_fields_specific['start-date'] = 'Horde_Kolab_Format_Xml_Type_EventDate'; $this->_fields_specific['end-date'] = 'Horde_Kolab_Format_Xml_Type_EventDate'; $end_date = clone $object['end-date']; if ($end_date->hour == 0 && $end_date->min == 0 && $end_date->sec == 0) { // move date to previous day 23:59:59. We cut off the time anyway. $end_date->sub(new DateInterval('PT1S')); $object['end-date'] = $end_date; } } return parent::save($object, $options); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Helper.php0000664000175000017500000001536012653734733022107 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Provides DOM utility methods. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Helper { /** * The XML document this object works with. * * @var DOMDocument */ protected $_xmldoc; /** * The XPath query handler. * * @var DOMXpath */ private $_xpath; /** * Constructor * * @param DOMDocument $xmldoc The XML document this object works with. */ public function __construct($xmldoc) { $this->_xmldoc = $xmldoc; $this->_xpath = new DOMXpath($this->_xmldoc); } /** * Fetch the value of a node. * * @param DOMNode $node Retrieve the text value for this node. * * @return string|null The text value or null if no value was identified. */ public function fetchNodeValue($node) { if (($child = $this->_fetchFirstTextNode($node)) !== null) { return $child->nodeValue; } return null; } /** * Fetch the the first text node. * * @param DOMNode $node Retrieve the text value for this node. * * @return DOMNode|null The first text node or null if no such node was * found. */ private function _fetchFirstTextNode($node) { foreach ($node->childNodes as $child) { if ($child->nodeType === XML_TEXT_NODE) { return $child; } } } /** * Store a value as a new text node. * * @param DOMNode $parent_node Attach the new node to this parent. * @param string $name Name of the new child node. * @param string $value Text value of the new child node. * * @return DOMNode The new child node. */ public function storeNewNodeValue($parent_node, $name, $value) { $node = $this->createNewNode($parent_node, $name); $this->createNodeValue($node, $name, $value); return $node; } /** * Store a value as a new text node. * * @param DOMNode $parent_node Attach the new node to this parent. * @param string $name Name of the new child node. * @param string $value Text value of the new child node. * * @return DOMNode The new child node. */ public function createNodeValue($parent_node, $name, $value) { $node = $this->_xmldoc->createTextNode($value); $parent_node->appendChild($node); return $node; } /** * Append an XML snippet. * * @param DOMNode $parent_node Attach the XML below this parent. * @param string $xml The XML to append. * * @return DOMNode The new child node. */ public function appendXml($parent_node, $xml) { $node = $this->_xmldoc->createDocumentFragment(); $node->appendXML($xml); $parent_node->appendChild($node); return $node; } /** * Create a new node. * * @param DOMNode $parent_node Attach the new node to this parent. * @param string $name Name of the new child node. * * @return DOMNode The new child node. */ public function createNewNode($parent_node, $name) { $node = $this->_xmldoc->createElement($name); $parent_node->appendChild($node); return $node; } /** * Store a value as a new text node. * * @param DOMNode $node Replace the text value of this node. * @param string $value Text value of the new child node. * * @return NULL */ public function replaceFirstNodeTextValue($node, $value) { if (($child = $this->_fetchFirstTextNode($node)) !== null) { $node->removeChild($child); } $new_node = $this->_xmldoc->createTextNode($value); if (empty($node->childNodes)) { $node->appendChild($new_node); } else { $node->insertBefore($new_node, $node->childNodes->item(0)); } } /** * Return a single named node matching the given XPath query. * * @param string $query The query. * * @return DOMNode|false The named DOMNode or empty if no node was found. */ public function findNode($query) { $result = $this->_xpath->query($query); if ($result->length) { return $result->item(0); } return false; } /** * Return a single named node below the given context matching the given * XPath query. * * @param string $query The query. * @param DOMNode $context Search below this node. * * @return DOMNode|false The named DOMNode or empty if no node was found. */ public function findNodeRelativeTo($query, DOMNode $context) { $result = $this->_xpath->query($query, $context); if ($result->length) { return $result->item(0); } return false; } /** * Return all nodes matching the given XPath query. * * @param string $query The query. * * @return DOMNodeList The list of DOMNodes. */ public function findNodes($query) { return $this->_xpath->query($query); } /** * Return all nodes matching the given XPath query. * * @param string $query The query. * @param DOMNode $context Search below this node. * * @return DOMNodeList The list of DOMNodes. */ public function findNodesRelativeTo($query, DOMNode $context) { return $this->_xpath->query($query, $context); } /** * Remove named nodes from a parent node. * * @param DOMNode $parent_node The parent node. * @param string $name The name of the children to be removed. * * @return NULL */ public function removeNodes($parent_node, $name) { foreach ($this->findNodesRelativeTo('./' . $name, $parent_node) as $child) { $parent_node->removeChild($child); } } /** * Output the document as XML string. * * @return string The XML output. */ public function __toString() { return $this->_xmldoc->saveXML(); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Hprefs.php0000664000175000017500000000246612653734733022122 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML handler for client preferences. * * Copyright 2007-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Hprefs extends Horde_Kolab_Format_Xml { /** * The name of the root element. * * @var string */ protected $_root_name = 'h-prefs'; /** * Specific data fields for the prefs object * * @var Kolab */ protected $_fields_specific = array( 'application' => 'Horde_Kolab_Format_Xml_Type_PrefsApplication', 'categories' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'pref' => 'Horde_Kolab_Format_Xml_Type_Multiple_String', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Note.php0000664000175000017500000000271612653734733021576 0ustar janjan * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML handler for note groupware objects. * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Thomas Jarosch * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Note extends Horde_Kolab_Format_Xml { /** * The name of the root element. * * @var string */ protected $_root_name = 'note'; /** * Specific data fields for the prefs object * * @var Kolab */ protected $_fields_specific = array( 'summary' => self::TYPE_STRING, 'background-color' => 'Horde_Kolab_Format_Xml_Type_Color_Background', 'foreground-color' => 'Horde_Kolab_Format_Xml_Type_Color_Foreground', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Parser.php0000664000175000017500000000763012653734733022125 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Handles parsing the provided XML input. * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Parser { /** * The XML parser. * * @var DOMDocument */ private $_document; /** * Constructor. * * @param DOMDocument $document The XML parser. */ public function __construct(DOMDocument $document) { $this->_document = $document; $this->_document->preserveWhiteSpace = false; $this->_document->formatOutput = true; } /** * Simply return the DOMDocument without parsing any data. * * @return DOMDocument The DOM document. */ public function getDocument() { return $this->_document; } /** * Load an object based on the given XML string. * * @param string $input The XML of the message as string. * @param array $options Additional options when parsing the XML. *
     * - relaxed: Relaxed error checking (default: false)
     * 
* * @return DOMDocument The DOM document. * * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. */ public function parse($input, $options = array()) { if (is_resource($input)) { rewind($input); $input = stream_get_contents($input); } try { return $this->_parseXml($input, $options); } catch (Horde_Kolab_Format_Exception_ParseError $e) { if (!function_exists('mb_detect_encoding')) { throw $e; } /** * If the first call does not return successfully this might mean we * got an attachment with broken encoding. There are some Kolab * client versions in the wild that might have done that. So the * next section starts a second attempt by guessing the encoding and * trying again. */ if (0 !== strcasecmp( mb_detect_encoding($input, 'UTF-8, ISO-8859-1'), 'UTF-8' )) { $input = mb_convert_encoding($input, 'UTF-8', 'ISO-8859-1'); } return $this->_parseXml($input, $options); } } /** * Parse the XML string. The root node is returned on success. * * @param string $input The XML of the message as string. * @param array $options Additional options when parsing the XML. * * @return DOMDocument The DOM document. * * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. */ private function _parseXml($input, $options = array()) { $result = @$this->_document->loadXML($input); if (!empty($options['relaxed'])) { return $this->_document; } if (!$result) { throw new Horde_Kolab_Format_Exception_ParseError($input); } if (empty($this->_document->documentElement)) { throw new Horde_Kolab_Format_Exception_ParseError($input); } if (!$this->_document->documentElement->hasChildNodes()) { throw new Horde_Kolab_Format_Exception_ParseError($input); } return $this->_document; } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml/Task.php0000664000175000017500000000454412653734733021574 0ustar janjan * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML handler for task groupware objects. * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Thomas Jarosch * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Task extends Horde_Kolab_Format_Xml { /** * The name of the root element. * * @var string */ protected $_root_name = 'task'; /** * Specific data fields for the prefs object * * @var Kolab */ protected $_fields_specific = array( 'summary' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'location' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'organizer' => 'Horde_Kolab_Format_Xml_Type_Composite_SimplePerson', 'start-date' => 'Horde_Kolab_Format_Xml_Type_DateTime', 'alarm' => 'Horde_Kolab_Format_Xml_Type_Integer', 'recurrence' => 'Horde_Kolab_Format_Xml_Type_Composite_Recurrence', 'attendee' => 'Horde_Kolab_Format_Xml_Type_Multiple_Attendee', 'priority' => 'Horde_Kolab_Format_Xml_Type_TaskPriority', 'completed' => 'Horde_Kolab_Format_Xml_Type_TaskCompletion', 'status' => 'Horde_Kolab_Format_Xml_Type_TaskStatus', 'due-date' => 'Horde_Kolab_Format_Xml_Type_DateTime', 'parent' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'horde-estimate' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', 'horde-alarm-methods' => 'Horde_Kolab_Format_Xml_Type_String_MaybeMissing', ); } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Date.php0000664000175000017500000001063312653734733021003 0ustar janjan * @author Thomas Jarosch * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab date handling functions. Based upon Kolab.php from Stuart Binge. * * Copyright 2004-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Stuart Binge * @author Thomas Jarosch * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Date { /** * Parse the provided string into a PHP DateTime object. * * @todo Drop in version 3.0.0. * * @param string $date_time The Kolab date-time value. * * @return DateTime The date-time value represented as PHP DateTime object. */ public static function readUtcDateTime($date_time) { return self::readDateTime($date_time); } /** * Parse the provided string into a PHP DateTime object. * * @todo Drop $timezone parameter in version 3.0.0. * * @param string $date The Kolab date value. * @param string $timezone The associated timezone. Deprecated. * * @return DateTime The date-time value represented as PHP DateTime object. */ public static function readDate($date, $timezone = null) { if (empty($date)) { return false; } return DateTime::createFromFormat( '!Y-m-d', $date ); } /** * Parse the provided string into a PHP DateTime object. * * @todo Drop $timezone parameter in version 3.0.0. * * @param string $date_time The Kolab date-time value. * @param string $timezone The associated timezone. Deprecated. * * @return DateTime The date-time value represented as PHP DateTime object. */ public static function readDateTime($date_time, $timezone = null) { if (empty($date_time)) { return false; } try { $date = new DateTime($date_time); $date->setTimezone(new DateTimeZone('UTC')); return $date; } catch (Exception $e) { return false; } } /** * Parse the provided string into a PHP DateTime object. * * @todo Drop $timezone parameter in version 3.0.0. * * @param string $date The string representation of the date (& time). * @param string $timezone The associated timezone. Deprecated. * * @return DateTime The date-time value represented as PHP DateTime object. */ public static function readDateOrDateTime($date, $timezone = null) { if (empty($date)) { return null; } return strlen($date) == 10 ? self::readDate($date, $timezone) : self::readDateTime($date, $timezone); } /** * Write the provided PHP DateTime object into a Kolab format UTC date-time * representation. * * @todo Drop in version 3.0.0. * * @param DateTime $date_time The PHP DateTime object. * * @return string The Kolab format UTC date-time string. */ public static function writeUtcDateTime(DateTime $date_time) { return self::writeDateTime($date_time); } /** * Write the provided PHP DateTime object into a Kolab format date-time * representation. * * @param DateTime $date_time The PHP DateTime object. * * @return string The Kolab format date-time string. */ public static function writeDateTime(DateTime $date_time) { $date_time->setTimezone(new DateTimeZone('UTC')); return $date_time->format('Y-m-d\TH:i:s\Z'); } /** * Write the provided PHP DateTime object into a Kolab format date * representation. * * @param DateTime $date The PHP DateTime object. * * @return string The Kolab format UTC date string. */ public static function writeDate(DateTime $date) { return $date->format('Y-m-d'); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Exception.php0000664000175000017500000000153512653734733022065 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * This class provides the standard error class for Kolab Format exceptions. * * Copyright 2009-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Exception extends Horde_Exception_Wrapped { }Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Factory.php0000664000175000017500000001242412653734733021535 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * A factory for generating Kolab format handlers. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Factory { /** * Parameters for the parser construction. * * @var array */ private $_params; /** * Constructor. * * @param array $params Additional parameters for the creation of parsers. */ public function __construct(array $params = array()) { $this->_params = $params; } /** * Generates a handler for a specific Kolab object type. * * @param string $format The format that the handler should work with. * @param string $type The object type that should be handled. * @param array $params Additional parameters. *
     * 'version' - The format version.
     * 
* * @return Horde_Kolab_Format The handler. * * @throws Horde_Kolab_Format_Exception If the specified handler does not * exist. */ public function create($format = 'Xml', $type = '', array $params = array()) { switch ($type) { case 'h-ledger': $type_class = 'Envelope'; break; default: $type_class = Horde_String::ucfirst(Horde_String::lower(str_replace('-', '', $type))); break; } $parser = Horde_String::ucfirst(Horde_String::lower($format)); $class = basename('Horde_Kolab_Format_' . $parser . '_' . $type_class); $params = array_merge($this->_params, $params); if (class_exists($class)) { switch ($parser) { case 'Xml': $instance = new $class($this->createXmlParser(), $this, $params); break; default: throw new Horde_Kolab_Format_Exception( sprintf( 'Failed to initialize the specified parser (Parser type %s does not exist)!', $parser ) ); } } else { throw new Horde_Kolab_Format_Exception( sprintf( 'Failed to load the specified Kolab Format handler (Class %s does not exist)!', $class ) ); } if (!empty($params['memlog'])) { if (!class_exists('Horde_Support_Memory')) { throw new Horde_Kolab_Format_Exception('The Horde_Support package seems to be missing (Class Horde_Support_Memory is missing)!'); } $instance = new Horde_Kolab_Format_Decorator_Memory( $instance, new Horde_Support_Memory(), $params['memlog'] ); } if (!empty($params['timelog'])) { if (!class_exists('Horde_Support_Timer')) { throw new Horde_Kolab_Format_Exception('The Horde_Support package seems to be missing (Class Horde_Support_Timer is missing)!'); } $instance = new Horde_Kolab_Format_Decorator_Timed( $instance, new Horde_Support_Timer(), $params['timelog'] ); } return $instance; } /** * Generates a XML parser. * * @return Horde_Kolab_Format_Xml_Parser The parser. */ public function createXmlParser() { return new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); } /** * Generates a XML helper instance. * * @param DOMDocument $xmldoc The XML document the helper works with. * * @return Horde_Kolab_Format_Xml_Helper The helper utility. */ public function createXmlHelper(DOMDocument $xmldoc) { return new Horde_Kolab_Format_Xml_Helper($xmldoc); } /** * Generates a XML type that deals with XML data modifications. * * @param string $type The value type. * @param array $params Additional parameters. * * @return Horde_Kolab_Format_Xml_Type The type. * * @throws Horde_Kolab_Format_Exception If the specified type does not * exist. */ public function createXmlType($type, $params = array()) { if (isset($params['api-version'])) { $class = $type . '_V' . $params['api-version']; } else { $class = $type; } if (class_exists($class)) { return new $class($this); } else if (class_exists($type)) { return new $type($this); } else { throw new Horde_Kolab_Format_Exception( sprintf('XML type %s not supported!', $type) ); } } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format/Xml.php0000664000175000017500000002076212653734733020672 0ustar janjan * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Kolab XML to array hash converter. * * For implementing a new format type you will have to inherit this * class and provide a _load/_save function. * * Copyright 2007-2009 Klarälvdalens Datakonsult AB * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Thomas Jarosch * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml implements Horde_Kolab_Format { /** * Defines a XML value that should get a default value if missing */ const PRODUCT_ID = __CLASS__; /** * Defines a XML value that should get a default value if missing */ const VALUE_DEFAULT = 0; /** * Defines a XML value that may be missing */ const VALUE_MAYBE_MISSING = 1; /** * Defines a XML value that may not be missing */ const VALUE_NOT_EMPTY = 2; /** * Defines a XML value that will be calculated by its own function */ const VALUE_CALCULATED = 3; /** * Defines a XML value as string type */ const TYPE_STRING = 'Horde_Kolab_Format_Xml_Type_String'; /** * Defines a XML value as integer type */ const TYPE_INTEGER = 'Horde_Kolab_Format_Xml_Type_Integer'; /** * Defines a XML value as boolean type */ const TYPE_BOOLEAN = 'Horde_Kolab_Format_Xml_Type_Boolean'; /** * Defines a XML value as date type */ const TYPE_DATE = 'Horde_Kolab_Format_Xml_Type_Date'; /** * Defines a XML value as datetime type */ const TYPE_DATETIME = 'Horde_Kolab_Format_Xml_Type_DateTime'; /** * Defines a XML value as date or datetime type */ const TYPE_DATE_OR_DATETIME = 'Horde_Kolab_Format_Xml_Type_DateTime'; /** * Defines a XML value as color type */ const TYPE_COLOR = 'Horde_Kolab_Format_Xml_Type_Color'; /** * Defines a XML value as composite value type */ const TYPE_COMPOSITE = 'Horde_Kolab_Format_Xml_Type_Composite'; /** * Defines a XML value as array type */ const TYPE_MULTIPLE = 'Horde_Kolab_Format_Xml_Type_Multiple'; /** * Defines a XML value as raw XML */ const TYPE_XML = 'Horde_Kolab_Format_Xml_Type_XmlAppend'; /** * Represents the Kolab format root node */ const TYPE_ROOT = 'Horde_Kolab_Format_Xml_Type_Root'; /** * The parser dealing with the input. * * @var Horde_Kolab_Format_Xml_Parser */ protected $_parser; /** * The factory for additional objects. * * @var Horde_Kolab_Format_Factory */ protected $_factory; /** * Requested version of the data array to return * * @var int */ protected $_version = 2; /** * The XML document this driver works with. * * @var DOMDocument */ protected $_xmldoc = null; /** * The name of the root element. * * @var string */ protected $_root_name = 'kolab'; /** * Kolab format version of the root element. * * @var string */ protected $_root_version = '1.0'; /** * Specific data fields for the contact object * * @var array */ protected $_fields_specific; /** * Constructor * * @param Horde_Kolab_Format_Xml_Parser $parser The XML parser. * @param Horde_Kolab_Format_Factory $factory The factory for helper * objects. * @param array $params Any additional options. */ public function __construct( Horde_Kolab_Format_Xml_Parser $parser, Horde_Kolab_Format_Factory $factory, $params = null ) { $this->_parser = $parser; $this->_factory = $factory; if (is_array($params) && isset($params['version'])) { $this->_version = $params['version']; } else { $this->_version = 2; } } /** * Throw the parser instance away. * * @return NULL */ private function _refreshParser() { $this->_parser = null; } /** * Fetch the XML parser. * * @return Horde_Kolab_Format_Xml_Parser The parser. */ private function _getParser() { if ($this->_parser === null) { $this->_parser = $this->_factory->createXmlParser(); } return $this->_parser; } /** * Load an object based on the given XML stream. The stream may only contain * UTF-8 data. * * @param resource $xml The XML stream of the message. * @param array $options Additional options when parsing the XML. *
     * - relaxed: Relaxed error checking (default: false)
     * 
* * @return array The data array representing the object. * * @throws Horde_Kolab_Format_Exception If parsing the XML data failed. * * @todo Check encoding of the returned array. It seems to be ISO-8859-1 at * the moment and UTF-8 would seem more appropriate. */ public function load($xml, $options = array()) { $this->_xmldoc = $this->_getParser()->parse($xml, $options); $this->_refreshParser(); $params = $this->_getParameters($options); $this->_getRoot($params)->load( $this->_root_name, $object, $this->_xmldoc, $this->_factory->createXmlHelper($this->_xmldoc), $params ); return $object; } /** * Convert the data to a XML stream. Strings contained in the data array may * only be provided as UTF-8 data. * * @param array $object The data array representing the object. * @param array $options Additional options when writing the XML. *
     * - previous: The previous XML text (default: empty string)
     * - relaxed: Relaxed error checking (default: false)
     * 
* * @return resource The data as XML stream. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($object, $options = array()) { if (!isset($options['previous'])) { $this->_xmldoc = $this->_getParser()->getDocument(); } else { $parse_options = $options; unset($parse_options['previous']); $this->_xmldoc = $this->_getParser()->parse( $options['previous'], $parse_options ); } $this->_refreshParser(); $params = $this->_getParameters($options); $this->_getRoot($params)->save( $this->_root_name, $object, $this->_xmldoc, $this->_factory->createXmlHelper($this->_xmldoc), $params ); return $this->_xmldoc->saveXML(); } /** * Return the API version of the data structures that are being used for in- * and output. * * @return int The version number; */ public function getVersion() { return $this->_version; } /** * Generate the internal parameter list for this operation. * * @param array $options The options for this operation. * * @return array */ private function _getParameters($options) { $params = array_merge( $options, array( 'expected-version' => $this->_root_version, 'api-version' => $this->_version ) ); if (!empty($this->_fields_specific)) { $params['attributes-specific'] = $this->_fields_specific; } return $params; } /** * Return the root handler. * * @param array $params Additional parameters. * * @return Horde_Kolab_Xml_Type_Root The root handler. */ private function _getRoot($params = array()) { return $this->_factory->createXmlType(self::TYPE_ROOT, $params); } } Horde_Kolab_Format-2.0.8/lib/Horde/Kolab/Format.php0000664000175000017500000000374512653734733020134 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * The Horde_Kolab_Format:: interface defines the basic properties of a Kolab * format handler. * * Copyright 2007-2010 Klarälvdalens Datakonsult AB * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you did not * receive this file, see * http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ interface Horde_Kolab_Format { /** The package version */ const VERSION = '2.0.8'; /** * Load an object based on the given XML stream. The stream may only contain * UTF-8 data. * * @param resource $xml The XML stream of the message. * @param array $options Additional options when parsing the XML. See the * concrete parsers for additional information. * * @return array The data array representing the object. * * @throws Horde_Kolab_Format_Exception */ public function load($xml, $options = array()); /** * Convert the data to a XML stream. Strings contained in the data array may * only be provided as UTF-8 data. * * @param array $object The data array representing the object. * @param array $options Additional options when writing the XML. See the * concrete parsers for additional information. * * @return resource The data as XML stream. * * @throws Horde_Kolab_Format_Exception */ public function save($object, $options = array()); } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/contact-kyr.xml0000664000175000017500000000230112653734733024450 0ustar janjan 20110111175940.2085781xeofrt3ks@legolas.home.edu 2011-01-11T15:59:41Z 2011-01-11T16:05:27Z public Horde::Kolab леле Какакака ле г леле Какакака Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/contact_address.xml0000664000175000017500000000162712653734733025364 0ustar janjan 1 1970-01-01T00:00:00Z 1970-01-01T00:00:00Z public Horde_Kolab_Format_Xml-@version@ (api version: 2) User Name
business Blumenlandstr. 1 Güldenburg Nordrhein-Westfalen 12345 DE
home WölkchenКакакака 1 & SOMEWHERE 12345 US
Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/contact_category.xml0000664000175000017500000000101312653734733025541 0ustar janjan 1 Test,Test 2,Test\,3 1970-01-01T00:00:00Z 1970-01-01T00:00:00Z public Horde::Kolab User Name User Name user@example.org Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/contact_mail.xml0000664000175000017500000000105612653734733024655 0ustar janjan 1 1970-01-01T00:00:00Z 1970-01-01T00:00:00Z public Horde_Kolab_Format_Xml-@version@ (api version: 2) User Name User Name user@example.org Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/contact_pgp.xml0000664000175000017500000000113412653734733024516 0ustar janjan 1 1970-01-01T00:00:00Z 1970-01-01T00:00:00Z public Horde_Kolab_Format_Xml-@version@ (api version: 2) User Name User Name user@example.org PGP Test Key Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/event_umlaut.xml0000664000175000017500000000131512653734733024726 0ustar janjan KOrganizer 3.3 (proko2 branch after 2.1.5), Kolab resource libkcal-543769073.139 2006-03-16T15:00:53Z 2007-01-25T11:36:40Z public 1 2006-03-15T18:30:00Z Summary Orga Nizer orga.nizer@example.com ...übbe... 0 busy 2007-03-15T20:00:00Z Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/event_umlaut_broken.xml0000664000175000017500000000131412653734733026265 0ustar janjan KOrganizer 3.3 (proko2 branch after 2.1.5), Kolab resource libkcal-543769073.139 2006-03-16T15:00:53Z 2007-01-25T11:36:40Z public 1 2006-03-15T18:30:00Z Summary Orga Nizer orga.nizer@example.com ...übbe... 0 busy 2007-03-15T20:00:00Z Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/preferences_read_old.xml0000664000175000017500000000052612653734733026353 0ustar janjan 1 1970-01-01T00:00:00Z 1970-01-01T00:00:00Z public Horde::Kolab Test test Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/preferences_write_old.xml0000664000175000017500000000046212653734733026571 0ustar janjan 1 1970-01-01T00:00:00Z public Horde_Kolab_Format_Xml-@version@ (api version: 2) Test test Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/recur.xml0000664000175000017500000000263512653734733023344 0ustar janjan KOrganizer 3.3 (proko2 branch after 2.1.5), Kolab resource libkcal-543769073.139 2006-03-16T15:00:53Z 2007-01-25T11:36:40Z public 1 2006-03-15T18:30:00Z Summary Orga Nizer orga.nizer@example.com 1 wednesday 2007-01-24 2006-04-05 2006-04-12 2006-07-19 2006-07-26 2006-08-02 2006-08-09 2006-08-16 2006-08-23 2006-07-12 2006-09-06 2006-09-13 2006-10-18 2006-10-25 2006-12-27 2007-01-17 2007-01-10 2007-01-03 0 busy 2007-03-15T20:00:00Z Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/recur_complete.xml0000664000175000017500000000170512653734733025231 0ustar janjan KOrganizer 3.3 (proko2 branch after 2.1.5), Kolab resource libkcal-543769073.139 2006-03-16T15:00:53Z 2007-01-25T11:36:40Z public 1 2006-03-15T18:30:00Z Summary Orga Nizer orga.nizer@example.com 1 wednesday 2007-01-24 2006-04-05 2006-04-05 2006-07-19 2006-07-26 0 busy 2007-03-15T20:00:00Z Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/recur_fail.xml0000664000175000017500000000256412653734733024340 0ustar janjan KOrganizer 3.3 (proko2 branch after 2.1.5), Kolab resource libkcal-543769073.139 2006-03-16T15:00:53Z 2007-01-25T11:36:40Z public 1 2006-03-15T18:30:00Z Summary Orga Nizer orga.nizer@example.com wednesday 2007-01-24 2006-04-05 2006-04-12 2006-07-19 2006-07-26 2006-08-02 2006-08-09 2006-08-16 2006-08-23 2006-07-12 2006-09-06 2006-09-13 2006-10-18 2006-10-25 2006-12-27 2007-01-17 2007-01-10 2007-01-03 0 busy 2006-03-15T20:00:00Z Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/fixtures/task.xml0000664000175000017500000000163412653734733023164 0ustar janjan 1e2f91e4977abfec573916f351db3e14 TEST Variable 2007-10-29T06:32:14Z 2007-11-12T15:40:04Z public Horde::Kolab Finish project description 2007-11-06T23:00:00Z 1 1 100 not-started 2007-11-07T18:00:00Z 30 Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Integration/ContactTest.php0000664000175000017500000000662312653734733025061 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the contact XML format. * * Copyright 2007-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Integration_ContactTest extends Horde_Kolab_Format_TestCase { public function testSingleEmail() { $contact = $this->_getContact(); $object = array( 'uid' => '1', 'name' => array( 'full-name' => 'User Name', ), 'email' => array( array( 'smtp-address' => 'user@example.org', 'display-name' => 'User Name' ) ), 'creation-date' => new DateTime('1970-01-01T00:00:00Z') ); $xml = $contact->save($object); $expect = file_get_contents(__DIR__ . '/../fixtures/contact_mail.xml'); $this->assertEquals( $this->removeLastModification($expect), $this->removeLastModification($xml) ); } public function testCategories() { $contact = $this->_getContact(); $xml = file_get_contents(__DIR__ . '/../fixtures/contact_category.xml'); $object = $contact->load($xml); $this->assertEquals(array('Test', 'Test 2', 'Test,3'), $object['categories']); } public function testUtf8() { $contact = $this->_getContact(); $xml = file_get_contents(__DIR__ . '/../fixtures/contact-kyr.xml'); $object = $contact->load($xml); $this->assertEquals('леле Какакака', $object['name']['full-name']); } public function testAddresses() { $contact = $this->_getContact(); $xml = file_get_contents(__DIR__ . '/../fixtures/contact_address.xml'); $object = $contact->load($xml); $this->assertEquals( array( array( 'type' => 'business', 'street' => 'Blumenlandstr. 1', 'locality' => 'Güldenburg', 'region' => 'Nordrhein-Westfalen', 'postal-code' => '12345', 'country' => 'DE', ), array( 'type' => 'home', 'street' => 'WölkchenКакакака 1', 'locality' => '&', 'region' => 'SOMEWHERE', 'postal-code' => '12345', 'country' => 'US', ) ), $object['address'] ); } private function _getContact() { $factory = new Horde_Kolab_Format_Factory(); return $factory->create('Xml', 'Contact'); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Integration/EventTest.php0000664000175000017500000000324212653734733024541 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test event handling. * * Copyright 2007-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Integration_EventTest extends Horde_Kolab_Format_TestCase { /** * Test for https://www.intevation.de/roundup/kolab/issue3525 * * @return NULL */ public function testIssue3525() { $xml = $this->getFactory()->create('XML', 'event'); // Load XML $event = file_get_contents( __DIR__ . '/../fixtures/event_umlaut.xml' ); $result = $xml->load($event); // Check that the xml loads fine $this->assertEquals('...übbe...', $result['body']); $xml = $this->getFactory()->create('XML', 'event'); // Load XML $event = file_get_contents( __DIR__ . '/../fixtures/event_umlaut_broken.xml' ); $result = $xml->load($event); $this->assertEquals('...übbe...', $result['body']); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Integration/PreferencesTest.php0000664000175000017500000000620312653734733025721 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the preferences XML format. * * Copyright 2007-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Integration_PreferencesTest extends Horde_Kolab_Format_TestCase { public function testLoadOldPrefs() { $object = $this->_loadOld(); $this->assertContains('test', $object['pref']); } public function testLoadOldApplication() { $object = $this->_loadOld(); $this->assertEquals('Test', $object['application']); } public function testOverwrite() { $preferences = $this->_getHprefs(); $xml = file_get_contents( __DIR__ . '/../fixtures/preferences_read_old.xml' ); $object = array( 'uid' => 1, 'pref' => array('test'), 'categories' => 'Test' ); $xml = $preferences->save($object, array('previous' => $xml)); $expect = file_get_contents( __DIR__ . '/../fixtures/preferences_write_old.xml' ); $this->assertEquals( $this->removeLastModification($expect), $this->removeLastModification($xml) ); } public function testCreationDateOnApiV1() { $preferences = $this->_getHprefsV1(); $object = array( 'uid' => 1, 'pref' => array('test'), 'categories' => 'Test', 'creation-date' => new DateTime('@1') ); $xml = $preferences->save($object); $this->assertEquals( ' 1 1970-01-01T00:00:01Z public Horde_Kolab_Format_Xml-@version@ (api version: 1) Test test ', $this->removeLastModification($xml) ); } private function _loadOld() { $preferences = $this->_getHprefs(); $xml = file_get_contents( __DIR__ . '/../fixtures/preferences_read_old.xml' ); return $preferences->load($xml); } private function _getHprefs() { $factory = new Horde_Kolab_Format_Factory(); return $factory->create('Xml', 'Hprefs'); } private function _getHprefsV1() { $factory = new Horde_Kolab_Format_Factory(); return $factory->create('Xml', 'Hprefs', array('version' => 1)); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Integration/RecurrenceTest.php0000664000175000017500000001151412653734733025556 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test recurrence handling * * Copyright 2007-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Integration_RecurrenceTest extends Horde_Kolab_Format_TestCase { public function testBug6388() { $xml = $this->getFactory()->create('XML', 'event'); $recur = file_get_contents(__DIR__ . '/../fixtures/recur_fail.xml'); // Check that the xml fails because of a missing interval value try { $xml->load($recur); $this->assertTrue(false); } catch (Exception $e) { $this->assertTrue($e instanceof Horde_Kolab_Format_Exception); } } public function testRecurrenceEnd() { $object = $this->_loadExclusions(); $this->assertInstanceOf('DateTime', $object['recurrence']['range']); } public function testExclusion() { $object = $this->_loadExclusions(); $this->assertTrue( $this->_hasDate( $object['recurrence']['exclusion'], '2006-08-16' ) ); } public function testExclusion2() { $object = $this->_loadExclusions(); $this->assertTrue( $this->_hasDate( $object['recurrence']['exclusion'], '2006-10-18' ) ); } public function testReloadedRecurrenceEnd() { $object = $this->_reloadExclusions(); $this->assertInstanceOf('DateTime', $object['recurrence']['range']); } public function testReloadedExclusion() { $object = $this->_reloadExclusions(); $this->assertTrue( $this->_hasDate( $object['recurrence']['exclusion'], '2006-08-16' ) ); } public function testReloadedExclusion2() { $object = $this->_reloadExclusions(); $this->assertTrue( $this->_hasDate( $object['recurrence']['exclusion'], '2006-10-18' ) ); } public function testComplete() { $object = $this->_loadComplete(); $this->assertTrue( $this->_hasDate( $object['recurrence']['complete'], '2006-04-05' ) ); } public function testComplete2() { $object = $this->_loadComplete(); $this->assertTrue( $this->_hasDate( $object['recurrence']['complete'], '2006-07-26' ) ); } public function testReloadedComplete() { $object = $this->_reloadComplete(); $this->assertTrue( $this->_hasDate( $object['recurrence']['complete'], '2006-04-05' ) ); } public function testReloadedComplete2() { $object = $this->_reloadComplete(); $this->assertTrue( $this->_hasDate( $object['recurrence']['complete'], '2006-07-26' ) ); } private function _hasDate($dates, $date) { foreach ($dates as $value) { if ($value->format('Y-m-d') == $date) { return true; } } return false; } private function _loadExclusions() { return $this->getFactory()->create('XML', 'event')->load( file_get_contents(__DIR__ . '/../fixtures/recur.xml') ); } private function _reloadExclusions() { $parser = $this->getFactory()->create('XML', 'event'); $object = $parser->load( file_get_contents(__DIR__ . '/../fixtures/recur.xml') ); $xml = $parser->save($object); return $parser->load($xml); } private function _loadComplete() { return $this->getFactory()->create('XML', 'event')->load( file_get_contents(__DIR__ . '/../fixtures/recur_complete.xml') ); } private function _reloadComplete() { $parser = $this->getFactory()->create('XML', 'event'); $object = $parser->load( file_get_contents(__DIR__ . '/../fixtures/recur_complete.xml') ); $xml = $parser->save($object); return $parser->load($xml); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Integration/TaskTest.php0000664000175000017500000000242612653734733024365 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test task handling. * * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Integration_TaskTest extends Horde_Kolab_Format_TestCase { /** * Test basic task handling */ public function testBasicTask() { $xml = $this->getFactory()->create('XML', 'task'); // Load XML $task = file_get_contents(__DIR__ . '/../fixtures/task.xml'); $result = $xml->load($task); // Check that the xml loads fine $this->assertEquals($result['body'], 'TEST'); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Integration/XmlTest.php0000664000175000017500000001006012653734733024214 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the XML format. * * Copyright 2007-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Integration_XmlTest extends Horde_Kolab_Format_TestCase { public function testBasic() { $this->assertContains( ' ', $this->_getPlain()->save(array(), array('relaxed' => true)) ); } public function testReadable() { $xml = $this->_getPlain(); $first = $xml->save(array(), array('relaxed' => true)); $object = $xml->load($first, array('relaxed' => true)); $this->assertEquals('1.0', $object['_format-version']); } public function testRoundtrip() { $xml = $this->_getPlain(); $first = $xml->save(array(), array('relaxed' => true)); $second = $xml->save( $xml->load($first, array('relaxed' => true)), array('relaxed' => true) ); $this->assertEquals( $this->removeLastModification($first), $this->removeLastModification($second) ); } public function testRoundtripWithPrevious() { $xml = $this->_getPlain(); $first = $xml->save(array(), array('relaxed' => true)); $second = $xml->save( $xml->load($first, array('relaxed' => true)), array('relaxed' => true, 'previous' => $first) ); $this->assertEquals( $this->removeLastModification($first), $this->removeLastModification($second) ); } public function testRoundtripWithPreviousOnApiV1() { $xml = new Horde_Kolab_Format_Xml( new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ), new Horde_Kolab_Format_Factory(), array('version' => 1) ); $first = $xml->save(array('uid' => 1)); $second = $xml->save($xml->load($first)); $this->assertEquals( $this->removeLastModification($first), $this->removeLastModification($second) ); } public function testReload() { $xml = $this->_getPlain(); $cdate = new DateTime('1970-01-01T00:00:00Z'); $cdate->setTimezone(new DateTimeZone('UTC')); $result = $xml->save( array( 'uid'=>'test', 'body' => 'body', 'dummy' => 'hello', 'creation-date' => $cdate ) ); $object = $xml->load($result); $this->assertEquals('body', $object['body']); $this->assertTrue(!isset($object['dummy'])); $this->assertEquals('public', $object['sensitivity']); $this->assertEquals($cdate, $object['creation-date']); $now = new DateTime('now', new DateTimeZone('UTC')); $this->assertTrue( $object['last-modification-date']->format('U') <= $now->format('U') ); $this->assertEquals( 'Horde_Kolab_Format_Xml-@version@ (api version: 2)', $object['product-id'] ); } private function _getPlain() { return new Horde_Kolab_Format_Xml( new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ), new Horde_Kolab_Format_Factory() ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Stub/BooleanDefault.php0000664000175000017500000000041512653734733024135 0ustar janjanelements = $params['array']; unset($params['array']); } if (isset($params['value'])) { $this->value = $params['value']; unset($params['value']); } if (isset($params['default'])) { $this->default = $params['default']; unset($params['default']); } return parent::load($name, $attributes, $parent_node, $helper, $params); } public function save( $name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array() ) { if (isset($params['array'])) { $this->elements = $params['array']; unset($params['array']); } if (isset($params['value'])) { $this->value = $params['value']; unset($params['value']); } if (isset($params['default'])) { $this->default = $params['default']; unset($params['default']); } return parent::save($name, $attributes, $parent_node, $helper, $params); } }Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Stub/DateTimeDefault.php0000664000175000017500000000064012653734733024252 0ustar janjandefault = array('date' => new DateTime()); parent::__construct($factory); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Stub/DateTimeNotEmpty.php0000664000175000017500000000036312653734733024447 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * A dummy object type. * * Copyright 2007-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Xml_Dummy extends Horde_Kolab_Format_Xml { /** * Save the object creation date. * * @param DOMNode $node The parent node to attach the child * to. * @param string $name The name of the node. * @param mixed $value The value to store. * @param boolean $missing Has the value been missing? * * @return DOMNode The new child node. */ function _saveValue($node, $name, $value, $missing) { $result =''; $result .= $name . ': '; $result .= $value; if ($missing) { $result .= ', missing'; } return $this->_saveDefault($node, $name, $result, array('type' => self::TYPE_STRING)); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Stub/IntegerDefault.php0000664000175000017500000000041312653734733024151 0ustar janjanlog[] = $message; } }Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Stub/MultipleDefault.php0000664000175000017500000000042512653734733024352 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the decorator for memory measurements. * * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Decorator_MemoryTest extends Horde_Kolab_Format_TestCase { public function testConstructor() { $this->getFactory()->create( 'XML', 'contact', array('memlog' => true) ); } public function testLogLoad() { $timed = $this->_getMemoryMock(); $a = ''; $timed->load($a); $this->assertContains( 'Kolab Format data parsing complete. Memory usage:', array_pop($this->logger->log) ); } public function testLogSave() { $timed = $this->_getMemoryMock(); $a = array(); $timed->save($a); $this->assertContains( 'Kolab Format data generation complete. Memory usage:', array_pop($this->logger->log) ); } private function _getMemoryMock() { $this->logger = new Horde_Kolab_Format_Stub_Log(); return new Horde_Kolab_Format_Decorator_Memory( $this->getMock('Horde_Kolab_Format'), new Horde_Support_Memory(), $this->logger ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Decorator/TimedTest.php0000664000175000017500000000525012653734733025101 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the decorator for time measurements. * * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Decorator_TimedTest extends Horde_Kolab_Format_TestCase { public function testConstructor() { $this->getFactory()->create( 'XML', 'contact', array('timelog' => true) ); } public function testTimeSpent() { $timed = $this->_getTimedMock(); $a = ''; $timed->load($a); $this->assertInternalType( 'float', $timed->timeSpent() ); } public function testTimeSpentIncreases() { $timed = $this->_getTimedMock(); $a = ''; $timed->load($a); $t_one = $timed->timeSpent(); $timed->save(array()); $this->assertTrue( $t_one < $timed->timeSpent() ); } public function testLogLoad() { $timed = $this->_getTimedMock(); $a = ''; $timed->load($a); $this->assertContains( 'Kolab Format data parsing complete. Time spent:', array_pop($this->logger->log) ); } public function testLogSave() { $timed = $this->_getTimedMock(); $a = array(); $timed->save($a); $this->assertContains( 'Kolab Format data generation complete. Time spent:', array_pop($this->logger->log) ); } public function testNoLog() { $timed = new Horde_Kolab_Format_Decorator_Timed( $this->getMock('Horde_Kolab_Format'), new Horde_Support_Timer(), true ); $a = array(); $timed->save($a); } private function _getTimedMock() { $this->logger = new Horde_Kolab_Format_Stub_Log(); return new Horde_Kolab_Format_Decorator_Timed( $this->getMock('Horde_Kolab_Format'), new Horde_Support_Timer(), $this->logger ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Exception/MissingUidTest.php0000664000175000017500000000220712653734733026125 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the MissingUid exception. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Exception_MissingUidTest extends PHPUnit_Framework_TestCase { public function testMissingUidTest() { $exception = new Horde_Kolab_Format_Exception_MissingUid(); $this->assertEquals( 'No UID in the Kolab XML object!', $exception->getMessage() ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Exception/MissingValueTest.php0000664000175000017500000000262512653734733026464 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the MissingValue exception. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Exception_MissingValueTest extends PHPUnit_Framework_TestCase { public function testMissingValueTest() { $exception = new Horde_Kolab_Format_Exception_MissingValue('value'); $this->assertEquals( 'Data value for "value" is empty in the Kolab XML object!', $exception->getMessage() ); } public function testParseErrorValue() { $exception = new Horde_Kolab_Format_Exception_MissingValue('value'); $this->assertEquals( 'value', $exception->getValue() ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Exception/ParseErrorTest.php0000664000175000017500000000352512653734733026142 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the ParseError exception. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Exception_ParseErrorTest extends PHPUnit_Framework_TestCase { public function testParseError() { $exception = new Horde_Kolab_Format_Exception_ParseError('error'); $this->assertEquals( "Failed parsing Kolab object input data of type string! Input was:\nerror", $exception->getMessage() ); } public function testParseErrorInput() { $exception = new Horde_Kolab_Format_Exception_ParseError('error'); $this->assertEquals( 'error', $exception->getInput() ); } public function testLongParseError() { $exception = new Horde_Kolab_Format_Exception_ParseError( 'error67890error67890error67890error67890error67890error67890' ); $this->assertEquals( "Failed parsing Kolab object input data of type string! Input was:\nerror67890error67890error67890error67890error67890... [shortened to 50 characters]", $exception->getMessage() ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/BooleanTest.php0000664000175000017500000001216312653734733025156 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the boolean attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_BooleanTest extends Horde_Kolab_Format_TestCase { public function testLoadTrue() { $attributes = $this->load( ' truec' ); $this->assertTrue($attributes['boolean']); } public function testLoadFalse() { $attributes = $this->load( ' falsec' ); $this->assertFalse($attributes['boolean']); } public function testLoadStrangeBoolean() { $attributes = $this->load( ' falsec' ); $this->assertFalse($attributes['boolean']); } public function testLoadMissingBoolean() { $attributes = $this->load( ' ' ); $this->assertFalse(isset($attributes['boolean'])); } public function testLoadDefault() { $attributes = $this->loadWithClass( 'Horde_Kolab_Format_Stub_BooleanDefault' ); $this->assertTrue($attributes['boolean']); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testLoadNotEmpty() { $this->loadWithClass('Horde_Kolab_Format_Stub_BooleanNotEmpty'); } public function testLoadNotEmptyRelaxed() { $attributes = $this->loadWithClass( 'Horde_Kolab_Format_Stub_BooleanNotEmpty', null, array('relaxed' => true) ); $this->assertFalse(isset($attributes['boolean'])); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( null, array('boolean' => true) ) ); } public function testSaveTrue() { $this->assertEquals( ' true ', $this->saveToXml( null, array('boolean' => true) ) ); } public function testSaveFalse() { $this->assertEquals( ' false ', $this->saveToXml( null, array('boolean' => false) ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' falsec ', $this->saveToXml( ' STRANGEc', array('boolean' => false) ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { $this->saveWithClass('Horde_Kolab_Format_Stub_BooleanNotEmpty'); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testSaveInvalidBoolean() { $this->saveWithClass( 'Horde_Kolab_Format_Stub_IntegerNotEmpty', null, array(), array('boolean' => 'INVALID') ); } public function testSaveNotEmptyWithOldValue() { $this->assertInstanceOf( 'DOMNode', $this->saveWithClass( 'Horde_Kolab_Format_Stub_BooleanNotEmpty', ' STRANGEc' ) ); } public function testSaveNotEmptyRelaxed() { $this->assertFalse( $this->saveWithClass( 'Horde_Kolab_Format_Stub_IntegerNotEmpty', null, array('relaxed' => true) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_Boolean'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/ColorTest.php0000664000175000017500000001533612653734733024662 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the color attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_ColorTest extends Horde_Kolab_Format_TestCase { public function testLoadColor() { $attributes = $this->load( ' #09aFAfc', array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) ); $this->assertEquals('#09aFAf', $attributes['color']); } public function testLoadStrangeColor() { $attributes = $this->load( ' #012345c', array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) ); $this->assertEquals('#012345', $attributes['color']); } public function testLoadMissingColor() { $attributes = $this->load( ' ', array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) ); $this->assertFalse(isset($attributes['color'])); } public function testLoadDefault() { list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Stub_ColorDefault', ' ' ); $attributes = array(); $params = array(); $type->load( $this->getElement($params), $attributes, $root_node, $helper, $params ); $this->assertEquals('#abcdef', $attributes['color']); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testLoadInvalid() { $attributes = $this->load( ' #09aFAfDc', array('value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY,) ); } public function testLoadInvalidRelaxed() { $attributes = $this->load( ' #09aFAfDc', array( 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true, ) ); $this->assertEquals('#09aFAfD', $attributes['color']); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( null, array('color' => '#affcce'), array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) ) ); } public function testSaveColor() { $this->assertEquals( ' #FFFFFF ', $this->saveToXml( null, array('color' => '#FFFFFF'), array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' #000000c ', $this->saveToXml( ' STRANGEc', array('color' => '#000000'), array('value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Stub_ColorNotEmpty', ' ' ); $attributes = array(); $params = array(); $type->save( $this->getElement($params), $attributes, $root_node, $helper, $params ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testSaveInvalidColor() { $this->saveToXml( ' ', array('color' => 'INVALID'), array('value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY,) ); } public function testSaveInvalidColorRelaxed() { $this->assertEquals( ' INVALID ', $this->saveToXml( ' ', array('color' => 'INVALID'), array( 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true ) ) ); } public function testSaveNotEmptyWithOldValue() { list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Stub_ColorNotEmpty', ' STRANGEc' ); $attributes = array(); $params = array(); $this->assertInstanceOf( 'DOMNode', $type->save( $this->getElement($params), $attributes, $root_node, $helper, $params ) ); } public function testSaveNotEmptyRelaxed() { $this->assertFalse( $this->saveToReturn( ' ', array(), array( 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true, ) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_Color'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/CompositeTest.php0000664000175000017500000001603012653734733025536 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the handler for attributes with composite values. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_CompositeTest extends Horde_Kolab_Format_TestCase { public function testLoadComposite() { $attributes = $this->load( ' a&TEST', array( 'array' => array( 'uid' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'test' => 'Horde_Kolab_Format_Xml_Type_String_Empty', ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ); $this->assertEquals(array('test' => 'TEST', 'uid' => 'a&'), $attributes['composite']); } public function testLoadDefault() { $attributes = $this->load( ' ', array( 'array' => array(), 'value' => Horde_Kolab_Format_Xml::VALUE_DEFAULT, 'default' => array('X' => 'Y'), ) ); $this->assertEquals(array('X' => 'Y'), $attributes['composite']); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testLoadNotEmpty() { $attributes = $this->load( ' ', array( 'array' => array(), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ); } public function testLoadNotEmptyRelaxed() { $attributes = $this->load( ' ', array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_STRING, ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true ) ); $this->assertFalse(isset($attributes['composite'])); } public function testSaveComposite() { $this->assertEquals( ' ', $this->saveToXml( null, array('composite' => array()), array( 'array' => array( 'uid' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'test' => 'Horde_Kolab_Format_Xml_Type_String_Empty', ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ) ); } public function testSaveMaybeMissing() { $this->assertEquals( ' 1& ', $this->saveToXml( null, array('composite' => array('uid' => 1, 'test' => '&')), array( 'array' => array( 'uid' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'test' => 'Horde_Kolab_Format_Xml_Type_String_Empty', ), 'value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, ) ) ); } public function testSaveModifiesOldValue() { $this->assertEquals( ' STRANGE1&c ', $this->saveToXml( ' STRANGEc', array('composite' => array('uid' => 1, 'test' => '&')), array( 'array' => array( 'uid' => 'Horde_Kolab_Format_Xml_Type_String_Empty', 'test' => 'Horde_Kolab_Format_Xml_Type_String_Empty', ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { $this->saveToXml( ' ', array(), array( 'array' => array(), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ); } public function testSaveNotEmptyWithOldValue() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( ' STRANGEc', array(), array( 'array' => array(), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ) ); } public function testSaveNotEmptyRelaxed() { $this->assertFalse( $this->saveToReturn( ' ', array(), array( 'array' => array(), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true, ) ) ); } public function testDeleteComposite() { $this->assertEquals( ' c ', $this->saveToXml( ' STRANGEca', array(), array( 'array' => array(), 'value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, ) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Stub_Composite'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/CreationDateTest.php0000664000175000017500000001306212653734733026140 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the creation-date attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_CreationDateTest extends Horde_Kolab_Format_TestCase { public function testLoadCreationDate() { $attributes = $this->load( ' 2011-06-28T08:42:11Zc', array('element' => 'creation-date') ); $this->assertInstanceOf('DateTime', $attributes['creation-date']); } public function testLoadCreationDateValue() { $attributes = $this->load( ' 2011-06-28T08:42:11Zc', array('element' => 'creation-date') ); $this->assertEquals( 1309250531, $attributes['creation-date']->format('U') ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testLoadInvalidCreationDateValue() { $attributes = $this->load( ' 2011A-06-28T08:42:11Zc', array('element' => 'creation-date') ); } public function testLoadInvalidCreationDateValueRelaxed() { $attributes = $this->load( ' 2011A-06-28T08:42:11Zc', array( 'relaxed' => true, 'element' => 'creation-date', ) ); $this->assertFalse($attributes['creation-date']); } public function testLoadStrangeCreationDate() { $attributes = $this->load( ' 1970-01-01T00:00:00Zc', array('element' => 'creation-date') ); $this->assertEquals(0, $attributes['creation-date']->format('U')); } public function testLoadMissingCreationDate() { $attributes = $this->load( ' ', array('element' => 'creation-date') ); $this->assertInstanceOf('DateTime', $attributes['creation-date']); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn() ); } public function testSaveXml() { $this->assertEquals( ' 1970-01-01T00:00:00Z ', $this->saveToXml( null, array('creation-date' => new DateTime('1970-01-01T00:00:00Z')), array('element' => 'creation-date') ) ); } public function testSaveDoesNotTouchOldValue() { $this->assertEquals( ' 1970-01-01T00:00:00Zc ', $this->saveToXml( ' 1970-01-01T00:00:00Zc', array('creation-date' => new DateTime('1970-01-01T00:00:00Z')), array('element' => 'creation-date') ) ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testSaveFailsOverwritingOldValue() { $this->saveToXml( ' 1970-01-01T00:00:00Zc', array('creation-date' => new DateTime('1971-01-01T00:00:00Z')), array('element' => 'creation-date') ); } public function testSaveRelaxedOverwritesOldValue() { $this->assertEquals( ' 1971-01-01T00:00:00Zc ', $this->saveToXml( ' 1970-01-01T00:00:00Zc', array('creation-date' => new DateTime('1971-01-01T00:00:00Z')), array( 'relaxed' => true, 'element' => 'creation-date' ) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_CreationDate'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/DateTimeTest.php0000664000175000017500000001465012653734733025276 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the date-time attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_DateTimeTest extends Horde_Kolab_Format_TestCase { public function setUp() { date_default_timezone_set('Europe/Berlin'); } public function testLoadDate() { $attributes = $this->load( ' 2011-06-29c' ); $this->assertTrue($attributes['datetime']['date-only']); } public function testLoadDateValue() { $attributes = $this->load( ' 2011-06-29c' ); $this->assertEquals( '2011-06-29T00:00:00+02:00', $attributes['datetime']['date']->format('c') ); } public function testLoadStrangeDateTime() { $attributes = $this->load( ' 2011-06-29c' ); $this->assertEquals( '2011-06-29T00:00:00+02:00', $attributes['datetime']['date']->format('c') ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testLoadEmptyDateTime() { $attributes = $this->load( ' ' ); } public function testLoadMissingDateTime() { $attributes = $this->load( ' ' ); $this->assertFalse(isset($attributes['datetime'])); } public function testLoadDefault() { $attributes = $this->loadWithClass( 'Horde_Kolab_Format_Stub_DateTimeDefault' ); $this->assertInstanceOf('DateTime', $attributes['datetime']['date']); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testLoadNotEmpty() { $this->loadWithClass('Horde_Kolab_Format_Stub_DateTimeNotEmpty'); } public function testLoadNotEmptyRelaxed() { $attributes = $this->loadWithClass( 'Horde_Kolab_Format_Stub_DateTimeNotEmpty', null, array('relaxed' => true) ); $this->assertFalse(isset($attributes['datetime'])); } public function testSaveDateTime() { $this->assertEquals( ' 2011-06-29T11:11:11Z ', $this->saveToXml( null, array( 'datetime' => array( 'date' => new DateTime( '2011-06-29T11:11:11', new DateTimeZone('UTC') ) ) ) ) ); } public function testSaveTimeZone() { $this->assertEquals( ' 2011-06-29T09:11:11Z ', $this->saveToXml( null, array( 'datetime' => array( 'date' => new DateTime( '2011-06-29T11:11:11', new DateTimeZone('Europe/Berlin') ) ) ) ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' 2011-06-29c ', $this->saveToXml( ' STRANGEc', array( 'datetime' => array( 'date' => new DateTime( '2011-06-29T11:11:11', new DateTimeZone('Europe/Berlin') ), 'date-only' => true ) ) ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { $this->saveWithClass('Horde_Kolab_Format_Stub_DateTimeNotEmpty'); } public function testSaveNotEmptyWithOldValue() { $this->assertInstanceOf( 'DOMNode', $this->saveWithClass( 'Horde_Kolab_Format_Stub_DateTimeNotEmpty', ' STRANGEc' ) ); } public function testDeleteNode() { $this->assertEquals( ' c ', $this->saveToXml( ' STRANGEc', array() ) ); } public function testSaveNotEmptyRelaxed() { $this->assertFalse( $this->saveWithClass( 'Horde_Kolab_Format_Stub_DateTimeNotEmpty', null, array('relaxed' => true) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_DateTime'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/IntegerTest.php0000664000175000017500000001110612653734733025170 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the integer attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_IntegerTest extends Horde_Kolab_Format_TestCase { public function testLoadInteger() { $attributes = $this->load( ' 1c' ); $this->assertSame(1, $attributes['integer']); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testLoadStrangeInteger() { $attributes = $this->load( ' falsec' ); } public function testLoadMissingInteger() { $attributes = $this->load( ' ' ); $this->assertFalse(isset($attributes['integer'])); } public function testLoadDefault() { $attributes = $this->loadWithClass( 'Horde_Kolab_Format_Stub_IntegerDefault' ); $this->assertSame(10, $attributes['integer']); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testLoadNotEmpty() { $this->loadWithClass('Horde_Kolab_Format_Stub_IntegerNotEmpty'); } public function testLoadNotEmptyRelaxed() { $attributes = $this->loadWithClass( 'Horde_Kolab_Format_Stub_IntegerNotEmpty', null, array('relaxed' => true) ); $this->assertFalse(isset($attributes['integer'])); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( null, array('integer' => 1) ) ); } public function testSaveInteger() { $this->assertEquals( ' 7 ', $this->saveToXml( null, array('integer' => 7) ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' 7c ', $this->saveToXml( ' STRANGEc', array('integer' => 7) ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { $this->saveWithClass('Horde_Kolab_Format_Stub_IntegerNotEmpty'); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testSaveInvalidInteger() { $this->saveWithClass( 'Horde_Kolab_Format_Stub_IntegerNotEmpty', null, array(), array('integer' => 'INVALID') ); } public function testSaveNotEmptyWithOldValue() { $this->assertInstanceOf( 'DOMNode', $this->saveWithClass( 'Horde_Kolab_Format_Stub_IntegerNotEmpty', ' STRANGEc' ) ); } public function testSaveNotEmptyRelaxed() { $this->assertFalse( $this->saveWithClass( 'Horde_Kolab_Format_Stub_IntegerNotEmpty', null, array('relaxed' => true) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_Integer'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/ModificationDateTest.php0000664000175000017500000000703012653734733026777 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the modification-date attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_ModificationDateTest extends Horde_Kolab_Format_TestCase { public function testLoadModificationDate() { $attributes = $this->load( ' 2011-06-28T08:42:11Zc', array('element' => 'modification-date') ); $this->assertInstanceOf('DateTime', $attributes['modification-date']); } public function testLoadModificationDateValue() { $attributes = $this->load( ' 2011-06-28T08:42:11Zc', array('element' => 'modification-date') ); $this->assertEquals( 1309250531, $attributes['modification-date']->format('U') ); } public function testLoadStrangeModificationDate() { $attributes = $this->load( ' 1970-01-01T00:00:00Zc', array('element' => 'modification-date') ); $this->assertEquals(0, $attributes['modification-date']->format('U')); } public function testLoadMissingModificationDate() { $attributes = $this->load( ' ', array('element' => 'modification-date') ); $this->assertInstanceOf('DateTime', $attributes['modification-date']); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn() ); } public function testSaveXml() { $this->assertRegexp( '#\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z#', $this->saveToXml( null, array(), array('element' => 'modification-date') ) ); } public function testSaveOverwritesOldValue() { $this->assertRegexp( '#\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z#', $this->saveToXml( ' 1970-01-01T00:00:00Zc', array(), array('element' => 'modification-date') ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_ModificationDate'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/MultipleTest.php0000664000175000017500000002043212653734733025370 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the handler for attributes with multiple values. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_MultipleTest extends Horde_Kolab_Format_TestCase { public function testLoadMultiple() { $attributes = $this->load( ' a' ); $this->assertEquals(array('a'), $attributes['string']); } public function testLoadSeveralMultiple() { $attributes = $this->load( ' a Ü SOMESTRANGEONE ', array( 'array' => array('type' => Horde_Kolab_Format_Xml::TYPE_STRING), 'value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, ) ); $this->assertEquals(array('a', 'Ü', 'SOME', ''), $attributes['string']); } public function testLoadDefault() { $params = array(); list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Stub_MultipleDefault', ' ' ); $attributes = array(); $type->load( $this->getElement($params), $attributes, $root_node, $helper, $params ); $this->assertEquals(array('X'), $attributes['string']); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testLoadNotEmpty() { $params = array(); list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Stub_MultipleNotEmpty', ' ' ); $attributes = array(); $type->load( $this->getElement($params), $attributes, $root_node, $helper, $params ); } public function testLoadNotEmptyRelaxed() { $attributes = $this->load( ' ', array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_STRING, ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true ) ); $this->assertFalse(isset($attributes['string'])); } public function testSave() { $this->assertEquals( array(), $this->saveToReturn( null, array('string' => array()), array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_STRING, ), 'value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, ) ) ); } public function testSaveMultiple() { $this->assertEquals( ' aBÜ ', $this->saveToXml( null, array('string' => array('a', 'B', 'Ü', '')), array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_STRING, ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' caBÜ ', $this->saveToXml( ' STRANGEc', array('string' => array('a', 'B', 'Ü', '')), array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_STRING, ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, ) ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { $params = array(); list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Stub_MultipleNotEmpty' ); $type->save( $this->getElement($params), array(), $root_node, $helper, $params ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testSaveInvalidMultiple() { $params = array('relaxed' => false); list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Xml_Type_Multiple_Boolean' ); $type->save( 'boolean', array('boolean' => array('INVALID')), $root_node, $helper, $params ); } public function testSaveInvalidMultipleRelaxed() { $this->assertEquals( ' INVALID ', $this->saveToXml( ' ', array('string' => array('INVALID')), array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_BOOLEAN, ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true ) ) ); } public function testSaveNotEmptyWithOldValue() { $params = array(); list($helper, $root_node, $type) = $this->getXmlType( 'Horde_Kolab_Format_Stub_MultipleNotEmpty', ' STRANGEc' ); $this->assertInstanceOf( 'DOMNodeList', $type->save( $this->getElement($params), array(), $root_node, $helper, $params ) ); } public function testSaveNotEmptyRelaxed() { $this->assertFalse( $this->saveToReturn( ' ', array(), array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_STRING, ), 'value' => Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY, 'relaxed' => true, ) ) ); } public function testDeleteMultiple() { $this->assertEquals( ' c ', $this->saveToXml( ' STRANGEca', array(), array( 'array' => array( 'type' => Horde_Kolab_Format_Xml::TYPE_STRING, ), 'value' => Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING, ) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_Multiple_String'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/PrefsApplicationTest.php0000664000175000017500000001413512653734733027043 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the "application" setting for preferences. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_PrefsApplicationTest extends Horde_Kolab_Format_TestCase { public function testLoadApplication() { $attributes = $this->load( ' TESTc', array('element' => 'application') ); $this->assertEquals('TEST', $attributes['application']); } public function testLoadCategories() { $attributes = $this->load( ' TESTc', array('element' => 'application') ); $this->assertEquals('TEST', $attributes['application']); } public function testLoadStrangeApplication() { $attributes = $this->load( ' STRANGEc', array('element' => 'application') ); $this->assertEquals('STRANGE', $attributes['application']); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testLoadEmptyApplication() { $attributes = $this->load( ' ', array('element' => 'application') ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testLoadMissingApplication() { $attributes = $this->load( ' ', array('element' => 'application') ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testLoadNotEmpty() { $attributes = $this->load( ' ', array('element' => 'application') ); } public function testLoadNotEmptyRelaxed() { $attributes = $this->load( ' ', array( 'element' => 'application', 'relaxed' => true, ) ); $this->assertFalse(isset($attributes['application'])); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( null, array('application' => 'TEST'), array('element' => 'application') ) ); } public function testSaveXml() { $this->assertEquals( ' TEST ', $this->saveToXml( null, array('application' => 'TEST'), array('element' => 'application') ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' NEWc ', $this->saveToXml( ' STRANGEc', array('application' => 'NEW'), array('element' => 'application') ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { $this->saveToXml( ' ', array(), array('element' => 'application') ); } public function testSaveNotEmptyWithOldValue() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( ' STRANGEc', array(), array('element' => 'application') ) ); } public function testDeleteCategories() { $this->assertEquals( ' cCAT ', $this->saveToXml( ' CATc', array('application' => 'CAT'), array('element' => 'application') ) ); } public function testSaveNotEmptyRelaxed() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( ' ', array(), array( 'element' => 'application', 'relaxed' => true, ) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_PrefsApplication'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/ProductIdTest.php0000664000175000017500000000657612653734733025507 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the product ID attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_ProductIdTest extends Horde_Kolab_Format_TestCase { public function testLoadProductId() { $attributes = $this->load( ' SOMETHINGc', array('element' => 'product-id') ); $this->assertEquals('SOMETHING', $attributes['product-id']); } public function testLoadStrangeProductId() { $attributes = $this->load( ' STRANGEc', array('element' => 'product-id') ); $this->assertEquals('STRANGE', $attributes['product-id']); } public function testLoadMissingProductId() { $attributes = $this->load( ' ', array('element' => 'product-id') ); $this->assertEquals('', $attributes['product-id']); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( null, array(), array( 'api-version' => 2, 'element' => 'product-id', ) ) ); } public function testSaveXml() { $this->assertEquals( ' Horde_Kolab_Format_Xml-@version@ (api version: 2) ', $this->saveToXml( null, array(), array( 'api-version' => 2, 'element' => 'product-id', ) ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' Horde_Kolab_Format_Xml-@version@ (api version: 2)c ', $this->saveToXml( ' STRANGEc', array(), array( 'api-version' => 2, 'element' => 'product-id', ) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_ProductId'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/RecurrenceTest.php0000664000175000017500000000600712653734733025674 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the recurrence handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_RecurrenceTest extends Horde_Kolab_Format_TestCase { /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testEmptyInterval() { $attributes = $this->load( ' TESTc' ); $this->assertEquals(array(), $attributes['recurrence']); } /** * @expectedException Horde_Kolab_Format_Exception_ParseError */ public function testIntervalBelowZero() { $attributes = $this->load( ' -1TESTc' ); $this->assertEquals(array(), $attributes['recurrence']); } /** * @expectedException Horde_Kolab_Format_Exception_ParseError */ public function testMissingCycle() { $attributes = $this->load( ' 2TESTc' ); } /** * @expectedException Horde_Kolab_Format_Exception_ParseError */ public function testMissingWeekday() { $attributes = $this->load( ' 1TESTc' ); $this->assertEquals(array(), $attributes['recurrence']); } public function testWeekly() { $attributes = $this->load( ' 11TESTc' ); $this->assertEquals( array( 'complete' => '', 'cycle' => 'weekly', 'day' => array(1), 'exclusion' => '', 'interval' => '1', 'type' => '' ), $attributes['recurrence'] ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_Composite_Recurrence'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/RootTest.php0000664000175000017500000001414512653734733024524 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the Document root handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_RootTest extends Horde_Kolab_Format_TestCase { public function testLoadRoot() { $attributes = $this->load( ' A' ); $this->assertEquals('A', $attributes['uid']); } /** * @expectedException Horde_Kolab_Format_Exception_InvalidRoot */ public function testMissingRootNode() { $attributes = $this->load( '' ); } public function testLoadApiVersion() { $attributes = $this->load( ' A' ); $this->assertEquals('2', $attributes['_api-version']); } public function testLoadLowerApiVersion() { $attributes = $this->load( ' A', array('api-version' => '1') ); $this->assertEquals('1', $attributes['_api-version']); } /** * @expectedException Horde_Kolab_Format_Exception_InvalidRoot */ public function testLoadHigherVersion() { $attributes = $this->load( ' c' ); } public function testLoadHigherVersionRelaxed() { $attributes = $this->load( ' c', array('relaxed' => true) ); $this->assertEquals('2.0', $attributes['_format-version']); } public function testLoadVersion() { $attributes = $this->load( ' Ac' ); $this->assertEquals('1.0', $attributes['_format-version']); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn(null, array('uid' => 'A')) ); } public function testSaveCreatesNewNode() { $this->assertRegexp( '#A#', $this->saveToXml(null, array('uid' => 'A')) ); } public function testSaveDoesNotTouchExistingNode() { $this->assertRegexp( '##', $this->saveToXml( ' c', array('uid' => 'A') ) ); } public function testAddNewType() { $this->assertRegexp( '#c saveToXml( ' c', array('uid' => 'A') ) ); } /** * @expectedException Horde_Kolab_Format_Exception_InvalidRoot */ public function testOverwriteHigherVersion() { $this->saveToXml( ' c', array() ); } public function testOverwriteHigherVersionRelaxed() { $this->assertRegexp( '#saveToXml( ' c', array('uid' => 'A'), array('relaxed' => true) ) ); } public function testSetHigherVersion() { $this->assertRegexp( '#saveToXml( ' c', array('uid' => 'A'), array('expected-version' => '2.0') ) ); } public function testSaveNewVersion() { $this->assertRegexp( '#saveToXml( null, array('uid' => 'A'), array('expected-version' => '2.0') ) ); } protected function getXmlType( $type, $previous = null, $kolab_type = 'kolab', $version = '1.0' ) { $factory = new Horde_Kolab_Format_Factory(); $doc = new DOMDocument('1.0', 'UTF-8'); if ($previous !== null) { $doc->loadXML($previous); } $helper = $factory->createXmlHelper($doc); $type = $factory->createXmlType($type); return array($helper, $doc, $type); } protected function getTestType($previous, &$params) { list($params, $root_node, $type, $helper) = parent::getTestType($previous, $params); if (!isset($params['expected-version'])) { $params['expected-version'] = '1.0'; } if (!isset($params['api-version'])) { $params['api-version'] = 2; } $params['element'] = 'kolab'; return array($params, $root_node, $type, $helper); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_Root'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/StringTest.php0000664000175000017500000001240112653734733025040 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the string attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_StringTest extends Horde_Kolab_Format_TestCase { public function testLoadString() { $attributes = $this->load( ' SOMETHINGc' ); $this->assertEquals('SOMETHING', $attributes['string']); } public function testLoadStrangeString() { $attributes = $this->load( ' STRANGEc' ); $this->assertEquals('STRANGE', $attributes['string']); } public function testLoadEmptyString() { $attributes = $this->load( ' ' ); $this->assertSame('', $attributes['string']); } public function testLoadMissingString() { $attributes = $this->load( ' ' ); $this->assertFalse(isset($attributes['string'])); } public function testLoadDefault() { $attributes = $this->loadWithClass('Horde_Kolab_Format_Stub_StringDefault'); $this->assertEquals('DEFAULT', $attributes['string']); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testLoadNotEmpty() { $this->loadWithClass('Horde_Kolab_Format_Stub_StringNotEmpty'); } public function testLoadNotEmptyRelaxed() { $attributes = $this->loadWithClass( 'Horde_Kolab_Format_Stub_StringNotEmpty', null, array('relaxed' => true) ); $this->assertFalse(isset($attributes['string'])); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( null, array('string' => 'TEST') ) ); } public function testSaveXml() { $this->assertEquals( ' STRING ', $this->saveToXml( null, array('string' => 'STRING'), array() ) ); } public function testSaveOverwritesOldValue() { $this->assertEquals( ' NEWc ', $this->saveToXml( ' STRANGEc', array('string' => 'NEW'), array() ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingValue */ public function testSaveNotEmpty() { $this->saveWithClass('Horde_Kolab_Format_Stub_StringNotEmpty'); } public function testSaveNotEmptyWithOldValue() { $this->assertInstanceOf( 'DOMNode', $this->saveWithClass( 'Horde_Kolab_Format_Stub_StringNotEmpty', ' STRANGEc' ) ); } public function testDeleteNode() { $this->assertEquals( ' c ', $this->saveToXml( ' STRANGEc', array(), array() ) ); } public function testSaveNotEmptyRelaxed() { $this->assertFalse( $this->saveWithClass( 'Horde_Kolab_Format_Stub_StringNotEmpty', null, array('relaxed' => true) ) ); } public function testSaveDefaultRelaxed() { $this->assertInstanceOf( 'DOMNode', $this->saveWithClass( 'Horde_Kolab_Format_Stub_StringDefault', null, array('relaxed' => true) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_String'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/Type/UidTest.php0000664000175000017500000001333112653734733024316 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the UID attribute handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_Type_UidTest extends Horde_Kolab_Format_TestCase { public function testLoadUid() { $attributes = $this->load( ' TESTc' ); $this->assertEquals('TEST', $attributes['uid']); } public function testLoadStrangeUid() { $attributes = $this->load( ' STRANGEc' ); $this->assertEquals('STRANGE', $attributes['uid']); } /** * @expectedException Horde_Kolab_Format_Exception_MissingUid */ public function testLoadMissingUidText() { $attributes = $this->load( ' c' ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingUid */ public function testLoadMissingUid() { $attributes = $this->load( ' c' ); } public function testLoadMissingUidRelaxed() { $attributes = $this->load( ' c', array('relaxed' => true) ); $this->assertTrue(!isset($attributes['uid'])); } public function testSave() { $this->assertInstanceOf( 'DOMNode', $this->saveToReturn( null, array('uid' => 1) ) ); } public function testSaveXml() { $this->assertEquals( ' 1 ', $this->saveToXml( null, array('uid' => 1) ) ); } /** * @expectedException Horde_Kolab_Format_Exception_MissingUid */ public function testSaveMissingData() { $this->saveToXml(); } public function testInvalidXml() { $this->assertEquals( ' ', $this->saveToXml( null, array(), array('relaxed' => true) ) ); } public function testNewUid() { $this->assertEquals( ' cTEST ', $this->saveToXml( ' c', array('uid' => 'TEST') ) ); } public function testOldUid() { $this->assertEquals( ' TESTc ', $this->saveToXml( ' TESTc', array('uid' => 'TEST') ) ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testOverwriteOldUid() { $this->saveToXml( ' OLDc', array('uid' => 'TEST') ); } public function testOverwriteOldUidRelaxed() { $this->assertEquals( ' TESTc ', $this->saveToXml( ' OLDc', array('uid' => 'TEST'), array('relaxed' => true) ) ); } public function testOverwriteStrangeUidRelaxed() { $this->assertEquals( ' TESTc ', $this->saveToXml( ' OLDc', array('uid' => 'TEST'), array('relaxed' => true) ) ); } public function testOverwriteStrangeUidRelaxedTwo() { $this->assertEquals( ' TESTc ', $this->saveToXml( ' c', array('uid' => 'TEST'), array('relaxed' => true) ) ); } protected function getTypeClass() { return 'Horde_Kolab_Format_Xml_Type_Uid'; } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/EnvelopeTest.php0000664000175000017500000000376312653734733024441 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the XML envelope handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_EnvelopeTest extends PHPUnit_Framework_TestCase { public function testSave() { $this->assertContains( 'test', $this->_getEnvelope()->save( array('uid' => 'test', 'type' => 'test') ) ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testMissingType() { $this->assertContains( 'test', $this->_getEnvelope()->save(array('uid' => 'test')) ); } public function testType() { $this->assertContains( '', $this->_getEnvelope()->save( array('uid' => 'test', 'type' => 'test') ) ); } public function testXml() { $this->assertContains( '', $this->_getEnvelope()->save( array('uid' => 'test', 'type' => 'test', 'xml' => '') ) ); } private function _getEnvelope() { $factory = new Horde_Kolab_Format_Factory(); return $factory->create('Xml', 'Envelope'); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/Xml/ParserTest.php0000664000175000017500000001007412653734733024111 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the Xml parser. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_Xml_ParserTest extends PHPUnit_Framework_TestCase { public function testParseString() { $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $this->assertInstanceOf( 'DOMDocument', $parser->parse("\n") ); } /** * @expectedException Horde_Kolab_Format_Exception_ParseError */ public function testParseMissingChild() { $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $parser->parse("\n"); } public function testParseResource() { $data = fopen('php://temp', 'r+'); fwrite($data, "\n"); $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $this->assertInstanceOf('DOMDocument', $parser->parse($data)); } public function testParseUmlaut() { $data = fopen('php://temp', 'r+'); fwrite($data, "\n<ä/>"); $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $this->assertInstanceOf('DOMDocument', $parser->parse($data)); } public function testParseUmlautWithUtf8Encoding() { $data = fopen('php://temp', 'r+'); fwrite($data, "\n<ä/>"); $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $this->assertInstanceOf('DOMDocument', $parser->parse($data)); } /** * @expectedException Horde_Kolab_Format_Exception_ParseError */ public function testParseUmlautWrongEncoding() { $data = fopen('php://temp', 'r+'); fwrite($data, "\n<ä/>"); $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $parser->parse($data); } /** * @expectedException Horde_Kolab_Format_Exception_ParseError */ public function testSecondParseAttemptBroken() { $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $parser->parse("\n"); $parser->parse(' 4de4f1ed-b920-4af4-bdc7-5848576a7caa ^S 2011-05-31T13:49:33Z 2011-05-31T13:49:33Z public Horde::Kolab Horde continuous integration got updated #000000 #ffff00 '); } public function testParseEmpty() { $parser = new Horde_Kolab_Format_Xml_Parser( new DOMDocument('1.0', 'UTF-8') ); $this->assertInstanceOf( 'DOMDocument', $parser->parse('', array('relaxed' => true)) ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/DateTest.php0000664000175000017500000001022312653734733022766 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the date-time handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_DateTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->_oldTimezone = date_default_timezone_get(); date_default_timezone_set('Europe/Berlin'); } public function tearDown() { date_default_timezone_set($this->_oldTimezone); } /** * @dataProvider provideUtcDates */ public function testReadUtc($string_date, $epoch) { $date = Horde_Kolab_Format_Date::readUtcDateTime($string_date); if ($date === false) { $this->fail(sprintf('Failed parsing date %s!', $string_date)); } $this->assertEquals($epoch, $date->format('U')); } public function provideUtcDates() { return array( array('2010-01-31T11:27:21Z', 1264937241), array('2005-12-19T02:55:23.437689Z', 1134960923), array('2001-06-19T11:01:23Z', 992948483), array('2005-12-19T02:55:23.43Z', 1134960923), // Leap second array('1998-12-31T23:59:59Z', 915148799), array('1998-12-31T23:59:60Z', 915148800), array('1999-01-01T00:00:00Z', 915148800), array('1999-01-01T00:00:01Z', 915148801), // No leap second array('2010-12-31T23:59:59Z', 1293839999), array('2010-12-31T23:59:60Z', 1293840000), array('2011-01-01T00:00:00Z', 1293840000), array('2011-01-01T00:00:01Z', 1293840001), ); } /** * @dataProvider provideInvalidUtcDates */ public function testReadInvalidUtc($string_date) { $this->assertFalse( Horde_Kolab_Format_Date::readUtcDateTime($string_date) ); } public function provideInvalidUtcDates() { return array( array('2010A-01-31T11:27:21Z'), array('2010-A01-31T11:27:21Z'), array('2010-019-31T11:27:21Z'), array('2010-01-331T11:27:21Z'), array('2010-01-33X11:27:21Z'), array('2005-12-19T02:55:23.x437689Z'), array('2005-12-19T02:55:23.437689809890787324'), ); } /** * @dataProvider provideUtcExportDates */ public function testWriteUtc($string_date, $result) { $date = Horde_Kolab_Format_Date::readUtcDateTime($string_date); $this->assertEquals( $result, Horde_Kolab_Format_Date::writeUtcDateTime($date) ); } public function provideUtcExportDates() { return array( array('2010-01-31T11:27:21Z', '2010-01-31T11:27:21Z'), array('2005-12-19T02:55:23.437689Z', '2005-12-19T02:55:23Z'), array('2001-06-19T11:01:23Z', '2001-06-19T11:01:23Z'), array('2005-12-19T02:55:23.43Z', '2005-12-19T02:55:23Z'), // Leap second array('1998-12-31T23:59:59Z', '1998-12-31T23:59:59Z'), array('1998-12-31T23:59:60Z', '1999-01-01T00:00:00Z'), array('1999-01-01T00:00:00Z', '1999-01-01T00:00:00Z'), array('1999-01-01T00:00:01Z', '1999-01-01T00:00:01Z'), // No leap second array('2010-12-31T23:59:59Z', '2010-12-31T23:59:59Z'), array('2010-12-31T23:59:60Z', '2011-01-01T00:00:00Z'), array('2011-01-01T00:00:00Z', '2011-01-01T00:00:00Z'), array('2011-01-01T00:00:01Z', '2011-01-01T00:00:01Z'), ); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/FactoryTest.php0000664000175000017500000001263412653734733023530 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the factory. * * Copyright 2010-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_FactoryTest extends PHPUnit_Framework_TestCase { public function testFactory() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Xml_Contact', $factory->create('Xml', 'Contact') ); } public function testFactoryUcfirst() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Xml_Contact', $factory->create('xml', 'Contact') ); } public function testFactoryStrtolower() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Xml_Contact', $factory->create('XML', 'Contact') ); } public function testTypeUcfirst() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Xml_Contact', $factory->create('Xml', 'contact') ); } public function testTypeStrtolower() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Xml_Contact', $factory->create('Xml', 'CONTACT') ); } public function testTypeDashes() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Xml_Contact', $factory->create('Xml', 'CON--TACT') ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testFactoryException() { $factory = new Horde_Kolab_Format_Factory(); $factory->create('UNKNOWN', 'contact'); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testUnknownFormatException() { $factory = new Horde_Kolab_Format_Factory(); $factory->create('Exception', 'InvalidRoot'); } public function testTimeLog() { if (!class_exists('Horde_Support_Timer')) { $this->markTestSkipped('Horde_Support package missing!'); } $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Decorator_Timed', $factory->create('Xml', 'contact', array('timelog' => true)) ); } public function testMemoryLog() { if (!class_exists('Horde_Support_Memory')) { $this->markTestSkipped('Horde_Support package missing!'); } $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Decorator_Memory', $factory->create('Xml', 'contact', array('memlog' => true)) ); } public function testConstructorParams() { if (!class_exists('Horde_Support_Timer')) { $this->markTestSkipped('Horde_Support package missing!'); } $factory = new Horde_Kolab_Format_Factory(array('timelog' => true)); $this->assertInstanceOf( 'Horde_Kolab_Format_Decorator_Timed', $factory->create('Xml', 'contact') ); } public function testTypeFactory() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Stub_Types', $factory->createXmlType('Horde_Kolab_Format_Stub_Types') ); } public function testTypeFactoryV1() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Stub_Types_V1', $factory->createXmlType( 'Horde_Kolab_Format_Stub_Types', array('api-version' => 1) ) ); } public function testTypeFactoryV2() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Stub_Types_V2', $factory->createXmlType( 'Horde_Kolab_Format_Stub_Types', array('api-version' => 2) ) ); } public function testTypeFactoryV3() { $factory = new Horde_Kolab_Format_Factory(); $this->assertInstanceOf( 'Horde_Kolab_Format_Stub_Types', $factory->createXmlType( 'Horde_Kolab_Format_Stub_Types', array('api-version' => 3) ) ); } /** * @expectedException Horde_Kolab_Format_Exception */ public function testTypeMissing() { $factory = new Horde_Kolab_Format_Factory(); $factory->createXmlType('Horde_Kolab_Format_Stub_Types_NOSUCH'); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Unit/XmlTest.php0000664000175000017500000000314412653734733022655 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Test the DOM based XML handler. * * Copyright 2011-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_Unit_XmlTest extends PHPUnit_Framework_TestCase { /** * @expectedException Horde_Kolab_Format_Exception_MissingUid */ public function testMissingUid() { $factory = new Horde_Kolab_Format_Factory(); $note = $factory->create('Xml', 'Note'); $note->save(array()); } public function testSave() { $factory = new Horde_Kolab_Format_Factory(); $note = $factory->create('Xml', 'Note'); $this->assertContains( '', $note->save(array('uid' => 'test')) ); } public function testVersion() { $factory = new Horde_Kolab_Format_Factory(); $note = $factory->create('Xml', 'Note'); $this->assertEquals(2, $note->getVersion()); } } Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/AllTests.php0000664000175000017500000000013212653734733022063 0ustar janjanrun(); Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/Autoload.php0000664000175000017500000000261712653734733022112 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** Load the basic test definition */ require_once __DIR__ . '/TestCase.php'; /** Load stub definitions */ require_once __DIR__ . '/Stub/BooleanDefault.php'; require_once __DIR__ . '/Stub/BooleanNotEmpty.php'; require_once __DIR__ . '/Stub/ColorDefault.php'; require_once __DIR__ . '/Stub/ColorNotEmpty.php'; require_once __DIR__ . '/Stub/Composite.php'; require_once __DIR__ . '/Stub/DateTimeDefault.php'; require_once __DIR__ . '/Stub/DateTimeNotEmpty.php'; require_once __DIR__ . '/Stub/IntegerDefault.php'; require_once __DIR__ . '/Stub/IntegerNotEmpty.php'; require_once __DIR__ . '/Stub/Log.php'; require_once __DIR__ . '/Stub/Dummy.php'; require_once __DIR__ . '/Stub/MultipleNotEmpty.php'; require_once __DIR__ . '/Stub/MultipleDefault.php'; require_once __DIR__ . '/Stub/StringDefault.php'; require_once __DIR__ . '/Stub/StringNotEmpty.php'; require_once __DIR__ . '/Stub/Types.php'; Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/bootstrap.php0000664000175000017500000000014312653734733022347 0ustar janjan ../../../../lib Horde_Kolab_Format-2.0.8/test/Horde/Kolab/Format/TestCase.php0000664000175000017500000001175012653734733022053 0ustar janjan * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ /** * Basic test case. * * @category Kolab * @package Kolab_Format * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @link http://www.horde.org/libraries/Horde_Kolab_Format */ class Horde_Kolab_Format_TestCase extends PHPUnit_Framework_TestCase { private $_factory; protected function getFactory() { if ($this->_factory === null) { $this->_factory = new Horde_Kolab_Format_Factory(); } return $this->_factory; } protected function removeLastModification($text) { return preg_replace( '#.*#', '', $text ); } protected function getXmlType( $type, $previous = null, $kolab_type = 'kolab', $version = '1.0' ) { $factory = new Horde_Kolab_Format_Factory(); $doc = new DOMDocument('1.0', 'UTF-8'); if ($previous !== null) { $doc->loadXML($previous); $helper = $factory->createXmlHelper($doc); $root_node = $helper->findNode('/' . $kolab_type); } else { $helper = $factory->createXmlHelper($doc); $root_node = $helper->createNewNode($doc, $kolab_type); $root_node->setAttribute('version', $version); } $type = $factory->createXmlType($type); return array($helper, $root_node, $type); } protected function load($previous, $params = array()) { list($params, $root_node, $type, $helper) = $this->getTestType( $previous, $params ); $attributes = array(); $this->_load($type, $attributes, $root_node, $helper, $params); return $attributes; } public function loadWithClass($class, $previous = null, $params = array()) { list($helper, $root_node, $type) = $this->getXmlType($class, $previous); $attributes = array(); $this->_load($type, $attributes, $root_node, $helper, $params); return $attributes; } private function _load($type, &$attributes, $root_node, $helper, $params) { $type->load( $this->getElement($params), $attributes, $root_node, $helper, $params ); } protected function saveToXml( $previous = null, $attributes = array(), $params = array() ) { list($params, $root_node, $type, $helper) = $this->getTestType( $previous, $params ); $type->save( $this->getElement($params), $attributes, $root_node, $helper, $params ); return (string)$helper; } protected function saveToReturn( $previous = null, $attributes = array(), $params = array() ) { list($params, $root_node, $type, $helper) = $this->getTestType( $previous, $params ); return $type->save( $this->getElement($params), $attributes, $root_node, $helper, $params ); } protected function saveWithClass($class, $previous = null, $params = array(), $attributes = array()) { list($helper, $root_node, $type) = $this->getXmlType($class, $previous); return $type->save( $this->getElement($params), $attributes, $root_node, $helper, $params ); } protected function getTestType($previous, &$params) { if (isset($params['kolab_type'])) { $kolab_type = $params['kolab_type']; unset($params['kolab_type']); } else { $kolab_type = 'kolab'; } if (isset($params['version'])) { $version = $params['version']; unset($params['version']); } else { $version = '1.0'; } list($helper, $root_node, $type) = $this->getXmlType( $this->getTypeClass(), $previous, $kolab_type, $version ); return array($params, $root_node, $type, $helper); } protected function getElement(&$params) { if (isset($params['element'])) { $element = $params['element']; unset($params['element']); return $element; } else { $elements = explode('_', $this->getTypeClass()); $element = Horde_String::lower(array_pop($elements)); return $element; } } protected function getTypeClass() { throw new Exception('Override!'); } }