package AxKit::App::TABOO::XSP::Language; use 5.6.0; use strict; use warnings; use Apache::AxKit::Language::XSP::SimpleTaglib; use Apache::AxKit::Exception; use AxKit; use AxKit::App::TABOO::Data::Language; use AxKit::App::TABOO::Data::Plurals::Languages; use Time::Piece ':override'; use XML::LibXML; use vars qw/$NS/; our $VERSION = '0.4'; =head1 NAME AxKit::App::TABOO::XSP::Language - Language management tag library for TABOO =head1 SYNOPSIS Add the language: namespace to your XSP Cxsp:pageE> tag, e.g.: Add this taglib to AxKit (via httpd.conf or .htaccess): AxAddXSPTaglib AxKit::App::TABOO::XSP::Language =head1 DESCRIPTION This XSP taglib provides two tags to retrieve a structured XML fragment with all information of a single language or all languages of a certain type. L has been used to write this taglib. =cut $NS = 'http://www.kjetil.kjernsmo.net/software/TABOO/NS/Language'; package AxKit::App::TABOO::XSP::Language::Handlers; =head1 Tag Reference =head2 Cget-language lang="foo"/E> This tag will replace itself with some structured XML containing all fields of languages of type C. It relates to the TABOO Data object L, and calls on that to do the hard work. The root element of the returned object is C and each language is wrapped in an element C and contains C and C. =cut sub get_language : struct attribOrChild(lang) { return << 'EOC' my $lang = AxKit::App::TABOO::Data::Language->new(); $lang->load(limit => {code => $attr_lang}); my $doc = XML::LibXML::Document->new(); my $root = $doc->createElementNS('http://www.kjetil.kjernsmo.net/software/TABOO/NS/Language/Output', 'lang:languages'); $doc->setDocumentElement($root); $doc = $lang->write_xml($doc, $root); $doc; EOC } =head2 Cget-languages/E> This tag will replace itself with some structured XML containing all languages. It relates to the TABOO Data object L, and calls on that to do the hard work. The root element of the returned object is C and each language is wrapped in an element C, and ordered alphabetically by local name. =cut # TODO: The code will also be available in an attribute C, sub get_languages : struct attribOrChild(code,onlycontent) { return << 'EOC' my $langs = AxKit::App::TABOO::Data::Plurals::Languages->new(); $langs->load(orderby => 'localname'); my $doc = XML::LibXML::Document->new(); my $root = $doc->createElementNS('http://www.kjetil.kjernsmo.net/software/TABOO/NS/Language/Output', 'lang:languages'); $doc->setDocumentElement($root); $doc = $langs->write_xml($doc, $root); $doc; EOC } =head2 Cexists lang="foo"/E> This tag will check if a language allready exists. It is a boolean tag, which has child elements CtrueE> and CfalseE>. It takes a lang parameter, which may be given as an attribute or a child element named C, and if the language is found in the data store, the contents of CtrueE> child element is included, otherwise, the contents of CfalseE> is included. =cut sub exists : attribOrChild(lang) { return ''; # Gotta be something here } sub exists___true__open { return << 'EOC'; my $lang = AxKit::App::TABOO::Data::Language->new(); if ($lang->load(what => '1', limit => {lang => $attr_lang})) { EOC } sub exists___true { return '}' } sub exists___false__open { return << 'EOC'; my $lang = AxKit::App::TABOO::Data::Language->new(); unless ($lang->load(what => '1', limit => {lang => $attr_lang})) { EOC } sub exists___false { return '}' } 1; =head1 FORMALITIES See L. =cut