Search in sources :

Example 76 with SAXException

use of org.xml.sax.SAXException in project OpenAM by OpenRock.

the class AMViewConfig method parseDocument.

private Document parseDocument(String fileName) {
    Document document = null;
    InputStream is = getClass().getClassLoader().getResourceAsStream(fileName);
    try {
        DocumentBuilder documentBuilder = XMLUtils.getSafeDocumentBuilder(false);
        document = documentBuilder.parse(is);
    } catch (UnsupportedEncodingException e) {
        AMModelBase.debug.error("AMViewConfig.parseDocument", e);
    } catch (ParserConfigurationException e) {
        AMModelBase.debug.error("AMViewConfig.parseDocument", e);
    } catch (SAXException e) {
        AMModelBase.debug.error("AMViewConfig.parseDocument", e);
    } catch (IOException e) {
        AMModelBase.debug.error("AMViewConfig.parseDocument", e);
    }
    return document;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 77 with SAXException

use of org.xml.sax.SAXException in project OpenAM by OpenRock.

the class SmsJsonConverter method getHiddenAttributeNames.

protected List<String> getHiddenAttributeNames() {
    ArrayList<String> hiddenAttributeNames = null;
    try {
        InputStream resource = getClass().getClassLoader().getResourceAsStream("amConsoleConfig.xml");
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(resource);
        NodeList nodes = (NodeList) XPathFactory.newInstance().newXPath().evaluate("//consoleconfig/servicesconfig/consoleservice/@realmEnableHideAttrName", doc, XPathConstants.NODESET);
        String rawList = nodes.item(0).getNodeValue();
        hiddenAttributeNames = new ArrayList<String>(Arrays.asList(rawList.split(" ")));
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return hiddenAttributeNames;
}
Also used : InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 78 with SAXException

use of org.xml.sax.SAXException in project OpenAM by OpenRock.

the class SmsServerPropertiesResource method getSchema.

private JsonValue getSchema(Properties syntaxProperties, Properties titleProperties, boolean isDefault) {
    JsonValue template = json(object());
    for (String tabName : getTabNames()) {
        try {
            Document propertySheet = getPropertySheet(tabName);
            Map<String, Set<String>> options = getOptions(propertySheet, tabName);
            List<String> sectionNames = getSectionNames(propertySheet);
            Set<String> optionalAttributes = getOptionalAttributes(propertySheet, tabName);
            int sectionOrder = 0;
            for (String sectionName : sectionNames) {
                final String sectionPath = "/properties/" + tabName + "/" + sectionName;
                template.putPermissive(new JsonPointer(sectionPath + "/title"), titleProperties.getProperty(sectionName));
                template.putPermissive(new JsonPointer(sectionPath + "/propertyOrder"), sectionOrder++);
                int attributeOrder = 0;
                for (String attributeName : getAttributeNamesForSection(sectionName, propertySheet)) {
                    final String title = titleProperties.getProperty(attributeName);
                    String property = syntaxProperties.getProperty(attributeName);
                    if (property == null) {
                        property = "";
                    }
                    final String type = syntaxRawToReal.get(property);
                    final Set<String> attributeOptions = getAttributeOptions(options, attributeName, type);
                    final boolean isOptional;
                    if (isDefault) {
                        isOptional = optionalAttributes.contains(attributeName);
                    } else {
                        isOptional = true;
                    }
                    final String path = sectionPath + "/" + attributeName;
                    if (attributeOptions != null && !attributeOptions.isEmpty()) {
                        template.putPermissive(new JsonPointer(path + "/type/enum"), attributeOptions);
                    } else {
                        template.putPermissive(new JsonPointer(path + "/type"), type);
                    }
                    template.putPermissive(new JsonPointer(path + "/title"), title);
                    template.putPermissive(new JsonPointer(path + "/propertyOrder"), attributeOrder++);
                    template.putPermissive(new JsonPointer(path + "/required"), !isOptional);
                    template.putPermissive(new JsonPointer(path + "/pattern"), ".+");
                    allAttributeNamesInNamedTabs.add(attributeName);
                }
            }
        } catch (ParserConfigurationException | IOException | XPathExpressionException | SAXException e) {
            logger.error("Error reading property sheet for tab " + tabName, e);
        }
    }
    return template;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) XPathExpressionException(javax.xml.xpath.XPathExpressionException) JsonValue(org.forgerock.json.JsonValue) JsonPointer(org.forgerock.json.JsonPointer) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 79 with SAXException

use of org.xml.sax.SAXException 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;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) JsonValue(org.forgerock.json.JsonValue) ArrayList(java.util.ArrayList) JsonPointer(org.forgerock.json.JsonPointer) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 80 with SAXException

use of org.xml.sax.SAXException 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;
}
Also used : XPath(javax.xml.xpath.XPath) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet)

Aggregations

SAXException (org.xml.sax.SAXException)2465 IOException (java.io.IOException)1622 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1049 Document (org.w3c.dom.Document)682 DocumentBuilder (javax.xml.parsers.DocumentBuilder)537 InputSource (org.xml.sax.InputSource)518 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)415 InputStream (java.io.InputStream)317 Element (org.w3c.dom.Element)311 NodeList (org.w3c.dom.NodeList)292 File (java.io.File)274 Node (org.w3c.dom.Node)247 ByteArrayInputStream (java.io.ByteArrayInputStream)235 StringReader (java.io.StringReader)224 SAXParser (javax.xml.parsers.SAXParser)209 SAXParseException (org.xml.sax.SAXParseException)196 TransformerException (javax.xml.transform.TransformerException)180 ArrayList (java.util.ArrayList)169 SAXParserFactory (javax.xml.parsers.SAXParserFactory)159 XMLReader (org.xml.sax.XMLReader)151