public XMLWriter(Writer writer, OutputFormat format) { this.writer = writer; this.format = format; namespaceStack.push(Namespace.NO_NAMESPACE); }
protected boolean isNamespaceDeclaration( Namespace ns ) { if (ns != null && ns != Namespace.XML_NAMESPACE) { String uri = ns.getURI(); if ( uri != null ) { if ( ! namespaceStack.contains( ns ) ) { return true; } } } return false; }
ProcessingInstruction pi = (ProcessingInstruction) node; if ("target".equals(localName)) { result.add(new DefaultAttribute("target", pi.getTarget())); } else if ("data".equals(localName)) { result.add(new DefaultAttribute("data", pi.getText())); } else { result.add(new DefaultAttribute(localName, pi.getValue(localName))); result.add(new DefaultAttribute("publicId", doctype.getPublicID())); } else if ("systemId".equals(localName)) { result.add(new DefaultAttribute("systemId", doctype.getSystemID())); } else if ("elementName".equals(localName)) { result.add(new DefaultAttribute("elementName", doctype.getElementName()));
public List<Namespace> declaredNamespaces() { BackedList<Namespace> answer = createResultList(); for (Node node : contentList()) { if (node instanceof Namespace) { answer.addLocal((Namespace) node); } } return answer; }
public void endNode() { try { if (!children) { Element element = new DefaultElement((String)elementStack.pop()); for (int i = 0; i < attributes.getLength(); ++i) { element.addAttribute(attributes.getQName(i), attributes.getValue(i)); } writer.write(element); attributes.clear(); children = true; // node just closed is child of node on top of stack started = true; } else { startElement(); writer.endElement("", "", (String)elementStack.pop()); } } catch (SAXException e) { throw new StreamException(e); } catch (IOException e) { throw new StreamException(e); } }
if (ns != null && ns != Namespace.NO_NAMESPACE && ns != Namespace.XML_NAMESPACE) { String prefix = ns.getPrefix(); String uri = namespaceStack.getURI(prefix); if (!ns.getURI().equals(uri)) { // output a new namespace declaration writeNamespace(ns); namespaceStack.push(ns); if (attName.startsWith("xmlns:")) { String prefix = attName.substring(6); if (namespaceStack.getNamespaceForPrefix(prefix) == null) { String uri = attribute.getValue(); namespaceStack.push(prefix, uri); writeNamespace(prefix, uri); if (namespaceStack.getDefaultNamespace() == null) { String uri = attribute.getValue(); namespaceStack.push(null, uri); writeNamespace(null, uri);
writer.write(qualifiedName); int previouslyDeclaredNamespaces = namespaceStack.size(); Namespace ns = element.getNamespace(); if (isNamespaceDeclaration( ns ) ) { namespaceStack.push(ns); writeNamespace(ns); Namespace additional = (Namespace) node; if (isNamespaceDeclaration( additional ) ) { namespaceStack.push(additional); writeNamespace(additional); while (namespaceStack.size() > previouslyDeclaredNamespaces) { namespaceStack.pop();
public void setRootElement(Element rootElement) { clearContent(); if (rootElement != null) { super.add(rootElement); rootElementAdded(rootElement); } }
public void add(Element element) { checkAddElementAllowed(element); super.add(element); rootElementAdded(element); }
/** * A Factory Method pattern which creates a BackedList implementation used * to store results of a filtered content query. * * @param <T> DOCUMENT ME! * @return DOCUMENT ME! */ protected <T extends Node> BackedList<T> createResultList() { return new BackedList<T>(this, contentList()); }
public Object clone() { DefaultDocument document = (DefaultDocument) super.clone(); document.rootElement = null; document.content = null; document.appendContent(this); return document; }
public String getText() { final Object contentShadow = content; if (contentShadow instanceof List) { return super.getText(); } else { if (contentShadow != null) { return getContentAsText(contentShadow); } else { return ""; } } }
public List<ProcessingInstruction> processingInstructions() { BackedList<ProcessingInstruction> answer = createResultList(); for (Node node : contentList()) { if (node instanceof ProcessingInstruction) { answer.addLocal((ProcessingInstruction) node); } } return answer; }
@SuppressWarnings({"unchecked"}) IdMappingData addId(PersistentClass pc, boolean audited) { final Element relIdMapping = new DefaultElement( "properties" ); final Element origIdMapping = new DefaultElement( "composite-id" );
/** * A Factory Method pattern which creates an empty a BackedList * implementation * * @param <T> DOCUMENT ME! * @return DOCUMENT ME! */ protected <T extends Node> List<T> createEmptyList() { return new BackedList<T>(this, contentList(), 0); }
public XMLWriter() throws UnsupportedEncodingException { this.format = DEFAULT_FORMAT; this.writer = new BufferedWriter( new OutputStreamWriter( System.out, StandardCharsets.UTF_8) ); this.autoFlush = true; namespaceStack.push(Namespace.NO_NAMESPACE); }
public List<Element> elements() { BackedList<Element> answer = createResultList(); for (Node node : contentList()) { if (node instanceof Element) { answer.addLocal((Element) node); } } return answer; }
public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException { this.format = format; this.writer = createWriter(out, format.getEncoding()); this.autoFlush = true; namespaceStack.push(Namespace.NO_NAMESPACE); }
public XMLWriter(OutputStream out) throws UnsupportedEncodingException { this.format = DEFAULT_FORMAT; this.writer = createWriter(out, format.getEncoding()); this.autoFlush = true; namespaceStack.push(Namespace.NO_NAMESPACE); }
public XMLWriter(OutputFormat format) throws UnsupportedEncodingException { this.format = format; this.writer = createWriter( System.out, format.getEncoding() ); this.autoFlush = true; namespaceStack.push(Namespace.NO_NAMESPACE); }