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);
}
}
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);
}
}
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();
}
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;
}
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);
}
}
Aggregations