File: OODoc.pm

package info (click to toggle)
libopenoffice-oodoc-perl 2.125-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 1,660 kB
  • ctags: 603
  • sloc: perl: 11,126; makefile: 12; xml: 11
file content (221 lines) | stat: -rw-r--r-- 5,645 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#-----------------------------------------------------------------------------
#
#	$Id : OODoc.pm 2.125 2010-07-08 JMG$
#
#	Created and maintained by Jean-Marie Gouarne
#	Copyright 2010 by Genicorp, S.A. (www.genicorp.com)
#
#-----------------------------------------------------------------------------

use OpenOffice::OODoc::File		2.203;
use OpenOffice::OODoc::Meta		2.017;
use OpenOffice::OODoc::Document		2.023;
use OpenOffice::OODoc::Manifest		2.007;

#-----------------------------------------------------------------------------

package	OpenOffice::OODoc;
use 5.008_000;
use strict;
our $VERSION				= '2.125';

require Exporter;
our @ISA    = qw(Exporter);
our @EXPORT = qw
	(
	ooXPath ooText ooMeta ooManifest ooImage ooStyles
	odfXPath odfText odfMeta odfManifest odfImage odfStyles
	odfConnector odfDocument ooDocument odfPackage odfContainer ooFile
	odfLocalEncoding localEncoding ooLocalEncoding
	odfEncodeText odfDecodeText ooEncodeText ooDecodeText
	ooLocaltime ooTimelocal odfLocaltime odfTimelocal
	odfTemplatePath ooTemplatePath
	odfWorkingDirectory workingDirectory ooWorkingDirectory
	odfReadConfig readConfig ooReadConfig
	);

our $INSTALLATION_PATH;

#-----------------------------------------------------------------------------
# config loader

sub	odfReadConfig
	{
	my $filename = shift;
	unless ($filename)
		{
		$filename = $INSTALLATION_PATH . '/config.xml'
			if $INSTALLATION_PATH;
		}
	unless ($filename)
		{
		warn	"[" . __PACKAGE__ . "::odfReadConfig] "	.
			"Missing configuration file\n";
		return undef;
		}
	my $config = XML::Twig->new->safe_parsefile($filename);
	unless ($config)
		{
		warn	"[" . __PACKAGE__ . "::odfReadConfig] "	.
			"Syntax error in configuration file $filename\n";
		return undef;
		}
	my $root = $config->get_xpath('//OpenOffice-OODoc', 0);
	unless ($root && $root->isElementNode)
		{
		return undef;
		}
	foreach my $node ($root->getChildNodes)
		{
		next unless $node->isElementNode;
		my $name = $node->getName; $name =~ s/-/::/g;
		my $varname = 'OpenOffice::OODoc::' . $name;
                no strict;
		$$varname = $node->string_value;
		$$varname = odfDecodeText($$varname);
		use strict;
		}
	OpenOffice::OODoc::Styles::ooLoadColorMap();
	return 1;
	}

#-----------------------------------------------------------------------------
# accessor for local character set control

sub	odfLocalEncoding
	{
	my $newcharset = shift;
	if ($newcharset)
	    	{
	    	if (Encode::find_encoding($newcharset))
		    {
		    $OpenOffice::OODoc::XPath::LOCAL_CHARSET = $newcharset;
		    }
		else
		    {
		    warn	"[" . __PACKAGE__ . "::odfLocalEncoding] " .
				"Unsupported encoding\n";
		    }
		}
	return $OpenOffice::OODoc::XPath::LOCAL_CHARSET;
	}

#-----------------------------------------------------------------------------
# accessor for default XML templates for document creation

sub	odfTemplatePath
	{
	return OpenOffice::OODoc::File::templatePath(@_);
	}

#-----------------------------------------------------------------------------
# accessor for default working directory control

sub	odfWorkingDirectory
	{
	my $path = shift;

	$OpenOffice::OODoc::File::WORKING_DIRECTORY = $path
		if defined $path;
	OpenOffice::OODoc::File::checkWorkingDirectory
		(
		$OpenOffice::OODoc::File::WORKING_DIRECTORY
		);

	return $OpenOffice::OODoc::File::WORKING_DIRECTORY;
	}
	
#-----------------------------------------------------------------------------
# shortcuts for low-level local/utf8 code conversion 

sub	odfEncodeText
	{
	return OpenOffice::OODoc::XPath::encode_text(@_);
	}

sub	odfDecodeText
	{
	return OpenOffice::OODoc::XPath::decode_text(@_);
	}

#-----------------------------------------------------------------------------
# constructors

sub     odfDocument
        {
        return OpenOffice::OODoc::Document->new(@_);
        }

sub     odfContainer
        {
        return OpenOffice::OODoc::File->new(@_);
        }

sub     odfXPath
        {
        return OpenOffice::OODoc::XPath->new(@_);
        }
        
sub     odfText
        {
        return OpenOffice::OODoc::Text->new(@_);
        }

sub     odfStyles
        {
        return OpenOffice::OODoc::Styles->new(@_);
        }

sub     odfImage
        {
        return OpenOffice::OODoc::Image->new(@_);
        }

sub     odfMeta
        {
        return OpenOffice::OODoc::Meta->new(@_);
        }

sub     odfManifest
        {
        return OpenOffice::OODoc::Manifest->new(@_);
        }

#-----------------------------------------------------------------------------
# initialization

BEGIN
	{
	*ooDocument		= *odfDocument;
	*odfConnector		= *odfDocument;
	*odfFile                = *odfContainer;
	*odfPackage		= *odfContainer;
	*ooFile			= *odfContainer;
	*ooXPath		= *odfXPath;
	*ooText			= *odfText;
	*ooStyles		= *odfStyles;
	*ooImage		= *odfImage;
	*ooMeta			= *odfMeta;
	*ooManifest		= *odfManifest;
	*localEncoding		= *odfLocalEncoding;
	*workingDirectory	= *odfWorkingDirectory;
	*readConfig		= *odfReadConfig;
	*ooLocalEncoding	= *odfLocalEncoding;
	*ooWorkingDirectory	= *odfWorkingDirectory;
	*ooReadConfig		= *odfReadConfig;
	*ooEncodeText		= *odfEncodeText;
	*ooDecodeText		= *odfDecodeText;
	*ooTemplatePath		= *odfTemplatePath;
	*odfLocaltime		= *OpenOffice::OODoc::XPath::odfLocaltime;
	*odfTimelocal		= *OpenOffice::OODoc::XPath::odfTimelocal;
	*ooLocaltime		= *odfLocaltime;
	*ooTimelocal		= *odfTimelocal;
	
	my $module_path = $INC{"OpenOffice/OODoc.pm"};
	$module_path =~ s/\.pm$//;
	$INSTALLATION_PATH = $module_path;
	odfReadConfig() if ( -e "$INSTALLATION_PATH/config.xml" );
	}

#-----------------------------------------------------------------------------
1;