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

org.wings.externalizer.StaticResourceExternalizer Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS 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 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */
package org.wings.externalizer;

import org.wings.Renderable;
import org.wings.StaticResource;
import org.wings.io.Device;
import org.wings.resource.HttpHeader;
import org.wings.resource.NamedResource;
import org.wings.resource.ResourceNotFoundException;

import java.io.IOException;
import java.util.Collection;

/**
 * @author Armin Haaf
 * @author Michael Reinsch
 */
public class StaticResourceExternalizer implements Externalizer {

    private static final Class[] SUPPORTED_CLASSES = {StaticResource.class};

    public static final StaticResourceExternalizer SHARED_INSTANCE = new StaticResourceExternalizer();

    @Override
    public String getId(StaticResource obj) {
        if (obj instanceof NamedResource)
            return ((NamedResource)obj).getResourceName();
        else
            return null;
    }

    @Override
    public String getExtension(StaticResource obj) {
        if (obj instanceof NamedResource)
            return null;
        else
            return obj.getExtension();
    }

    @Override
    public String getMimeType(StaticResource obj) {
        if (obj != null)
            return obj.getMimeType();
        else
            return "unknown";
    }

    @Override
    public int getLength(StaticResource obj) {
        if (obj != null)
            return obj.getLength();
        return -1;
    }

    @Override
    public boolean isFinal(StaticResource obj) {
        return true;
    }

    @Override
    public void write(Object obj, Device out) throws IOException, ResourceNotFoundException {
        ((Renderable) obj).write(out);
    }

    @Override
    public Class[] getSupportedClasses() {
        return SUPPORTED_CLASSES;
    }

    @Override
    public String[] getSupportedMimeTypes() {
        return null;
    }

    @Override
    public Collection getHeaders(StaticResource obj) {
        if (obj != null)
            return obj.getHeaders();
        else
            return null;
    }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy