742N/A## -*- coding: utf-8 -*-
742N/A##
742N/A## CDDL HEADER START
742N/A##
742N/A## The contents of this file are subject to the terms of the
742N/A## Common Development and Distribution License (the "License").
742N/A## You may not use this file except in compliance with the License.
742N/A##
742N/A## You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
742N/A## or http://www.opensolaris.org/os/licensing.
742N/A## See the License for the specific language governing permissions
742N/A## and limitations under the License.
742N/A##
742N/A## When distributing Covered Code, include this CDDL HEADER in each
742N/A## file and include the License file at usr/src/OPENSOLARIS.LICENSE.
742N/A## If applicable, add the following below this CDDL HEADER, with the
742N/A## fields enclosed by brackets "[]" replaced with your own identifying
742N/A## information: Portions Copyright [yyyy] [name of copyright owner]
742N/A##
742N/A## CDDL HEADER END
742N/A##
3158N/A## Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
742N/A##
742N/A<%!
742N/A import os.path
742N/A import pkg.server.api as api
742N/A import pkg.server.api_errors as api_errors
742N/A
2651N/A CLIENT_API_VERSION = 12
742N/A%>\
742N/A<%page args="g_vars"/>\
742N/A<%
742N/A base = g_vars["base"]
2852N/A http_depot = g_vars["http_depot"]
742N/A config = api.ConfigInterface(CLIENT_API_VERSION, base)
742N/A request = api.RequestInterface(CLIENT_API_VERSION, base)
742N/A
742N/A # XXX default language if one can't be automatically determined,
742N/A # where to set this?
742N/A dlang = "en"
742N/A
742N/A # First, get the list of desired languages from the request.
742N/A rlangs = request.get_accepted_languages()
742N/A
742N/A # Second, check each language name (which should either be an ISO
742N/A # 639(.1/.2) code or an l10n simple name) to see if a directory of
742N/A # content exists for it.
742N/A for rl in rlangs:
742N/A if os.path.exists(os.path.join(config.web_root, rl)):
742N/A dlang = rl
742N/A break
742N/A
742N/A # Third, determine if we need to redirect the user to a particular
742N/A # page.
742N/A rpath = request.path_info.strip("/")
2028N/A pub = g_vars["pub"]
2028N/A if pub:
2028N/A # Ignore publisher component of path.
2028N/A rpath = rpath.replace(pub, "").strip("/")
2028N/A
2222N/A prefix = ""
742N/A if rpath == "":
2222N/A # Because the redirect is relative if the original request
2222N/A # didn't end with a '/', special care has to be taken for
2222N/A # this particular case.
2222N/A if pub and not request.path_info.endswith("/"):
2222N/A prefix = pub + "/"
742N/A rpath = "index.shtml"
2852N/A if http_depot:
2852N/A prefix = http_depot
742N/A
742N/A # Finally, redirect the client to the content appropriate for their
742N/A # language and region.
3158N/A raise api_errors.RedirectException("{0}{1}/{2}".format(
3158N/A prefix, dlang, rpath))
742N/A%>\