use of org.w3c.dom.Document in project weixin-java-tools by chanjarster.
the class WxCryptUtilTest method testValidateSignatureError.
public void testValidateSignatureError() throws ParserConfigurationException, SAXException, IOException {
try {
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
String afterEncrpt = pc.encrypt(replyMsg);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
StringReader sr = new StringReader(afterEncrpt);
InputSource is = new InputSource(sr);
Document document = db.parse(is);
Element root = document.getDocumentElement();
NodeList nodelist1 = root.getElementsByTagName("Encrypt");
String encrypt = nodelist1.item(0).getTextContent();
String fromXML = String.format(xmlFormat, encrypt);
// 这里签名错误
pc.decrypt("12345", timestamp, nonce, fromXML);
} catch (RuntimeException e) {
assertEquals(e.getMessage(), "加密消息签名校验失败");
return;
}
fail("错误流程不抛出异常???");
}
use of org.w3c.dom.Document in project weixin-java-tools by chanjarster.
the class WxCryptUtil method extractEncryptPart.
static String extractEncryptPart(String xml) {
try {
DocumentBuilder db = builderLocal.get();
Document document = db.parse(new InputSource(new StringReader(xml)));
Element root = document.getDocumentElement();
return root.getElementsByTagName("Encrypt").item(0).getTextContent();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.w3c.dom.Document in project cogtool by cogtool.
the class BalsamiqButtonAPIConverter method parseBalsamiqFile.
/** Helper function used by importDesign.
* This method is used to parse the tags of each .bmml file in the
* directory. The file represents a {@link File} in the directory.
*
* @param inputFile the specified directory or file
* @see the new design in the project window.
*/
public void parseBalsamiqFile(File inputFile) throws IOException {
String fileName = inputFile.getName();
int lastIndex = fileName.lastIndexOf(".");
fileName = (lastIndex == -1) ? fileName : fileName.substring(0, lastIndex);
/* Check to make sure that this frame has not been created yet. Cycles
* by transitions may exist in the design and these files do not need
* to be parsed more than once. */
if (!visitedFramesNames.contains(fileName)) {
visitedFramesNames.add(fileName);
// Create a Xerces DOM Parser. A DOM Parser can parse an XML file
// and create a tree representation of it. This same parser method
// is used in ImportCogTool.java to import from CogTool XML.
DOMParser parser = new DOMParser();
InputStream fis = new FileInputStream(inputFile);
Reader input = new InputStreamReader(fis, "UTF-8");
// Parse the Document and traverse the DOM
try {
parser.parse(new InputSource(input));
} catch (SAXException e) {
throw new RcvrImportException("Not a valid XML file to parse.");
}
//Traverse the xml tags in the tree beginning at the root, the document
Document document = parser.getDocument();
parseFrame(document, fileName);
}
}
use of org.w3c.dom.Document in project cw-omnibus by commonsguy.
the class WeatherFragment method buildForecasts.
private ArrayList<Forecast> buildForecasts(String raw) throws Exception {
ArrayList<Forecast> forecasts = new ArrayList<Forecast>();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(raw)));
NodeList times = doc.getElementsByTagName("start-valid-time");
for (int i = 0; i < times.getLength(); i++) {
Element time = (Element) times.item(i);
Forecast forecast = new Forecast();
forecasts.add(forecast);
forecast.setTime(time.getFirstChild().getNodeValue());
}
NodeList temps = doc.getElementsByTagName("value");
for (int i = 0; i < temps.getLength(); i++) {
Element temp = (Element) temps.item(i);
Forecast forecast = forecasts.get(i);
forecast.setTemp(Integer.valueOf(temp.getFirstChild().getNodeValue()));
}
NodeList icons = doc.getElementsByTagName("icon-link");
for (int i = 0; i < icons.getLength(); i++) {
Element icon = (Element) icons.item(i);
Forecast forecast = forecasts.get(i);
forecast.setIcon(icon.getFirstChild().getNodeValue());
}
return (forecasts);
}
use of org.w3c.dom.Document in project cw-android by commonsguy.
the class StaticFileDemo method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
try {
InputStream in = getResources().openRawResource(R.raw.words);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in, null);
NodeList words = doc.getElementsByTagName("word");
for (int i = 0; i < words.getLength(); i++) {
items.add(((Element) words.item(i)).getAttribute("value"));
}
in.close();
} catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), Toast.LENGTH_LONG).show();
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
}
Aggregations