use of org.dom4j.DocumentException in project cuba by cuba-platform.
the class UserSetHelper method addEntities.
public static String addEntities(String filterXml, Collection ids) {
Document document;
try {
document = DocumentHelper.parseText(filterXml);
} catch (DocumentException e) {
throw new RuntimeException(e);
}
Element param = document.getRootElement().element("and").element("c").element("param");
String currentIds = param.getTextTrim();
Set<String> set = parseSet(currentIds);
String listOfIds = createIdsString(set, ids);
param.setText(listOfIds);
return document.asXML();
}
use of org.dom4j.DocumentException in project cuba by cuba-platform.
the class AbstractViewRepository method addFile.
protected void addFile(Element commonRootElem, String fileName) {
if (readFileNames.contains(fileName))
return;
log.debug("Deploying views config: " + fileName);
readFileNames.add(fileName);
InputStream stream = null;
try {
stream = resources.getResourceAsStream(fileName);
if (stream == null) {
throw new IllegalStateException("Resource is not found: " + fileName);
}
SAXReader reader = new SAXReader();
Document doc;
try {
doc = reader.read(new InputStreamReader(stream, StandardCharsets.UTF_8));
} catch (DocumentException e) {
throw new RuntimeException("Unable to parse view file " + fileName, e);
}
Element rootElem = doc.getRootElement();
for (Element includeElem : Dom4j.elements(rootElem, "include")) {
String incFile = includeElem.attributeValue("file");
if (!StringUtils.isBlank(incFile))
addFile(commonRootElem, incFile);
}
for (Element viewElem : Dom4j.elements(rootElem, "view")) {
commonRootElem.add(viewElem.createCopy());
}
} finally {
IOUtils.closeQuietly(stream);
}
}
use of org.dom4j.DocumentException in project cuba by cuba-platform.
the class AppComponents method getDescriptorDoc.
private Document getDescriptorDoc(AppComponent component) {
String descriptorPath = component.getDescriptorPath();
InputStream descrStream = getClass().getClassLoader().getResourceAsStream(descriptorPath);
if (descrStream == null) {
throw new RuntimeException(String.format("App component descriptor was not found in '%s'", descriptorPath));
}
try {
SAXReader reader = new SAXReader();
return reader.read(new InputStreamReader(descrStream, StandardCharsets.UTF_8));
} catch (DocumentException e) {
throw new RuntimeException(String.format("Error reading app component descriptor '%s'", descriptorPath), e);
} finally {
try {
descrStream.close();
} catch (IOException ignored) {
}
}
}
use of org.dom4j.DocumentException in project cuba by cuba-platform.
the class DesktopThemeLoaderImpl method readXmlDocument.
private Document readXmlDocument(Resource resource) throws IOException {
Document doc;
InputStream stream = null;
try {
stream = resource.getInputStream();
try {
SAXReader reader = new SAXReader();
doc = reader.read(stream);
} catch (DocumentException e) {
throw new RuntimeException(e);
}
} finally {
IOUtils.closeQuietly(stream);
}
return doc;
}
use of org.dom4j.DocumentException in project cuba by cuba-platform.
the class MetadataLoader method loadDatatypesFromClasspathResource.
protected void loadDatatypesFromClasspathResource() {
SAXReader reader = new SAXReader();
URL resource = Datatypes.class.getResource(getGetDatatypesResourcePath());
if (resource != null) {
log.info("Loading datatypes from " + resource);
try {
Document document = reader.read(resource);
Element element = document.getRootElement();
List<Element> datatypeElements = Dom4j.elements(element, "datatype");
for (Element datatypeElement : datatypeElements) {
String datatypeClassName = datatypeElement.attributeValue("class");
try {
Datatype datatype;
Class<Datatype> datatypeClass = ReflectionHelper.getClass(datatypeClassName);
try {
final Constructor<Datatype> constructor = datatypeClass.getConstructor(Element.class);
datatype = constructor.newInstance(datatypeElement);
} catch (Throwable e) {
datatype = datatypeClass.newInstance();
}
String id = datatypeElement.attributeValue("id");
if (Strings.isNullOrEmpty(id))
id = guessDatatypeId(datatype);
datatypeRegistry.register(datatype, id, true);
} catch (Throwable e) {
log.error(String.format("Fail to load datatype '%s'", datatypeClassName), e);
}
}
} catch (DocumentException e) {
log.error("Fail to load datatype settings", e);
}
}
}
Aggregations