/** * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 注意:远程解析XML出错,与服务器是否支持SSL等配置有关 * * @return 时间戳字符串 * @throws IOException * @throws DocumentException * @throws MalformedURLException */ @SuppressWarnings("unchecked") public static String query_timestamp() throws MalformedURLException, DocumentException, IOException { // 构造访问query_timestamp接口的URL串 String strUrl = ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset; StringBuffer result = new StringBuffer(); SAXReader reader = new SAXReader(); Document doc = reader.read(new URL(strUrl).openStream()); List<Node> nodeList = doc.selectNodes("//alipay/*"); for (Node node : nodeList) { // 截取部分不需要解析的信息 if (node.getName().equals("is_success") && node.getText().equals("T")) { // 判断是否有成功标示 List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*"); for (Node node1 : nodeList1) { result.append(node1.getText()); } } } return result.toString(); }
@Override public boolean load(Document doc) { super.load(doc); Node node; node = doc.selectSingleNode("//depth"); if (node != null) { setZ(Double.parseDouble(node.getText())); if (getZ() >= 0) setZUnits(Z_UNITS.DEPTH); else { setZUnits(Z_UNITS.ALTITUDE); setZ(-getZ()); } } node = doc.selectSingleNode("//height"); if (node != null) { setZUnits(Z_UNITS.HEIGHT); setZ(Double.parseDouble(node.getText())); } node = doc.selectSingleNode("//altitude"); if (node != null) { setZUnits(Z_UNITS.ALTITUDE); setZ(Double.parseDouble(node.getText())); } node = doc.selectSingleNode("//z"); if (node != null) setZ(Double.parseDouble(node.getText())); node = doc.selectSingleNode("//zunits"); if (node != null) setZUnits(Z_UNITS.valueOf(node.getText())); return true; }
protected void writeNode(Node node) throws IOException { int nodeType = node.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: writeElement((Element) node); break; case Node.ATTRIBUTE_NODE: writeAttribute((Attribute) node); break; case Node.TEXT_NODE: writeNodeText(node); // write((Text) node); break; case Node.CDATA_SECTION_NODE: writeCDATA(node.getText()); break; case Node.ENTITY_REFERENCE_NODE: writeEntity((Entity) node); break; case Node.PROCESSING_INSTRUCTION_NODE: writeProcessingInstruction((ProcessingInstruction) node); break; case Node.COMMENT_NODE: writeComment(node.getText()); break; case Node.DOCUMENT_NODE: write((Document) node); break; case Node.DOCUMENT_TYPE_NODE: writeDocType((DocumentType) node); break; case Node.NAMESPACE_NODE: // Will be output with attributes // write((Namespace) node); break; default: throw new IOException("Invalid node type: " + node); } }
public void testWithoutItemsEnumParentWithExplicitLabelsAndValues() throws Exception { BeanWithEnum testBean = new BeanWithEnum(); testBean.setTestEnum(TestEnum.VALUE_2); getPageContext().getRequest().setAttribute("testBean", testBean); this.selectTag.setPath("testBean.testEnum"); this.tag.setItemLabel("enumLabel"); this.tag.setItemValue("enumValue"); this.selectTag.doStartTag(); int result = this.tag.doStartTag(); assertEquals(BodyTag.SKIP_BODY, result); result = this.tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, result); this.selectTag.doEndTag(); String output = getWriter().toString(); SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Node value1 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_1']"); Node value2 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_2']"); assertEquals("Label: VALUE_1", value1.getText()); assertEquals("Label: VALUE_2", value2.getText()); assertEquals(value2, rootElement.selectSingleNode("option[@selected]")); }
public int receiptsettle(String esb2ensemble) { this.conn = DbConnection.getConn(); CallableStatement cs = null; int n = -1; try { // ESB收到消息后解析报文 Document doc1 = DocumentHelper.parseText(esb2ensemble); // 获取叶子节点b Node node1 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/v1"); String v1 = node1.getText(); System.out.println(v1); Node node3 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/v2"); String v3 = node3.getText(); System.out.println(v3); Node node4 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/v3"); String v4 = node4.getText(); System.out.println(v4); Node node5 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/v4"); String v5 = node5.getText(); System.out.println(v5); int vv5 = Integer.parseInt(v5); try { cs = conn.prepareCall("{call sp_receiptsettle(?,?,?,?)}"); cs.setString(1, v1); cs.setString(2, v3); cs.setString(3, v4); cs.setInt(4, vv5); cs.execute(); n = 0; } catch (SQLException e) { e.printStackTrace(); return n; } finally { try { cs.close(); this.conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } catch (DocumentException e) { e.printStackTrace(); } return 0; }
private static Object getDefaultValue(final Node parameterNode) { Node rootNode = parameterNode.selectSingleNode("default-value"); // $NON-NLS-1$ if (rootNode == null) { return (null); } String dataType = XmlDom4JHelper.getNodeText("@type", rootNode); // $NON-NLS-1$ if (dataType == null) { dataType = XmlDom4JHelper.getNodeText("@type", parameterNode); // $NON-NLS-1$ } if ("string-list".equals(dataType)) { // $NON-NLS-1$ List nodes = rootNode.selectNodes("list-item"); // $NON-NLS-1$ if (nodes == null) { return (null); } ArrayList rtnList = new ArrayList(); for (Iterator it = nodes.iterator(); it.hasNext(); ) { rtnList.add(((Node) it.next()).getText()); } return (rtnList); } else if ("property-map-list".equals(dataType)) { // $NON-NLS-1$ List nodes = rootNode.selectNodes("property-map"); // $NON-NLS-1$ if (nodes == null) { return (null); } ArrayList rtnList = new ArrayList(); for (Iterator it = nodes.iterator(); it.hasNext(); ) { Node mapNode = (Node) it.next(); rtnList.add(SequenceDefinition.getMapFromNode(mapNode)); } return (rtnList); } else if ("property-map".equals(dataType)) { // $NON-NLS-1$ return (SequenceDefinition.getMapFromNode( rootNode.selectSingleNode("property-map"))); // $NON-NLS-1$ } else if ("long".equals(dataType)) { // $NON-NLS-1$ try { return (new Long(rootNode.getText())); } catch (Exception e) { } return (null); } else if ("result-set".equals(dataType)) { // $NON-NLS-1$ return (MemoryResultSet.createFromActionSequenceInputsNode(parameterNode)); } else { // Assume String return (rootNode.getText()); } }
public int settlepay(String esb2ensemble) { this.conn = DbConnection.getConn(); CallableStatement cs = null; int n = -1; try { // ESB收到消息后解析报文 Document doc1 = DocumentHelper.parseText(esb2ensemble); // 获取叶子节点b Node node3 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/client"); String v3 = node3.getText(); Node node4 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/acct"); String v4 = node4.getText(); Node node5 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/payamt"); String v5 = node5.getText(); int vv5 = Integer.parseInt(v5); Node node6 = doc1.selectSingleNode("ROOT/BODY/SVR_MESSAGE_IN/baseacctno"); String v6 = node6.getText(); try { cs = conn.prepareCall("{call sp_settlepay(?,?,?,?)}"); cs.setString(1, v3); cs.setString(2, v4); cs.setInt(3, vv5); cs.setString(4, v6); cs.execute(); n = 0; } catch (SQLException e) { e.printStackTrace(); return n; } finally { try { cs.close(); this.conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } catch (DocumentException e) { e.printStackTrace(); } return 0; }
public void setDateMinimum(final Node dateMinimumNode) { if (dateMinimumNode != null) { try { setDateMinimum(DateFormat.getDateInstance().parse(dateMinimumNode.getText())); } catch (ParseException e) { getLogger() .error( Messages.getInstance() .getString( "TimeSeriesCollectionChartDefinition.ERROR_0001_INVALID_DATE", //$NON-NLS-1$ dateMinimumNode.getText()), e); } } }
@Override public void loadFromXML(String XML) { try { Document doc = DocumentHelper.parseText(XML); // basePoint Node node = doc.selectSingleNode("StationKeeping/basePoint/point"); ManeuverLocation loc = new ManeuverLocation(); loc.load(node.asXML()); setManeuverLocation(loc); // Speed Node speedNode = doc.selectSingleNode("StationKeeping/speed"); setSpeed(Double.parseDouble(speedNode.getText())); setSpeedUnits(speedNode.valueOf("@unit")); // Duration setDuration(Integer.parseInt(doc.selectSingleNode("StationKeeping/duration").getText())); // Trajectory setRadius( Double.parseDouble(doc.selectSingleNode("StationKeeping/trajectory/radius").getText())); } catch (Exception e) { NeptusLog.pub().error(this, e); return; } }
private void processElementChildren( final Element element, final String key, final Map<String, String> properties) { for (int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); if (logger.isDebugEnabled()) { logger.debug(String.format("Processing xml element %s", node.getPath())); } if (node instanceof Element) { StringBuilder sbPrefix = new StringBuilder(key); if (sbPrefix.length() > 0) { sbPrefix.append("."); } sbPrefix.append(node.getName()); if (!excludeProperties.contains(sbPrefix.toString())) { processElementChildren((Element) node, sbPrefix.toString(), properties); } } else { StringBuilder sb = new StringBuilder(); if (properties.containsKey(key)) { sb.append(properties.get(key)); if (sb.length() > 0) { sb.append(multivalueSeparator); } } String value = node.getText(); if (StringUtils.isNotBlank(value)) { if (logger.isDebugEnabled()) { logger.debug(String.format("Adding value [%s] for property [%s].", value, key)); } sb.append(value); properties.put(key, StringUtils.trim(sb.toString())); } } } }
@SuppressWarnings("unchecked") @Override public Relationship parse(Node relationshipNode) { Node schemaNode = relationshipNode.selectSingleNode("@schema"); String schemaName = schemaNode != null ? schemaNode.getText().trim() : null; String tableName = relationshipNode.selectSingleNode("@table").getText().trim(); LOG.info("creating composite to extract " + tableName); CompositeReferingToMultipleTablesRelationship relationship = new CompositeReferingToMultipleTablesRelationship(schemaName, tableName); List<Node> relateNodes = relationshipNode.selectNodes("relate"); for (Node relateNode : relateNodes) { String column = relateNode.selectSingleNode("@column").getText().trim(); String seedTableName = relateNode.selectSingleNode("@seedTable").getText().trim(); String seedColumn = relateNode.selectSingleNode("@seedColumn").getText().trim(); LOG.info( String.format( "\tadding relationship to composite %s.%s ->%s.%s", seedTableName, seedColumn, tableName, column)); relationship.addTableRelationship(column, seedTableName, seedColumn); } return relationship; }
@Test public void testHtmlWithTags() throws Exception { final String htmlText = "<html><head><title>Title</title></head>" + "<body><p>this is a test</p></body></html>"; // Create FetchedDatum using data String url = "http://domain.com/page.html"; String contentType = "text/html; charset=utf-8"; HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaderNames.CONTENT_TYPE, contentType); ContentBytes content = new ContentBytes(htmlText.getBytes("utf-8")); FetchedDatum fetchedDatum = new FetchedDatum(url, url, System.currentTimeMillis(), headers, content, contentType, 0); // Call parser.parse SimpleParser parser = new SimpleParser(new ParserPolicy(), true); ParsedDatum parsedDatum = parser.parse(fetchedDatum); // Now take the resulting HTML, process it using Dom4J SAXReader reader = new SAXReader(new Parser()); reader.setEncoding("UTF-8"); String htmlWithMarkup = parsedDatum.getParsedText(); Document doc = reader.read(new StringInputStream(htmlWithMarkup)); // We have to do helicopter stunts since HTML has a global namespace on it, set // at the <html> element level. XPath xpath = DocumentHelper.createXPath("/xhtml:html/xhtml:body/xhtml:p"); Map<String, String> namespaceUris = new HashMap<String, String>(); namespaceUris.put("xhtml", "http://www.w3.org/1999/xhtml"); xpath.setNamespaceURIs(namespaceUris); Node paragraphNode = xpath.selectSingleNode(doc); Assert.assertNotNull(paragraphNode); Assert.assertEquals("this is a test", paragraphNode.getText()); }
public void setStacked(final Node stackedNode) { if (stackedNode != null) { String boolStr = stackedNode.getText(); Boolean booleanValue = new Boolean(boolStr); setStacked(booleanValue.booleanValue()); } }
public void setDomainVerticalTickLabels(final Node domainVerticalTickLabelsNode) { if (domainVerticalTickLabelsNode != null) { String boolStr = domainVerticalTickLabelsNode.getText(); Boolean booleanValue = new Boolean(boolStr); setDomainVerticalTickLabels(booleanValue.booleanValue()); } }
public void setBorderVisible(final Node borderVisibleNode) { if (borderVisibleNode != null) { String boolStr = borderVisibleNode.getText(); Boolean booleanValue = new Boolean(boolStr); setBorderVisible(booleanValue.booleanValue()); } }
public void setThreeD(final Node threeDNode) { if (threeDNode != null) { String boolStr = threeDNode.getText(); Boolean booleanValue = new Boolean(boolStr); setThreeD(booleanValue.booleanValue()); } }
/** @param markersVisibleNode set the markers visibility from an XML node */ public void setMarkersVisible(final Node markersVisibleNode) { if (markersVisibleNode != null) { String boolStr = markersVisibleNode.getText(); Boolean booleanValue = new Boolean(boolStr); setMarkersVisible(booleanValue.booleanValue()); } }
public void setPlotBackground(final Node plotBackgroundNode) { if (plotBackgroundNode != null) { Node backgroundTypeNode = plotBackgroundNode.selectSingleNode(ChartDefinition.BACKGROUND_TYPE_ATTRIBUTE_NAME); if (backgroundTypeNode != null) { String backgroundTypeStr = backgroundTypeNode.getText(); if (ChartDefinition.COLOR_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundPaint(JFreeChartEngine.getPaint(plotBackgroundNode)); setPlotBackgroundImage((Image) null); } else if (ChartDefinition.IMAGE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundImage(plotBackgroundNode); setPlotBackgroundPaint(null); } else if (ChartDefinition.TEXTURE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundPaint( JFreeChartEngine.getTexturePaint( plotBackgroundNode, getWidth(), getHeight(), getSession())); setPlotBackgroundImage((Image) null); } else if (ChartDefinition.GRADIENT_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundPaint( JFreeChartEngine.getGradientPaint(plotBackgroundNode, getWidth(), getHeight())); setPlotBackgroundImage((Image) null); } } } }
private boolean canInclude(String path, List<Node> rules, Matcher matcher) { boolean canInclude = false; logger.info( "[Timing] Testing inclusion rule: " + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date())); /* Rules are listed from least to most important */ matcher.find(); for (Node rule : rules) { String mode = rule.getName(); String tokenizedRule = rule.getText(); for (int i = 1; i <= matcher.groupCount(); i++) { tokenizedRule = tokenizedRule.replaceAll("\\$" + i, matcher.group(i)); } if ("include".equals(mode)) { if (path.matches(tokenizedRule)) { canInclude = true; } } else if ("exclude".equals(mode)) { if (path.matches(tokenizedRule)) { canInclude = false; } } else { logger.warn("Inclusion rule mode " + mode + " not supported."); } } logger.info( "[Timing] Finished testing inclusion rule: " + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date())); return canInclude; }
private void addElementsToProperties(List elements, Properties props, String parentPath) { for (java.lang.Object o : elements) { Node ele = (Node) o; if (ele.getNodeType() != 1) { // text continue; } String contents = ele.getText().trim(); String newParentPath = ""; if (!StringUtils.isEmpty(parentPath)) { newParentPath = parentPath + "."; } newParentPath += ele.getName(); if (!StringUtils.isEmpty(contents)) { props.setProperty(newParentPath, contents); } if (ele instanceof Element) { List children = ((Element) ele).content(); addElementsToProperties(children, props, newParentPath); } } }
public void setLegendIncluded(final Node legendNode) { if (legendNode != null) { String boolStr = legendNode.getText(); Boolean booleanValue = new Boolean(boolStr); setLegendIncluded(booleanValue.booleanValue()); } }
/** * It gives back a tag value * * @param xpath * @return tag value */ public String getXMLConfigValue(String xpath) throws Exception { String retVal = ""; Node node = document.selectSingleNode(xpath); if (node != null) { retVal = node.getText().trim(); } return retVal; }
@Override public Dataset createChart(final Document doc) { if (actionPath != null) { // if we have a solution then get the values values = getActionData(); } else { // TODO support other methods of getting data } if (values == null) { // we could not get any data return null; } // get the chart node from the document Node chartAttributes = doc.selectSingleNode("//" + AbstractChartComponent.CHART_NODE_NAME); // $NON-NLS-1$ // create the definition TimeSeriesCollectionChartDefinition chartDefinition = new TimeSeriesCollectionChartDefinition( (IPentahoResultSet) values, byRow, chartAttributes, getSession()); // set the misc values from chartDefinition setChartType(chartDefinition.getChartType()); setTitle(chartDefinition.getTitle()); // get the URL template Node urlTemplateNode = chartAttributes.selectSingleNode(AbstractChartComponent.URLTEMPLATE_NODE_NAME); if (urlTemplateNode != null) { setUrlTemplate(urlTemplateNode.getText()); } // get the additional parameter Node paramName2Node = chartAttributes.selectSingleNode(AbstractChartComponent.PARAM2_NODE_NAME); if (paramName2Node != null) { seriesName = paramName2Node.getText(); } if ((chartDefinition.getWidth() != -1) && (width == -1)) { setWidth(chartDefinition.getWidth()); } if ((chartDefinition.getHeight() != -1) && (height == -1)) { setHeight(chartDefinition.getHeight()); } return chartDefinition; }
private String findValue(String xpathString, Node node) { XPath xpath = getXpath(xpathString); xpath.setNamespaceURIs(prefixNamespaceMap); Node resultNode = xpath.selectSingleNode(node); if (resultNode != null) { return resultNode.getText(); } else { return null; } }
private List<String> findValues(String xpathString, Node node) { XPath xpath = getXpath(xpathString); xpath.setNamespaceURIs(prefixNamespaceMap); List<? extends Node> nodeList = xpath.selectNodes(node); List<String> result = new ArrayList<String>(nodeList.size()); for (Node foundNode : nodeList) { result.add(foundNode.getText()); } return result; }
public void loadJobNode(Node arg0) throws LoadJobException { try { selectionPanel.getClearButton().doClick(); List fileList = arg0.selectNodes("filelist/file"); for (int i = 0; fileList != null && i < fileList.size(); i++) { Node fileNode = (Node) fileList.get(i); if (fileNode != null) { Node fileName = (Node) fileNode.selectSingleNode("@name"); if (fileName != null && fileName.getText().length() > 0) { Node filePwd = (Node) fileNode.selectSingleNode("@password"); selectionPanel .getLoader() .addFile( new File(fileName.getText()), (filePwd != null) ? filePwd.getText() : null); } } } Node fileDestination = (Node) arg0.selectSingleNode("destination/@value"); if (fileDestination != null) { destinationTextField.setText(fileDestination.getText()); } Node fileOverwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (fileOverwrite != null) { overwriteCheckbox.setSelected(fileOverwrite.getText().equals("true")); } Node fileCompressed = (Node) arg0.selectSingleNode("compressed/@value"); if (fileCompressed != null && TRUE.equals(fileCompressed.getText())) { outputCompressedCheck.doClick(); } Node filePrefix = (Node) arg0.selectSingleNode("prefix/@value"); if (filePrefix != null) { outPrefixTextField.setText(filePrefix.getText()); } Node pdfVersion = (Node) arg0.selectSingleNode("pdfversion/@value"); if (pdfVersion != null) { for (int i = 0; i < versionCombo.getItemCount(); i++) { if (((StringItem) versionCombo.getItemAt(i)).getId().equals(pdfVersion.getText())) { versionCombo.setSelectedIndex(i); break; } } } log.info(GettextResource.gettext(config.getI18nResourceBundle(), "Decrypt section loaded.")); } catch (Exception ex) { log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error: "), ex); } }
private static Object getBeanById(Element e) throws Exception { Object object = null; Node node = e.selectSingleNode("//id"); log.debug("没有找到属性" + e.getName() + "的id"); if (node != null) { Integer id = Integer.parseInt(node.getText()); // object = shiftService.getObjectById(Class.forName(domain_package_dot+e.getName()),id); } return object; }
@Test public void testGetPasswordEncoder_ClassNotFound() throws Exception { config = new SpringSecurityHibernateConfig(document); Node node = mock(Node.class); when(node.getText()).thenReturn("org.pentaho.ClassNotFoundEncoder"); when(document.selectSingleNode(anyString())).thenReturn(node); PasswordEncoder passwordEncoder = config.getPasswordEncoder(); assertNull(passwordEncoder); }
@Test public void testGetPasswordEncoder() throws Exception { config = new SpringSecurityHibernateConfig(document); Node node = mock(Node.class); when(node.getText()).thenReturn(DefaultPentahoPasswordEncoder.class.getName()); when(document.selectSingleNode(anyString())).thenReturn(node); PasswordEncoder passwordEncoder = config.getPasswordEncoder(); assertTrue(passwordEncoder instanceof DefaultPentahoPasswordEncoder); }
public void setOrientation(final Node orientationNode) { if (orientationNode != null) { String orientationStr = orientationNode.getText(); if (ChartDefinition.VERTICAL_ORIENTATION.equalsIgnoreCase(orientationStr)) { setOrientation(PlotOrientation.VERTICAL); } else if (ChartDefinition.HORIZONTAL_ORIENTATION.equalsIgnoreCase(orientationStr)) { setOrientation(PlotOrientation.HORIZONTAL); } } }