# Copyright (c) 2008-2011 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: RealmFile.pm,v 1.3 2011/01/12 03:15:51 nagler Exp $ package Bivio::Search::Parser::RealmFile; use strict; use Bivio::Base 'Search.Parser'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.3 $ =~ /\d+/g); my($_M) = b_use('Biz.Model'); my($_FP) = b_use('Type.FilePath'); my($_S) = b_use('Type.String'); my($_HANDLER) = _handler_map(); sub do_iterate_realm_models { my($self, $op, $req) = @_; $_M->new($req, 'RealmFile') ->do_iterate( $op, 'realm_file_id asc', {is_folder => 0}, ); return; } sub handle_new_text { return _do(@_); } sub handle_new_excerpt { return _do(@_); } sub handle_realm_file_new_excerpt { my($proto, $parseable, @rest) = @_; return undef unless my $self = ref($proto) ? $proto : $proto->new_text($parseable, @rest); return $self->put(excerpt => ${$_S->canonicalize_and_excerpt($self->get('text'))}); } sub realms_for_rebuild_db { my($self, $req) = @_; return $_M->new($req, 'RealmFile') ->map_iterate( sub {shift->get('realm_id')}, 'unauth_iterate_start', 'realm_id', {path => '/'}, ); } sub _do { my($proto) = shift; my($parseable) = @_; return unless my $handler = $_HANDLER->{$parseable->get('content_type')}; my($method) = $proto->my_caller; $method =~ s/^handle/handle_realm_file/; return unless my $self = $handler->$method(@_); return $self; } sub _handler_map { return { map({ my($c) = $_; map(($_ => $c), $c->CONTENT_TYPE_LIST), } @{__PACKAGE__->use('IO.ClassLoader') ->map_require_all('SearchParserRealmFile')}), }; } 1;