All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.shindig.gadgets.templates.TemplateContext Maven / Gradle / Ivy

Go to download

Renders gadgets, provides the gadget metadata service, and serves all javascript required by the OpenSocial specification.

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.0
 *
 * Unless 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.apache.shindig.gadgets.templates;

import org.apache.shindig.gadgets.Gadget;
import org.w3c.dom.Node;

import java.util.Collection;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

/**
 * Context for processing a single template.
 */
public class TemplateContext {
  private final Map top;
  private final Gadget gadget;

  private Object cur = null;
  // TODO: support unique Id
  private Map context = ImmutableMap.of();
  private Map myMap = null;
  private Node templateRoot;
  private Map resources = Maps.newLinkedHashMap();
  
  public TemplateContext(Gadget gadget, Map top) {
    this.gadget = gadget;
    this.top = top;
    this.cur = top;
  }
  
  public Map getTop() {
    return top;
  }
  
  public Object getCur() {
    return cur;
  }

  public Object setCur(Object data) {
    Object oldCur = cur;
    cur = data;
    return oldCur;
  }

  public Map getContext() {
    return context;
  }

  public Map setContext(Map newContext) {
    Map oldContext = context;
    context = newContext;
    return oldContext;
  }
  
  public Map setMy(Map myMap) {
    Map oldMy = this.myMap;
    this.myMap = myMap;
    return oldMy;
  }
  
  public Map getMy() {
    return myMap;
  }
  
  public Gadget getGadget() {
    return gadget;
  }

  public Node setTemplateRoot(Node root) {
    Node oldRoot = this.templateRoot;
    this.templateRoot = root;
    return oldRoot;
  }
  
  public Node getTemplateRoot() {
    return this.templateRoot;
  }
  
  public void addResource(Object key, TemplateResource resource) {
    if (!resources.containsKey(key)) {
      resources.put(key, resource);
    }
  }
  
  public Collection getResources() {
    return resources.values();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy