use of javax.xml.xpath.XPathExpressionException in project OpenAM by OpenRock.
the class SmsServerPropertiesResource method getOptions.
private Map<String, Set<String>> getOptions(Document propertySheet, String tabName) {
Map<String, Set<String>> radioOptions = new HashMap<>();
try {
XPath xPath = XPathFactory.newInstance().newXPath();
List<String> attributeNamesForTab = getDefaultValueNames(tabName);
for (String defaultValueName : attributeNamesForTab) {
String convertedName = getConvertedName(defaultValueName);
String expression = "//propertysheet/section/property/cc[@name='" + convertedName + "']/option/@value";
NodeList optionsList = (NodeList) xPath.compile(expression).evaluate(propertySheet, XPathConstants.NODESET);
Set<String> options = new HashSet<>();
for (int i = 0; i < optionsList.getLength(); i++) {
options.add(optionsList.item(i).getNodeValue());
}
if (!options.isEmpty()) {
radioOptions.put(defaultValueName, options);
}
}
} catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException e) {
logger.error("Error reading property sheet", e);
}
return radioOptions;
}
use of javax.xml.xpath.XPathExpressionException in project OpenAM by OpenRock.
the class SmsServerPropertiesResource method readInstance.
@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context serverContext, ReadRequest readRequest) {
Map<String, String> uriVariables = getUriTemplateVariables(serverContext);
final String tabName = getTabName(uriVariables);
if (tabName == null) {
return new BadRequestException("Tab name not specified.").asPromise();
}
final String serverName = getServerName(uriVariables);
if (serverName == null) {
return new BadRequestException("Server name not specified.").asPromise();
}
try {
ServiceConfigManager scm = getServiceConfigManager(serverContext);
ServiceConfig serverConfigs = getServerConfigs(scm);
Properties defaultAttributes = getAttributes(serverConfigs.getSubConfig(SERVER_DEFAULT_NAME));
final ServiceConfig serverConfig = serverConfigs.getSubConfig(serverName);
if (serverConfig == null) {
return new BadRequestException("Unknown Server " + serverName).asPromise();
}
Properties serverSpecificAttributes = getAttributes(serverConfig);
Map<String, String> defaultSection = new HashMap<>();
JsonValue result = json(object(field("default", defaultSection)));
List<String> attributeNamesForTab;
if (tabName.equalsIgnoreCase(DIRECTORY_CONFIGURATION_TAB_NAME)) {
InputStream resourceStream = new StringInputStream(getServerConfigXml(serverConfig));
Document serverXml = dBuilder.parse(resourceStream);
XPath xPath = XPathFactory.newInstance().newXPath();
final String baseExpression = "//iPlanetDataAccessLayer/ServerGroup[@name='sms']/";
String minConnections = (String) xPath.compile(baseExpression + "@" + DSConfigMgr.MIN_CONN_POOL).evaluate(serverXml, XPathConstants.STRING);
String maxConnections = (String) xPath.compile(baseExpression + "@" + DSConfigMgr.MAX_CONN_POOL).evaluate(serverXml, XPathConstants.STRING);
String dirDN = (String) xPath.compile(baseExpression + "User/DirDN").evaluate(serverXml, XPathConstants.STRING);
String directoryPassword = (String) xPath.compile(baseExpression + "User/DirPassword").evaluate(serverXml, XPathConstants.STRING);
result.put("minConnections", minConnections);
result.put("maxConnections", maxConnections);
result.put("dirDN", dirDN);
result.put("directoryPassword", directoryPassword);
NodeList serverNames = (NodeList) xPath.compile(baseExpression + "Server/@name").evaluate(serverXml, XPathConstants.NODESET);
for (int i = 0; i < serverNames.getLength(); i++) {
final String directoryServerName = serverNames.item(i).getNodeValue();
final String serverExpression = baseExpression + "Server[@name='" + directoryServerName + "']";
String hostExpression = serverExpression + "/@host";
String portExpression = serverExpression + "/@port";
String typeExpression = serverExpression + "/@type";
NodeList serverAttributes = (NodeList) xPath.compile(hostExpression + "|" + portExpression + "|" + typeExpression).evaluate(serverXml, XPathConstants.NODESET);
for (int a = 0; a < serverAttributes.getLength(); a++) {
final Node serverAttribute = serverAttributes.item(a);
result.addPermissive(new JsonPointer("servers/" + directoryServerName + "/" + serverAttribute.getNodeName()), serverAttribute.getNodeValue());
}
}
} else {
if (tabName.equalsIgnoreCase(ADVANCED_TAB_NAME)) {
attributeNamesForTab = getAdvancedTabAttributeNames(serverConfig);
} else {
attributeNamesForTab = getDefaultValueNames(tabName);
}
for (String attributeName : attributeNamesForTab) {
final String defaultAttribute = (String) defaultAttributes.get(attributeName);
if (defaultAttribute != null) {
defaultSection.put(attributeName, (String) defaultAttributes.get(attributeName));
}
final String serverSpecificAttribute = (String) serverSpecificAttributes.get(attributeName);
if (serverSpecificAttribute != null) {
result.add(attributeName, serverSpecificAttribute);
}
}
}
return newResultPromise(newResourceResponse(serverName + "/properties/" + tabName, String.valueOf(result.hashCode()), result));
} catch (SMSException | SSOException | ParserConfigurationException | SAXException | IOException | XPathExpressionException e) {
logger.error("Error reading property sheet for tab " + tabName, e);
}
return new BadRequestException("Error reading properties file for " + tabName).asPromise();
}
use of javax.xml.xpath.XPathExpressionException in project OpenAM by OpenRock.
the class SmsServerPropertiesResource method getOptionalAttributes.
private Set<String> getOptionalAttributes(Document propertySheet, String tabName) {
XPath xPath = XPathFactory.newInstance().newXPath();
Set<String> optionalValues = new HashSet<>();
try {
String expression = "//propertysheet/section/property[@required='false']/cc/@name";
NodeList optionalValuesList = (NodeList) xPath.compile(expression).evaluate(propertySheet, XPathConstants.NODESET);
for (int i = 0; i < optionalValuesList.getLength(); i++) {
optionalValues.add(optionalValuesList.item(i).getNodeValue());
}
} catch (XPathExpressionException e) {
logger.error("Error reading property sheet for tab " + tabName, e);
}
return optionalValues;
}
use of javax.xml.xpath.XPathExpressionException in project OpenAM by OpenRock.
the class SchemaResourceNamesStep method initialize.
@Override
public void initialize() throws UpgradeException {
if (VersionUtils.isCurrentVersionLessThan(AM_13, true)) {
Map<String, Document> serviceXmlContent = UpgradeServiceUtils.getServiceDefinitions(getAdminToken());
serviceModifications = new HashMap<>();
for (Map.Entry<String, Document> service : serviceXmlContent.entrySet()) {
try {
DEBUG.message("Finding resource names in {}", service.getKey());
ServiceModifier modifier = new ServiceModifier();
NodeList nodes = (NodeList) xpath.evaluate("//*[@" + RESOURCE_NAME + "]", service.getValue().getDocumentElement(), XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
ElementModifier target = buildPath(element, modifier);
target.resourceNameModifier = new ResourceNameModifier(element.getAttribute(RESOURCE_NAME));
}
if (!modifier.modifiers.isEmpty()) {
serviceModifications.put(service.getKey(), modifier);
}
} catch (XPathExpressionException e) {
throw new UpgradeException(e);
}
}
}
}
use of javax.xml.xpath.XPathExpressionException in project Tundra by Permafrost.
the class xpath method exists.
// ---( server methods )---
public static final void exists(IData pipeline) throws ServiceException {
// --- <<IS-START(exists)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] object:0:optional $content
// [i] field:0:optional $encoding
// [i] field:0:required $expression
// [i] record:0:optional $namespace
// [i] - field:0:optional default
// [o] field:0:required $exists?
IDataCursor cursor = pipeline.getCursor();
try {
Object content = IDataHelper.get(cursor, "$content");
Charset charset = IDataHelper.get(cursor, "$encoding", Charset.class);
String expression = IDataHelper.get(cursor, "$expression", String.class);
NamespaceContext namespace = IDataHelper.get(cursor, "$namespace", IDataNamespaceContext.class);
XPathExpression compiledExpression = XPathHelper.compile(expression, namespace);
Node node = null;
if (content instanceof Node) {
node = (Node) content;
} else if (content instanceof InputSource) {
node = DocumentHelper.parse((InputSource) content, namespace);
} else if (content != null) {
node = DocumentHelper.parse(InputStreamHelper.normalize(content, charset), charset, true, namespace);
}
IDataHelper.put(cursor, "$exists?", XPathHelper.exists(node, compiledExpression), String.class);
} catch (XPathExpressionException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
Aggregations