public Document createDocument() { DefaultDocument answer = new DefaultDocument(); answer.setDocumentFactory(this); return answer; }
public Object clone() { DefaultDocument document = (DefaultDocument) super.clone(); document.rootElement = null; document.content = null; document.appendContent(this); return document; }
protected void addNode(int index, Node node) { if (node != null) { Document document = node.getDocument(); if ((document != null) && (document != this)) { // XXX: could clone here String message = "The Node already has an existing document: " + document; throw new IllegalAddException(this, node, message); } contentList().add(index, node); childAdded(node); } }
public List<ProcessingInstruction> processingInstructions() { List<ProcessingInstruction> answer = createResultList(); for (Node node : contentList()) { if (node instanceof ProcessingInstruction) { answer.add((ProcessingInstruction) node); } } return answer; }
protected boolean removeNode(Node node) { if (node == rootElement) { rootElement = null; } if (contentList().remove(node)) { childRemoved(node); return true; } return false; }
public void setContent(List<Node> content) { rootElement = null; contentRemoved(); } else { int size = content.size(); List<Node> newContent = createContentList(size); childAdded(node);
public Document addDocType(String docTypeName, String publicId, String systemId) { setDocType(getDocumentFactory().createDocType(docTypeName, publicId, systemId)); return this; }
Document doc = new DefaultDocument(); doc.add(new DefaultElement("body")); Document fragment = DocumentHelper .parseText("<p>Some inline text with <b>highlighted</b> content</p>"); doc.getRootElement().add(fragment.getRootElement()); System.out.println(doc.asXML());
public void clearContent() { contentRemoved(); content = null; rootElement = null; }
protected List<Node> contentList() { if (content == null) { content = createContentList(); if (rootElement != null) { content.add(rootElement); } } return content; }
public void testAsXMLWithEncodingAndContent() throws Exception { DefaultDocument document = new DefaultDocument(); document.setXMLEncoding("UTF-16"); Element root = document.addElement("root"); root.setText("text with an \u00FC in it"); // u00FC is umlaut String xml = document.asXML(); assertTrue(xml.indexOf("UTF-16") != -1); assertTrue(xml.indexOf('\u00FC') != -1); }
protected DocumentFactory getDocumentFactory() { if (super.getDocumentFactory() == null) { return DOCUMENT_FACTORY; } else { return super.getDocumentFactory(); } }
public ProcessingInstruction processingInstruction(String target) { for (Node node : contentList()) { if (node instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) node; if (target.equals(pi.getName())) { return pi; } } } return null; }
public List<ProcessingInstruction> processingInstructions(String target) { List<ProcessingInstruction> answer = createResultList(); for (Node node : contentList()) { if (node instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) node; if (target.equals(pi.getName())) { answer.add(pi); } } } return answer; }
public void setContent(List content) { rootElement = null; contentRemoved(); } else { int size = content.size(); List newContent = createContentList(size); childAdded(node);
public Document addDocType(String docTypeName, String publicId, String systemId) { setDocType(getDocumentFactory().createDocType(docTypeName, publicId, systemId)); return this; }
protected boolean removeNode(Node node) { if (node == rootElement) { rootElement = null; } if (contentList().remove(node)) { childRemoved(node); return true; } return false; }
public SubComponent(String id, String parentId) { super(parentId + "#" + id, null, new DefaultDocument(new BaseElement("generated-document").addAttribute("component", parentId).addAttribute("sub-component", id))); this.baseId = id; this.parentId = parentId; this.displayId = "Component: " + parentId + ", Sub-Component: " + id; }
public void clearContent() { contentRemoved(); content = null; rootElement = null; }
protected List<Node> contentList() { if (content == null) { content = createContentList(); if (rootElement != null) { content.add(rootElement); } } return content; }