-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from cajuncoding/feature/add_support_to_load_ac…
…cessibility_from_xml_or_az_func_config Feature/add support to load accessibility from xml or az func config
- Loading branch information
Showing
10 changed files
with
137 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"version": "2.0", | ||
"extensionBundle": { | ||
"id": "Microsoft.Azure.Functions.ExtensionBundle", | ||
"version": "[1.*, 2.0.0)" | ||
} | ||
"version": "2.0"//, | ||
// "extensionBundle": { | ||
// "id": "Microsoft.Azure.Functions.ExtensionBundle", | ||
// "version": "[1.*, 2.0.0)" | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...rverless-az-func/src/main/java/com/cajuncoding/apachefop/serverless/utils/XPathUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.cajuncoding.apachefop.serverless.utils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.StringReader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.xpath.XPath; | ||
import javax.xml.xpath.XPathExpressionException; | ||
import javax.xml.xpath.XPathFactory; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.w3c.dom.Document; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
|
||
public class XPathUtils { | ||
|
||
public static XPathUtils fromXml(String xmlContent) | ||
{ | ||
try (var xmlContentStream = IOUtils.toInputStream(xmlContent, StandardCharsets.UTF_8)) { | ||
return XPathUtils.fromXml(xmlContentStream); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return new XPathUtils(null); | ||
} | ||
|
||
public static XPathUtils fromXml(InputStream xmlContentStream) | ||
{ | ||
Document xmlDocument = null; | ||
try { | ||
xmlDocument = DocumentBuilderFactory.newInstance() | ||
.newDocumentBuilder() | ||
.parse(xmlContentStream); | ||
} catch (SAXException | IOException | ParserConfigurationException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return new XPathUtils(xmlDocument); | ||
} | ||
|
||
protected Document _xmlDoc; | ||
|
||
public XPathUtils(Document xmlDoc) | ||
{ | ||
_xmlDoc = xmlDoc; | ||
} | ||
|
||
public Document getXmlDocument() { | ||
return _xmlDoc; | ||
} | ||
|
||
public <T>T evalXPath(String xpath, Class<T> classType) throws XPathExpressionException | ||
{ | ||
return evalXPathInternal(xpath, classType); | ||
} | ||
|
||
public String evalXPathAsString(String xpath, String defaultIfNotFound) throws XPathExpressionException | ||
{ | ||
try { | ||
var result = evalXPathInternal(xpath, String.class); | ||
return result != null ? result : defaultIfNotFound; | ||
} catch (XPathExpressionException e) { | ||
return defaultIfNotFound; | ||
} | ||
} | ||
|
||
public boolean evalXPathAsBoolean(String xpath, boolean defaultIfNotFound) | ||
{ | ||
try { | ||
var result = evalXPathInternal(xpath, Boolean.class); | ||
return (boolean)(result != null ? result : defaultIfNotFound); | ||
} catch (XPathExpressionException e) { | ||
return defaultIfNotFound; | ||
} | ||
} | ||
|
||
public <T>T evalXPathInternal(String xpathCommand, Class<T> classType) throws XPathExpressionException | ||
{ | ||
if(_xmlDoc == null) | ||
return null; | ||
|
||
XPath xpath = XPathFactory.newInstance().newXPath(); | ||
// //XPathExpression xpathExpression = xpathCompiler.compile(xpath); | ||
// var result = xpathExpression.evaluate(_xmlDoc, returnType); | ||
var result = xpath.evaluateExpression(xpathCommand, _xmlDoc, classType); | ||
return result; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters