ilog.views.svg
Class SVGInputStream

java.lang.Object
  extended by ilog.views.io.IlvInputStream
      extended by ilog.views.svg.SVGInputStream

public class SVGInputStream
extends IlvInputStream

This class is an IlvInputStream that allows you to read the contents of an XML file using SVG grammar specifications.

See Also:
SVGStreamFactory

Constructor Summary
SVGInputStream(InputStream stream, SVGStreamFactory factory)
          Creates an SVGInputStream from an InputStream and linked to an SVGStreamFactory.
 
Method Summary
static EntityResolver getEntityResolver()
          Returns the XML entity resolver for reading SVG files.
 void read(IlvGraphicBag bag)
          Reads the SVGInputStream and puts the read objects into the given IlvGraphicBag.
static void setEntityResolver(EntityResolver resolver)
          Sets the XML entity resolver for reading SVG files.
 
Methods inherited from class ilog.views.io.IlvInputStream
getDocumentBase, getGraphicBag, getObjects, invokeConstructor, isASCIIMode, readBoolean, readBooleanArray, readColor, readColorArray, readDouble, readDoubleArray, readExtensions, readFloat, readFloatArray, readFont, readFontArray, readGradient, readInt, readIntArray, readLong, readLongArray, readObject, readObject, readObjectArray, readObjects, readPattern, readPersistentObject, readPersistentObjects, readPoint, readPointArray, readRect, readRectArray, readShape, readShort, readShortArray, readString, readStringArray, readStroke, readTexture, readTransformer, readTransformerArray, registerGraphic, setCopyPasteMode, setDocumentBase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SVGInputStream

public SVGInputStream(InputStream stream,
                      SVGStreamFactory factory)
Creates an SVGInputStream from an InputStream and linked to an SVGStreamFactory. The factory could be null, in which case the default options will be used.

Parameters:
stream - The input stream.
factory - The SVG stream factory.
See Also:
SVGStreamFactory
Method Detail

read

public void read(IlvGraphicBag bag)
          throws IOException,
                 IlvReadFileException
Reads the SVGInputStream and puts the read objects into the given IlvGraphicBag.

Overrides:
read in class IlvInputStream
Parameters:
bag - The IlvGraphicBag in which objects will be added.
Throws:
IOException - if there are any I/O errors.
IlvReadFileException - if the the file is not correctly SVG formatted.

setEntityResolver

public static void setEntityResolver(EntityResolver resolver)
Sets the XML entity resolver for reading SVG files. SVG files may contain references to external files on the internet. Loading these SVG files will not work if the computer has no internet connection. To solve this problems, it is possible to install an entity resolver which redirects the loading of external files to local files. By default, JViews has an entity resolver installed which redirects all standard SVG DTD files to local copies of these files. Therefore, in normal situations, users never need to call this method.

Here is a simple example of an entity resolver that ensures that the svg11.dtd is always loaded from a local resource instead of the internet:

 
 class MyResolver implements org.xml.sax.EntityResolver
 {
   private final static String SVG11_DTD_URI =
       "svg11.dtd";
   private final static String SVG11_PUBLIC_ID =
       "-//W3C//DTD SVG 1.1//EN";

   private EntityResolver parent;

   public MyResolver(EntityResolver parent)
   {
     this.parent = parent;
   }

   public InputSource resolveEntity(String publicId, String systemId)
     throws IOException, SAXException
   {
     InputSource is = null;

     if ((publicId != null && publicId.equals(SVG11_PUBLIC_ID)) ||
         systemId.endsWith("svg11.dtd")) {
       is =  new InputSource(
               MyResolver.class.getResource(SVG11_DTD_URI).toString());
     }

     if (is == null && parent != null)
       is = parent.resolveEntity(publicId, systemId);
     if (is == null)
       is = new InputSource(systemId);
     if (publicId != null && is != null)
       is.setPublicId(publicId);
     return is;
   }
 }
 
To install this entity resolver, call:
 
 SVGInputStream.setEntityResolver(
     new MyResolver(SVGInputStream.getEntityResolver()));
 
Calling this method with null argument reinstalls the default standard entity resolver.

Since:
JViews 8.1
See Also:
getEntityResolver()

getEntityResolver

public static EntityResolver getEntityResolver()
Returns the XML entity resolver for reading SVG files. If no entity resolver was set, it returns the standard SVG entity resolver of ILOG JViews.

Since:
JViews 8.1
See Also:
setEntityResolver(org.xml.sax.EntityResolver)


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.