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

com.squeakysand.jsp.tldgenerator.TldWriter Maven / Gradle / Ivy

Go to download

Tool for automating the generation of JSP Custom Tag Library Descriptor (<code>.tld</code>) files. This is the basic code for doing the generation, you would normally some other code around this code to invoke it meaningfully. For example, see the <a href="../jsptld-maven-plugin">JSP TLD Maven Plugin</a> page.

The newest version!
/*
 * Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
 *
 * 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.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 com.squeakysand.jsp.tldgenerator;

import java.io.File;
import java.io.IOException;

import javax.xml.bind.JAXBException;

import com.squeakysand.commons.xml.JaxbHelper;
import com.squeakysand.schema.javaee.Taglib;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TldWriter {

    private static final Logger LOG = LoggerFactory.getLogger(TldWriter.class);

//    private static final String TLD_FILENAME_PATTERN = "%s-%s.tld";

    private static final String SCHEMA_LOCATION = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd";

    private File destinationFile;
    private Taglib taglib;

    public TldWriter(File destinationDir, String filename, Taglib taglib) {
//        String shortName = taglib.getShortName().getValue();
//        String version = taglib.getTlibVersion();
//        String tldFilename = String.format(TLD_FILENAME_PATTERN, shortName, version);
        destinationFile = new File(destinationDir, filename);
        this.taglib = taglib;
    }

    public void write() throws IOException, JAXBException {
        LOG.info("writing tld to {}", destinationFile.getAbsolutePath());
        JaxbHelper.marshallToFile(taglib, destinationFile, SCHEMA_LOCATION);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy