use of javax.xml.parsers.ParserConfigurationException in project OpenAM by OpenRock.
the class SmsServerPropertiesResource method getDirectorySchema.
private JsonValue getDirectorySchema(Properties titleProperties, Debug logger) {
try {
JsonValue directoryConfigSchema = json(object());
dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
dBuilder = dbFactory.newDocumentBuilder();
Document document = dBuilder.parse(getClass().getResourceAsStream(DIRECTORY_CONFIG_XML));
XPath xPath = XPathFactory.newInstance().newXPath();
final String sectionExpression = "//propertysheet/section/@defaultValue";
String sectionRawValue = (String) xPath.compile(sectionExpression).evaluate(document, XPathConstants.STRING);
String sectionTitle = titleProperties.getProperty(sectionRawValue);
final String baseExpression = "//propertysheet/section/property/label/@defaultValue";
NodeList attributes = (NodeList) xPath.compile(baseExpression).evaluate(document, XPathConstants.NODESET);
final String path = "/_schema/properties/directoryConfiguration/" + sectionRawValue;
directoryConfigSchema.putPermissive(new JsonPointer(path + "/title"), sectionTitle);
for (int i = 0; i < attributes.getLength(); i++) {
String attributeRawName = attributes.item(i).getNodeValue();
String attributePath = path + "/" + attributeRawName;
directoryConfigSchema.putPermissive(new JsonPointer(attributePath + "/title"), titleProperties.getProperty(attributeRawName));
directoryConfigSchema.putPermissive(new JsonPointer(attributePath + "/propertyOrder"), i);
directoryConfigSchema.putPermissive(new JsonPointer(attributePath + "/type"), "string");
}
final String serverPath = path + "/servers";
directoryConfigSchema.putPermissive(new JsonPointer(serverPath + "/title"), titleProperties.get("amconfig.serverconfig.xml.server.table.header"));
directoryConfigSchema.putPermissive(new JsonPointer(serverPath + "/type"), "array");
directoryConfigSchema.putPermissive(new JsonPointer(serverPath + "/items/type"), "object");
List<String> columnNames = new ArrayList<>();
columnNames.add("name");
columnNames.add("host");
columnNames.add("port");
columnNames.add("type");
for (String columnName : columnNames) {
final String attributePath = serverPath + "/items/properties/" + SERVER_TABLE_PROPERTY_PREFIX + columnName;
directoryConfigSchema.putPermissive(new JsonPointer(attributePath + "/title"), titleProperties.getProperty(SERVER_TABLE_PROPERTY_PREFIX + columnName));
directoryConfigSchema.putPermissive(new JsonPointer(attributePath + "/type"), "string");
directoryConfigSchema.putPermissive(new JsonPointer(attributePath + "/propertyOrder"), columnNames.indexOf(columnName));
}
return directoryConfigSchema;
} catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException e) {
logger.error("Error creating document builder", e);
}
return null;
}
use of javax.xml.parsers.ParserConfigurationException 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.parsers.ParserConfigurationException 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.parsers.ParserConfigurationException in project tdi-studio-se by Talend.
the class CpuProfiler method refreshBciProfileCache.
/*
* @see ICpuProfiler#refreshBciProfileCache(IProgressMonitor)
*/
@Override
public void refreshBciProfileCache(IProgressMonitor monitor) throws JvmCoreException {
if (type != ProfilerType.BCI) {
return;
}
validateAgent();
if (!isBciProfilerRunning()) {
return;
}
String dumpString = (String) invokeCpuProfilerMXBeanMethod(DUMP, null, null);
if (dumpString == null) {
return;
}
ByteArrayInputStream input = null;
try {
input = new ByteArrayInputStream(dumpString.getBytes());
CpuDumpParser parser = new CpuDumpParser(input, cpuModel, monitor);
parser.parse();
} catch (ParserConfigurationException e) {
throw new JvmCoreException(IStatus.ERROR, Messages.parseCpuDumpFailedMsg, e);
} catch (SAXException e) {
throw new JvmCoreException(IStatus.ERROR, Messages.parseCpuDumpFailedMsg, e);
} catch (IOException e) {
throw new JvmCoreException(IStatus.ERROR, Messages.parseCpuDumpFailedMsg, e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
// do nothing
}
}
}
}
use of javax.xml.parsers.ParserConfigurationException in project tdi-studio-se by Talend.
the class ThreadDumpEditor method parseDumpFile.
/**
* Parses the dump file.
*
* @param filePath The file path
*/
private void parseDumpFile(final String filePath) {
Job job = new Job(Messages.parseThreadDumpFileJobLabel) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final ThreadDumpParser parser = new ThreadDumpParser(new File(filePath), threadListElements, monitor);
try {
parser.parse();
} catch (ParserConfigurationException e) {
//$NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load thread dump file.", e);
} catch (SAXException e) {
//$NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load thread dump file.", e);
} catch (IOException e) {
//$NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not load thread dump file.", e);
}
setProfileInfo(parser.getProfileInfo());
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (threadSashForm != null) {
threadSashForm.refresh();
}
}
});
return Status.OK_STATUS;
}
};
job.schedule();
}
Aggregations