I haven't been able to find something that does this in either ECS 1.2 or 1.3.
I'm using ecs heavily for creating xml documents and needed a way to create a
<!DOCTYPE blah PUBLIC "--/blah/foo/en" "http://foo.net/blah.dtd">. It only does
what I need it to do for now but that's more that I could do with
org.apache.ecs.html.Doctype which is what this code is based on.
Does this class actually fill a gap?
cheers,
bld
----- The Code ----
/*
* Insert lawyer here.
*/
package org.apache.ecs.xml;
import org.apache.ecs.SinglePartElement;
import org.apache.ecs.Printable;
import org.apache.ecs.Element;
/**
* This class creates a <!DOCTYPE> tag.<p>
*
* Format:<br>
*
* <!DOCTYPE [name] PUBLIC [identifier] [uri]><p>
*
* usage:<br>
* XMLDocument d = new XMLDocument()<br>
* .addToProlog( new XMLDoctype( "foo", "\"--/bar/baz/en\"",
"\"http://qoz.net/foo.dtd\"" );<br>
* .addElement( new XML( ...
*
*
* @see Doctype
*
* @author <a href="mailto:[EMAIL PROTECTED]">Bruce Durling</a>
* @version 0.1
*/
public class XMLDoctype extends SinglePartElement implements Printable
{
public static final String elementName = "!DOCTYPE";
protected String name;
protected String identifier;
protected String uri;
{
setElementType(elementName);
setCase(Element.UPPERCASE);
}
/**
* Basic Constructor.
*
*/
public XMLDoctype()
{
updateElementType();
}
/**
* Constructor.
*
* @param name Root element of the XML document.
* @param id Public identifier.
* @param uri URI of the DTD.
*/
public XMLDoctype( String name, String id, String uri )
{
this.name = name;
this.identifier = id;
this.uri = uri;
updateElementType();
}
protected void updateElementType()
{
setElementType( elementName
+ " " + name
+ " " + "PUBLIC"
+ " " + identifier
+ " " + uri );
}
/**
* Updates the name of the root element.
*
* @param name Name of the root element.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype setName( String name )
{
this.name = name;
updateElementType();
return( this );
}
/**
* Updates the name of the pulbic identifier.
*
* @param identifier The pulblic identifier.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype setIdentifier( String identifier )
{
this.identifier = identifier;
updateElementType();
return( this );
}
/**
* Updates the URI of the dtd.
*
* @param uri URI of the dtd.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype setUri( String uri )
{
this.uri = uri;
updateElementType();
return(this);
}
/**
* Adds and Element to the element.
*
* @param hashcode name of the element for hash table.
* @param element Adds an Element to the element.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype addElement( String hashcode, Element element )
{
addElementToRegistry( hashcode, element );
return(this);
}
/**
* Adds an Element to the element.
*
* @param hashcode name of the element for the hash table.
* @param element Adds an Element to the element.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype addElement( String hashcode, String element )
{
addElementToRegistry(hashcode,element);
return(this);
}
/**
* Adds an Element to the element.
*
* @param element Ads an Element to the element.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype addElement(Element element)
{
addElementToRegistry(element);
return(this);
}
/**
* Adds an Element to the element.
*
* @param element Adds an Element to the element.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype addElement(String element)
{
addElementToRegistry(element);
return(this);
}
/**
* Removes an Element from the element.
*
* @param hashcode the name of the element to be removed.
* @return a value of type 'XMLDoctype'
*/
public XMLDoctype removeElement(String hashcode)
{
removeElementFromRegistry(hashcode);
return(this);
}
}// XMLDoctype
--
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]