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

org.apache.myfaces.trinidadbuild.plugin.jdeveloper.TldContentHandler Maven / Gradle / Ivy

/*
 *  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.myfaces.trinidadbuild.plugin.jdeveloper;

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

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class TldContentHandler
{
  /**
    * Content Handler.
    */
  public TldContentHandler()
  {
  }

  /**
    * Parse the .tld file to get the information
    * needed for the .jpr
    */
  public void parseTld(File file)
  throws SAXException,
         IOException,
         ParserConfigurationException
  {
    // Create a builder factory
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);

    // Create the Builder and parse the file
    DocumentBuilder docBuilder = factory.newDocumentBuilder();
    
    // Set Entity Resolver to resolve external entities, i.e.
    // the "http://...." in the 
   * 
   * The http URL causes this exception for some unknown reason. I have
   * searched high and low on the web for a real solution and finally found
   * this workaround at 
   * http://forum.java.sun.com/thread.jspa?threadID=284209&forumID=34
   * Apparently a LOT of developers are seeing similar problems and they too
   * are not able to find a solution. This workaround works perfectly and all
   * is well.
   */
  private class PluginEntityResolver
    implements EntityResolver
  {
    public InputSource resolveEntity(String publicId, String systemId)
    {
      if ("-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN".equals(publicId))
      {
        String xmlStr = "";
        byte[] buf = xmlStr.getBytes();
        ByteArrayInputStream bais = new ByteArrayInputStream(buf);
        return new InputSource(bais);
      }
      else 
        return null;
    }
  }

} // endclass TldContentHandler




© 2015 - 2025 Weber Informatics LLC | Privacy Policy