nl.tue.gale.ae.processor.xmlmodule.ViewModule.java Source code

Java tutorial

Introduction

Here is the source code for nl.tue.gale.ae.processor.xmlmodule.ViewModule.java

Source

/*
    
   This file is part of GALE (Generic Adaptation Language and Engine).
    
GALE 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 3 of the License, or (at your option) 
any later version.
    
GALE 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 GALE. If not, see <http://www.gnu.org/licenses/>.
    
 */
/**
 * ViewModule.java
 * Last modified: $Date$
 * In revision:   $Revision$
 * Modified by:   $Author: dsmits $
 *
 * Copyright (c) 2008-2011 Eindhoven University of Technology.
 * All Rights Reserved.
 *
 * This software is proprietary information of the Eindhoven University
 * of Technology. It may be used according to the GNU LGPL license.
 */
package nl.tue.gale.ae.processor.xmlmodule;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import nl.tue.gale.ae.GaleContext;
import nl.tue.gale.ae.ProcessorException;
import nl.tue.gale.ae.Resource;
import nl.tue.gale.ae.processor.view.LayoutView;
import nl.tue.gale.common.GaleUtil;

import org.dom4j.Attribute;
import org.dom4j.Element;

public class ViewModule extends AbstractModule {
    private List<String> mimeToHandle = Arrays
            .asList(new String[] { "text/xhtml", "text/xml", "application/xml", "application/smil" });

    public List<String> getMimeToHandle() {
        return mimeToHandle;
    }

    public void setMimeToHandle(List<String> mimeToHandle) {
        this.mimeToHandle = mimeToHandle;
    }

    @SuppressWarnings("unchecked")
    public Element traverse(Element element, Resource resource) throws ProcessorException {
        GaleContext gale = GaleContext.of(resource);
        LayoutView view = (LayoutView) gale.cfgm().getObject(
                "gale://gale.tue.nl/config/presentation#view-" + element.attributeValue("name"), resource);
        List<String> params = new LinkedList<String>();
        for (Attribute a : (List<Attribute>) element.attributes())
            if (!a.getName().equals("name"))
                params.add(a.getName() + "=" + a.getValue());
        resource.put("current-view", element.attributeValue("name"));
        Element result = view.getXml(resource, params.toArray());
        processor.traverseChildren(result, resource);
        GaleUtil.replaceNode(element, result);
        resource.remove("current-view");
        return null;
    }
}