Initial commit from SVN.
This commit is contained in:
294
Foundation/src/com/foundation/util/xml/AbstractNode.java
Normal file
294
Foundation/src/com/foundation/util/xml/AbstractNode.java
Normal file
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (c) 2008,2009 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.common.comparison.Comparator;
|
||||
import com.common.util.ICollection;
|
||||
import com.common.util.IHashMap;
|
||||
import com.common.util.IIterator;
|
||||
import com.common.util.IList;
|
||||
import com.common.util.LiteList;
|
||||
import com.foundation.util.HashMap;
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ManagedList;
|
||||
|
||||
public abstract class AbstractNode extends Element implements IAbstractNode {
|
||||
/** Ordered child elements defined between the node start and end tags. */
|
||||
private ManagedList elements = null;
|
||||
/** Ordered attributes defined in the node. */
|
||||
private ManagedList attributes = null;
|
||||
/**
|
||||
* AbstractNode constructor.
|
||||
*/
|
||||
public AbstractNode() {
|
||||
}//AbstractNode()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getElements()
|
||||
*/
|
||||
public IManagedList getElements() {
|
||||
if(elements == null) {
|
||||
elements = new ManagedList(new ElementListManager(this));
|
||||
}//if//
|
||||
|
||||
return elements;
|
||||
}//getElements()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#addAttribute(com.foundation.util.xml.IAttribute)
|
||||
*/
|
||||
public boolean addAttribute(IAttribute attribute) {
|
||||
return getAttributes().add(attribute) != -1;
|
||||
}//addAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#addAttribute(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public IAttribute addAttribute(String name, Object value) {
|
||||
IAttribute result = new Property(name, value == null ? "" : value.toString());
|
||||
|
||||
return addAttribute(result) ? result : null;
|
||||
}//addAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttribute(java.lang.String)
|
||||
*/
|
||||
public IAttribute getAttribute(String attributeName) {
|
||||
IAttribute result = null;
|
||||
|
||||
if(attributes != null) {
|
||||
for(int index = 0, length = attributes.getSize(); result == null && index < length; index++) {
|
||||
IAttribute next = (IAttribute) attributes.get(index);
|
||||
|
||||
if(Comparator.equals(next.getName(), attributeName)) {
|
||||
result = next;
|
||||
}//if//
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
return result;
|
||||
}//getAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeNames()
|
||||
*/
|
||||
public IList getAttributeNames() {
|
||||
LiteList result = LiteList.EMPTY_LIST;
|
||||
|
||||
if(attributes != null) {
|
||||
result = new LiteList(attributes.getSize());
|
||||
|
||||
for(int index = 0, length = attributes.getSize(); index < length; index++) {
|
||||
IAttribute next = (IAttribute) attributes.get(index);
|
||||
|
||||
result.add(next.getName());
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
return result;
|
||||
}//getAttributeNames()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeValue(java.lang.String)
|
||||
*/
|
||||
public String getAttributeValue(String attributeName) {
|
||||
IAttribute attribute = getAttribute(attributeName);
|
||||
|
||||
return attribute != null ? attribute.getValue() : null;
|
||||
}//getAttributeValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeValue(java.lang.String, boolean, boolean)
|
||||
*/
|
||||
public String getAttributeValue(String attributeName, boolean trim, boolean emptySameAsNull) {
|
||||
return getAttributeValue(attributeName, trim, emptySameAsNull, null);
|
||||
}//getAttributeValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeValue(java.lang.String, boolean, boolean, java.lang.String)
|
||||
*/
|
||||
public String getAttributeValue(String attributeName, boolean trim, boolean emptySameAsNull, String defaultValue) {
|
||||
IAttribute attribute = getAttribute(attributeName);
|
||||
String value = attribute != null ? attribute.getValue() : null;
|
||||
|
||||
if(value != null) {
|
||||
if(trim) {
|
||||
value = value.trim();
|
||||
}//if//
|
||||
|
||||
if((emptySameAsNull) && (value.length() == 0)) {
|
||||
value = null;
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
return value == null ? defaultValue : value;
|
||||
}//getAttributeValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeBooleanValue(java.lang.String)
|
||||
*/
|
||||
public Boolean getAttributeBooleanValue(String attributeName) {
|
||||
return getAttributeBooleanValue(attributeName, null);
|
||||
}//getAttributeBooleanValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeBooleanValue(java.lang.String, java.lang.Boolean)
|
||||
*/
|
||||
public Boolean getAttributeBooleanValue(String attributeName, Boolean defaultValue) {
|
||||
String value = getAttributeValue(attributeName, true, true, null);
|
||||
|
||||
return value == null ? defaultValue : Boolean.valueOf(value);
|
||||
}//getAttributeBooleanValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeIntegerValue(java.lang.String)
|
||||
*/
|
||||
public Integer getAttributeIntegerValue(String attributeName) {
|
||||
return getAttributeIntegerValue(attributeName, null);
|
||||
}//getAttributeIntegerValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeIntegerValue(java.lang.String, java.lang.Integer)
|
||||
*/
|
||||
public Integer getAttributeIntegerValue(String attributeName, Integer defaultValue) {
|
||||
String value = getAttributeValue(attributeName, true, true, null);
|
||||
|
||||
return value == null ? defaultValue : Integer.valueOf(value);
|
||||
}//getAttributeIntegerValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeLongValue(java.lang.String)
|
||||
*/
|
||||
public Long getAttributeLongValue(String attributeName) {
|
||||
return getAttributeLongValue(attributeName, null);
|
||||
}//getAttributeLongValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributeLongValue(java.lang.String, java.lang.Long)
|
||||
*/
|
||||
public Long getAttributeLongValue(String attributeName, Long defaultValue) {
|
||||
String value = getAttributeValue(attributeName, true, true, null);
|
||||
|
||||
return value == null ? defaultValue : Long.valueOf(value);
|
||||
}//getAttributeLongValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#getAttributes()
|
||||
*/
|
||||
public IManagedList getAttributes() {
|
||||
if(attributes == null) {
|
||||
attributes = new ManagedList(10, 20);
|
||||
}//if//
|
||||
|
||||
return attributes;
|
||||
}//getAttributes()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#hasAttribute(java.lang.String)
|
||||
*/
|
||||
public boolean hasAttribute(String attributeName) {
|
||||
//TODO: This is inefficient - callers should simply get the IAttribute object so that it doesn't have to be found twice.
|
||||
return getAttribute(attributeName) != null;
|
||||
}//hasAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#removeAttribute(java.lang.String)
|
||||
*/
|
||||
public boolean removeAttribute(String attributeName) {
|
||||
IAttribute result = null;
|
||||
|
||||
if(attributes != null) {
|
||||
for(int index = 0, length = attributes.getSize(); result == null && index < length; index++) {
|
||||
IAttribute next = (IAttribute) attributes.get(index);
|
||||
|
||||
if(Comparator.equals(next.getName(), attributeName)) {
|
||||
attributes.remove(index);
|
||||
result = next;
|
||||
}//if//
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
return result != null;
|
||||
}//removeAttribute()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#createNode(java.lang.String)
|
||||
*/
|
||||
public INode createNode(String name) {
|
||||
INode result = new Node(name);
|
||||
|
||||
getElements().add(result);
|
||||
|
||||
return result;
|
||||
}//createNode()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#createText()
|
||||
*/
|
||||
public IText createText() {
|
||||
IText result = new Text();
|
||||
|
||||
getElements().add(result);
|
||||
|
||||
return result;
|
||||
}//createText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#createText(java.lang.String)
|
||||
*/
|
||||
public IText createText(String text) {
|
||||
IText result = new Text();
|
||||
|
||||
getElements().add(result);
|
||||
result.setText(text);
|
||||
|
||||
return result;
|
||||
}//createText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#createComment()
|
||||
*/
|
||||
public IComment createComment() {
|
||||
IComment result = new Comment();
|
||||
|
||||
getElements().add(result);
|
||||
|
||||
return result;
|
||||
}//createComment()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#createComment(java.lang.String)
|
||||
*/
|
||||
public IComment createComment(String comment) {
|
||||
IComment result = new Comment();
|
||||
|
||||
getElements().add(result);
|
||||
result.setText(comment);
|
||||
|
||||
return result;
|
||||
}//createComment()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#findNodes(java.lang.String, com.common.util.ICollection)
|
||||
*/
|
||||
public void findNodes(String name, ICollection results) {
|
||||
findNodes(name, results, false);
|
||||
}//findNodes()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#findNodes(java.lang.String, com.common.util.ICollection)
|
||||
*/
|
||||
public void findNodes(String name, ICollection results, boolean recursive) {
|
||||
IIterator iterator = getElements().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Object next = iterator.next();
|
||||
|
||||
if((((IElement) next).isNode()) && (((INode) next).getName().equals(name))) {
|
||||
results.add(next);
|
||||
}//if//
|
||||
|
||||
if(next instanceof IAbstractNode && recursive) {
|
||||
((IAbstractNode) next).findNodes(name, results, recursive);
|
||||
}//if//
|
||||
}//while//
|
||||
}//findNodes()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAbstractNode#findNode(java.lang.String)
|
||||
*/
|
||||
public INode findNode(String name) {
|
||||
IIterator iterator = getElements().iterator();
|
||||
INode result = null;
|
||||
|
||||
while((result == null) && (iterator.hasNext())) {
|
||||
Object next = iterator.next();
|
||||
|
||||
if((((IElement) next).isNode()) && (((INode) next).getName().equals(name))) {
|
||||
result = (INode) next;
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
return result;
|
||||
}//findNode()//
|
||||
}//AbstractNode//
|
||||
62
Foundation/src/com/foundation/util/xml/Comment.java
Normal file
62
Foundation/src/com/foundation/util/xml/Comment.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public class Comment extends Element implements IComment {
|
||||
private String text = null;
|
||||
/**
|
||||
* Comment constructor.
|
||||
*/
|
||||
public Comment() {
|
||||
super();
|
||||
}//Comment()//
|
||||
/**
|
||||
* Comment constructor.
|
||||
* @param comment The initial text of the comment.
|
||||
*/
|
||||
public Comment(String comment) {
|
||||
super();
|
||||
|
||||
setText(comment);
|
||||
}//Comment()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IComment#getText()
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}//getText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#isComment()
|
||||
*/
|
||||
public boolean isComment() {
|
||||
return true;
|
||||
}//isComment()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IComment#setText(java.lang.String)
|
||||
*/
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}//setText()//
|
||||
/**
|
||||
* Writes the element to the buffer.
|
||||
* @param out The output stream that will be given the formatted element data.
|
||||
* @param builder The document builder that will provide guidance.
|
||||
* @param prepend The string that will be added before any other characters in a perticular line.
|
||||
* @param postpend The string that will be added after any other characters in a perticular line.
|
||||
* @param compact Whether the output should be kept compact, or should include formatting characters.
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws java.io.IOException {
|
||||
if(!builder.getIgnoreComments().booleanValue() && !compact) {
|
||||
out.write(prepend);
|
||||
out.write("<!--");
|
||||
out.write(builder.getIgnoreTextWhitespace().booleanValue() ? getText().trim() : getText());
|
||||
out.write("-->");
|
||||
out.write(postpend);
|
||||
}//if//
|
||||
}//write()//
|
||||
}//Comment//
|
||||
92
Foundation/src/com/foundation/util/xml/DocType.java
Normal file
92
Foundation/src/com/foundation/util/xml/DocType.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2006,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* Encapsulates the DOCTYPE information that exists at the very top of most XML documents.
|
||||
* <p>See http://en.wikipedia.org/wiki/Document_Type_Declaration for a good description and links to resources.</p>
|
||||
*/
|
||||
public class DocType extends Element implements IDocType {
|
||||
private String name = null;
|
||||
private String visibility = null;
|
||||
private String publicIdentifier = null;
|
||||
private String systemIdentifier = null;
|
||||
/**
|
||||
* DocType constructor.
|
||||
* @param name The document type name.
|
||||
* @param visibility The document type visibility.
|
||||
* @param publicIdentifier The document type's public identifier or null if not available.
|
||||
* @param systemIdentifier The document type's system identifier (path to the dtd).
|
||||
*/
|
||||
public DocType(String name, String visibility, String publicIdentifier, String systemIdentifier) {
|
||||
super();
|
||||
|
||||
this.name = name;
|
||||
this.visibility = visibility;
|
||||
this.publicIdentifier = publicIdentifier;
|
||||
this.systemIdentifier = systemIdentifier;
|
||||
}//DocType()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IDocType#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}//getName()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IDocType#getVisibility()
|
||||
*/
|
||||
public String getVisibility() {
|
||||
return visibility;
|
||||
}//getVisibility()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IDocType#getPublicIdentifier()
|
||||
*/
|
||||
public String getPublicIdentifier() {
|
||||
return publicIdentifier;
|
||||
}//getPublicIdentifier()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IDocType#getSystemIdentifier()
|
||||
*/
|
||||
public String getSystemIdentifier() {
|
||||
return systemIdentifier;
|
||||
}//getSystemIdentifier()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#write(com.foundation.util.xml.XmlOutputStream, com.foundation.util.xml.DocumentBuilder, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws IOException {
|
||||
out.write(prepend);
|
||||
out.write("<!DOCTYPE");
|
||||
|
||||
if(getName() != null) {
|
||||
out.write(' ');
|
||||
out.write(getName());
|
||||
}//if//
|
||||
|
||||
if(getVisibility() != null) {
|
||||
out.write(' ');
|
||||
out.write(getVisibility());
|
||||
}//if//
|
||||
|
||||
if(getPublicIdentifier() != null) {
|
||||
out.write(" \"");
|
||||
out.write(getPublicIdentifier());
|
||||
out.write("\"");
|
||||
}//if//
|
||||
|
||||
if(getSystemIdentifier() != null) {
|
||||
out.write(" \"");
|
||||
out.write(getSystemIdentifier());
|
||||
out.write("\"");
|
||||
}//if//
|
||||
|
||||
out.write(">");
|
||||
out.write(postpend);
|
||||
}//write()//
|
||||
}//DocType//
|
||||
159
Foundation/src/com/foundation/util/xml/Document.java
Normal file
159
Foundation/src/com/foundation/util/xml/Document.java
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.foundation.util.IManagedList;
|
||||
import com.foundation.util.ManagedList;
|
||||
|
||||
public class Document extends AbstractNode implements IDocument {
|
||||
private IDocType docType = null;
|
||||
private ManagedList metadataNodes = null;
|
||||
/**
|
||||
* Document constructor.
|
||||
*/
|
||||
public Document() {
|
||||
super();
|
||||
}//Document()//
|
||||
/**
|
||||
* Gets the name of the node.
|
||||
* @return The node's name which is how the node is identified.
|
||||
*/
|
||||
public String getName() {
|
||||
//This method is not supported.//
|
||||
return null;
|
||||
}//getName()//
|
||||
/**
|
||||
* Gets this node's parent node.
|
||||
* @return The parent node, or null if this node does not have a parent.
|
||||
*/
|
||||
public IAbstractNode getParent() {
|
||||
return null;
|
||||
}//getParent()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getEndCharacter()
|
||||
*/
|
||||
public int getEndCharacter() {
|
||||
return 0;
|
||||
}//getEndCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getEndLine()
|
||||
*/
|
||||
public int getEndLine() {
|
||||
return 0;
|
||||
}//getEndLine()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartCharacter()
|
||||
*/
|
||||
public int getStartCharacter() {
|
||||
return 0;
|
||||
}//getStartCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartLine()
|
||||
*/
|
||||
public int getStartLine() {
|
||||
return 0;
|
||||
}//getStartLine()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IDocument#getDocType()
|
||||
*/
|
||||
public IDocType getDocType() {
|
||||
return docType;
|
||||
}//getDocType()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IDocument#setDocType(com.foundation.util.xml.IDocType)
|
||||
*/
|
||||
public void setDocType(IDocType docType) {
|
||||
this.docType = docType;
|
||||
}//setDocType()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#isDocument()
|
||||
*/
|
||||
public boolean isDocument() {
|
||||
return true;
|
||||
}//isDocument()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IDocument#getMetadataNodes()
|
||||
*/
|
||||
public IManagedList getMetadataElements() {
|
||||
if(metadataNodes == null) {
|
||||
metadataNodes = new ManagedList(new MetadataNodeListManager(this));
|
||||
}//if//
|
||||
|
||||
return metadataNodes;
|
||||
}//getMetadataNodes()//
|
||||
/**
|
||||
* Writes the element to the buffer.
|
||||
* @param out The output stream that will be given the formatted element data.
|
||||
* @param builder The document builder that will provide guidance.
|
||||
* @param prepend The string that will be added before any other characters in a perticular line.
|
||||
* @param postpend The string that will be added after any other characters in a perticular line.
|
||||
* @param compact Whether the output should be kept compact, or should include formatting characters.
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws java.io.IOException {
|
||||
IIterator iterator = null;
|
||||
|
||||
if(getMetadataElements().getSize() > 0) {
|
||||
iterator = getMetadataElements().iterator();
|
||||
|
||||
for(int index = 0; index < getMetadataElements().getSize(); index++) {
|
||||
IElement element = (IElement) getMetadataElements().get(index);
|
||||
|
||||
if(element instanceof MetadataNode) {
|
||||
element.write(out, builder, prepend, postpend, false);
|
||||
}//if//
|
||||
else if(element instanceof IComment) {
|
||||
//Always display the header comments so that we can include a legal header.//
|
||||
//Note: If the user wants all comments stripped then it should set the builder's ignore comments flag.//
|
||||
element.write(out, builder, prepend, postpend, false);
|
||||
}//else if//
|
||||
}//for//
|
||||
}//if//
|
||||
|
||||
if(docType != null) {
|
||||
docType.write(out, builder, prepend, postpend, compact);
|
||||
}//if//
|
||||
|
||||
iterator = getElements().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
Element element = (Element) iterator.next();
|
||||
|
||||
element.write(out, builder, prepend, postpend, compact);
|
||||
}//while//
|
||||
}//write()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
DocumentBuilder builder = new DocumentBuilder();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(20000);
|
||||
XmlOutputStream xout = new XmlOutputStream(bout, "UTF8");
|
||||
String result = null;
|
||||
|
||||
builder.allowEncodedCharacters(false);
|
||||
|
||||
try {
|
||||
write(xout, builder, null, null, false);
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
//Ignored.//
|
||||
}//catch//
|
||||
|
||||
try {
|
||||
result = new String(bout.toByteArray(), "UTF8");
|
||||
}//try//
|
||||
catch(Throwable e) {
|
||||
//Ignored.//
|
||||
}//catch//
|
||||
|
||||
return result;
|
||||
}//toString()//
|
||||
}//Document//
|
||||
2366
Foundation/src/com/foundation/util/xml/DocumentBuilder.java
Normal file
2366
Foundation/src/com/foundation/util/xml/DocumentBuilder.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2007 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
/**
|
||||
* This exception is raised if an XML stream is improperly formatted. This does not get used if the document does not conform to the document spec.
|
||||
*/
|
||||
public class DocumentFormatException extends Exception {
|
||||
private int lineNumber = 0;
|
||||
private int characterOffset = 0;
|
||||
/**
|
||||
* DocumentFormatException constructor.
|
||||
*/
|
||||
public DocumentFormatException() {
|
||||
super();
|
||||
}//DocumentFormatException()//
|
||||
/**
|
||||
* DocumentFormatException constructor.
|
||||
*/
|
||||
public DocumentFormatException(XmlInputStream stream) {
|
||||
super();
|
||||
|
||||
this.lineNumber = stream.getNextLineIndex();
|
||||
this.characterOffset = stream.getNextLineCharacterOffset();
|
||||
}//DocumentFormatException()//
|
||||
/**
|
||||
* DocumentFormatException constructor.
|
||||
* @param message The exception message.
|
||||
*/
|
||||
public DocumentFormatException(String message) {
|
||||
super(message);
|
||||
}//DocumentFormatException()//
|
||||
/**
|
||||
* DocumentFormatException constructor.
|
||||
* @param message The exception message.
|
||||
*/
|
||||
public DocumentFormatException(String message, XmlInputStream stream) {
|
||||
super(message);
|
||||
|
||||
this.lineNumber = stream.getNextLineIndex();
|
||||
this.characterOffset = stream.getNextLineCharacterOffset();
|
||||
}//DocumentFormatException()//
|
||||
/**
|
||||
* Gets the character offset within the line where the exception occured.
|
||||
* @return The line relative offset of the character causing the exception.
|
||||
*/
|
||||
public int getCharacterOffset() {
|
||||
return characterOffset;
|
||||
}//getCharacterOffset()//
|
||||
/**
|
||||
* Gets the line number in the document where the exception occured.
|
||||
* @return The line number at which the exception occured.
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
return lineNumber;
|
||||
}//getLineNumber()//
|
||||
}//DocumentFormatException//
|
||||
164
Foundation/src/com/foundation/util/xml/Element.java
Normal file
164
Foundation/src/com/foundation/util/xml/Element.java
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public abstract class Element implements IElement {
|
||||
private IAbstractNode parent = null;
|
||||
private int startCharacter = -1;
|
||||
private int startLine = -1;
|
||||
private int startLineCharacter = -1;
|
||||
private int endCharacter = -1;
|
||||
private int endLine = -1;
|
||||
private int endLineCharacter = -1;
|
||||
private boolean hasErrors = false;
|
||||
/**
|
||||
* Element constructor.
|
||||
*/
|
||||
public Element() {
|
||||
super();
|
||||
}//Element()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#hasErrors()
|
||||
*/
|
||||
public boolean hasErrors() {
|
||||
return hasErrors;
|
||||
}//hasErrors()//
|
||||
/**
|
||||
* Sets whether the element has errors in it but is still detectable.
|
||||
* @param hasErrors Whether the reader detected errors in this element of the document.
|
||||
*/
|
||||
public void hasErrors(boolean hasErrors) {
|
||||
this.hasErrors = hasErrors;
|
||||
}//hasErrors()//
|
||||
/**
|
||||
* Gets this node's parent node.
|
||||
* @return The parent node, or null if this node does not have a parent.
|
||||
*/
|
||||
public IAbstractNode getParent() {
|
||||
return parent;
|
||||
}//getParent()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#isComment()
|
||||
*/
|
||||
public boolean isComment() {
|
||||
return false;
|
||||
}//isComment()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#isNode()
|
||||
*/
|
||||
public boolean isNode() {
|
||||
return false;
|
||||
}//isNode()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#isText()
|
||||
*/
|
||||
public boolean isText() {
|
||||
return false;
|
||||
}//isText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#isDocument()
|
||||
*/
|
||||
public boolean isDocument() {
|
||||
return false;
|
||||
}//isDocument()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#isInvalid()
|
||||
*/
|
||||
public boolean isInvalid() {
|
||||
return false;
|
||||
}//isInvalid()//
|
||||
/**
|
||||
* Sets this node's parent node.
|
||||
* @param parent The parent node, or null if this node does not have a parent.
|
||||
*/
|
||||
protected void setParent(IAbstractNode parent) {
|
||||
this.parent = parent;
|
||||
}//setParent()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#write(com.foundation.util.xml.XmlOutputStream, com.foundation.util.xml.DocumentBuilder, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public abstract void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws java.io.IOException;
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#getStartLine()
|
||||
*/
|
||||
public int getStartLine() {
|
||||
return startLine;
|
||||
}//getStartLine()//
|
||||
/**
|
||||
* Sets the line number on which the node begins.
|
||||
* @param startLine The line number where the start of the node is.
|
||||
*/
|
||||
public void setStartLine(int startLine) {
|
||||
this.startLine = startLine;
|
||||
}//setStartLine()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#getStartCharacter()
|
||||
*/
|
||||
public int getStartCharacter() {
|
||||
return startCharacter;
|
||||
}//getStartCharacter()//
|
||||
/**
|
||||
* Sets the character number within the file where the text begins (inclusive).
|
||||
* @param startCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setStartCharacter(int startCharacter) {
|
||||
this.startCharacter = startCharacter;
|
||||
}//setStartCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#getStartLineCharacter()
|
||||
*/
|
||||
public int getStartLineCharacter() {
|
||||
return startLineCharacter;
|
||||
}//getStartLineCharacter()/
|
||||
/**
|
||||
* Sets the character number within the line where the text begins (inclusive).
|
||||
* @param startLineCharacter The index of the character from the beginning of the line.
|
||||
*/
|
||||
public void setStartLineCharacter(int startLineCharacter) {
|
||||
this.startLineCharacter = startLineCharacter;
|
||||
}//setStartLineCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#getEndCharacter()
|
||||
*/
|
||||
public int getEndCharacter() {
|
||||
return endCharacter;
|
||||
}//getEndCharacter()//
|
||||
/**
|
||||
* Sets the character number within the file where the text ends (inclusive).
|
||||
* @param endCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setEndCharacter(int endCharacter) {
|
||||
this.endCharacter = endCharacter;
|
||||
}//setEndCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#getEndLine()
|
||||
*/
|
||||
public int getEndLine() {
|
||||
return endLine;
|
||||
}//getEndLine()//
|
||||
/**
|
||||
* Sets the line number on which the node ends.
|
||||
* @param endLine The line number where the end of the node is.
|
||||
*/
|
||||
public void setEndLine(int endLine) {
|
||||
this.endLine = endLine;
|
||||
}//setEndLine()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#getEndLineCharacter()
|
||||
*/
|
||||
public int getEndLineCharacter() {
|
||||
return endLineCharacter;
|
||||
}//getEndLineCharacter()//
|
||||
/**
|
||||
* Sets the character number within the line where the text ends (inclusive).
|
||||
* @param endLineCharacter The index of the character from the beginning of the line.
|
||||
*/
|
||||
public void setEndLineCharacter(int endLineCharacter) {
|
||||
this.endLineCharacter = endLineCharacter;
|
||||
}//setEndLineCharacter()//
|
||||
}//Element//
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.foundation.util.*;
|
||||
|
||||
/**
|
||||
* Defines how the node's elements collection will be managed.
|
||||
*/
|
||||
final class ElementListManager extends ListManager {
|
||||
private AbstractNode node = null;
|
||||
/**
|
||||
* ElementListManager constructor.
|
||||
* @param node The node that this manager is servicing. Every element added to the collection will be given this node as its' parent.
|
||||
*/
|
||||
public ElementListManager(AbstractNode node) {
|
||||
super();
|
||||
|
||||
if(node == null) {
|
||||
throw new NullPointerException("It is not allowed to pass the ElementListManager a null node reference.");
|
||||
}//if//
|
||||
|
||||
this.node = node;
|
||||
}//ElementListManager()//
|
||||
/**
|
||||
* Determines whether the value can be added to the collection.
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @param value The value that may be added.
|
||||
* @return Whether the value can be added to the collection.
|
||||
*/
|
||||
public boolean canAdd(IManagedCollection managed, Object value, byte context) {
|
||||
return (super.canAdd(managed, value, context)) && (value instanceof Element) && (!(value instanceof IDocument));
|
||||
}//canAdd()//
|
||||
/**
|
||||
* Determines whether the user can make the collection immutable (unchangeable).
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @return Whether the collection immutable flag can be set.
|
||||
*/
|
||||
public boolean canMakeImmutable(IManagedCollection managed) {
|
||||
return false;
|
||||
}//canMakeImmutable()//
|
||||
/**
|
||||
* Determines whether the collection should ask the manager to allow an add operation.
|
||||
* @return Whether this manager will be asked for permission before an add operation.
|
||||
*/
|
||||
public boolean checkOnAdd() {
|
||||
return true;
|
||||
}//checkOnAdd()//
|
||||
/**
|
||||
* Determines whether the collection should notify the manager after an add operation occurs.
|
||||
* @return Whether this manager will be notified after an add operation.
|
||||
*/
|
||||
public boolean notifyOnPostAdd() {
|
||||
return true;
|
||||
}//notifyOnPostAdd()//
|
||||
/**
|
||||
* Determines whether the collection should notify the manager after a remove operation occurs.
|
||||
* @return Whether this manager will be notified after a remove operation.
|
||||
*/
|
||||
public boolean notifyOnPostRemove() {
|
||||
return true;
|
||||
}//notifyOnPostRemove()//
|
||||
/**
|
||||
* Allows the manager to provide functionality after a value has been added to the collection.
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @param value The value that has be added.
|
||||
* @see #preAdd(Object)
|
||||
*/
|
||||
public void postAdd(IManagedCollection managed, Object value, byte context) {
|
||||
if(value instanceof Element) {
|
||||
((Element) value).setParent(node);
|
||||
}//if//
|
||||
|
||||
super.postAdd(managed, value, context);
|
||||
}//postAdd()//
|
||||
/**
|
||||
* Allows the manager to provide functionality after a value has been removed from the collection.
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @param value The value that has be removed.
|
||||
* @see #preRemove(Object)
|
||||
*/
|
||||
public void postRemove(IManagedCollection managed, Object value, byte context) {
|
||||
if(value instanceof Element) {
|
||||
((Element) value).setParent(null);
|
||||
}//if//
|
||||
|
||||
super.postRemove(managed, value, context);
|
||||
}//postRemove()//
|
||||
}//ElementListManager//
|
||||
176
Foundation/src/com/foundation/util/xml/IAbstractNode.java
Normal file
176
Foundation/src/com/foundation/util/xml/IAbstractNode.java
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (c) 2008,2009 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.common.util.ICollection;
|
||||
import com.common.util.IList;
|
||||
import com.foundation.util.IManagedList;
|
||||
|
||||
public interface IAbstractNode extends IElement {
|
||||
/**
|
||||
* Gets the collection of ordered elements that are defined within this node.
|
||||
* @return An ordered collection of IElement objects.
|
||||
*/
|
||||
public IManagedList getElements();
|
||||
/**
|
||||
* Adds the attribute to the node.
|
||||
* @param attribute The attribute to add. This attribute's name should be unique in the node's collection of attributes.
|
||||
* @return Whether the attribute was added.
|
||||
*/
|
||||
public boolean addAttribute(IAttribute attribute);
|
||||
/**
|
||||
* Adds the attribute to the node.
|
||||
* @param name The attribute name.
|
||||
* @param value The value for the attribute. The toString() method will be called to get a string representation. A null value is converted to an empty string.
|
||||
* @return The added attribute, or null if the add failed.
|
||||
*/
|
||||
public IAttribute addAttribute(String name, Object value);
|
||||
/**
|
||||
* Gets the attribute that has the associated attribute name.
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @return The attribute that has the given attribute name.
|
||||
*/
|
||||
public IAttribute getAttribute(String attributeName);
|
||||
/**
|
||||
* Gets the collection of attribute names for this node.
|
||||
* @return A collection of all of the attribute names in this node.
|
||||
*/
|
||||
public IList getAttributeNames();
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @return The attribute value that associated with the given attribute name. This will be <code>null</code> if the attribute name is not in the mapping.
|
||||
*/
|
||||
public String getAttributeValue(String attributeName);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @param trim Whether the value should be trimed of excees spacing before and after any values.
|
||||
* @param emptySameAsNull Whether the empty values (after optional trimming) should be replaced by null values.
|
||||
* @return The attribute value that associated with the given attribute name. This will be <code>null</code> if the attribute name is not in the mapping.
|
||||
*/
|
||||
public String getAttributeValue(String attributeName, boolean trim, boolean emptySameAsNull);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @param trim Whether the value should be trimed of excees spacing before and after any values.
|
||||
* @param emptySameAsNull Whether the empty values (after optional trimming) should be replaced by null values.
|
||||
* @param defaultValue The value to be returned if the result would have been null.
|
||||
* @return The attribute value that associated with the given attribute name. This will be the default value if the attribute name is not in the mapping.
|
||||
*/
|
||||
public String getAttributeValue(String attributeName, boolean trim, boolean emptySameAsNull, String defaultValue);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* <p>Conversion of text to Integer performed by Integer.valueOf(String).</p>
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @return The attribute value that associated with the given attribute name. This will be <code>null</code> if the attribute name is not in the mapping.
|
||||
*/
|
||||
public Integer getAttributeIntegerValue(String attributeName);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* <p>Conversion of text to Integer performed by Integer.valueOf(String).</p>
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @param defaultValue The value to be returned if the result would have been null.
|
||||
* @return The attribute value that associated with the given attribute name. This will be the default value if the attribute name is not in the mapping.
|
||||
*/
|
||||
public Integer getAttributeIntegerValue(String attributeName, Integer defaultValue);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* <p>Conversion of text to Long performed by Long.valueOf(String).</p>
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @return The attribute value that associated with the given attribute name. This will be <code>null</code> if the attribute name is not in the mapping.
|
||||
*/
|
||||
public Long getAttributeLongValue(String attributeName);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* <p>Conversion of text to Long performed by Long.valueOf(String).</p>
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @param defaultValue The value to be returned if the result would have been null.
|
||||
* @return The attribute value that associated with the given attribute name. This will be the default value if the attribute name is not in the mapping.
|
||||
*/
|
||||
public Long getAttributeLongValue(String attributeName, Long defaultValue);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* <p>Conversion of text to Boolean performed by Boolean.valueOf(String).</p>
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @return The attribute value that associated with the given attribute name. This will be <code>null</code> if the attribute name is not in the mapping.
|
||||
*/
|
||||
public Boolean getAttributeBooleanValue(String attributeName);
|
||||
/**
|
||||
* Gets the value of the attribute that has the associated attribute name.
|
||||
* <p>Conversion of text to Boolean performed by Boolean.valueOf(String).</p>
|
||||
* @param attributeName The name of the attribute to lookup.
|
||||
* @param defaultValue The value to be returned if the result would have been null.
|
||||
* @return The attribute value that associated with the given attribute name. This will be the default value if the attribute name is not in the mapping.
|
||||
*/
|
||||
public Boolean getAttributeBooleanValue(String attributeName, Boolean defaultValue);
|
||||
/**
|
||||
* Gets the collection of attributes defined within the node start tag.
|
||||
* @return The ordered collection of IAttribute objects.
|
||||
*/
|
||||
public IManagedList getAttributes();
|
||||
/**
|
||||
* Determines whether the attribute exists in this node.
|
||||
* @param attributeName The name of the attribute to look for.
|
||||
* @return Whether this node has this attribute.
|
||||
*/
|
||||
public boolean hasAttribute(String attributeName);
|
||||
/**
|
||||
* Removes the attribute from the node.
|
||||
* @param attributeName Identifies the attribute to remove by its' name.
|
||||
* @return Whether the attribute was removed.
|
||||
*/
|
||||
public boolean removeAttribute(String attributeName);
|
||||
/**
|
||||
* A convienence method that creates a new node and adds it to the end of the collection of elements.
|
||||
* @param name An optional name for the node. The node's name can also be set by calling the <code>INode.setName(String)</code> method.
|
||||
* @return A new empty node element that is pre-added to this node's collection of contained elements.
|
||||
*/
|
||||
public INode createNode(String name);
|
||||
/**
|
||||
* A convienence method that creates a new text node and adds it to the end of the collection of elements.
|
||||
* @return A new empty text element that is pre-added to this node's collection of contained elements.
|
||||
*/
|
||||
public IText createText();
|
||||
/**
|
||||
* A convienence method that creates a new text node and adds it to the end of the collection of elements.
|
||||
* @param text The text to place in the text element.
|
||||
* @return A new text element that is pre-added to this node's collection of contained elements.
|
||||
*/
|
||||
public IText createText(String text);
|
||||
/**
|
||||
* A convienence method that creates a new comment node and adds it to the end of the collection of elements.
|
||||
* @return A new empty comment element that is pre-added to this node's collection of contained elements.
|
||||
*/
|
||||
public IComment createComment();
|
||||
/**
|
||||
* A convienence method that creates a new comment node and adds it to the end of the collection of elements.
|
||||
* @param comment The text to place in the comment element.
|
||||
* @return A new comment element that is pre-added to this node's collection of contained elements.
|
||||
*/
|
||||
public IComment createComment(String comment);
|
||||
/**
|
||||
* Locate the first node with the given name.
|
||||
* @param name The name of the node to find.
|
||||
* @return The node found, or null.
|
||||
*/
|
||||
public INode findNode(String name);
|
||||
/**
|
||||
* Locates all nodes with the given name that are children of just this node.
|
||||
* @param name The name of the nodes to find.
|
||||
* @param results The collection to fill with results.
|
||||
*/
|
||||
public void findNodes(String name, ICollection results);
|
||||
/**
|
||||
* Locates all nodes with the given name.
|
||||
* @param name The name of the nodes to find.
|
||||
* @param results The collection to fill with results.
|
||||
* @param recursive Whether the nodes in the tree should be recursively navigated to find results.
|
||||
*/
|
||||
public void findNodes(String name, ICollection results, boolean recursive);
|
||||
}//IAbstractNode//
|
||||
77
Foundation/src/com/foundation/util/xml/IAttribute.java
Normal file
77
Foundation/src/com/foundation/util/xml/IAttribute.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
/**
|
||||
* Note that the hasErrors flag represents errors in the name of the attribute, while the hasValueErrors represents errors in the value.
|
||||
*/
|
||||
public interface IAttribute extends IElement {
|
||||
public static final int QUOTE_TYPE_DOUBLE = 0;
|
||||
public static final int QUOTE_TYPE_SINGLE = 1;
|
||||
public static final int QUOTE_TYPE_NONE = 2;
|
||||
/**
|
||||
* Gets whether the element has errors in the value.
|
||||
* <p>The hasErrors flag represents errors only in the attribute name.
|
||||
* @return Whether the reader detected errors in the value.
|
||||
*/
|
||||
public boolean hasValueErrors();
|
||||
/**
|
||||
* Gets the name of the attribute.
|
||||
* @return The attribute's name which is how the attribute is identified.
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* Gets the attribute's value.
|
||||
* @return The value associated with this attribute.
|
||||
*/
|
||||
public String getValue();
|
||||
/**
|
||||
* Gets the type of quote used for the attribute in the xml.
|
||||
* @return One of the QUOTE_TYPE_xx identifiers.
|
||||
*/
|
||||
public int getQuoteType();
|
||||
/**
|
||||
* Sets the type of quote used for the attribute in the xml.
|
||||
* @param quoteType One of the QUOTE_TYPE_xx identifiers.
|
||||
*/
|
||||
public void setQuoteType(int quoteType);
|
||||
/**
|
||||
* Gets the number of quote characters that begin and end the attribute's value.
|
||||
* @return The count of characters at the beginning and end of the attribute value that are quoting the value.
|
||||
*/
|
||||
public int getQuoteCharacterCount();
|
||||
/**
|
||||
* Gets the attribute's value.
|
||||
* @param trim Whether the value should be trimed of excees spacing before and after any values.
|
||||
* @param emptySameAsNull Whether the empty values (after optional trimming) should be replaced by null values.
|
||||
* @return The value associated with this attribute.
|
||||
*/
|
||||
public String getValue(boolean trim, boolean emptySameAsNull);
|
||||
/**
|
||||
* Sets the attribute's value.
|
||||
* @param value The value associated with this attribute.
|
||||
*/
|
||||
public void setValue(String value);
|
||||
/**
|
||||
* Sets the name of the node.
|
||||
* @param name The node's name which is how the node is identified.
|
||||
*/
|
||||
public void setName(String name);
|
||||
/**
|
||||
* Gets the index of the last value character.
|
||||
* <p>This will be non-negative no matter what, though if there is no value then this will be the same as the endCharacter value.
|
||||
* @return The last character in the value.
|
||||
*/
|
||||
public int getNameEndCharacter();
|
||||
/**
|
||||
* Gets the index of the first value character (including the quotes).
|
||||
* <p>If this is not -1, then a value was specified and the endCharacter refers the the last character of the value (which would be the ending quote).
|
||||
* @return The first character in the value.
|
||||
*/
|
||||
public int getValueStartCharacter();
|
||||
}//IAttribute//
|
||||
21
Foundation/src/com/foundation/util/xml/IComment.java
Normal file
21
Foundation/src/com/foundation/util/xml/IComment.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2007 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public interface IComment extends IElement {
|
||||
/**
|
||||
* Gets the text for this comment element.
|
||||
* @return The text associated with this comment element.
|
||||
*/
|
||||
public String getText();
|
||||
/**
|
||||
* Sets the text for this comment element.
|
||||
* @param text The text associated with this comment element.
|
||||
*/
|
||||
public void setText(String text);
|
||||
}//IComment//
|
||||
31
Foundation/src/com/foundation/util/xml/IDocType.java
Normal file
31
Foundation/src/com/foundation/util/xml/IDocType.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public interface IDocType extends IElement {
|
||||
/**
|
||||
* Gets the document type name (ie: HTML).
|
||||
* @return The document type name.
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* Gets the document type visibility (ie: PUBLIC).
|
||||
* @return The document type visibility.
|
||||
*/
|
||||
public String getVisibility();
|
||||
/**
|
||||
* Gets the document type's public identifier (ie: -//W3C//DTD XHTML Basic 1.0//EN).
|
||||
* @return The document type's public identifier or null if not available.
|
||||
*/
|
||||
public String getPublicIdentifier();
|
||||
/**
|
||||
* Gets the document type's system identifier (ie: http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd).
|
||||
* @return The document type's system identifier (path to the dtd).
|
||||
*/
|
||||
public String getSystemIdentifier();
|
||||
}//IDocType//
|
||||
32
Foundation/src/com/foundation/util/xml/IDocument.java
Normal file
32
Foundation/src/com/foundation/util/xml/IDocument.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.foundation.util.IManagedList;
|
||||
|
||||
/**
|
||||
* Note: A document contains metadata elements, then a doctype, then elements, in that order.
|
||||
*/
|
||||
public interface IDocument extends IAbstractNode {
|
||||
/**
|
||||
* Gets the collection of ordered metadata nodes and comments defined at the very top of the document.
|
||||
* <p>Note that these node objects cannot contain child elements. We may at some point define a special class for this data instead of using the Node class.</p>
|
||||
* @return The ordered metadata nodes <?name attr="value" ... ?> defined at the top of the document.
|
||||
*/
|
||||
public IManagedList getMetadataElements();
|
||||
/**
|
||||
* Gets the DOCTYPE data for the document.
|
||||
* @return The document type metadata or null if none was provided.
|
||||
*/
|
||||
public IDocType getDocType();
|
||||
/**
|
||||
* Sets the DOCTYPE data for the document.
|
||||
* @param docType The document type metadata or null if none is provided.
|
||||
*/
|
||||
public void setDocType(IDocType docType);
|
||||
}//IDocument//
|
||||
85
Foundation/src/com/foundation/util/xml/IElement.java
Normal file
85
Foundation/src/com/foundation/util/xml/IElement.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public interface IElement {
|
||||
/**
|
||||
* Gets whether the element has errors in it but is still detectable.
|
||||
* @return Whether the reader detected errors in this element of the document.
|
||||
*/
|
||||
public boolean hasErrors();
|
||||
/**
|
||||
* Gets this element's parent node.
|
||||
* @return The parent node, or null if this element does not have a parent (only the case for the document).
|
||||
*/
|
||||
public IAbstractNode getParent();
|
||||
/**
|
||||
* Determines whether this is an IComment instance.
|
||||
* @return Whether this instance implements IComment.
|
||||
*/
|
||||
public boolean isComment();
|
||||
/**
|
||||
* Determines whether this is an INode instance.
|
||||
* @return Whether this instance implements INode.
|
||||
*/
|
||||
public boolean isNode();
|
||||
/**
|
||||
* Determines whether this is an IText instance.
|
||||
* @return Whether this instance implements IText.
|
||||
*/
|
||||
public boolean isText();
|
||||
/**
|
||||
* Determines whether this is an IDocument instance.
|
||||
* @return Whether this instance implements IDocument.
|
||||
*/
|
||||
public boolean isDocument();
|
||||
/**
|
||||
* Determines whether this is an IInvalid instance.
|
||||
* @return Whether this instance implements IInvalid.
|
||||
*/
|
||||
public boolean isInvalid();
|
||||
/**
|
||||
* Writes the element to the buffer.
|
||||
* @param out The output stream that will be given the formatted element data.
|
||||
* @param builder The document builder that will provide guidance.
|
||||
* @param prepend The string that will be added before any other characters in a perticular line.
|
||||
* @param postpend The string that will be added after any other characters in a perticular line.
|
||||
* @param compact Whether the output should be kept compact, or should include formatting characters.
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws java.io.IOException;
|
||||
/**
|
||||
* Gets the line number on which the text begins.
|
||||
* @return The line number where the start of the text is.
|
||||
*/
|
||||
public int getStartLine();
|
||||
/**
|
||||
* Gets the line number on which the text ends.
|
||||
* @return The line number where the end of the text is.
|
||||
*/
|
||||
public int getEndLine();
|
||||
/**
|
||||
* Gets the character number within the line where the text begins (inclusive).
|
||||
* @return The index of the character from the beginning of the line.
|
||||
*/
|
||||
public int getStartLineCharacter();
|
||||
/**
|
||||
* Gets the character number within the line where the text ends (inclusive).
|
||||
* @return The index of the character from the beginning of the line.
|
||||
*/
|
||||
public int getEndLineCharacter();
|
||||
/**
|
||||
* Gets the character number within the file where the text begins (inclusive).
|
||||
* @return The index of the character from the beginning of the file.
|
||||
*/
|
||||
public int getStartCharacter();
|
||||
/**
|
||||
* Gets the character number within the file where the text ends (inclusive).
|
||||
* @return The index of the character from the beginning of the file.
|
||||
*/
|
||||
public int getEndCharacter();
|
||||
}//IElement//
|
||||
21
Foundation/src/com/foundation/util/xml/IInvalid.java
Normal file
21
Foundation/src/com/foundation/util/xml/IInvalid.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public interface IInvalid extends IElement {
|
||||
/**
|
||||
* Gets the invalid text for this element.
|
||||
* @return The invalid text associated with this element.
|
||||
*/
|
||||
public String getInvalidText();
|
||||
/**
|
||||
* Sets the invalid text for this element.
|
||||
* @param invalidText The invalid text associated with this element.
|
||||
*/
|
||||
public void setInvalidText(String invalidText);
|
||||
}//IInvalid//
|
||||
11
Foundation/src/com/foundation/util/xml/IMetadataNode.java
Normal file
11
Foundation/src/com/foundation/util/xml/IMetadataNode.java
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public interface IMetadataNode extends INode {
|
||||
}//IMetadataNode//
|
||||
71
Foundation/src/com/foundation/util/xml/INode.java
Normal file
71
Foundation/src/com/foundation/util/xml/INode.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
/**
|
||||
* Possible use cases:<br>
|
||||
* <tagname attribute="abc"></tagname><br>
|
||||
* <tagname attribute="abc"/><br>
|
||||
* <tagname attribute="abc"> <-- some html tags such as <p> may not have an end tag.<br>
|
||||
* The StartCharacter and EndCharacter represent the very first and very last character indices in the node.
|
||||
* INode adds to that StartTagTailStartCharacter, StartTagTailEndCharacter, StartTagEndNameCharacter, and EndTagStartCharacter so that all of the beginning and ends of the formatting characters have known positions.
|
||||
* <p>
|
||||
* For an INode, the ordering would be thus:<br>
|
||||
* 1) StartCharacter<br>
|
||||
* Node Name<br>
|
||||
* 2) StartTagEndNameCharacter<br>
|
||||
* Node attributes, comments, etc...<br>
|
||||
* 3) StartTagTailStartCharacter<br>
|
||||
* 4) StartTagTailEndCharacter (may be the same as EndCharacter in some use cases)<br>
|
||||
* Child nodes, comments, etc..<br>
|
||||
* 5) EndTagStartCharacter (optional for some use cases - will be zero if not provided)<br>
|
||||
* 6) EndCharacter<br>
|
||||
*/
|
||||
public interface INode extends IAbstractNode {
|
||||
/**
|
||||
* Gets whether the node should always display an end tag.
|
||||
* @return Whether the node should display an end tag even if one is not required.
|
||||
*/
|
||||
public boolean useEndTag();
|
||||
/**
|
||||
* Gets whether the node has no ending tag and the starting tag does not end with a slash.
|
||||
* <br>For example: <mynode attr='abc'>.
|
||||
* @return Whether the node does not have a proper XML ending.
|
||||
*/
|
||||
public boolean isEndless();
|
||||
/**
|
||||
* Gets the global character offset of the last character of the start tag (inclusive).
|
||||
* @return The index of the character from the beginning of the file.
|
||||
*/
|
||||
public int getStartTagTailStartCharacter();
|
||||
/**
|
||||
* Gets the global character offset of the last character of the start tag (inclusive).
|
||||
* @return The index of the character from the beginning of the file.
|
||||
*/
|
||||
public int getStartTagTailEndCharacter();
|
||||
/**
|
||||
* Gets the global character offset of the last character of the start tag name (inclusive).
|
||||
* @return The index of the character from the beginning of the file.
|
||||
*/
|
||||
public int getStartTagEndNameCharacter();
|
||||
/**
|
||||
* Gets the global character offset of the first character of the ending tag (inclusive).
|
||||
* @return The index of the character from the beginning of the file.
|
||||
*/
|
||||
public int getEndTagStartCharacter();
|
||||
/**
|
||||
* Gets the name of the node.
|
||||
* @return The node's name which is how the node is identified.
|
||||
*/
|
||||
public String getName();
|
||||
/**
|
||||
* Sets the name of the node.
|
||||
* @param name The node's name which is how the node is identified.
|
||||
*/
|
||||
public void setName(String name);
|
||||
}//INode//
|
||||
21
Foundation/src/com/foundation/util/xml/IText.java
Normal file
21
Foundation/src/com/foundation/util/xml/IText.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2007 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
public interface IText extends IElement {
|
||||
/**
|
||||
* Gets the text for this text element.
|
||||
* @return The text associated with this text element.
|
||||
*/
|
||||
public String getText();
|
||||
/**
|
||||
* Sets the text for this text element.
|
||||
* @param text The text associated with this text element.
|
||||
*/
|
||||
public void setText(String text);
|
||||
}//IText//
|
||||
64
Foundation/src/com/foundation/util/xml/Invalid.java
Normal file
64
Foundation/src/com/foundation/util/xml/Invalid.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Invalid extends Element implements IInvalid {
|
||||
private String invalidText = null;
|
||||
/**
|
||||
* Invalid constructor.
|
||||
*/
|
||||
public Invalid() {
|
||||
}//Invalid()//
|
||||
/**
|
||||
* Invalid constructor.
|
||||
* @param invalidText The invalid text.
|
||||
*/
|
||||
public Invalid(String invalidText) {
|
||||
setInvalidText(invalidText);
|
||||
}//Invalid()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IInvalid#getInvalidText()
|
||||
*/
|
||||
public String getInvalidText() {
|
||||
return invalidText;
|
||||
}//getInvalidText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IInvalid#setInvalidText(java.lang.String)
|
||||
*/
|
||||
public void setInvalidText(String invalidText) {
|
||||
this.invalidText = invalidText;
|
||||
}//setInvalidText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#isInvalid()
|
||||
*/
|
||||
public boolean isInvalid() {
|
||||
return true;
|
||||
}//isInvalid()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#write(com.foundation.util.xml.XmlOutputStream, com.foundation.util.xml.DocumentBuilder, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws IOException {
|
||||
out.write(prepend);
|
||||
out.write(getInvalidText());
|
||||
out.write(postpend);
|
||||
}//write()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#hasErrors()
|
||||
*/
|
||||
public boolean hasErrors() {
|
||||
return true;
|
||||
}//hasErrors()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#hasErrors(boolean)
|
||||
*/
|
||||
public void hasErrors(boolean hasErrors) {
|
||||
//Does nothing.. invalid tags obviously have errors.//
|
||||
}//hasErrors()//
|
||||
}//Invalid//
|
||||
141
Foundation/src/com/foundation/util/xml/MetadataNode.java
Normal file
141
Foundation/src/com/foundation/util/xml/MetadataNode.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.foundation.util.*;
|
||||
|
||||
/*
|
||||
* The node that occurs at the top of a document only and provides some metadata on the document.
|
||||
*/
|
||||
public class MetadataNode extends Node implements IMetadataNode {
|
||||
/**
|
||||
* MetadataNode constructor.
|
||||
*/
|
||||
public MetadataNode() {
|
||||
super();
|
||||
}//MetadataNode()//
|
||||
/**
|
||||
* MetadataNode constructor.
|
||||
* @param name The initial name for the node.
|
||||
*/
|
||||
public MetadataNode(String name) {
|
||||
super(name);
|
||||
}//MetadataNode()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartTagTailEndCharacter()
|
||||
*/
|
||||
public int getStartTagTailEndCharacter() {
|
||||
return getEndCharacter();
|
||||
}//getStartTagTailEndCharacter()//
|
||||
/**
|
||||
* Sets the global character offset of the last character of the start tag (inclusive).
|
||||
* @param startTagTailEndCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setStartTagTailEndCharacter(int startTagTailEndCharacter) {
|
||||
setEndCharacter(startTagTailEndCharacter);
|
||||
}//setStartTagTailEndCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartTagTailEndLine()
|
||||
*/
|
||||
public int getStartTagTailEndLine() {
|
||||
return getEndLine();
|
||||
}//getStartTagTailEndLine()//
|
||||
/**
|
||||
* Sets the line offset of the last character of the start tag.
|
||||
* @param startTagTailEndLine The line number where the end of the node is.
|
||||
*/
|
||||
public void setStartTagTailEndLine(int startTagTailEndLine) {
|
||||
setEndLine(startTagTailEndLine);
|
||||
}//setStartTagTailEndLine()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartTagTailEndLineCharacter()
|
||||
*/
|
||||
public int getStartTagTailEndLineCharacter() {
|
||||
return getEndLineCharacter();
|
||||
}//getStartTagTailEndLineCharacter()//
|
||||
/**
|
||||
* Sets the line character offset of the last character of the start tag (inclusive).
|
||||
* @param startTagTailEndLineCharacter The index of the character from the beginning of the line.
|
||||
*/
|
||||
public void setStartTagTailEndLineCharacter(int startTagTailEndLineCharacter) {
|
||||
setEndLineCharacter(startTagTailEndLineCharacter);
|
||||
}//setStartTagTailEndLineCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getEndTagStartCharacter()
|
||||
*/
|
||||
public int getEndTagStartCharacter() {
|
||||
return 0;
|
||||
}//getEndTagStartCharacter()//
|
||||
/**
|
||||
* Sets the global character offset of the first character of the ending tag (inclusive).
|
||||
* @param endTagStartCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setEndTagStartCharacter(int endTagStartCharacter) {
|
||||
}//setEndTagStartCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getEndTagStartLine()
|
||||
*/
|
||||
public int getEndTagStartLine() {
|
||||
return 0;
|
||||
}//getEndTagStartLine()//
|
||||
/**
|
||||
* Sets the line offset of the first character of the ending tag.
|
||||
* @param endTagStartLine The line number where the end of the node is.
|
||||
*/
|
||||
public void setEndTagStartLine(int endTagStartLine) {
|
||||
}//setEndTagStartLine()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getEndTagStartLineCharacter()
|
||||
*/
|
||||
public int getEndTagStartLineCharacter() {
|
||||
return 0;
|
||||
}//getEndTagStartLineCharacter()//
|
||||
/**
|
||||
* Sets the line character offset of the first character of the ending tag (inclusive).
|
||||
* @param endTagStartLineCharacter The index of the character from the beginning of the line.
|
||||
*/
|
||||
public void setEndTagStartLineCharacter(int endTagStartLineCharacter) {
|
||||
}//setEndTagStartLineCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#createNode(java.lang.String)
|
||||
*/
|
||||
public INode createNode(String name) {
|
||||
return null;
|
||||
}//createNode()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getElements()
|
||||
*/
|
||||
public IManagedList getElements() {
|
||||
return ManagedList.EMPTY_LIST;
|
||||
}//getElements()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#write(com.foundation.util.xml.XmlOutputStream, com.foundation.util.xml.DocumentBuilder, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws java.io.IOException {
|
||||
out.write(prepend);
|
||||
out.write("<?");
|
||||
out.write(getName());
|
||||
|
||||
//Write the attributes.//
|
||||
for(int index = 0; index < getAttributes().getSize(); index++) {
|
||||
IAttribute attribute = (IAttribute) getAttributes().get(index);
|
||||
|
||||
out.write(' ');
|
||||
attribute.write(out, builder, null, null, compact);
|
||||
}//for//
|
||||
|
||||
out.write("?>");
|
||||
out.write(postpend);
|
||||
}//write()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "Metadata Node: " + getName();
|
||||
}//toString()//
|
||||
}//MetadataNode//
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.common.util.*;
|
||||
import com.foundation.util.*;
|
||||
|
||||
/**
|
||||
* Defines how the node's elements collection will be managed.
|
||||
*/
|
||||
final class MetadataNodeListManager extends ListManager {
|
||||
private Document document = null;
|
||||
/**
|
||||
* ElementListManager constructor.
|
||||
* @param node The node that this manager is servicing. Every element added to the collection will be given this node as its' parent.
|
||||
*/
|
||||
public MetadataNodeListManager(Document document) {
|
||||
super();
|
||||
|
||||
if(document == null) {
|
||||
throw new NullPointerException("It is not allowed to pass the MetadataNodeListManager a null document reference.");
|
||||
}//if//
|
||||
|
||||
this.document = document;
|
||||
}//ElementListManager()//
|
||||
/**
|
||||
* Determines whether the value can be added to the collection.
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @param value The value that may be added.
|
||||
* @return Whether the value can be added to the collection.
|
||||
*/
|
||||
public boolean canAdd(IManagedCollection managed, Object value, byte context) {
|
||||
return (super.canAdd(managed, value, context)) && (value instanceof MetadataNode || value instanceof Property);
|
||||
}//canAdd()//
|
||||
/**
|
||||
* Determines whether the user can make the collection immutable (unchangeable).
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @return Whether the collection immutable flag can be set.
|
||||
*/
|
||||
public boolean canMakeImmutable(IManagedCollection managed) {
|
||||
return false;
|
||||
}//canMakeImmutable()//
|
||||
/**
|
||||
* Determines whether the collection should ask the manager to allow an add operation.
|
||||
* @return Whether this manager will be asked for permission before an add operation.
|
||||
*/
|
||||
public boolean checkOnAdd() {
|
||||
return true;
|
||||
}//checkOnAdd()//
|
||||
/**
|
||||
* Determines whether the collection should notify the manager after an add operation occurs.
|
||||
* @return Whether this manager will be notified after an add operation.
|
||||
*/
|
||||
public boolean notifyOnPostAdd() {
|
||||
return true;
|
||||
}//notifyOnPostAdd()//
|
||||
/**
|
||||
* Determines whether the collection should notify the manager after a remove operation occurs.
|
||||
* @return Whether this manager will be notified after a remove operation.
|
||||
*/
|
||||
public boolean notifyOnPostRemove() {
|
||||
return true;
|
||||
}//notifyOnPostRemove()//
|
||||
/**
|
||||
* Allows the manager to provide functionality after a value has been added to the collection.
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @param value The value that has be added.
|
||||
* @see #preAdd(Object)
|
||||
*/
|
||||
public void postAdd(IManagedCollection managed, Object value, byte context) {
|
||||
if(value instanceof Node) {
|
||||
((Node) value).setParent(document);
|
||||
}//if//
|
||||
|
||||
super.postAdd(managed, value, context);
|
||||
}//postAdd()//
|
||||
/**
|
||||
* Allows the manager to provide functionality after a value has been removed from the collection.
|
||||
* @param managed The collection that is being managed by this ICollectionManager.
|
||||
* @param value The value that has be removed.
|
||||
* @see #preRemove(Object)
|
||||
*/
|
||||
public void postRemove(IManagedCollection managed, Object value, byte context) {
|
||||
if(value instanceof Node) {
|
||||
((Node) value).setParent(null);
|
||||
}//if//
|
||||
|
||||
super.postRemove(managed, value, context);
|
||||
}//postRemove()//
|
||||
}//ElementListManager//
|
||||
218
Foundation/src/com/foundation/util/xml/Node.java
Normal file
218
Foundation/src/com/foundation/util/xml/Node.java
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.common.util.*;
|
||||
|
||||
public class Node extends AbstractNode implements INode {
|
||||
/** The name of the node. */
|
||||
private String name = null;
|
||||
/** The global character offset of the first character of the start tag. */
|
||||
private int startTagTailStartCharacter = -1;
|
||||
/** The global character offset of the last character of the start tag. */
|
||||
private int startTagTailEndCharacter = -1;
|
||||
/** The global character offset of the last character of the start tag name. */
|
||||
private int startTagEndNameCharacter = -1;
|
||||
/** The global character offset of the first character of the ending tag. */
|
||||
private int endTagStartCharacter = -1;
|
||||
/** Whether the node has no end tag and was not properly (by XML standards) ended in the start tag. Example of a node where isEndless is true: <mynode attr='abc'>. */
|
||||
private boolean isEndless = false;
|
||||
/** Whether to display an end tag even if one is not necessary (set to true if reading and an end tag existed). */
|
||||
private boolean useEndTag = false;
|
||||
/**
|
||||
* Node constructor.
|
||||
*/
|
||||
public Node() {
|
||||
super();
|
||||
}//Node()//
|
||||
/**
|
||||
* Node constructor.
|
||||
* @param name The initial name for the node.
|
||||
*/
|
||||
public Node(String name) {
|
||||
super();
|
||||
|
||||
setName(name);
|
||||
}//Node()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#useEndTag()
|
||||
*/
|
||||
public boolean useEndTag() {
|
||||
return useEndTag;
|
||||
}//useEndTag()//
|
||||
/**
|
||||
* Sets whether the node should always display an end tag.
|
||||
* @param useEndTag Whether the node should display an end tag even if one is not required.
|
||||
*/
|
||||
public void useEndTag(boolean useEndTag) {
|
||||
this.useEndTag = useEndTag;
|
||||
}//useEndTag()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#isEndless()
|
||||
*/
|
||||
public boolean isEndless() {
|
||||
return isEndless;
|
||||
}//isEndless()//
|
||||
/**
|
||||
* Sets whether the node has no ending tag and the starting tag does not end with a slash.
|
||||
* <br>For example: <mynode attr='abc'>.
|
||||
* @param isEndless Whether the node does not have a proper XML ending.
|
||||
*/
|
||||
public void isEndless(boolean isEndless) {
|
||||
this.isEndless = isEndless;
|
||||
}//isEndless()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartTagTailStartCharacter()
|
||||
*/
|
||||
public int getStartTagTailStartCharacter() {
|
||||
return startTagTailStartCharacter;
|
||||
}//getStartTagTailStartCharacter()//
|
||||
/**
|
||||
* Sets the global character offset of the first character of the start tag (inclusive).
|
||||
* @param startTagTailStartCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setStartTagTailStartCharacter(int startTagTailStartCharacter) {
|
||||
this.startTagTailStartCharacter = startTagTailStartCharacter;
|
||||
}//setStartTagTailStartCharacter()//
|
||||
/* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartTagTailEndCharacter()
|
||||
*/
|
||||
public int getStartTagTailEndCharacter() {
|
||||
return startTagTailEndCharacter;
|
||||
}//getStartTagTailEndCharacter()//
|
||||
/**
|
||||
* Sets the global character offset of the last character of the start tag (inclusive).
|
||||
* @param startTagTailEndCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setStartTagTailEndCharacter(int startTagTailEndCharacter) {
|
||||
this.startTagTailEndCharacter = startTagTailEndCharacter;
|
||||
}//setStartTagTailEndCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getStartTagEndNameCharacter()
|
||||
*/
|
||||
public int getStartTagEndNameCharacter() {
|
||||
return startTagEndNameCharacter;
|
||||
}//getStartTagEndNameCharacter()//
|
||||
/**
|
||||
* Sets the global character offset of the last character of the start tag name (inclusive).
|
||||
* @param startTagEndNameCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setStartTagEndNameCharacter(int startTagEndNameCharacter) {
|
||||
this.startTagEndNameCharacter = startTagEndNameCharacter;
|
||||
}//setStartTagEndNameCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.INode#getEndTagStartCharacter()
|
||||
*/
|
||||
public int getEndTagStartCharacter() {
|
||||
return endTagStartCharacter;
|
||||
}//getEndTagStartCharacter()//
|
||||
/**
|
||||
* Sets the global character offset of the first character of the ending tag (inclusive).
|
||||
* @param endTagStartCharacter The index of the character from the beginning of the file.
|
||||
*/
|
||||
public void setEndTagStartCharacter(int endTagStartCharacter) {
|
||||
this.endTagStartCharacter = endTagStartCharacter;
|
||||
}//setEndTagStartCharacter()//
|
||||
/**
|
||||
* Gets the name of the node.
|
||||
* @return The node's name which is how the node is identified.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}//getName()//
|
||||
/**
|
||||
* Determines whether this is an IComment instance.
|
||||
* @return Whether this instance implements IComment.
|
||||
*/
|
||||
public boolean isComment() {
|
||||
return false;
|
||||
}//isComment()//
|
||||
/**
|
||||
* Determines whether this is an INode instance.
|
||||
* @return Whether this instance implements INode.
|
||||
*/
|
||||
public boolean isNode() {
|
||||
return true;
|
||||
}//isNode()//
|
||||
/**
|
||||
* Determines whether this is an IText instance.
|
||||
* @return Whether this instance implements IText.
|
||||
*/
|
||||
public boolean isText() {
|
||||
return false;
|
||||
}//isText()//
|
||||
/**
|
||||
* Sets the name of the node.
|
||||
* @param name The node's name which is how the node is identified.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}//setName()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IElement#write(com.foundation.util.xml.XmlOutputStream, com.foundation.util.xml.DocumentBuilder, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws java.io.IOException {
|
||||
IIterator iterator = null;
|
||||
|
||||
out.write(prepend);
|
||||
out.write('<');
|
||||
out.write(getName());
|
||||
iterator = getAttributes().iterator();
|
||||
|
||||
//Write the attributes.//
|
||||
while(iterator.hasNext()) {
|
||||
if(iterator.hasNext()) {
|
||||
out.write(' ');
|
||||
}//if//
|
||||
|
||||
((IAttribute) iterator.next()).write(out, builder, null, null, compact);
|
||||
}//while//
|
||||
|
||||
//Write the child elements.//
|
||||
if(getElements().getSize() == 1 && getElements().getFirst() instanceof IText) {
|
||||
out.write('>');
|
||||
((IText) getElements().getFirst()).write(out, builder, "", "", compact);
|
||||
out.write("</");
|
||||
out.write(getName());
|
||||
out.write('>');
|
||||
}//if//
|
||||
else if(getElements().getSize() > 0 || useEndTag()) {
|
||||
out.write('>');
|
||||
out.write(postpend);
|
||||
iterator = getElements().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
IElement element = (IElement) iterator.next();
|
||||
|
||||
element.write(out, builder, compact ? prepend : "\t" + prepend, postpend, compact);
|
||||
}//while//
|
||||
|
||||
out.write(prepend);
|
||||
out.write("</");
|
||||
out.write(getName());
|
||||
out.write('>');
|
||||
}//else if//
|
||||
else {
|
||||
if(isEndless()) {
|
||||
out.write(">");
|
||||
}//if//
|
||||
else {
|
||||
out.write("/>");
|
||||
}//else//
|
||||
}//else//
|
||||
|
||||
out.write(postpend);
|
||||
}//write()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "Node: " + getName() + " Indicies: " + getStartCharacter() + ", " + getStartTagEndNameCharacter() + ", " + getStartTagTailStartCharacter() + ", " + getStartTagTailEndCharacter() + ", " + getEndTagStartCharacter() + ", " + getEndCharacter();
|
||||
}//toString()//
|
||||
}//Node//
|
||||
287
Foundation/src/com/foundation/util/xml/Property.java
Normal file
287
Foundation/src/com/foundation/util/xml/Property.java
Normal file
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2009 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.common.util.optimized.CharHashSet;
|
||||
|
||||
/*
|
||||
* Implements a simple XML property which is a member of a node.
|
||||
*/
|
||||
public class Property extends Element implements IAttribute {
|
||||
public static final CharHashSet ENCODED_CHARS_DOUBLE_QUOTES;
|
||||
public static final CharHashSet ENCODED_CHARS_SINGLE_QUOTES;
|
||||
public static final CharHashSet ENCODED_CHARS_NO_QUOTES;
|
||||
public static final CharHashSet ENCODED_CHARS_DOUBLE_QUOTES_PLUS_SLASH;
|
||||
public static final CharHashSet ENCODED_CHARS_SINGLE_QUOTES_PLUS_SLASH;
|
||||
public static final CharHashSet ENCODED_CHARS_NO_QUOTES_PLUS_SLASH;
|
||||
|
||||
static {
|
||||
ENCODED_CHARS_DOUBLE_QUOTES = new CharHashSet(DocumentBuilder.defaultEncodedCharacters, DocumentBuilder.defaultEncodedCharacters.getSize() + 10, CharHashSet.DEFAULT_LOAD_FACTOR, CharHashSet.STYLE_NO_DUPLICATES);
|
||||
ENCODED_CHARS_DOUBLE_QUOTES.addAll(new char[] {'"', '\n', '\r', '&', '<', '>'});
|
||||
ENCODED_CHARS_DOUBLE_QUOTES.isChangeable(false);
|
||||
ENCODED_CHARS_SINGLE_QUOTES = new CharHashSet(DocumentBuilder.defaultEncodedCharacters, DocumentBuilder.defaultEncodedCharacters.getSize() + 10, CharHashSet.DEFAULT_LOAD_FACTOR, CharHashSet.STYLE_NO_DUPLICATES);
|
||||
ENCODED_CHARS_SINGLE_QUOTES.addAll(new char[] {'\'', '\n', '\r', '&', '<', '>'});
|
||||
ENCODED_CHARS_SINGLE_QUOTES.isChangeable(false);
|
||||
ENCODED_CHARS_NO_QUOTES = new CharHashSet(DocumentBuilder.defaultEncodedCharacters, DocumentBuilder.defaultEncodedCharacters.getSize() + 10, CharHashSet.DEFAULT_LOAD_FACTOR, CharHashSet.STYLE_NO_DUPLICATES);
|
||||
ENCODED_CHARS_NO_QUOTES.addAll(new char[] {' ', '\n', '\r', '&', '<', '>'});
|
||||
ENCODED_CHARS_NO_QUOTES.isChangeable(false);
|
||||
|
||||
ENCODED_CHARS_DOUBLE_QUOTES_PLUS_SLASH = new CharHashSet(DocumentBuilder.defaultEncodedCharacters, DocumentBuilder.defaultEncodedCharacters.getSize() + 10, CharHashSet.DEFAULT_LOAD_FACTOR, CharHashSet.STYLE_NO_DUPLICATES);
|
||||
ENCODED_CHARS_DOUBLE_QUOTES_PLUS_SLASH.addAll(new char[] {'"', '\n', '\r', '&', '<', '>', '\\'});
|
||||
ENCODED_CHARS_DOUBLE_QUOTES_PLUS_SLASH.isChangeable(false);
|
||||
ENCODED_CHARS_SINGLE_QUOTES_PLUS_SLASH = new CharHashSet(DocumentBuilder.defaultEncodedCharacters, DocumentBuilder.defaultEncodedCharacters.getSize() + 10, CharHashSet.DEFAULT_LOAD_FACTOR, CharHashSet.STYLE_NO_DUPLICATES);
|
||||
ENCODED_CHARS_SINGLE_QUOTES_PLUS_SLASH.addAll(new char[] {'\'', '\n', '\r', '&', '<', '>', '\\'});
|
||||
ENCODED_CHARS_SINGLE_QUOTES_PLUS_SLASH.isChangeable(false);
|
||||
ENCODED_CHARS_NO_QUOTES_PLUS_SLASH = new CharHashSet(DocumentBuilder.defaultEncodedCharacters, DocumentBuilder.defaultEncodedCharacters.getSize() + 10, CharHashSet.DEFAULT_LOAD_FACTOR, CharHashSet.STYLE_NO_DUPLICATES);
|
||||
ENCODED_CHARS_NO_QUOTES_PLUS_SLASH.addAll(new char[] {' ', '\n', '\r', '&', '<', '>', '\\'});
|
||||
ENCODED_CHARS_NO_QUOTES_PLUS_SLASH.isChangeable(false);
|
||||
}//static//
|
||||
|
||||
/** The type of quotes to wrapper the value in. Note that none requires that the value have no spacing in it. */
|
||||
private int quoteType = QUOTE_TYPE_DOUBLE;
|
||||
/** The name of the attribute. */
|
||||
private String name = null;
|
||||
/** The attribute value, or null if there isn't one (ie an attribute in the xml followed by no equals sign). */
|
||||
private String value = null;
|
||||
/** Whether the element has errors in the value. */
|
||||
private boolean hasValueErrors = false;
|
||||
/** This will be non-negative no matter what, though if there is no value then this will be the same as the endCharacter value. */
|
||||
private int valueStartCharacter = -1;
|
||||
/** If this is not -1, then a value was specified and the endCharacter refers the the last character of the value (which would be the ending quote). */
|
||||
private int nameEndCharacter = -1;
|
||||
/**
|
||||
* Property constructor.
|
||||
* @param name The name of the attibute which cannot later be changed because that is what uniquely identifies this attribute.
|
||||
*/
|
||||
public Property(String name) {
|
||||
super();
|
||||
|
||||
setName(name);
|
||||
}//Property()//
|
||||
/**
|
||||
* Property constructor.
|
||||
* @param name The name of the attibute which cannot later be changed because that is what uniquely identifies this attribute.
|
||||
* @param value The initial attribute value.
|
||||
*/
|
||||
public Property(String name, String value) {
|
||||
super();
|
||||
|
||||
setName(name);
|
||||
setValue(value);
|
||||
}//Property()//
|
||||
/**
|
||||
* Property constructor.
|
||||
* @param name The name of the attibute which cannot later be changed because that is what uniquely identifies this attribute.
|
||||
* @param value The initial attribute value.
|
||||
* @param quoteType One of the QUOTE_TYPE_xx identifiers.
|
||||
*/
|
||||
public Property(String name, String value, int quoteType) {
|
||||
super();
|
||||
|
||||
setName(name);
|
||||
setValue(value);
|
||||
setQuoteType(quoteType);
|
||||
}//Property()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAttribute#getQuoteType()
|
||||
*/
|
||||
public int getQuoteType() {
|
||||
return quoteType;
|
||||
}//getQuoteType()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAttribute#setQuoteType(int)
|
||||
*/
|
||||
public void setQuoteType(int quoteType) {
|
||||
this.quoteType = quoteType;
|
||||
}//setQuoteType()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAttribute#getQuoteCharacterCount()
|
||||
*/
|
||||
public int getQuoteCharacterCount() {
|
||||
return quoteType == QUOTE_TYPE_NONE ? 0 : 1;
|
||||
}//getQuoteCharacterCount()//
|
||||
/**
|
||||
* Gets the name of the attribute.
|
||||
* @return The attribute's name which is how the attribute is identified.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}//getName()//
|
||||
/**
|
||||
* Sets the name of the attribute.
|
||||
* @param name The attribute's name which is how the attribute is identified.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}//setName()//
|
||||
/**
|
||||
* Gets the attribute's value.
|
||||
* @return The value associated with this attribute.
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}//getValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAttribute#getValue(boolean, boolean)
|
||||
*/
|
||||
public String getValue(boolean trim, boolean emptySameAsNull) {
|
||||
String value = this.value;
|
||||
|
||||
if(value != null) {
|
||||
if(trim) {
|
||||
value = value.trim();
|
||||
}//if//
|
||||
|
||||
if((emptySameAsNull) && (value.length() == 0)) {
|
||||
value = null;
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
return value;
|
||||
}//getValue()//
|
||||
/**
|
||||
* Sets the attribute's value.
|
||||
* @param value The value associated with this attribute.
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}//setValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#isComment()
|
||||
*/
|
||||
public boolean isComment() {
|
||||
return false;
|
||||
}//isComment()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#isNode()
|
||||
*/
|
||||
public boolean isNode() {
|
||||
return false;
|
||||
}//isNode()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#isText()
|
||||
*/
|
||||
public boolean isText() {
|
||||
return false;
|
||||
}//isText()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.Element#write(com.foundation.util.xml.XmlOutputStream, com.foundation.util.xml.DocumentBuilder, java.lang.String, java.lang.String, boolean)
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws IOException {
|
||||
out.write(name);
|
||||
|
||||
if(value != null) {
|
||||
CharHashSet encodedCharacters = null;
|
||||
|
||||
out.write('=');
|
||||
|
||||
switch(quoteType) {
|
||||
case QUOTE_TYPE_DOUBLE: {
|
||||
out.write('"');
|
||||
|
||||
//When allowing encoded characters, the XML reader will read the \ character inside quotes and interperate it as a control character, otherwise it is just a slash.//
|
||||
if(builder.allowEncodedCharacters()) {
|
||||
encodedCharacters = ENCODED_CHARS_DOUBLE_QUOTES_PLUS_SLASH;
|
||||
}//if//
|
||||
else {
|
||||
encodedCharacters = ENCODED_CHARS_DOUBLE_QUOTES;
|
||||
}//else//
|
||||
break;
|
||||
}//case//
|
||||
case QUOTE_TYPE_SINGLE: {
|
||||
out.write('\'');
|
||||
|
||||
//When allowing encoded characters, the XML reader will read the \ character inside quotes and interperate it as a control character, otherwise it is just a slash.//
|
||||
if(builder.allowEncodedCharacters()) {
|
||||
encodedCharacters = ENCODED_CHARS_SINGLE_QUOTES_PLUS_SLASH;
|
||||
}//if//
|
||||
else {
|
||||
encodedCharacters = ENCODED_CHARS_SINGLE_QUOTES;
|
||||
}//else//
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
//When allowing encoded characters, the XML reader will read the \ character inside quotes and interperate it as a control character, otherwise it is just a slash.//
|
||||
if(builder.allowEncodedCharacters()) {
|
||||
encodedCharacters = ENCODED_CHARS_NO_QUOTES_PLUS_SLASH;
|
||||
}//if//
|
||||
else {
|
||||
encodedCharacters = ENCODED_CHARS_NO_QUOTES;
|
||||
}//else//
|
||||
break;
|
||||
}//default//
|
||||
}//switch//
|
||||
|
||||
out.write(builder.preProcess(value, encodedCharacters));
|
||||
|
||||
switch(quoteType) {
|
||||
case QUOTE_TYPE_DOUBLE: {
|
||||
out.write('"');
|
||||
break;
|
||||
}//case//
|
||||
case QUOTE_TYPE_SINGLE: {
|
||||
out.write('\'');
|
||||
break;
|
||||
}//case//
|
||||
default: {
|
||||
break;
|
||||
}//default//
|
||||
}//switch//
|
||||
}//if//
|
||||
}//write()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAttribute#getNameEndCharacter()
|
||||
*/
|
||||
public int getNameEndCharacter() {
|
||||
return nameEndCharacter;
|
||||
}//getNameEndCharacter()//
|
||||
/**
|
||||
* Sets the index of the last value character.
|
||||
* <p>This will be non-negative no matter what, though if there is no value then this will be the same as the endCharacter value.
|
||||
* @param nameEndCharacter The last character in the value.
|
||||
*/
|
||||
public void setNameEndCharacter(int nameEndCharacter) {
|
||||
this.nameEndCharacter = nameEndCharacter;
|
||||
}//setNameEndCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAttribute#getValueStartCharacter()
|
||||
*/
|
||||
public int getValueStartCharacter() {
|
||||
return valueStartCharacter;
|
||||
}//getValueStartCharacter()//
|
||||
/**
|
||||
* Sets the index of the first value character (including the quotes).
|
||||
* <p>If this is not -1, then a value was specified and the endCharacter refers the the last character of the value (which would be the ending quote).
|
||||
* @param valueStartCharacter The first character in the value.
|
||||
*/
|
||||
public void setValueStartCharacter(int valueStartCharacter) {
|
||||
this.valueStartCharacter = valueStartCharacter;
|
||||
}//setValueStartCharacter()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.util.xml.IAttribute#hasValueErrors()
|
||||
*/
|
||||
public boolean hasValueErrors() {
|
||||
return hasValueErrors;
|
||||
}//hasValueErrors()//
|
||||
/**
|
||||
* Determines whether the element has errors in the value.
|
||||
* <p>The hasErrors flag represents errors only in the attribute name.
|
||||
* @param hasValueErrors Whether the reader detected errors in the value.
|
||||
*/
|
||||
public void hasValueErrors(boolean hasValueErrors) {
|
||||
this.hasValueErrors = hasValueErrors;
|
||||
}//hasValueErrors()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "Attribute: " + getName() + " Indicies: " + getStartCharacter() + ", " + getNameEndCharacter() + ", " + getValueStartCharacter() + ", " + getEndCharacter();
|
||||
}//toString()//
|
||||
}//Property//
|
||||
84
Foundation/src/com/foundation/util/xml/Text.java
Normal file
84
Foundation/src/com/foundation/util/xml/Text.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import com.common.util.optimized.CharHashSet;
|
||||
|
||||
public class Text extends Element implements IText {
|
||||
public static final CharHashSet ENCODED_CHARS;
|
||||
|
||||
static {
|
||||
ENCODED_CHARS = new CharHashSet(DocumentBuilder.defaultEncodedCharacters, DocumentBuilder.defaultEncodedCharacters.getSize() + 10, CharHashSet.DEFAULT_LOAD_FACTOR, CharHashSet.STYLE_NO_DUPLICATES);
|
||||
ENCODED_CHARS.addAll(new char[] {'&', '<', '>'});
|
||||
}//static//
|
||||
|
||||
private String text = null;
|
||||
/**
|
||||
* Text constructor.
|
||||
*/
|
||||
public Text() {
|
||||
super();
|
||||
}//Text()//
|
||||
/**
|
||||
* Text constructor.
|
||||
* @param text The initial textual string associated with this text object.
|
||||
*/
|
||||
public Text(String text) {
|
||||
super();
|
||||
|
||||
setText(text);
|
||||
}//Text()//
|
||||
/**
|
||||
* Gets the text for this text element.
|
||||
* @return The text associated with this text element.
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}//getText()//
|
||||
/**
|
||||
* Determines whether this is an IComment instance.
|
||||
* @return Whether this instance implements IComment.
|
||||
*/
|
||||
public boolean isComment() {
|
||||
return false;
|
||||
}//isComment()//
|
||||
/**
|
||||
* Determines whether this is an INode instance.
|
||||
* @return Whether this instance implements INode.
|
||||
*/
|
||||
public boolean isNode() {
|
||||
return false;
|
||||
}//isNode()//
|
||||
/**
|
||||
* Determines whether this is an IText instance.
|
||||
* @return Whether this instance implements IText.
|
||||
*/
|
||||
public boolean isText() {
|
||||
return true;
|
||||
}//isText()//
|
||||
/**
|
||||
* Sets the text for this text element.
|
||||
* @param text The text associated with this text element.
|
||||
*/
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}//setText()//
|
||||
/**
|
||||
* Writes the element to the buffer.
|
||||
* @param out The output stream that will be given the formatted element data.
|
||||
* @param builder The document builder that will provide guidance.
|
||||
* @param prepend The string that will be added before any other characters in a perticular line.
|
||||
* @param postpend The string that will be added after any other characters in a perticular line.
|
||||
* @param compact Whether the output should be kept compact, or should include formatting characters.
|
||||
*/
|
||||
public void write(XmlOutputStream out, DocumentBuilder builder, String prepend, String postpend, boolean compact) throws java.io.IOException {
|
||||
out.write(prepend);
|
||||
out.write(builder.preProcess(getText(), ENCODED_CHARS));
|
||||
out.write(postpend);
|
||||
}//write()//
|
||||
}//Text//
|
||||
220
Foundation/src/com/foundation/util/xml/XmlInputStream.java
Normal file
220
Foundation/src/com/foundation/util/xml/XmlInputStream.java
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2008 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import com.common.io.StreamSupport;
|
||||
|
||||
/**
|
||||
* <p>TODO: Read the encoding from the xml metadata if available.</p>
|
||||
*/
|
||||
class XmlInputStream {
|
||||
private static final char lineSeparator;
|
||||
private String input = null;
|
||||
/** The index of the next character in the stream (the one retrieved by calling <code>next()</code>). */
|
||||
private int nextCharacterIndex = 0;
|
||||
private int nextLineIndex = 0;
|
||||
private int nextLineCharacterOffset = 0;
|
||||
private int currentCharacterIndex = 0;
|
||||
private int currentLineIndex = 0;
|
||||
private int currentLineCharacterOffset = 0;
|
||||
/** The sections of the input to ignore. The internal indices must still be maintained relative to the entire text, but the ignored section characters will not be reported to the user of the stream. */
|
||||
private int[] ignoredSections = null;
|
||||
/** The total number of characters to be skipped due to ignored sections. */
|
||||
private int totalSkippedCharacters = 0;
|
||||
/** The current number of characters that have been skipped due to ignored sections. */
|
||||
private int currentSkippedCharacters = 0;
|
||||
/** The next ignored section in the ignoredSections array. */
|
||||
private int nextIgnoredSectionIndex = 0;
|
||||
|
||||
static {
|
||||
String separator = System.getProperty("line.separator");
|
||||
|
||||
lineSeparator = separator.charAt(separator.length() - 1);
|
||||
}//static//
|
||||
/**
|
||||
* XmlInputStream constructor.
|
||||
* <p>Note: Currently we read the entire text imediately.</p>
|
||||
* @param in The stream containing the XML text.
|
||||
* @param encoding The encoding of the XML text.
|
||||
*/
|
||||
XmlInputStream(InputStream in, String encoding) throws IOException {
|
||||
this(in, encoding, null);
|
||||
}//XmlInputStream()//
|
||||
/**
|
||||
* XmlInputStream constructor.
|
||||
* @param input The XML text.
|
||||
*/
|
||||
XmlInputStream(String input) throws IOException {
|
||||
this(input, null);
|
||||
}//XmlInputStream()//
|
||||
/**
|
||||
* XmlInputStream constructor.
|
||||
* <p>Note: Currently we read the entire text imediately.</p>
|
||||
* @param in The stream containing the XML text.
|
||||
* @param encoding The encoding of the XML text.
|
||||
* @param ignoredSections The sections of the input to ignore. The internal indices must still be maintained relative to the entire text, but the ignored section characters will not be reported to the user of the stream.
|
||||
*/
|
||||
XmlInputStream(InputStream in, String encoding, int[] ignoredSections) throws IOException {
|
||||
this(StreamSupport.readText(in, encoding), ignoredSections);
|
||||
}//XmlInputStream()//
|
||||
/**
|
||||
* XmlInputStream constructor.
|
||||
* @param input The XML text.
|
||||
* @param ignoredSections The sections of the input to ignore. The internal indices must still be maintained relative to the entire text, but the ignored section characters will not be reported to the user of the stream. The ignored sections must be an even array of ascending start/stop index pairs where the start & stop may be equal, but the next start must be at least one greater than the previous stop index.
|
||||
*/
|
||||
XmlInputStream(String input, int[] ignoredSections) throws IOException {
|
||||
super();
|
||||
this.input = input;
|
||||
this.ignoredSections = ignoredSections;
|
||||
|
||||
if(ignoredSections != null) {
|
||||
for(int index = 0; index < ignoredSections.length; index += 2) {
|
||||
totalSkippedCharacters += ignoredSections[index + 1] - ignoredSections[index] + 1;
|
||||
}//for//
|
||||
}//if//
|
||||
}//XmlInputStream()//
|
||||
/**
|
||||
* Determines whether there are enough characters in the stream to peek at the character at the desired offset.
|
||||
* @param offset The offset of the character the user wants to view. A value of zero will peek at the next character.
|
||||
* @return Will be true if such a character exists.
|
||||
*/
|
||||
public boolean canPeek(int offset) throws IOException {
|
||||
return input.length() - (totalSkippedCharacters - currentSkippedCharacters) > nextCharacterIndex + offset;
|
||||
}//canPeek()//
|
||||
/**
|
||||
* The offset of the next character in the context of the current line.
|
||||
* @return The offset of the next character in the current line. This offset starts at zero (the beginning of the line) an increments until the line ends.
|
||||
*/
|
||||
public int getNextLineCharacterOffset() {
|
||||
return nextLineCharacterOffset;
|
||||
}//getNextLineCharacterOffset()//
|
||||
/**
|
||||
* Gets the current line index (for the next character to be retrieved).
|
||||
* @return The index of the line that the next character resides on where lines begin with index zero.
|
||||
*/
|
||||
public int getNextLineIndex() {
|
||||
return nextLineIndex;
|
||||
}//getNextLineIndex()//
|
||||
/**
|
||||
* Gets the index of the next character within the entire stream.
|
||||
* @return The stream character index of the next character where the first stream character is index zero.
|
||||
*/
|
||||
public int getNextCharacterIndex() {
|
||||
return nextCharacterIndex;
|
||||
}//getNextCharacterIndex()//
|
||||
/**
|
||||
* The offset of the current character in the context of the current line.
|
||||
* @return The offset of the current character in the current line. This offset starts at zero (the beginning of the line) an increments until the line ends.
|
||||
*/
|
||||
public int getCurrentLineCharacterOffset() {
|
||||
return currentLineCharacterOffset;
|
||||
}//getCurrentLineCharacterOffset()//
|
||||
/**
|
||||
* Gets the current line index (for the current character to be retrieved).
|
||||
* @return The index of the line that the current character resides on where lines begin with index zero.
|
||||
*/
|
||||
public int getCurrentLineIndex() {
|
||||
return currentLineIndex;
|
||||
}//getCurrentLineIndex()//
|
||||
/**
|
||||
* Gets the index of the current character within the entire stream.
|
||||
* @return The stream character index of the current character where the first stream character is index zero.
|
||||
*/
|
||||
public int getCurrentCharacterIndex() {
|
||||
return currentCharacterIndex;
|
||||
}//getCurrentCharacterIndex()//
|
||||
/**
|
||||
* Determines whether there is a next character in the stream.
|
||||
* @return Will be true if there is at least one more character in the stream.
|
||||
*/
|
||||
public boolean hasNext() throws IOException {
|
||||
return canPeek(0);
|
||||
}//hasNext()//
|
||||
/**
|
||||
* Gets the next character in the stream.
|
||||
* @return The next character in the stream. This character will not be retrievable again from this stream.
|
||||
*/
|
||||
public char next() throws IOException {
|
||||
char result = input.charAt(nextCharacterIndex);
|
||||
|
||||
currentCharacterIndex = nextCharacterIndex;
|
||||
currentLineCharacterOffset = nextLineCharacterOffset;
|
||||
currentLineIndex = nextLineIndex;
|
||||
|
||||
//Track the character index in the stream.//
|
||||
nextCharacterIndex++;
|
||||
nextLineCharacterOffset++;
|
||||
|
||||
//Track the line and line offset indexes in the stream.//
|
||||
if(result == lineSeparator) {
|
||||
nextLineCharacterOffset = 0;
|
||||
nextLineIndex++;
|
||||
}//if//
|
||||
|
||||
//If we have ignored sections then skip them now if the next index falls within one such section.//
|
||||
if(ignoredSections != null && nextIgnoredSectionIndex < ignoredSections.length && nextCharacterIndex == ignoredSections[nextIgnoredSectionIndex]) {
|
||||
int ignoredLength = 0;
|
||||
char ch = result;
|
||||
|
||||
//Iteratively identify the ignored length since it is possible that two or more ignored sections are consecutive.//
|
||||
while(nextIgnoredSectionIndex < ignoredSections.length && nextCharacterIndex + ignoredLength == ignoredSections[nextIgnoredSectionIndex]) {
|
||||
ignoredLength += ignoredSections[nextIgnoredSectionIndex + 1] - ignoredSections[nextIgnoredSectionIndex] + 1;
|
||||
nextIgnoredSectionIndex += 2;
|
||||
}//while//
|
||||
|
||||
currentSkippedCharacters += ignoredLength;
|
||||
nextCharacterIndex += ignoredLength;
|
||||
|
||||
//Skip over the ignored characters, but also track the next indices.//
|
||||
while(ignoredLength-- > 0) {
|
||||
nextLineCharacterOffset++;
|
||||
|
||||
if(ch == lineSeparator) {
|
||||
nextLineCharacterOffset = 0;
|
||||
nextLineIndex++;
|
||||
}//if//
|
||||
|
||||
ch = input.charAt(nextCharacterIndex);
|
||||
}//while//
|
||||
}//if//
|
||||
|
||||
return result;
|
||||
}//next()//
|
||||
/**
|
||||
* Peeks at one of the next characters in the stream.
|
||||
* @param offset The positive offset of the character to peek at. If this is zero, then the next character returned by the next() method will be returned.
|
||||
* @return The character at the given offset in the stream.
|
||||
*/
|
||||
public char peek(int offset) throws IOException {
|
||||
int index = nextCharacterIndex + offset;
|
||||
|
||||
if(ignoredSections != null && nextIgnoredSectionIndex < ignoredSections.length && ignoredSections[nextIgnoredSectionIndex] <= index) {
|
||||
int ignoredSectionIndex = nextIgnoredSectionIndex;
|
||||
|
||||
while(ignoredSectionIndex < ignoredSections.length && ignoredSections[ignoredSectionIndex] <= index) {
|
||||
int ignoredLength = ignoredSections[nextIgnoredSectionIndex + 1] - ignoredSections[nextIgnoredSectionIndex] + 1;
|
||||
|
||||
index += ignoredLength;
|
||||
ignoredSectionIndex += 2;
|
||||
}//while//
|
||||
}//if//
|
||||
|
||||
return input.charAt(index);
|
||||
}//peek()//
|
||||
/**
|
||||
* Skips the next <code>count</code> characters in the stream. This is the same as calling the <code>next()<code> method <code>count</code> times without saving the results.
|
||||
* @param count The number of characters to be skipped.
|
||||
*/
|
||||
public void skip(int count) throws IOException {
|
||||
while(count-- > 0) {
|
||||
next();
|
||||
}//while//
|
||||
}//next()//
|
||||
}//XmlInputStream//
|
||||
75
Foundation/src/com/foundation/util/xml/XmlOutputStream.java
Normal file
75
Foundation/src/com/foundation/util/xml/XmlOutputStream.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2002,2007 Declarative Engineering LLC.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Declarative Engineering LLC
|
||||
* verson 1 which accompanies this distribution, and is available at
|
||||
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||||
*/
|
||||
package com.foundation.util.xml;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
|
||||
/*
|
||||
* Wrappers any output stream to provide streaming for an XML document.
|
||||
* <p>TODO: Read the encoding from the xml metadata if available.</p>
|
||||
*/
|
||||
class XmlOutputStream extends java.io.OutputStream {
|
||||
private static final int CHARACTER_BUFFER_SIZE = 1000;
|
||||
private java.io.OutputStream out = null;
|
||||
//private CharsetEncoder encoder = null;
|
||||
//private CharBuffer charBuffer = CharBuffer.allocate(CHARACTER_BUFFER_SIZE);
|
||||
//private ByteBuffer byteBuffer = null;
|
||||
/**
|
||||
* XmlOutputStream constructor.
|
||||
* @param out The output stream to wrapper.
|
||||
* @param encoding The character set encoding to use.
|
||||
*/
|
||||
XmlOutputStream(java.io.OutputStream out, String encoding) {
|
||||
super();
|
||||
|
||||
//this.encoder = Charset.forName(encoding).newEncoder();
|
||||
this.out = out;
|
||||
//this.byteBuffer = ByteBuffer.allocate(((int) Math.ceil(encoder.maxBytesPerChar())) * CHARACTER_BUFFER_SIZE);
|
||||
}//XmlOutputStream()//
|
||||
/**
|
||||
* Writes a string to the stream.
|
||||
* @param string The string to append to this stream.
|
||||
*/
|
||||
public void write(char ch) throws java.io.IOException {
|
||||
//TODO: For some reason using the character buffer and byte buffer doesn't work. The encoder screws up the byte buffer. This should be debugged at some point since the alternative is inefficient and possibly buggy.
|
||||
//byteBuffer.rewind();
|
||||
//charBuffer.rewind();
|
||||
//charBuffer.append(ch);
|
||||
//encoder.encode(charBuffer, byteBuffer, false);
|
||||
//out.write(byteBuffer.array(), 0, byteBuffer.position());
|
||||
write("" + ch);
|
||||
}//write()//
|
||||
/* (non-Javadoc)
|
||||
* @see java.io.OutputStream#write(int)
|
||||
*/
|
||||
public void write(int b) throws java.io.IOException {
|
||||
out.write(b);
|
||||
}//write()//
|
||||
/**
|
||||
* Writes a string to the stream.
|
||||
* @param string The string to append to this stream.
|
||||
*/
|
||||
public void write(String string) throws java.io.IOException {
|
||||
/*
|
||||
int offset = 0;
|
||||
|
||||
while(offset < string.length()) {
|
||||
byteBuffer.rewind();
|
||||
charBuffer.rewind();
|
||||
charBuffer.append(string.length() - offset > CHARACTER_BUFFER_SIZE ? string.substring(offset, offset + CHARACTER_BUFFER_SIZE) : offset == 0 ? string : string.substring(offset));
|
||||
encoder.encode(charBuffer, byteBuffer, false);
|
||||
out.write(byteBuffer.array(), 0, byteBuffer.position());
|
||||
offset += CHARACTER_BUFFER_SIZE;
|
||||
}//while//
|
||||
*/
|
||||
out.write(string.getBytes("UTF8"));
|
||||
}//write()//
|
||||
}//XmlOutputStream//
|
||||
Reference in New Issue
Block a user