/*
 * $HeadURL$
 * $Id$
 * Copyright (c) 2006-2013 by Public Library of Science http://plos.org http://ambraproject.org
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ambraproject.wombat.controller;

import org.ambraproject.wombat.config.site.Site;
import org.ambraproject.wombat.service.EntityNotFoundException;
import org.ambraproject.wombat.service.remote.EditorialContentService;
import org.mortbay.util.ajax.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;

/**
 * Controller serves a container page for externally generated content
 */
@Controller
public class ExternalContentController extends WombatController {

  @Autowired
  private EditorialContentService editorialContentService;

  @RequestMapping(value = {"/c/{pageName}", "/{site}/c/{pageName}"})
  public String renderExternalContent(Model model, @SiteParam Site site, @PathVariable String pageName)
          throws IOException {

    String repoKeyPrefix = "c";
    String repoKey = repoKeyPrefix.concat(".").concat(pageName);

    try {
      model.addAttribute("externalServiceName", "ember"); // may not need, but kept for prototype
      model.addAttribute("externalData", editorialContentService.getJson("externalContent", repoKey));
    } catch (EntityNotFoundException e) {
      // Return a 404 if no object found.
      throw new NotFoundException(e);
    }

    return site + "/ftl/externalContent/container";
  }

}

@@ -1455,16 +1455,62 @@
 rvice;%0A%0A
+  private final String REPO_KEY_PREFIX = %22c%22;%0A
   @Reque
@@ -1728,56 +1728,26 @@
 oKey
-Prefix = %22c%22;%0A    String repoKey = repoKeyPrefix
+ = REPO_KEY_PREFIX
 .con
@@ -1777,21 +1777,8 @@
 e);%0A
-%0A    try %7B%0A  
     
@@ -1868,16 +1868,27 @@
 rototype
+%0A%0A    try %7B
 %0A      m

use constant repo key prefix and cleanup try/catch