001/* A representative of a DocBuilder 002 003 Copyright (c) 2006-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 */ 027package ptolemy.vergil.actor; 028 029import java.net.URL; 030 031import ptolemy.actor.gui.Effigy; 032import ptolemy.actor.gui.EffigyFactory; 033import ptolemy.actor.gui.PtolemyEffigy; 034import ptolemy.kernel.CompositeEntity; 035import ptolemy.kernel.util.IllegalActionException; 036import ptolemy.kernel.util.NameDuplicationException; 037 038/////////////////////////////////////////////////////////////////// 039//// DocBuilderEffigy 040 041/** 042 An effigy for a DocBuilder. 043 044 @author Christopher Brooks 045 @version $Id$ 046 @since Ptolemy II 5.2 047 @Pt.ProposedRating Green (cxh) 048 @Pt.AcceptedRating Red (cxh) 049 */ 050public class DocBuilderEffigy extends PtolemyEffigy { 051 052 /** Create a new effigy in the given directory with the given name. 053 * @param container The directory that contains this effigy. 054 * @param name The name of this effigy. 055 * @exception IllegalActionException If thrown by the superclass. 056 * @exception NameDuplicationException If thrown by the superclass. 057 */ 058 public DocBuilderEffigy(CompositeEntity container, String name) 059 throws IllegalActionException, NameDuplicationException { 060 super(container, name); 061 } 062 063 /////////////////////////////////////////////////////////////////// 064 //// inner classes //// 065 066 /** A factory for creating new effigies. 067 */ 068 public static class Factory extends EffigyFactory { 069 /** Create a factory with the given name and container. 070 * @param container The container. 071 * @param name The name. 072 * @exception IllegalActionException If the container is incompatible 073 * with this entity. 074 * @exception NameDuplicationException If the name coincides with 075 * an entity already in the container. 076 */ 077 public Factory(CompositeEntity container, String name) 078 throws IllegalActionException, NameDuplicationException { 079 super(container, name); 080 } 081 082 /////////////////////////////////////////////////////////////// 083 //// public methods //// 084 085 /** Return false, indicating that this effigy factory is not 086 * capable of creating an effigy without a URL being specified. 087 * @return False. 088 */ 089 @Override 090 public boolean canCreateBlankEffigy() { 091 return false; 092 } 093 094 /** Create a new effigy in the given container. 095 * @param container The container for the effigy. 096 * @param base The base for relative file references, or null if 097 * there are no relative file references. This is ignored in this 098 * class. 099 * @param input The input URL, which is ignored. 100 * @return A new instance of DocBuilderEffigy. 101 * @exception Exception If the URL cannot be read. 102 */ 103 @Override 104 public Effigy createEffigy(CompositeEntity container, URL base, 105 URL input) throws Exception { 106 if (input != null) { 107 String extension = getExtension(input); 108 if (extension.equals("xml")) { 109 // Check for DTD designation. 110 if (checkForDTD(input, 111 "<!DOCTYPE doc PUBLIC \"-//UC Berkeley//DTD DocML", 112 null)) { 113 // This is a doc file. 114 DocBuilderEffigy effigy = new DocBuilderEffigy( 115 container, container.uniqueName("effigy")); 116 return effigy; 117 } 118 } 119 } 120 return null; 121 } 122 } 123}