Search in sources :

Example 86 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project android by JetBrains.

the class AndroidThemePreviewPanel method rebuild.

/**
   * Rebuild the preview
   * @param forceRepaint if true, a component repaint will be issued
   */
private void rebuild(boolean forceRepaint) {
    try {
        Configuration configuration = myContext.getConfiguration();
        int minApiLevel = configuration.getTarget() != null ? configuration.getTarget().getVersion().getApiLevel() : Integer.MAX_VALUE;
        ThemePreviewBuilder builder = new ThemePreviewBuilder().setBackgroundColor(getBackground()).addAllComponents(ThemePreviewBuilder.AVAILABLE_BASE_COMPONENTS).addNavigationBar(configuration.supports(Features.THEME_PREVIEW_NAVIGATION_BAR)).addAllComponents(myCustomComponents).addComponentFilter(new ThemePreviewBuilder.SearchFilter(mySearchTerm)).addComponentFilter(new ThemePreviewBuilder.ApiLevelFilter(minApiLevel)).addComponentFilter(myGroupFilter);
        myIsAppCompatTheme = ThemeEditorUtils.isSelectedAppCompatTheme(myContext);
        if (myIsAppCompatTheme) {
            builder.addComponentFilter(mySupportReplacementsFilter).addAllComponents(mySupportLibraryComponents);
        // sometimes we come here when the mySupportLibraryComponents and the mySupportReplacementsFilter are not ready yet
        // that is not too bad, as when they are ready, we will call reload again, and then the components list will be correct.
        }
        myAndroidPreviewPanel.setDocument(builder.build());
        if (forceRepaint) {
            repaint();
        }
    } catch (ParserConfigurationException e) {
        LOG.error("Unable to generate dynamic theme preview", e);
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 87 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project android by JetBrains.

the class Template method processXml.

private void processXml(@NotNull final RenderingContext context, @NotNull String xml) throws TemplateProcessingException {
    try {
        xml = XmlUtils.stripBom(xml);
        InputSource inputSource = new InputSource(new StringReader(xml));
        SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new DefaultHandler() {

            @Override
            public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
                try {
                    Map<String, Object> paramMap = context.getParamMap();
                    if (TAG_PARAMETER.equals(name)) {
                        String id = attributes.getValue(ATTR_ID);
                        if (!paramMap.containsKey(id)) {
                            String value = attributes.getValue(ATTR_DEFAULT);
                            Object mapValue = value;
                            if (value != null && !value.isEmpty()) {
                                String type = attributes.getValue(ATTR_TYPE);
                                if ("boolean".equals(type)) {
                                    mapValue = Boolean.valueOf(value);
                                }
                            }
                            paramMap.put(id, mapValue);
                        }
                    } else if (TAG_GLOBAL.equals(name)) {
                        String id = attributes.getValue(ATTR_ID);
                        if (!paramMap.containsKey(id)) {
                            paramMap.put(id, TypedVariable.parseGlobal(attributes));
                        }
                    } else if (TAG_GLOBALS.equals(name)) {
                        // Handle evaluation of variables
                        File globalsFile = getPath(attributes, ATTR_FILE);
                        if (globalsFile != null) {
                            processFile(context, globalsFile);
                        }
                    // else: <globals> root element
                    } else if (TAG_EXECUTE.equals(name)) {
                        File recipeFile = getPath(attributes, ATTR_FILE);
                        if (recipeFile != null) {
                            executeRecipeFile(context, recipeFile);
                        }
                    } else if (!name.equals("template") && !name.equals("category") && !name.equals("option") && !name.equals(TAG_THUMBS) && !name.equals(TAG_THUMB) && !name.equals(TAG_ICONS) && !name.equals(TAG_DEPENDENCY) && !name.equals(TAG_FORMFACTOR)) {
                        LOG.error("WARNING: Unknown template directive " + name);
                    }
                } catch (TemplateProcessingException e) {
                    throw new SAXException(e);
                }
            }
        });
    } catch (SAXException ex) {
        if (ex.getCause() instanceof TemplateProcessingException) {
            throw (TemplateProcessingException) ex.getCause();
        }
        throw new TemplateProcessingException(ex);
    } catch (ParserConfigurationException ex) {
        throw new TemplateProcessingException(ex);
    } catch (IOException ex) {
        throw new TemplateProcessingException(ex);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Attributes(org.xml.sax.Attributes) IOException(java.io.IOException) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) StringReader(java.io.StringReader) TemplateProcessingException(com.android.tools.idea.templates.FreemarkerUtils.TemplateProcessingException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Map(java.util.Map) File(java.io.File)

Example 88 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project aries by apache.

the class AbstractModelBuilder method parse.

private BeansModel parse(List<URL> osgiBeansDescriptorURLs, List<URL> beanDescriptorURLs) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(true);
    if (osgiBeansDescriptorURLs.isEmpty()) {
        throw new IllegalArgumentException("Missing osgi-beans descriptors");
    }
    SAXParser parser;
    try {
        parser = factory.newSAXParser();
    } catch (ParserConfigurationException | SAXException e) {
        return Throw.exception(e);
    }
    OSGiBeansHandler handler = getHandler(beanDescriptorURLs);
    for (URL osgiBeansDescriptorURL : osgiBeansDescriptorURLs) {
        try (InputStream inputStream = osgiBeansDescriptorURL.openStream()) {
            InputSource source = new InputSource(inputStream);
            if (source.getByteStream().available() == 0) {
                throw new IllegalArgumentException("Specified osgi-beans descriptor is empty: " + osgiBeansDescriptorURL);
            }
            try {
                parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
                parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", loadXsds());
            } catch (IllegalArgumentException | SAXNotRecognizedException | SAXNotSupportedException e) {
            // No op, we just don't validate the XML
            }
            parser.parse(source, handler);
        } catch (IOException | SAXException e) {
            return Throw.exception(e);
        }
    }
    return handler.createBeansModel();
}
Also used : InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) IOException(java.io.IOException) URL(java.net.URL) SAXException(org.xml.sax.SAXException) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 89 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project adempiere by adempiere.

