use of org.hl7.elm.r1.Element in project wpcleaner by WPCleaner.
the class ApiJsonResult method getPage.
/**
* Get a page corresponding to a page node.
*
* @param wiki Wiki.
* @param pageNode Page node.
* @param knownPages Already known pages.
* @param useDisambig True if disambiguation property should be used.
* @return Page.
*/
protected static Page getPage(EnumWikipedia wiki, Element pageNode, List<Page> knownPages, boolean useDisambig) {
if (pageNode == null) {
return null;
}
String title = pageNode.getAttributeValue("title");
Attribute pageIdAttr = pageNode.getAttribute("pageid");
Integer pageId = null;
if (pageIdAttr != null) {
try {
String tmp = pageIdAttr.getValue();
pageId = Integer.valueOf(tmp);
} catch (NumberFormatException e) {
//
}
}
String revisionId = pageNode.getAttributeValue("lastrevid");
Page page = DataManager.getPage(wiki, title, pageId, revisionId, knownPages);
page.setNamespace(pageNode.getAttributeValue("ns"));
if (pageNode.getAttribute("missing") != null) {
page.setExisting(Boolean.FALSE);
} else if (pageId != null) {
page.setExisting(Boolean.TRUE);
}
if (pageNode.getAttribute("redirect") != null) {
page.getRedirects().isRedirect(true);
}
if (useDisambig) {
Element pageProps = pageNode.getChild("pageprops");
boolean dabPage = (pageProps != null) && (pageProps.getAttribute("disambiguation") != null);
page.setDisambiguationPage(Boolean.valueOf(dabPage));
}
return page;
}
use of org.hl7.elm.r1.Element in project wpcleaner by WPCleaner.
the class ApiXmlResult method shouldContinue.
/**
* Manage query-continue in request.
*
* @param root Root of the DOM tree.
* @param queryContinue XPath query to the query-continue node.
* @param properties Properties defining request.
* @return True if request should be continued.
*/
protected boolean shouldContinue(Element root, String queryContinue, Map<String, String> properties) {
if ((root == null) || (queryContinue == null)) {
return false;
}
boolean result = false;
XPathExpression<Element> xpa = XPathFactory.instance().compile(queryContinue, Filters.element());
List<Element> results = xpa.evaluate(root);
if ((results == null) || (results.isEmpty())) {
xpa = XPathFactory.instance().compile("/api/continue", Filters.element());
results = xpa.evaluate(root);
}
if (results != null) {
for (Object currentNode : results) {
List attributes = ((Element) currentNode).getAttributes();
if (attributes != null) {
for (Object currentAttribute : attributes) {
Attribute attribute = (Attribute) currentAttribute;
properties.put(attribute.getName(), attribute.getValue());
result = true;
}
}
}
}
return result;
}
use of org.hl7.elm.r1.Element in project wpcleaner by WPCleaner.
the class ApiXmlExpandResult method executeExpandTemplates.
/**
* Execute expand templates request.
*
* @param properties Properties defining request.
* @return Expanded text.
* @throws APIException Exception thrown by the API.
*/
@Override
public String executeExpandTemplates(Map<String, String> properties) throws APIException {
try {
XPathExpression<Element> xpaText = XPathFactory.instance().compile("/api/expandtemplates/wikitext", Filters.element());
Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);
Element text = xpaText.evaluateFirst(root);
return (text != null) ? text.getText() : null;
} catch (JDOMException e) {
log.error("Error expanding templates", e);
throw new APIException("Error parsing XML", e);
}
}
use of org.hl7.elm.r1.Element in project wpcleaner by WPCleaner.
the class ApiXmlLoginResult method constructLogin.
/**
* Analyze login answer.
*
* @param root Root element in MediaWiki answer.
* @return Result of the login.
* @throws APIException Exception thrown by the API.
*/
private LoginResult constructLogin(Element root) throws APIException {
// try {
XPathExpression<Element> xpa = XPathFactory.instance().compile("/api/login", Filters.element());
Element node = xpa.evaluateFirst(root);
if (node != null) {
String result = node.getAttributeValue("result");
if ("Success".equalsIgnoreCase(result)) {
getWiki().getConnection().setLgInformation(node.getAttributeValue("lgtoken"), node.getAttributeValue("lgusername"), node.getAttributeValue("lguserid"));
return LoginResult.createCorrectLogin();
} else if (EnumLoginResult.NEED_TOKEN.getCode().equalsIgnoreCase(result)) {
return LoginResult.createNeedTokenLogin(node.getAttributeValue("token"));
}
String details = node.getAttributeValue("details");
if (details == null) {
details = node.getAttributeValue("reason");
}
return LoginResult.createErrorLogin(result, details, node.getAttributeValue("wait"));
}
// }
return LoginResult.createErrorLogin(null, null, null);
}
use of org.hl7.elm.r1.Element in project beneficiary-fhir-data by CMSgov.
the class TransformerUtils method addExtensionValueQuantity.
/**
* Adds an {@link Extension} to the specified {@link DomainResource}. {@link Extension#getValue()}
* will be set to a {@link Quantity} with the specified system and value.
*
* @param fhirElement the FHIR element to add the {@link Extension} to
* @param extensionUrl the {@link Extension#getUrl()} to use
* @param quantitySystem the {@link Quantity#getSystem()} to use
* @param quantityValue the {@link Quantity#getValue()} to use
*/
static void addExtensionValueQuantity(IBaseHasExtensions fhirElement, String extensionUrl, String quantitySystem, BigDecimal quantityValue) {
IBaseExtension<?, ?> extension = fhirElement.addExtension();
extension.setUrl(extensionUrl);
extension.setValue(new Quantity().setSystem(extensionUrl).setValue(quantityValue));
// CodeableConcept codeableConcept = new CodeableConcept();
// extension.setValue(codeableConcept);
//
// Coding coding = codeableConcept.addCoding();
// coding.setSystem(codingSystem).setCode(codingCode);
}
Aggregations