Change getMimeType and setMimeType to response->content_type.

This commit is contained in:
Colin Kuskie 2010-11-21 22:35:26 -08:00
parent e5adc07a05
commit fd8f03a186
52 changed files with 138 additions and 175 deletions

View file

@ -434,10 +434,10 @@ sub www_editSubmission {
if( $params->{asHashRef} ) {
return { text => $content, title => $title, };
} elsif( $session->form->get('asJson') ) {
$session->http->setMimeType( 'application/json' );
$session->response->content_type( 'application/json' );
return JSON->new->encode( { text => $content, title => $title, id => $assetId ne 'new' ? $assetId : 'new' . rand } );
} else {
$session->http->setMimeType( 'text/html' );
$session->response->content_type( 'text/html' );
return $asset->processStyle( $content );
}
}

View file

@ -217,11 +217,11 @@ sub www_editSubmissionForm {
return { text => $content, title => $title, };
}
elsif ( $session->form->get('asJson') ) {
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode( { text => $content, title => $title, id => 'list' . rand } );
}
else {
$session->http->setMimeType('text/html');
$session->response->content_type('text/html');
return $parent->ems->processStyle($content);
}
} ## end else [ if ( scalar(@$res) == ...)]
@ -292,10 +292,10 @@ sub www_editSubmissionForm {
; # not setting mimie type
}
elsif ( $session->form->get('asJson') ) {
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
}
else {
$session->http->setMimeType('text/html');
$session->response->content_type('text/html');
}
my $content = $asset->processTemplate( {
errors => $params->{errors} || [],

View file

@ -547,7 +547,7 @@ sub www_download {
my $storage = $self->getStorageLocation;
$self->session->http->setMimeType( "image/jpeg" );
$self->session->response->content_type( "image/jpeg" );
$self->session->http->setLastModified( $self->getContentLastModified );
my $resolution = $self->session->form->get("resolution");

View file

@ -857,7 +857,7 @@ sub www_getAttributes {
return $session->privilege->noAccess() unless $self->canView;
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
my @results;
my @categories = keys %{$self->getParent->getCategories};
@ -904,7 +904,7 @@ sub www_getScreenshots {
return $self->session->privilege->noAccess() unless $self->canView;
$self->session->http->setMimeType('text/xml');
$self->session->response->content_type('text/xml');
my $xml = qq |<?xml version="1.0" encoding="UTF-8"?>
<content>
@ -958,7 +958,7 @@ sub www_getScreenshotsConfig {
return $self->session->privilege->noAccess() unless $self->canView;
$self->session->http->setMimeType('text/xml');
$self->session->response->content_type('text/xml');
return $self->processTemplate($var,$self->getParent->get("screenshotsConfigTemplateId"));
}

View file

@ -288,7 +288,7 @@ sub www_view {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canView;
my $mimeType=$self->mimeType;
$self->session->http->setMimeType($mimeType || 'text/html');
$self->session->response->content_type($mimeType || 'text/html');
$self->session->http->setCacheControl($self->cacheTimeout);
my $output = $self->view(1);
if (!defined $output) {

View file

@ -575,7 +575,7 @@ sub process {
# Return a JSONinfied version of vars if JSON is the only requested content type.
if ( defined $session->request && $session->request->header('Accept') eq 'application/json' ) {
$session->http->setMimeType( 'application/json' );
$session->response->content_type( 'application/json' );
return to_json( $vars );
}

View file

@ -1816,7 +1816,7 @@ sub www_ical {
# Set mime of text/icalendar
#$self->session->http->setMimeType("text/plain");
#$self->session->response->content_type("text/plain");
$self->session->http->setFilename("feed.ics","text/calendar");
return $ical;
}

View file

@ -231,7 +231,7 @@ Get the data asynchronously.
sub www_ajaxGetData {
my $self = shift;
$self->session->http->setMimeType("application/json");
$self->session->response->content_type("application/json");
return $self->getDataJson;
}
@ -253,7 +253,7 @@ sub www_ajaxUpdateData {
$data ||= $self->data;
$self->session->http->setMimeType("application/json");
$self->session->response->content_type("application/json");
return $data;
}

View file

@ -823,9 +823,9 @@ sub www_addSubmission {
my $title = $i18n->get('select form to submit') ;
my $asJson = $session->form->get('asJson');
if( $asJson ) {
$session->http->setMimeType( 'application/json' );
$session->response->content_type( 'application/json' );
} else {
$session->http->setMimeType( 'text/html' );
$session->response->content_type( 'text/html' );
}
my $content = '<h1>' . $title . '</h1><ul>' . $listOfLinks . '</ul>' ;
if( $asJson ) {
@ -1377,7 +1377,7 @@ sub www_getAllSubmissions {
push @{ $tableInfo->{ records } }, \%fields;
}
$session->http->setMimeType( 'application/json' );
$session->response->content_type( 'application/json' );
return JSON->new->encode( $tableInfo );
}
@ -1414,7 +1414,7 @@ sub www_getBadgesAsJson {
$results{'startIndex'} = 0;
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode(\%results);
}
@ -1444,7 +1444,7 @@ sub www_getSubmissionById {
$result->{title} = $submissionId;
$result->{id} = $submissionId;
}
$self->session->http->setMimeType('application/json');
$self->session->response->content_type('application/json');
return JSON->new->encode($result);
}
@ -1461,7 +1461,7 @@ sub www_getRegistrantAsJson {
my $session = $self->session;
my $db = $session->db;
return $session->privilege->insufficient() unless $self->canView;
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
my @tickets = ();
my @tokens = ();
my @ribbons = ();
@ -1640,7 +1640,7 @@ sub www_getRegistrantsAsJson {
$results{'dir'} = "asc";
# build json datasource
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode(\%results);
}
@ -1675,7 +1675,7 @@ sub www_getRibbonsAsJson {
$results{'startIndex'} = 0;
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode(\%results);
}
@ -1788,7 +1788,7 @@ sub www_getScheduleDataJSON {
$results{totalDatePages} = scalar(@dateRecords);
$results{currentDatePage} = $datePageNumber;
$results{dateRecords} = \@dateRecords;
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode(\%results);
}
@ -1944,7 +1944,7 @@ className='WebGUI::Asset::Sku::EMSTicket' and state='published' and revisionDate
$results{'startIndex'} = $startIndex;
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode(\%results);
}
@ -1981,7 +1981,7 @@ sub www_getTokensAsJson {
$results{'startIndex'} = 0;
$results{'sort'} = undef;
$results{'dir'} = "asc";
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode(\%results);
}
@ -2065,7 +2065,7 @@ sub www_importEventsSave {
$|=1;
# set up
$session->http->setMimeType("text/plain");
$session->response->content_type("text/plain");
my $start = [Time::HiRes::gettimeofday];
my $i18n = WebGUI::International->new($session,'Asset_EventManagementSystem');
my $csv = Text::CSV_XS->new({ binary => 1 });

View file

@ -1145,11 +1145,11 @@ sub www_addAlbumService {
lastUpdated => $date->epochToHuman($album->revisionDate, '%y-%m-%d %j:%n:%s'),
};
if ($as eq "xml") {
$session->http->setMimeType('text/xml');
$session->response->content_type('text/xml');
return XML::Simple::XMLout($document, NoAttr => 1);
}
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->pretty->encode($document);
}
@ -1206,7 +1206,7 @@ sub www_listAlbumsRss {
push @{ $var->{albums} }, $assetVar;
}
$self->session->http->setMimeType('text/xml');
$self->session->response->content_type('text/xml');
return $self->processTemplate( $var, $self->templateIdListAlbumsRss );
}
@ -1344,10 +1344,10 @@ sub www_listAlbumsService {
albums => \@assets
};
if ($as eq "xml") {
$session->http->setMimeType('text/xml');
$session->response->content_type('text/xml');
return XML::Simple::XMLout($document, NoAttr => 1);
}
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->pretty->encode($document);
}
@ -1612,7 +1612,7 @@ sub www_listFilesForUserRss {
push @{ $var->{user_files} }, $assetVar;
}
$self->session->http->setMimeType('text/xml');
$self->session->response->content_type('text/xml');
return $self->processTemplate( $var, $self->templateIdListFilesForUserRss );
}

View file

@ -1159,11 +1159,11 @@ sub www_addFileService {
lastUpdated => $date->epochToHuman($file->revisionDate, '%y-%m-%d %j:%n:%s'),
};
if ($as eq "xml") {
$session->http->setMimeType('text/xml');
$session->response->content_type('text/xml');
return XML::Simple::XMLout($document, NoAttr => 1);
}
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->pretty->encode($document);
}
@ -1739,7 +1739,7 @@ sub www_viewRss {
= $self->session->datetime->epochToMail( $file->{creationDate} );
}
$self->session->http->setMimeType('text/xml');
$self->session->response->content_type('text/xml');
return $self->processTemplate( $var, $self->getParent->templateIdViewAlbumRss );
}

View file

@ -466,7 +466,7 @@ sub view {
}
$self->session->http->setMimeType($var{header});
$self->session->response->content_type($var{header});
if($var{header} ne "text/html") {
return $var{content};
@ -494,7 +494,7 @@ sub www_view {
return $self->session->privilege->noAccess() unless $self->canView;
$self->prepareView;
my $output = $self->view;
if ($self->session->http->getMimeType ne "text/html") {
if ($self->session->response->content_type ne "text/html") {
return $output;
} else {
$self->session->http->sendHeader;

View file

@ -482,7 +482,7 @@ sub www_ajaxDeletePoint {
my $i18n = WebGUI::International->new( $session, 'Asset_Map' );
my $assetId = $session->form->get('assetId');
my $asset = WebGUI::Asset->newById( $session, $assetId );
$session->http->setMimeType('application/json');
$session->response->content_type('application/json');
return JSON->new->encode({error => $i18n->get('error delete unauthorized')})
unless $asset && $asset->canEdit;
@ -535,7 +535,7 @@ sub www_ajaxEditPointSave {
# We're returning as HTML because application/json causes download pop-up
# and text/plain causes <pre>...</pre> in firefox
$session->http->setMimeType("text/html");
$session->response->content_type("text/html");
$session->log->preventDebugOutput;
my $assetId = $form->get('assetId');
@ -591,7 +591,7 @@ sub www_ajaxSetCenter {
my $form = $self->session->form;
my $i18n = WebGUI::International->new( $session, 'Asset_Map' );
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
return JSON->new->encode({message => $i18n->get("error set center unauthorized")})
unless $self->canEdit;
@ -619,7 +619,7 @@ sub www_ajaxSetPointLocation {
my $form = $self->session->form;
my $i18n = WebGUI::International->new( $session, 'Asset_Map' );
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
my $assetId = $form->get('assetId');
my $asset = WebGUI::Asset->newById( $session, $assetId );

View file

@ -1109,7 +1109,7 @@ sub www_getCompareFormData {
my @listingIds = $session->form->checkList("listingId");
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
my $db = $session->db;
my (@searchParams,@searchParams_sorted,@searchParamList,$searchParamList);
@ -1301,7 +1301,7 @@ sub www_getCompareListData {
}
$jsonOutput->{ResultSet} = {Result=>\@results};
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
return JSON->new->encode($jsonOutput);
}

View file

@ -577,7 +577,7 @@ override www_view => sub {
}
else {
$self->prepareView();
$self->session->http->setMimeType($mimeType);
$self->session->response->content_type($mimeType);
return $self->view();
}
};

View file

@ -1295,7 +1295,7 @@ sub www_loadSurvey {
warnings => $warnings #List of warnings to display to the user
};
$self->session->http->setMimeType('application/json');
$self->session->response->content_type('application/json');
return to_json($return);
}
@ -1762,7 +1762,7 @@ sub www_loadQuestions {
if(! $self->session->form->param('shownsummary')){
my ($summary,$html) = $self->getSummary();
my $json = to_json( { type => 'summary', summary => $summary, html => $html });
$self->session->http->setMimeType('application/json');
$self->session->response->content_type('application/json');
return $json;
}
}
@ -1869,7 +1869,7 @@ sub surveyEnd {
$exitUrl = $exitUrl || $self->exitURL || $self->getUrl || q{/};
$exitUrl = $self->session->url->gateway($exitUrl) if($exitUrl !~ /^https?:/i);
my $json = to_json( { type => 'forward', url => $exitUrl } );
$self->session->http->setMimeType('application/json');
$self->session->response->content_type('application/json');
return $json;
}
@ -1963,7 +1963,7 @@ sub prepareShowSurveyTemplate {
my $out = $self->processTemplate( $section, $self->surveyQuestionsId );
WebGUI::Macro::process($self->session, \$out);
$self->session->http->setMimeType('application/json');
$self->session->response->content_type('application/json');
return to_json( { type => 'displayquestions', section => $section, questions => $questions, html => $out } );
}

View file

@ -1621,7 +1621,7 @@ sub www_deleteThingDataViaAjax {
my $thingId = $self->session->form->process("thingId");
my $thingDataId = $self->session->form->process('thingDataId');
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
unless ($thingId && $thingDataId) {
$session->response->status(400);
@ -1635,7 +1635,7 @@ sub www_deleteThingDataViaAjax {
$self->deleteThingData($thingId,$thingDataId);
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
return JSON->new->encode({message => "Data with thingDataId $thingDataId was deleted."});
}
else {
@ -2704,7 +2704,7 @@ sub www_getThingViaAjax {
my $self = shift;
my $session = $self->session;
my $thingId = shift || $session->form->process('thingId');
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
unless ($thingId) {
$session->response->status(400);
@ -2725,7 +2725,7 @@ sub www_getThingViaAjax {
}
$thingProperties->{field_loop} = \@field_loop;
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
return JSON->new->encode($thingProperties);
}
else {
@ -2747,7 +2747,7 @@ sub www_getThingsViaAjax {
my $self = shift;
my $session = $self->session;
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
my @visibleThings;
my $things = $self->getThings;
@ -3134,7 +3134,7 @@ sub www_searchViaAjax {
my $var = $self->getSearchTemplateVars($thingId,$thingProperties);
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
return JSON->new->encode($var);
}
else {
@ -3554,7 +3554,7 @@ sub www_viewThingDataViaAjax {
my $thingId = shift || $session->form->process('thingId');
my $thingDataId = shift || $session->form->process('thingDataId');
$session->http->setMimeType("application/json");
$session->response->content_type("application/json");
unless ($thingId && $thingDataId) {
$session->response->status(400);