the class OFXBankStatementHandler method init.

/**
	 * 	Initialize the loader
	 * 	 * @param controller Reference to the BankStatementLoaderController
	@return Initialized succesfully
	 */
protected boolean init(MBankStatementLoader controller) {
    boolean result = false;
    if (controller == null) {
        m_errorMessage = "ErrorInitializingParser";
        m_errorDescription = "ImportController is a null reference";
        return result;
    }
    this.m_controller = controller;
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        m_parser = factory.newSAXParser();
        result = true;
    } catch (ParserConfigurationException e) {
        m_errorMessage = "ErrorInitializingParser";
        m_errorDescription = "Unable to configure SAX parser: " + e.getMessage();
    } catch (SAXException e) {
        m_errorMessage = "ErrorInitializingParser";
        m_errorDescription = "Unable to initialize SAX parser: " + e.getMessage();
    }
    return result;
}
Also used : ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 90 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project adempiere by adempiere.

the class MigrationFromXML method loadXML.

/**
	 * Load the XML migration file or files.  
	 */
@SuppressWarnings("unchecked")
private void loadXML() {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setIgnoringElementContentWhitespace(true);
    // file can be a file or directory
    File file = new File(getFileName());
    try {
        builder = dbf.newDocumentBuilder();
        List<File> migrationFiles = new ArrayList<File>();
        if (!file.exists()) {
            log.log(Level.WARNING, "No file or directory found");
            return;
        } else if (// file exists
        file.isDirectory()) {
            log.log(Level.CONFIG, "Processing migration files in directory: " + file.getAbsolutePath());
            // Recursively find files
            migrationFiles = (List<File>) FileUtils.listFiles(file, new String[] { "xml" }, true);
            Collections.sort(migrationFiles, fileComparator);
        } else {
            log.log(Level.CONFIG, "Processing migration file: " + file.getAbsolutePath());
            migrationFiles.add(file);
        }
        success = true;
        for (File migFile : migrationFiles) {
            loadFile(migFile);
            if (!success)
                break;
        }
    } catch (ParserConfigurationException | SAXException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (AdempiereException e) {
        if (!isForce())
            throw new AdempiereException("Loading Migration from XML failed.", e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) AdempiereException(org.adempiere.exceptions.AdempiereException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) File(java.io.File) SAXException(org.xml.sax.SAXException)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1353 SAXException (org.xml.sax.SAXException)975 IOException (java.io.IOException)891 Document (org.w3c.dom.Document)710 DocumentBuilder (javax.xml.parsers.DocumentBuilder)631 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)569 Element (org.w3c.dom.Element)372 InputSource (org.xml.sax.InputSource)246 NodeList (org.w3c.dom.NodeList)226 Node (org.w3c.dom.Node)210 SAXParser (javax.xml.parsers.SAXParser)175 TransformerException (javax.xml.transform.TransformerException)163 File (java.io.File)162 InputStream (java.io.InputStream)158 SAXParserFactory (javax.xml.parsers.SAXParserFactory)137 ByteArrayInputStream (java.io.ByteArrayInputStream)129 StringReader (java.io.StringReader)117 ArrayList (java.util.ArrayList)115 DOMSource (javax.xml.transform.dom.DOMSource)109 StreamResult (javax.xml.transform.stream.StreamResult)93