use of net.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 net.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 net.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 net.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;
}
use of net.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class WindowConfigurationStorage method unmarschall.
protected XMLElement unmarschall(final String marshalled, final JDialog dialog) {
if (marshalled != null) {
final IXMLParser parser = XMLLocalParserFactory.createLocalXMLParser();
final IXMLReader xmlReader = new StdXMLReader(new StringReader(marshalled));
parser.setReader(xmlReader);
try {
final XMLElement storage = (XMLElement) parser.parse();
if (storage != null) {
x = Integer.parseInt(storage.getAttribute("x", "-1"));
y = Integer.parseInt(storage.getAttribute("y", "-1"));
width = Integer.parseInt(storage.getAttribute("width", "-1"));
height = Integer.parseInt(storage.getAttribute("height", "-1"));
UITools.setBounds(dialog, x, y, width, height);
return storage;
}
} catch (final NumberFormatException e) {
LogUtils.severe(e);
} catch (final XMLException e) {
LogUtils.severe(e);
}
}
UITools.setBounds(dialog, -1, -1, -1, -1);
return null;
}
Aggregations