本文整理汇总了Java中org.w3c.dom.DocumentFragment.getFirstChild方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentFragment.getFirstChild方法的具体用法?Java DocumentFragment.getFirstChild怎么用?Java DocumentFragment.getFirstChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.DocumentFragment
的用法示例。
在下文中一共展示了DocumentFragment.getFirstChild方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBlockForSdt
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public static DocumentFragment createBlockForSdt(FOConversionContext context,
NodeIterator pPrNodeIt,
String pStyleVal, NodeIterator childResults, String tag) {
DocumentFragment docfrag = createBlock(context,
pPrNodeIt,
pStyleVal, childResults,
true);
// Set margins, but only for a shading container,
// not a borders container
if (tag.equals(Containerization.TAG_SHADING) && docfrag!=null) {
// docfrag.getNodeName() is #document-fragment
Node foBlock = docfrag.getFirstChild();
if (foBlock!=null) {
((Element)foBlock).setAttribute("margin-top", "0in");
((Element)foBlock).setAttribute("margin-bottom", "0in");
// ((Element)foBlock).setAttribute("padding-top", "0in");
// ((Element)foBlock).setAttribute("padding-bottom", "0in");
}
}
return docfrag;
}
示例2: setFont
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/**
* Use RunFontSelector to determine the correct font for the list item label.
*
* @param context
* @param foListItemLabelBody
* @param pPr
* @param rPr
* @param text
*/
protected static void setFont(FOConversionContext context, Element foListItemLabelBody, PPr pPr, RPr rPr, String text) {
DocumentFragment result = (DocumentFragment)context.getRunFontSelector().fontSelector(pPr, rPr, text);
log.debug(XmlUtils.w3CDomNodeToString(result));
// eg <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Times New Roman">1)</fo:inline>
// Now get the attribute value
if (result!=null && result.getFirstChild()!=null) {
Attr attr = ((Element)result.getFirstChild()).getAttributeNode("font-family");
if (attr!=null) {
foListItemLabelBody.setAttribute("font-family", attr.getValue());
}
}
}
示例3: testRenderWithUnknownNamespace
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public final void testRenderWithUnknownNamespace() throws Exception {
DocumentFragment fragment = xmlFragment(fromString(
""
+ "<foo xmlns='http://www.w3.org/XML/1998/namespace'"
+ " xmlns:bar='http://bobs.house.of/XML&BBQ'>"
+ "<bar:baz boo='howdy' xml:lang='es'/>"
+ "</foo>"));
// Remove any XMLNS attributes and prefixes.
Element el = (Element) fragment.getFirstChild();
while (el.getAttributes().getLength() != 0) {
el.removeAttributeNode((Attr) el.getAttributes().item(0));
}
el.setPrefix("");
el.getFirstChild().setPrefix("");
assertEquals(
""
+ "<xml:foo>"
+ "<_ns1:baz xmlns:_ns1=\"http://bobs.house.of/XML&BBQ\""
+ " boo=\"howdy\" xml:lang=\"es\"></_ns1:baz>"
+ "</xml:foo>",
Nodes.render(fragment, MarkupRenderMode.XML));
}
示例4: childElementList
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/** Return a List of Element objects that are children of the given DocumentFragment */
public static List<? extends Element> childElementList(DocumentFragment fragment) {
if (fragment == null) return null;
List<Element> elements = new LinkedList<Element>();
Node node = fragment.getFirstChild();
if (node != null) {
do {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) node;
elements.add(childElement);
}
} while ((node = node.getNextSibling()) != null);
}
return elements;
}
示例5: doSomething
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public DocumentFragment doSomething(NodeIterator rtf) {
System.out.println("Got here 2: " + rtf);
DocumentFragment df = (DocumentFragment) rtf.nextNode();
Element node = (Element) df.getFirstChild();
System.out.println("node=" + node);
System.out.println("namesp uri: " + node.getNamespaceURI());
System.out.println("local name: " + node.getLocalName());
return df;
}
示例6: finish
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void finish(FilePosition endOfDocument)
throws IllegalDocumentStateException {
stripIgnorableText();
DocumentFragment root = getRootElement();
if (needsDebugData) {
FilePosition rootStart = Nodes.getFilePositionFor(root);
if (rootStart == null || InputSource.UNKNOWN.equals(rootStart.source())) {
if (root.getFirstChild() == null) {
rootStart = endOfDocument;
} else {
rootStart = Nodes.getFilePositionFor(root.getFirstChild());
}
}
if (rootStart.startCharInFile() <= endOfDocument.startCharInFile()) {
Nodes.setFilePositionFor(
root, FilePosition.span(rootStart, endOfDocument));
}
}
int nOpen = getNOpenElements();
if (nOpen != 1) {
Element openEl = getElement(nOpen - 1);
throw new IllegalDocumentStateException(new Message(
DomParserMessageType.MISSING_END, endOfDocument,
MessagePart.Factory.valueOf(openEl.getTagName()),
Nodes.getFilePositionFor(openEl)));
}
}
示例7: childElementList
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/** Return a List of Element objects that are children of the given DocumentFragment */
public static List<? extends Element> childElementList(DocumentFragment fragment) {
if (fragment == null) return null;
List<Element> elements = FastList.newInstance();
Node node = fragment.getFirstChild();
if (node != null) {
do {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) node;
elements.add(childElement);
}
} while ((node = node.getNextSibling()) != null);
}
return elements;
}
示例8: actionPerformed
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
Node nodeToAdd = null;
switch (nodeType) {
case Node.ELEMENT_NODE:
URL urlObj = null;
if (document instanceof SVGOMDocument) {
urlObj = ((SVGOMDocument) document).getURLObject();
}
String uri = (urlObj == null) ? "" : urlObj.toString();
Map prefixes = new HashMap();
prefixes.put(SVGConstants.XMLNS_PREFIX,
SVGConstants.SVG_NAMESPACE_URI);
prefixes.put(SVGConstants.XMLNS_PREFIX + ":"
+ SVGConstants.XLINK_PREFIX,
SVGConstants.XLINK_NAMESPACE_URI);
SAXDocumentFactory df = new SAXDocumentFactory(document
.getImplementation(), XMLResourceDescriptor
.getXMLParserClassName());
DocumentFragment documentFragment = (DocumentFragment) DOMUtilities
.parseXML(toParse, document, uri, prefixes,
SVGConstants.SVG_SVG_TAG, df);
nodeToAdd = documentFragment.getFirstChild();
break;
case Node.TEXT_NODE:
nodeToAdd = document.createTextNode(toParse);
break;
case Node.COMMENT_NODE:
nodeToAdd = document.createComment(toParse);
break;
case Node.CDATA_SECTION_NODE:
nodeToAdd = document.createCDATASection(toParse);
}
// Append the new node to the parentNode
TreePath[] treePaths = tree.getSelectionPaths();
if (treePaths != null) {
TreePath treePath = treePaths[treePaths.length - 1];
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath
.getLastPathComponent();
NodeInfo nodeInfo = (NodeInfo) node.getUserObject();
addChangesToHistory();
historyBrowserInterface.appendChild(nodeInfo.getNode(),
nodeToAdd);
}
}
示例9: createBlockForPPr
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/**
* This is invoked on every paragraph, whether it has a pPr or not.
*
* @param wmlPackage
* @param pPrNodeIt
* @param pStyleVal
* @param childResults - the already transformed contents of the paragraph.
* @return
*/
public static DocumentFragment createBlockForPPr(
FOConversionContext context,
NodeIterator pPrNodeIt,
String pStyleVal, NodeIterator childResults) {
DocumentFragment df = createBlock(
context,
pPrNodeIt,
pStyleVal, childResults,
false);
// Arabic (and presumably Hebrew) fix
// If we have inline direction="rtl" (created by TextDirection class)
// wrap the inline with:
// <bidi-override direction="rtl" unicode-bidi="embed">
/* See further:
From: Glenn Adams <[email protected]>
Date: Fri, Mar 21, 2014 at 8:41 AM
Subject: Re: right align arabic in table-cell
To: FOP Users <[email protected]>
*/
Element block = (Element)df.getFirstChild();
NodeList blockChildren = block.getChildNodes();
for (int i = 0 ; i <blockChildren.getLength(); i++ ) {
if (blockChildren.item(i) instanceof Element) {
Element inline = (Element)blockChildren.item(i);
if (inline !=null && inline.getAttribute("direction")!=null
&& inline.getAttribute("direction").equals("rtl")) {
inline.removeAttribute("direction");
Element bidiOverride = df.getOwnerDocument().createElementNS("http://www.w3.org/1999/XSL/Format",
"fo:bidi-override");
bidiOverride.setAttribute("unicode-bidi", "embed" );
bidiOverride.setAttribute("direction", "rtl" );
block.replaceChild(bidiOverride, inline);
bidiOverride.appendChild(inline);
}
}
}
if (foContainsElement(block, "leader")) {
// ptab to leader implementation:
// for leader to work as expected in fop, we need text-align-last; see http://xmlgraphics.apache.org/fop/faq.html#leader-expansion
// this code adds that.
// Note that it doesn't seem to be necessary for leader in TOC, but it doesn't hurt
block.setAttribute("text-align-last", "justify");
}
return df;
}
示例10: writeNode
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public static void writeNode(Node n, XMLStreamWriter writer, boolean repairing)
throws XMLStreamException {
switch (n.getNodeType()) {
case Node.ELEMENT_NODE:
writeElement((Element)n, writer, repairing);
break;
case Node.TEXT_NODE:
writer.writeCharacters(((Text)n).getNodeValue());
break;
case Node.COMMENT_NODE:
writer.writeComment(((Comment)n).getData());
break;
case Node.CDATA_SECTION_NODE:
writer.writeCData(((CDATASection)n).getData());
break;
case Node.ENTITY_REFERENCE_NODE:
writer.writeEntityRef(((EntityReference)n).getNodeValue());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
ProcessingInstruction pi = (ProcessingInstruction)n;
writer.writeProcessingInstruction(pi.getTarget(), pi.getData());
break;
case Node.DOCUMENT_NODE:
writeDocument((Document)n, writer, repairing);
break;
case Node.DOCUMENT_FRAGMENT_NODE: {
DocumentFragment frag = (DocumentFragment)n;
Node child = frag.getFirstChild();
while (child != null) {
writeNode(child, writer, repairing);
child = child.getNextSibling();
}
break;
}
case Node.DOCUMENT_TYPE_NODE:
try {
if (((DocumentType)n).getTextContent() != null) {
writer.writeDTD(((DocumentType)n).getTextContent());
}
} catch (UnsupportedOperationException ex) {
//can we ignore? DOM writers really don't allow this
//as there isn't a way to write a DTD in dom
}
break;
default:
throw new IllegalStateException("Found type: " + n.getClass().getName());
}
}
示例11: parseDocument
import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/** Parse a document returning the document element. */
private Element parseDocument(String features) throws ParseException {
Function<DOMImplementation, DocumentType> doctypeMaker = findDoctype();
Document doc = makeDocument(doctypeMaker, features, domImpl);
OpenElementStack elementStack = makeElementStack(doc, mq);
// Make sure the elementStack is empty.
elementStack.open(false);
skipTopLevelDocIgnorables(true);
do {
parseDom(elementStack);
skipTopLevelDocIgnorables(false);
} while (!tokens.isEmpty());
FilePosition endPos = checkEnd(elementStack);
DocumentFragment root = elementStack.getRootElement();
Node firstChild = root.getFirstChild();
if (firstChild == null || firstChild.getNodeType() != Node.ELEMENT_NODE) {
throw new ParseException(new Message(
DomParserMessageType.MISSING_DOCUMENT_ELEMENT, endPos));
}
// Check that there isn't any extraneous content after the root element.
for (Node child = firstChild.getNextSibling(); child != null;
child = child.getNextSibling()) {
switch (child.getNodeType()) {
case Node.COMMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
continue;
case Node.TEXT_NODE:
if ("".equals(child.getNodeValue().trim())) { continue; }
break;
default: break;
}
throw new ParseException(new Message(
DomParserMessageType.MISPLACED_CONTENT,
Nodes.getFilePositionFor(child)));
}
Nodes.setFilePositionFor(doc, Nodes.getFilePositionFor(root));
doc.appendChild(firstChild);
if (elementStack.needsNamespaceFixup()) {
firstChild = fixup(firstChild, ns);
}
return (Element) firstChild;
}