List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSubAwardBudget10_10V1_3Generator.java
/** * /*from w ww. j av a 2s . com*/ * This method is used to get RRBudget from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return RRBudget corresponding to the BudgetSubAwards object. */ private RRBudget1013Document getRRBudget(BudgetSubAwardsContract budgetSubAwards) { RRBudget1013Document rrBudget = RRBudget1013Document.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement.getElementsByTagNameNS(RR_BUDGET_10_1_3_NAMESPACE_URI, RR_BUDGET_10_1_3_LOCAL_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRBudget1013Document) XmlObject.Factory.parse(bgtIS); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } return rrBudget; }
From source file:com.flozano.socialauth.plugin.googleplus.AlbumsPluginImpl.java
@Override public List<Album> getAlbums() throws Exception { Response response = providerSupport.api(ALBUMS_URL, MethodType.GET.toString(), null, null, null); Element root;/*from w w w.j av a 2 s .c om*/ try { root = XMLParseUtil.loadXmlResource(response.getInputStream()); } catch (Exception e) { throw new ServerDataException("Failed to parse the albums from response." + ALBUMS_URL, e); } List<Album> albums = new ArrayList<Album>(); if (root != null) { NodeList albumList = root.getElementsByTagName("entry"); if (albumList != null && albumList.getLength() > 0) { LOG.info("Found albums : " + albumList.getLength()); for (int i = 0; i < albumList.getLength(); i++) { Album album = new Album(); Element p = (Element) albumList.item(i); NodeList id = p.getElementsByTagNameNS(ALBUM_NAMESPACE, "id"); String albumId = XMLParseUtil.getElementData(id.item(0)); album.setId(albumId); album.setName(XMLParseUtil.getElementData(p, "title")); NodeList count = p.getElementsByTagNameNS(ALBUM_NAMESPACE, "numphotos"); album.setPhotosCount(Integer.parseInt(XMLParseUtil.getElementData(count.item(0)))); NodeList mediaGroup = p.getElementsByTagNameNS(MEDIA_NAMESPACE, "group"); String url = null; if (mediaGroup != null && mediaGroup.getLength() > 0) { Element el = (Element) mediaGroup.item(0); if (el != null) { NodeList thumbnail = el.getElementsByTagNameNS(MEDIA_NAMESPACE, "thumbnail"); if (thumbnail != null) { Element tl = (Element) thumbnail.item(0); if (tl != null) { url = tl.getAttribute("url"); } } } } album.setCoverPhoto(url); String rel = null; String href = null; NodeList link = p.getElementsByTagName("link"); if (link != null && link.getLength() > 0) { for (int j = 0; j < link.getLength(); j++) { Element l = (Element) link.item(j); if (l != null) { rel = l.getAttribute("rel"); if (rel != null && rel.equalsIgnoreCase("alternate")) { href = l.getAttribute("href"); } } } } album.setLink(href); List<Photo> photos = getAlbumPhotos(albumId); album.setPhotos(photos); albums.add(album); System.out.println(album); } } else { LOG.info("No albums were obtained from : " + ALBUMS_URL); } } return albums; }
From source file:com.flozano.socialauth.plugin.googleplus.AlbumsPluginImpl.java
private List<Photo> getAlbumPhotos(final String id) throws Exception { Response response = providerSupport.api(PHOTOS_URL + id, MethodType.GET.toString(), null, null, null); LOG.info("Getting Photos of Album :: " + id); Element root;//w w w . j a v a 2 s.c om try { root = XMLParseUtil.loadXmlResource(response.getInputStream()); } catch (Exception e) { throw new ServerDataException("Failed to parse the photos from response." + PHOTOS_URL + id, e); } List<Photo> photos = new ArrayList<Photo>(); if (root != null) { NodeList photoList = root.getElementsByTagName("entry"); if (photoList != null && photoList.getLength() > 0) { LOG.info("Found photos : " + photoList.getLength()); for (int i = 0; i < photoList.getLength(); i++) { Photo photo = new Photo(); Element pl = (Element) photoList.item(i); NodeList pid = pl.getElementsByTagNameNS(ALBUM_NAMESPACE, "id"); String photoId = XMLParseUtil.getElementData(pid.item(0)); photo.setId(photoId); photo.setTitle(XMLParseUtil.getElementData(pl, "title")); NodeList mediaGroup = pl.getElementsByTagNameNS(MEDIA_NAMESPACE, "group"); String urlLarge = null; String urlMedium = null; String urlSmall = null; String urlThumb = null; int width = 0; if (mediaGroup != null && mediaGroup.getLength() > 0) { Element el = (Element) mediaGroup.item(0); if (el != null) { NodeList content = el.getElementsByTagNameNS(MEDIA_NAMESPACE, "content"); if (content != null) { Element cl = (Element) content.item(0); if (cl != null) { urlLarge = cl.getAttribute("url"); } } NodeList thumbnail = el.getElementsByTagNameNS(MEDIA_NAMESPACE, "thumbnail"); if (thumbnail != null && thumbnail.getLength() > 0) { for (int k = 0; k < thumbnail.getLength(); k++) { Element thumb = (Element) thumbnail.item(k); if (thumb != null) { width = Integer.parseInt(thumb.getAttribute("width")); if (width == 288) { urlMedium = thumb.getAttribute("url"); } else if (width == 144) { urlSmall = thumb.getAttribute("url"); } else if (width == 72) { urlThumb = thumb.getAttribute("url"); } } } } } } photo.setLargeImage(urlLarge); photo.setMediumImage(urlMedium); photo.setSmallImage(urlSmall); photo.setThumbImage(urlThumb); photos.add(photo); } } else { LOG.info("No photos were obtained from : " + PHOTOS_URL); } } return photos; }
From source file:de.fhg.iais.cortex.services.ingest.worker.BinaryResolutionWorker.java
private CortexModel replaceLocalUrisInEDM(CortexModel model, String itemId) { if ((model == null) || (model.getAny().size() < 1)) { return model; }// www .j a va 2 s. c om Element rdf = model.getAny().get(0); if (rdf != null) { //replace in edm model Element aggregation = (Element) rdf .getElementsByTagNameNS(GlobalConstants.ORE_NAMESPACE_URI, "Aggregation").item(0); if (aggregation != null) { Element thumbnail = (Element) aggregation .getElementsByTagNameNS(GlobalConstants.EDM_NAMESPACE_URI, "object").item(0); if (thumbnail != null) { if (thumbnail.getAttributeNS(GlobalConstants.RDF_NAMESPACE_URI, Parser.RESOURCE) != null) { Attr attr = thumbnail.getAttributeNodeNS(GlobalConstants.RDF_NAMESPACE_URI, Parser.RESOURCE); String href = attr.getValue(); String value = amendRelativeUris(itemId, href); attr.setNodeValue(value); } } } else { throw new DbcException( "Ingest failed: " + itemId + " has no ore:Aggregation. Please check your Mappings."); } } return model; }
From source file:it.pronetics.madstore.repository.jcr.impl.JcrEntryRepository.java
@Transactional(propagation = Propagation.REQUIRED, readOnly = false) public String updateIfNewer(final String collectionKey, final Element entryElement) { if (entryElement == null || collectionKey == null || collectionKey.equals("")) { throw new IllegalArgumentException("Parameters cannot be null or empty strings!"); } else if (entryElement.getAttribute(AtomConstants.ATOM_KEY).equals("")) { throw new AtomRepositoryException("The entry element has no key!"); }/* www . j ava2s . co m*/ return (String) jcrTemplate.execute(new JcrCallback() { public Object doInJcr(final Session session) throws IOException, RepositoryException { String entryKey = entryElement.getAttribute(AtomConstants.ATOM_KEY); if (contains(collectionKey, entryKey)) { Element repositoryEntry = read(collectionKey, entryKey); String repositoryEntryUpdated = repositoryEntry .getElementsByTagNameNS(AtomConstants.ATOM_NS, AtomConstants.ATOM_ENTRY_UPDATED).item(0) .getTextContent(); String newEntryUpdated = entryElement .getElementsByTagNameNS(AtomConstants.ATOM_NS, AtomConstants.ATOM_ENTRY_UPDATED).item(0) .getTextContent(); DateTime repositoryEntryDateTime = new DateTime(repositoryEntryUpdated); DateTime newEntryDateTime = new DateTime(newEntryUpdated); if (newEntryDateTime.isAfter(repositoryEntryDateTime)) { if (delete(collectionKey, entryKey) != null) { importNodeFromDomEntry(collectionKey, entryKey, entryElement, session); indexManager.delete(collectionKey, entryKey); indexManager.index(collectionKey, entryKey, entryElement); session.save(); return entryKey; } else { throw new IllegalStateException("Unable to delete: " + entryKey); } } else { return null; } } else { LOG.warn("Entry {} does not exist in collection {}. Nothing to update.", entryKey, collectionKey); return null; } } }); }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398TrainingSubAwardBudgetV1_0Generator.java
/** * /*w w w . j a v a 2 s . co m*/ * This method is used to get PHS398TrainingBudget from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return PHS398TrainingBudget corresponding to the BudgetSubAwards object. */ private PHS398TrainingBudget getPHS398TrainingBudget(BudgetSubAwardsContract budgetSubAwards) throws S2SException { PHS398TrainingBudget rrBudget = PHS398TrainingBudget.Factory.newInstance(); PHS398TrainingBudgetDocument rrBudgetDocument = PHS398TrainingBudgetDocument.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement.getElementsByTagNameNS(PHS398_TRAINING_BUDGET_10_NAMESPACE_URI, "PHS398_TrainingBudget"); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; InputStream bgtIS = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudgetDocument = (PHS398TrainingBudgetDocument) XmlObject.Factory.parse(bgtIS); rrBudget = rrBudgetDocument.getPHS398TrainingBudget(); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } finally { if (bgtIS != null) { try { bgtIS.close(); } catch (IOException e) { } } } return rrBudget; }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398TrainingSubAwardBudgetV2_0Generator.java
/** * //w w w.ja va 2s . c o m * This method is used to get PHS398TrainingBudget from BudgetSubAwards * * @param budgetSubAwards(BudgetSubAwards) budget sub awards entry. * @return PHS398TrainingBudget corresponding to the BudgetSubAwards object. */ private PHS398TrainingBudget getPHS398TrainingBudget(BudgetSubAwardsContract budgetSubAwards) throws S2SException { PHS398TrainingBudget rrBudget = PHS398TrainingBudget.Factory.newInstance(); PHS398TrainingBudgetDocument rrBudgetDocument = PHS398TrainingBudgetDocument.Factory.newInstance(); String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc; try { subAwdFormsDoc = stringToDom(subAwdXML); } catch (S2SException e1) { return rrBudget; } Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement.getElementsByTagNameNS(PHS398_TRAINING_BUDGET_20_NAMESPACE_URI, "PHS398_TrainingBudget"); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; InputStream bgtIS = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudgetDocument = (PHS398TrainingBudgetDocument) XmlObject.Factory.parse(bgtIS); rrBudget = rrBudgetDocument.getPHS398TrainingBudget(); } catch (S2SException e) { return rrBudget; } catch (XmlException e) { return rrBudget; } catch (IOException e) { return rrBudget; } finally { if (bgtIS != null) { try { bgtIS.close(); } catch (IOException e) { } } } return rrBudget; }
From source file:be.agiv.security.handler.WSTrustHandler.java
private void handleInboundMessage(SOAPMessageContext context) throws SOAPException, TransformerException { Element bodyElement = context.getMessage().getSOAPBody(); /*//from w w w. ja v a2 s. c om * First tried this via an xalan XPathAPI expression. But we received * some DOM error when using Axis2. */ NodeList nodeList = bodyElement.getElementsByTagNameNS(WSConstants.WSTRUST_NAMESPACE, "RequestedSecurityToken"); Element requestedSecurityTokenElement; if (nodeList.getLength() > 0) { requestedSecurityTokenElement = (Element) nodeList.item(0).getFirstChild(); } else { requestedSecurityTokenElement = null; } this.requestedSecurityToken = requestedSecurityTokenElement; }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRFedNonFedSubAwardBudget5_30V1_3Generator.java
private RRFedNonFedBudget12Document getRRFedNonFedBudget(BudgetSubAwardsContract budgetSubAwards) { RRFedNonFedBudget12Document rrBudget; String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc;//ww w. ja v a2 s . c o m subAwdFormsDoc = stringToDom(subAwdXML); Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement .getElementsByTagNameNS(RR_FED_NON_FED_BUDGET30_12_NAMESPACE_URI, LOCAL_FED_NON_FED_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; try { subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRFedNonFedBudget12Document) XmlObject.Factory.parse(bgtIS); return rrBudget; } catch (XmlException | IOException e) { throw new RuntimeException(e); } }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSubAwardBudget10_30_1_4V1_4Generator.java
private RRBudget1014Document getRRBudget1014(BudgetSubAwardsContract budgetSubAwards) throws IOException, XmlException { RRBudget1014Document rrBudget; String subAwdXML = budgetSubAwards.getSubAwardXmlFileData(); Document subAwdFormsDoc;//from w w w . jav a 2 s.co m subAwdFormsDoc = stringToDom(subAwdXML); Element subAwdFormsElement = subAwdFormsDoc.getDocumentElement(); NodeList subAwdNodeList = subAwdFormsElement.getElementsByTagNameNS(RR_BUDGET10_14_NAMESPACE_URI, RR_BUDGET10_14_LOCAL_NAME); Node subAwdNode = null; if (subAwdNodeList != null) { if (subAwdNodeList.getLength() == 0) { return null; } subAwdNode = subAwdNodeList.item(0); } byte[] subAwdNodeBytes = null; subAwdNodeBytes = docToBytes(nodeToDom(subAwdNode)); InputStream bgtIS = new ByteArrayInputStream(subAwdNodeBytes); rrBudget = (RRBudget1014Document) XmlObject.Factory.parse(bgtIS); return rrBudget; }