List of usage examples for javax.xml.transform.dom DOMResult setNode
public void setNode(Node node)
From source file:com.oracle.tutorial.jdbc.RSSFeedsTable.java
public void addRSSFeed(String fileName) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, TransformerConfigurationException, TransformerException, SQLException { // Parse the document and retrieve the name of the RSS feed String titleString = null;// w w w . jav a2 s .c o m javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(fileName); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xPath = xPathfactory.newXPath(); Node titleElement = (Node) xPath.evaluate("/rss/channel/title[1]", doc, XPathConstants.NODE); if (titleElement == null) { System.out.println("Unable to retrieve title element"); return; } else { titleString = titleElement.getTextContent().trim().toLowerCase().replaceAll("\\s+", "_"); System.out.println("title element: [" + titleString + "]"); } System.out.println(JDBCTutorialUtilities.convertDocumentToString(doc)); PreparedStatement insertRow = null; SQLXML rssData = null; System.out.println("Current DBMS: " + this.dbms); try { if (this.dbms.equals("mysql")) { // For databases that support the SQLXML data type, this creates a // SQLXML object from org.w3c.dom.Document. System.out.println("Adding XML file " + fileName); String insertRowQuery = "insert into RSS_FEEDS (RSS_NAME, RSS_FEED_XML) values" + " (?, ?)"; insertRow = con.prepareStatement(insertRowQuery); insertRow.setString(1, titleString); System.out.println("Creating SQLXML object with MySQL"); rssData = con.createSQLXML(); System.out.println("Creating DOMResult object"); DOMResult dom = (DOMResult) rssData.setResult(DOMResult.class); dom.setNode(doc); insertRow.setSQLXML(2, rssData); System.out.println("Running executeUpdate()"); insertRow.executeUpdate(); } else if (this.dbms.equals("derby")) { System.out.println("Adding XML file " + fileName); String insertRowQuery = "insert into RSS_FEEDS (RSS_NAME, RSS_FEED_XML) values" + " (?, xmlparse(document cast (? as clob) preserve whitespace))"; insertRow = con.prepareStatement(insertRowQuery); insertRow.setString(1, titleString); String convertedDoc = JDBCTutorialUtilities.convertDocumentToString(doc); insertRow.setClob(2, new StringReader(convertedDoc)); System.out.println("Running executeUpdate()"); insertRow.executeUpdate(); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } catch (Exception ex) { System.out.println("Another exception caught:"); ex.printStackTrace(); } finally { if (insertRow != null) { insertRow.close(); } } }
From source file:eu.betaas.service.securitymanager.service.impl.AuthorizationService.java
/** * Check the condition specified in the token with the condition saved in the * GW (concerning the specific thingService) * @param ct: extracted Condition from the token * @param req: RequestCtx (required by XACML API) * @return boolean true or false (true if the condition matches) *//*from ww w . j av a 2 s.com*/ private boolean checkCondition(ConditionType ct, RequestCtx req) { boolean access = false; JAXBElement<ConditionType> jaxbCT = of.createCondition(ct); JAXBContext jc = null; try { jc = JAXBContext.newInstance(ConditionType.class); Marshaller mar = jc.createMarshaller(); // create DOM Document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); mar.marshal(jaxbCT, doc); // convert ConditionType to XML Node (org.w3c.dom.Node) DOMResult res = new DOMResult(); res.setNode(doc.getDocumentElement()); Node conditionNode = res.getNode(); // prepare for the Condition PolicyMetaData metadata = new PolicyMetaData(2, 0); VariableManager vm = new VariableManager(new HashMap(), metadata); Condition condition = Condition.getInstance(conditionNode, metadata, vm); // evaluate condition -- first convert RequestCtx into EvaluationCtx EvaluationCtx context = new BasicEvaluationCtx(req); EvaluationResult result = condition.evaluate(context); BooleanAttribute bool = (BooleanAttribute) (result.getAttributeValue()); // get the condition evaluation result in boolean access = bool.getValue(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParsingException e) { // TODO Auto-generated catch block e.printStackTrace(); } log.info("Checking Condition in the Access Right return: " + access); return access; }
From source file:org.springframework.oxm.support.AbstractMarshaller.java
/** * Template method for handling {@code DOMResult}s. * <p>This implementation delegates to {@code marshalDomNode}. * @param graph the root of the object graph to marshal * @param domResult the {@code DOMResult} * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if the {@code domResult} is empty * @see #marshalDomNode(Object, org.w3c.dom.Node) *//*from ww w . j av a 2 s .co m*/ protected void marshalDomResult(Object graph, DOMResult domResult) throws XmlMappingException { if (domResult.getNode() == null) { domResult.setNode(buildDocument()); } marshalDomNode(graph, domResult.getNode()); }