| 1 | #/*==================================================================== | ||
| 2 | # * Babel Objects, Version 1.0 | ||
| 3 | # * ==================================================================== | ||
| 4 | # * | ||
| 5 | # * Copyright (c) 2000 The Babel Objects Network. All rights reserved. | ||
| 6 | # * | ||
| 7 | # * This source file is subject to version 1.1 of The Babel Objects | ||
| 8 | # * License, that is bundled with this package in the file LICENSE, | ||
| 9 | # * and is available through the world wide web at : | ||
| 10 | # * | ||
| 11 | # * http://www.BabelObjects.Org/law/license/1.1.txt | ||
| 12 | # * | ||
| 13 | # * If you did not receive a copy of the Babel Objects license and are | ||
| 14 | # * unable to obtain it through the world wide web, please send a note | ||
| 15 | # * to license@BabelObjects.Org so we can mail you a copy immediately. | ||
| 16 | # * | ||
| 17 | # * -------------------------------------------------------------------- | ||
| 18 | # * | ||
| 19 | # * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | ||
| 20 | # * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 21 | # * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| 22 | # * DISCLAIMED. IN NO EVENT SHALL THE BABEL OBJECTS NETWORK OR | ||
| 23 | # * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 24 | # * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 25 | # * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
| 26 | # * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
| 27 | # * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| 28 | # * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
| 29 | # * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | # * SUCH DAMAGE. | ||
| 31 | # * | ||
| 32 | # * ==================================================================== | ||
| 33 | # * | ||
| 34 | # * This software consists of voluntary contributions made by many | ||
| 35 | # * individuals on behalf of The Babel Objects Network. For more | ||
| 36 | # * information on The Babel Objects Network, please see | ||
| 37 | # * <http://www.BabelObjects.org/>. | ||
| 38 | # * | ||
| 39 | # */ | ||
| 40 | |||
| 41 | package BabelObjects::Component::Directory::Bookmark; | ||
| 42 | |||
| 43 | use Carp; | ||
| 44 | use strict; | ||
| 45 | |||
| 46 | use BabelObjects::Util::Dvlpt::Log; | ||
| 47 | use URI::Bookmarks; | ||
| 48 | |||
| 49 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); | ||
| 50 | |||
| 51 | require Exporter; | ||
| 52 | require AutoLoader; | ||
| 53 | |||
| 54 | @ISA = qw(Exporter AutoLoader); | ||
| 55 | # Items to export into callers namespace by default. Note: do not export | ||
| 56 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 57 | # Do not simply export all your public functions/methods/constants. | ||
| 58 | @EXPORT = qw( | ||
| 59 | ); | ||
| 60 | $VERSION = '1.00'; | ||
| 61 | |||
| 62 | my $ROAMING_DIR = "/opt/www/www.babelobjects.org/roaming"; | ||
| 63 | |||
| 64 | my $aLog; | ||
| 65 | my $bookmark; | ||
| 66 | my $file; | ||
| 67 | |||
| 68 | my %fields = ( | ||
| 69 | runData => undef | ||
| 70 | ); | ||
| 71 | |||
| 72 | sub new { | ||
| 73 | my $proto = shift; | ||
| 74 | my $args = shift; | ||
| 75 | |||
| 76 | my $class = ref($proto) || $proto; | ||
| 77 | |||
| 78 | my $self = { | ||
| 79 | _permitted => \%fields, | ||
| 80 | %fields | ||
| 81 | }; | ||
| 82 | |||
| 83 | bless ($self, $class); | ||
| 84 | |||
| 85 | my %parameters = %$args; | ||
| 86 | |||
| 87 | $aLog = new BabelObjects::Util::Dvlpt::Log(); | ||
| 88 | $aLog->log("\n-- BabelObjects::Component::Directory::Bookmark --"); | ||
| 89 | |||
| 90 | foreach (keys %parameters) { | ||
| 91 | # the following lines are useful to verify argument values | ||
| 92 | #$aLog->log("Before : $_ = ".$parameters{$_}); | ||
| 93 | $self->$_($parameters{$_}); | ||
| 94 | #$aLog->log("After : $_ = ".$self->$_); | ||
| 95 | } | ||
| 96 | |||
| 97 | my $user = $self->runData->getParameter("user"); | ||
| 98 | if (! $user) { | ||
| 99 | $user = "default"; | ||
| 100 | } | ||
| 101 | |||
| 102 | $file = $self->verifyAndCorrectBookmark($user); | ||
| 103 | $bookmark = new URI::Bookmarks(file => $file); | ||
| 104 | |||
| 105 | return $self; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub verifyAndCorrectBookmark { | ||
| 109 | my $self = shift; | ||
| 110 | my $user = shift; | ||
| 111 | |||
| 112 | my $file = "$ROAMING_DIR/$user/bookmarks"; | ||
| 113 | |||
| 114 | open(FILE, "$file"); | ||
| 115 | open(NEWFILE, ">$file.html"); | ||
| 116 | while(<FILE>) { | ||
| 117 | s/\cM//g; | ||
| 118 | print NEWFILE $_; | ||
| 119 | } | ||
| 120 | close(NEWFILE); | ||
| 121 | close(FILE); | ||
| 122 | |||
| 123 | return "$ROAMING_DIR/$user/bookmarks.html"; | ||
| 124 | } | ||
| 125 | |||
| 126 | sub t_go { | ||
| 127 | my $self = shift; | ||
| 128 | |||
| 129 | return "OK"; | ||
| 130 | } | ||
| 131 | |||
| 132 | sub getBoInfo { | ||
| 133 | my $self = shift; | ||
| 134 | |||
| 135 | # this method is a little silly because the information | ||
| 136 | # is redundant between here and xml file | ||
| 137 | |||
| 138 | my %attributes = (); | ||
| 139 | |||
| 140 | # BO Tags that can be called in bo page | ||
| 141 | |||
| 142 | $attributes{"folders"} = "FOLDERS"; | ||
| 143 | $attributes{"title"} = "Title"; | ||
| 144 | $attributes{"urls"} = "URLS"; | ||
| 145 | |||
| 146 | # BO Transitions that are called with T input field | ||
| 147 | # Please note that "t_" is automatically added | ||
| 148 | # do not put "t_" in your T var | ||
| 149 | |||
| 150 | $attributes{"t_go"} = "t_go"; | ||
| 151 | |||
| 152 | return %attributes; | ||
| 153 | } | ||
| 154 | |||
| 155 | sub getFolders { | ||
| 156 | my $self = shift; | ||
| 157 | my $root = shift; | ||
| 158 | |||
| 159 | my @folders; | ||
| 160 | |||
| 161 | my @daughters = $root->daughters; | ||
| 162 | |||
| 163 | foreach (@daughters) { | ||
| 164 | if ($_->type eq "folder") { | ||
| 165 | push(@folders, $_); | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | return @folders; | ||
| 170 | } | ||
| 171 | |||
| 172 | sub getUrls { | ||
| 173 | my $self = shift; | ||
| 174 | my $root = shift; | ||
| 175 | |||
| 176 | my @urls; | ||
| 177 | |||
| 178 | my @daughters = $root->daughters; | ||
| 179 | |||
| 180 | foreach (@daughters) { | ||
| 181 | if ($_->type eq "bookmark") { | ||
| 182 | push(@urls, $_); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | return @urls; | ||
| 187 | } | ||
| 188 | |||
| 189 | sub getFOLDERS { | ||
| 190 | my $self = shift; | ||
| 191 | |||
| 192 | my @folders; | ||
| 193 | my $aFolder = $self->runData->getParameter("folder"); | ||
| 194 | my $user = $self->runData->getParameter("user"); | ||
| 195 | |||
| 196 | if ($aFolder eq "") { | ||
| 197 | @folders = $self->getFolders($bookmark->tree_root()); | ||
| 198 | } else { | ||
| 199 | @folders = $self->getFolders(($bookmark->name_to_nodes($aFolder))[0]); | ||
| 200 | #$aLog->log(@folders." folders"); | ||
| 201 | } | ||
| 202 | |||
| 203 | print "<table><tr><td>"; | ||
| 204 | print "<dl>\n"; | ||
| 205 | my $middle = @folders / 2; | ||
| 206 | my $i = 0; | ||
| 207 | foreach (@folders) { | ||
| 208 | $i = $i + 1; | ||
| 209 | # According to the visualization mode, | ||
| 210 | # we create one or more columns | ||
| 211 | print "<dt><a href=\"javascript:submitForFolder('".$user."','".$_->name."')\">" | ||
| 212 | .$_->name | ||
| 213 | ."</a>\n"; | ||
| 214 | if ($i == $middle) { | ||
| 215 | print "</dl></td><td><dl>"; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | print "</dl>\n"; | ||
| 219 | print "</td></tr></table>"; | ||
| 220 | } | ||
| 221 | |||
| 222 | sub getURLS { | ||
| 223 | my $self = shift; | ||
| 224 | |||
| 225 | my @urls; | ||
| 226 | my $aFolder = $self->runData->getParameter("folder"); | ||
| 227 | |||
| 228 | if ($aFolder eq "") { | ||
| 229 | @urls = $self->getUrls($bookmark->tree_root()); | ||
| 230 | } else { | ||
| 231 | #@urls = $self->lookup($aFolder); | ||
| 232 | @urls = $self->getUrls($bookmark->name_to_nodes($aFolder)); | ||
| 233 | } | ||
| 234 | |||
| 235 | print "<dl>\n"; | ||
| 236 | foreach (@urls) { | ||
| 237 | # According to the visualization mode, | ||
| 238 | # we create one or more columns | ||
| 239 | print "<dt><a target=\"out\" " | ||
| 240 | ."href=\"".$_->attributes->{HREF}."\">" | ||
| 241 | .$_->name | ||
| 242 | ."</a>"; | ||
| 243 | print "<dt>", $_->attributes->{description}, "\n"; | ||
| 244 | print "<dt><font size=-1>", $_->attributes->{HREF}, "</font>\n"; | ||
| 245 | } | ||
| 246 | print "</dl>"; | ||
| 247 | } | ||
| 248 | |||
| 249 | sub getTitle { | ||
| 250 | my $self = shift; | ||
| 251 | |||
| 252 | return $bookmark->title(); | ||
| 253 | } | ||
| 254 | |||
| 255 | sub getValue { | ||
| 256 | my $self = shift; | ||
| 257 | my $key = shift; | ||
| 258 | my $x; | ||
| 259 | |||
| 260 | my $doc = $self->parameters; | ||
| 261 | my $context = $self->context; | ||
| 262 | |||
| 263 | foreach $x ($doc->$context->parameter) { | ||
| 264 | my $name = $x->name->getString; | ||
| 265 | if (lc($name) eq $key) { | ||
| 266 | return $x->value->getString; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | return "PB"; | ||
| 271 | } | ||
| 272 | |||
| 273 | sub AUTOLOAD { | ||
| 274 | my $self = shift; | ||
| 275 | my $type = ref($self) or croak "$self is not an object"; | ||
| 276 | |||
| 277 | my $name = $AUTOLOAD; | ||
| 278 | $name =~ s/.*://; # strip fully-qualified portion | ||
| 279 | |||
| 280 | unless (exists $self->{_permitted}->{$name} ) { | ||
| 281 | # croak "Can't access `$name' field in class $type"; | ||
| 282 | # On intercepte ici les erreurs liées aux tentatives d'appel | ||
| 283 | # des méthodes inexistantes | ||
| 284 | #$aLog->log("AUTOLOAD : $self = $AUTOLOAD -->"); | ||
| 285 | $aLog->log("Can't access `$name' field in class $type"); | ||
| 286 | return $AUTOLOAD; | ||
| 287 | } | ||
| 288 | |||
| 289 | if (@_) { | ||
| 290 | return $self->{$name} = shift; | ||
| 291 | } else { | ||
| 292 | return $self->{$name}; | ||
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 296 | 1; | ||
| 297 | |||
| 298 | __END__ |