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 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 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 OptionPanelWindowConfigurationStorage method decorateDialog.
public static OptionPanelWindowConfigurationStorage decorateDialog(final String marshalled, final JDialog dialog) {
final OptionPanelWindowConfigurationStorage storage = new OptionPanelWindowConfigurationStorage();
final XMLElement xml = storage.unmarschall(marshalled, dialog);
if (xml != null) {
storage.panel = xml.getAttribute("panel", null);
return storage;
}
return null;
}
use of net.n3.nanoxml.XMLElement in project freeplane by freeplane.
the class UnknownElementWriter method writeAttributes.
public void writeAttributes(final ITreeWriter writer, final Object userObject, final IExtension extension) {
final UnknownElements elements = (UnknownElements) extension;
final XMLElement unknownElements = elements.getUnknownElements();
if (unknownElements != null) {
final Enumeration<String> unknownAttributes = unknownElements.enumerateAttributeNames();
while (unknownAttributes.hasMoreElements()) {
final String name = unknownAttributes.nextElement();
final String value = unknownElements.getAttribute(name, null);
writer.addAttribute(name, value);
}
}
}
Aggregations