use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class StdXMLBuilder method startElement.
/**
* This method is called when a new XML element is encountered.
*
* @see #endElement
* @param name
* the name of the element.
* @param nsPrefix
* the prefix used to identify the namespace. If no namespace has
* been specified, this parameter is null.
* @param nsURI
* the URI associated with the namespace. If no namespace has
* been specified, or no URI is associated with nsPrefix, this
* parameter is null.
* @param systemID
* the system ID of the XML data source.
* @param lineNr
* the line in the source where the element starts.
*/
public void startElement(final String name, final String nsPrefix, final String nsURI, final String systemID, final int lineNr) {
String fullName = name;
if (nsPrefix != null) {
fullName = nsPrefix + ':' + name;
}
final XMLElement elt = new XMLElement(fullName, nsURI, systemID, lineNr);
last = elt;
if (stack.empty()) {
root = elt;
} else {
final XMLElement top = (XMLElement) stack.peek();
top.addChild(elt);
}
stack.push(elt);
}
use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class StdXMLBuilder method endElement.
/**
* This method is called when the end of an XML elemnt is encountered.
*
* @see #startElement
* @param name
* the name of the element.
* @param nsPrefix
* the prefix used to identify the namespace. If no namespace has
* been specified, this parameter is null.
* @param nsURI
* the URI associated with the namespace. If no namespace has
* been specified, or no URI is associated with nsPrefix, this
* parameter is null.
*/
public void endElement(final String name, final String nsPrefix, final String nsURI) {
final XMLElement elt = (XMLElement) stack.pop();
if (elt.getChildrenCount() == 1) {
final XMLElement child = elt.getChildAtIndex(0);
if (child.getName() == null) {
elt.setContent(child.getContent());
elt.removeChildAtIndex(0);
}
}
}
use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class StdXMLBuilder method addAttribute.
/**
* This method is called when a new attribute of an XML element is
* encountered.
*
* @param key
* the key (name) of the attribute.
* @param nsPrefix
* the prefix used to identify the namespace. If no namespace has
* been specified, this parameter is null.
* @param nsURI
* the URI associated with the namespace. If no namespace has
* been specified, or no URI is associated with nsPrefix, this
* parameter is null.
* @param value
* the value of the attribute.
* @param type
* the type of the attribute. If no type is known, "CDATA" is
* returned.
* @throws java.lang.Exception
* If an exception occurred while processing the event.
*/
public void addAttribute(final String key, final String nsPrefix, final String nsURI, final String value, final String type) throws Exception {
String fullName = key;
if (nsPrefix != null) {
fullName = nsPrefix + ':' + key;
}
final XMLElement top = stack.peek();
if (top.hasAttribute(fullName)) {
throw new XMLParseException(top.getSystemID(), top.getLineNr(), "Duplicate attribute: " + key);
}
if (nsPrefix != null) {
top.setAttribute(fullName, nsURI, value);
} else {
top.setAttribute(fullName, value);
}
}
use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class StdXMLBuilder method addPCData.
/**
* This method is called when a PCDATA element is encountered. A Java reader
* is supplied from which you can read the data. The reader will only read
* the data of the element. You don't need to check for boundaries. If you
* don't read the full element, the rest of the data is skipped. You also
* don't have to care about entities; they are resolved by the parser.
*
* @param reader
* the Java reader from which you can retrieve the data.
* @param systemID
* the system ID of the XML data source.
* @param lineNr
* the line in the source where the element starts.
*/
public void addPCData(final Reader reader, final String systemID, final int lineNr) {
int bufSize = 2048;
int sizeRead = 0;
final StringBuilder str = new StringBuilder(bufSize);
final char[] buf = new char[bufSize];
for (; ; ) {
if (sizeRead >= bufSize) {
bufSize *= 2;
str.ensureCapacity(bufSize);
}
int size;
try {
size = reader.read(buf);
} catch (final IOException e) {
break;
}
if (size < 0) {
break;
}
str.append(buf, 0, size);
sizeRead += size;
}
final XMLElement elt = prototype.createElement(null, systemID, lineNr);
elt.setContent(str.toString());
if (!stack.empty()) {
final XMLElement top = (XMLElement) stack.peek();
top.addChild(elt);
}
}
use of org.freeplane.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class TreeXmlReader method endElement.
/*
* (non-Javadoc)
* @see
* freeplane.persistence.xml.n3.nanoxml.IXMLBuilder#endElement(java.lang
* .String, java.lang.String, java.lang.String)
*/
public void endElement(final String name, final String nsPrefix, final String nsURI) throws Exception {
final XMLElement lastBuiltElement = xmlBuilder.getParentElement();
xmlBuilder.endElement(name, nsPrefix, nsURI);
if (saveAsXmlUntil == lastBuiltElement) {
saveAsXmlUntil = null;
}
if (saveAsXmlUntil != null) {
return;
}
tag = null;
if (0 == elementStack.size()) {
return;
}
final Object element = currentElement;
currentElement = elementStack.removeLast();
try {
if (nodeCreator instanceof IElementContentHandler) {
((IElementContentHandler) nodeCreator).endElement(currentElement, name, element, lastBuiltElement, elementContentAsString);
} else if (nodeCreator instanceof IElementDOMHandler) {
((IElementDOMHandler) nodeCreator).endElement(currentElement, name, element, lastBuiltElement);
}
} catch (Exception e) {
LogUtils.severe("Can not process element" + name, e);
}
final XMLElement top = lastBuiltElement.getParent();
if (nodeCreator != null && top != null && top.hasChildren()) {
final int lastChildIndex = top.getChildrenCount() - 1;
top.removeChildAtIndex(lastChildIndex);
}
nodeCreator = (IElementHandler) nodeCreatorStack.removeLast();
elementContentAsString = null;
}
Aggregations