use of org.w3c.dom.DocumentFragment in project rhino by PLOS.
the class AuthorsXmlExtractor method getOtherFootnotesMap.
/**
* Grab all footnotes and put them into their own map
*
* @param doc the article XML document
* @param xpath XpathReader to use to process xpath expressions
* @return a Map of footnote IDs and values
*/
private static Map<String, String> getOtherFootnotesMap(Document doc, XpathReader xpath) throws XPathException {
Map<String, String> otherFootnotesMap = new HashMap<>();
//Grab all 'other' footnotes and put them into their own map
NodeList footnoteNodeList = xpath.selectNodes(doc, "//fn[@fn-type='other']");
for (int a = 0; a < footnoteNodeList.getLength(); a++) {
Node node = footnoteNodeList.item(a);
// Not all <aff>'s have the 'id' attribute.
String id = (node.getAttributes().getNamedItem("id") == null) ? "" : node.getAttributes().getNamedItem("id").getTextContent();
log.debug("Found footnote node: {}", id);
DocumentFragment df = doc.createDocumentFragment();
df.appendChild(node);
String footnote;
try {
footnote = getAsXMLString(xpath.selectNode(df, "//p"));
} catch (TransformerException e) {
throw new RuntimeException(e);
}
otherFootnotesMap.put(id, footnote);
}
return otherFootnotesMap;
}
use of org.w3c.dom.DocumentFragment in project rhino by PLOS.
the class AuthorsXmlExtractor method getAddressMap.
/**
* Grab all addresses and put them into their own map
*
* @param doc the article XML document
* @param xpath XpathReader to use to process xpath expressions
* @return a Map of address IDs and values
*/
private static Map<String, String> getAddressMap(Document doc, XpathReader xpath) throws XPathException {
Map<String, String> addressMap = new HashMap<>();
//Grab all the Current address information and place them into a map
NodeList currentAddressNodeList = xpath.selectNodes(doc, "//fn[@fn-type='current-aff']");
for (int a = 0; a < currentAddressNodeList.getLength(); a++) {
Node node = currentAddressNodeList.item(a);
String id = (node.getAttributes().getNamedItem("id") == null) ? "" : node.getAttributes().getNamedItem("id").getTextContent();
log.debug("Current address node: {}", id);
DocumentFragment df = doc.createDocumentFragment();
df.appendChild(node);
String address = xpath.selectString(df, "//p");
addressMap.put(id, address);
}
return addressMap;
}
use of org.w3c.dom.DocumentFragment in project uPortal by Jasig.
the class RenderingPipelineIntegrationTest method testRenderingPipeline.
@Test
public void testRenderingPipeline() throws Exception {
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
final Document doc = builder.newDocument();
final DocumentFragment headFragment = doc.createDocumentFragment();
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final IPortalUrlBuilder portalUrlBuilder = mock(IPortalUrlBuilder.class);
final IPortletUrlBuilder portletUrlBuilder = mock(IPortletUrlBuilder.class);
when(portalUrlBuilder.getUrlString()).thenReturn("URL_PLACEHOLDER");
when(portletUrlBuilder.getPortalUrlBuilder()).thenReturn(portalUrlBuilder);
when(portalUrlBuilder.getTargetedPortletUrlBuilder()).thenReturn(portletUrlBuilder);
when(portalUrlBuilder.getPortletUrlBuilder(any(IPortletWindowId.class))).thenReturn(portletUrlBuilder);
when(this.resourcesElementsProvider.getResourcesXmlFragment(any(HttpServletRequest.class), eq("/media/skins/respondr/defaultSkin/skin.xml"))).thenReturn(headFragment.getChildNodes());
when(this.portalUrlProvider.getDefaultUrl(any(HttpServletRequest.class))).thenReturn(portalUrlBuilder);
when(this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
when(this.portalUrlProvider.getPortalUrlBuilderByPortletFName(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
final IPortletWindow portletWindow = mock(IPortletWindow.class);
when(portletWindowRegistry.getPortletWindow(any(HttpServletRequest.class), any(StartElement.class))).thenReturn(new Tuple<IPortletWindow, StartElement>(portletWindow, null));
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(any(HttpServletRequest.class), any(String.class))).thenReturn(portletWindow);
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(any(HttpServletRequest.class), anyString())).thenReturn(portletWindow);
when(portletWindow.getPortletWindowId()).thenReturn(new MockPortletWindowId("1"));
final PipelineEventReader<?, ?> eventReader = this.component.getEventReader(request, response);
for (final Object event : eventReader) {
logger.debug(toString(event));
}
final String mediaType = eventReader.getOutputProperty(OutputKeys.MEDIA_TYPE);
assertEquals("text/html", mediaType);
}
use of org.w3c.dom.DocumentFragment in project jdk8u_jdk by JetBrains.
the class DocumentSerializer method deserialize.
/**
* @param ctx
* @param inputSource
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
private Node deserialize(Node ctx, InputSource inputSource) throws XMLEncryptionException {
try {
if (dbf == null) {
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
dbf.setValidating(false);
}
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.parse(inputSource);
Document contextDocument = null;
if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
contextDocument = (Document) ctx;
} else {
contextDocument = ctx.getOwnerDocument();
}
Element fragElt = (Element) contextDocument.importNode(d.getDocumentElement(), true);
DocumentFragment result = contextDocument.createDocumentFragment();
Node child = fragElt.getFirstChild();
while (child != null) {
fragElt.removeChild(child);
result.appendChild(child);
child = fragElt.getFirstChild();
}
return result;
} catch (SAXException se) {
throw new XMLEncryptionException("empty", se);
} catch (ParserConfigurationException pce) {
throw new XMLEncryptionException("empty", pce);
} catch (IOException ioe) {
throw new XMLEncryptionException("empty", ioe);
}
}
use of org.w3c.dom.DocumentFragment in project webservices-axiom by apache.
the class TestCreateDocumentFragmentInterfaces method runTest.
@Override
protected void runTest() throws Throwable {
Document document = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder().newDocument();
DocumentFragment fragment = document.createDocumentFragment();
assertFalse(fragment instanceof OMInformationItem);
}
Aggregations