use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.
the class ThemeConstantsRepository method loadThemeProperties.
public void loadThemeProperties(String fileName, Map<String, String> themeMap) {
InputStream propertiesStream = null;
try {
propertiesStream = resources.getResourceAsStream(fileName);
if (propertiesStream == null) {
throw new DevelopmentException("Unable to load theme constants for: '" + fileName + "'");
}
InputStreamReader propertiesReader = new InputStreamReader(propertiesStream, StandardCharsets.UTF_8);
Properties properties = new Properties();
try {
properties.load(propertiesReader);
} catch (IOException e) {
throw new DevelopmentException("Unable to parse theme constants for: '" + fileName + "'");
}
Object includeValue = properties.get("@include");
if (includeValue != null) {
String[] themeIncludes = StringUtils.split(includeValue.toString(), " ,");
for (String include : themeIncludes) {
loadThemeProperties(include, themeMap);
}
}
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
if (key != null && !"@include".equals(key) && value != null) {
themeMap.put(key.toString(), value.toString());
}
}
} finally {
IOUtils.closeQuietly(propertiesStream);
}
}
use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.
the class XmlInheritanceProcessor method getResultRoot.
public Element getResultRoot() {
Element result;
Element root = document.getRootElement();
String ancestorTemplate = root.attributeValue("extends");
if (!StringUtils.isBlank(ancestorTemplate)) {
InputStream ancestorStream = resources.getResourceAsStream(ancestorTemplate);
if (ancestorStream == null) {
ancestorStream = getClass().getResourceAsStream(ancestorTemplate);
if (ancestorStream == null) {
throw new DevelopmentException("Template is not found", "Ancestor's template path", ancestorTemplate);
}
}
Document ancestorDocument;
try {
ancestorDocument = screenXmlParser.parseDescriptor(ancestorStream);
} finally {
IOUtils.closeQuietly(ancestorStream);
}
XmlInheritanceProcessor processor = new XmlInheritanceProcessor(ancestorDocument, params);
result = processor.getResultRoot();
process(result, root);
if (log.isTraceEnabled()) {
StringWriter writer = new StringWriter();
Dom4j.writeDocument(result.getDocument(), true, writer);
log.trace("Resulting template:\n" + writer.toString());
}
} else {
result = root;
}
return result;
}
use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.
the class DsContextLoader method loadProperties.
private void loadProperties(Element element, ValueDatasource datasource) {
Element propsEl = element.element("properties");
if (propsEl != null) {
for (Element propEl : Dom4j.elements(propsEl)) {
String name = propEl.attributeValue("name");
String className = propEl.attributeValue("class");
if (className != null) {
datasource.addProperty(name, ReflectionHelper.getClass(className));
} else {
String typeName = propEl.attributeValue("datatype");
Datatype datatype = typeName == null ? Datatypes.getNN(String.class) : Datatypes.get(typeName);
datasource.addProperty(name, datatype);
}
}
String idProperty = propsEl.attributeValue("idProperty");
if (idProperty != null) {
if (datasource.getMetaClass().getProperty(idProperty) == null)
throw new DevelopmentException(String.format("Property '%s' is not defined", idProperty));
datasource.setIdName(idProperty);
}
}
}
use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.
the class DsContextLoader method loadHierarchicalDatasource.
protected Datasource loadHierarchicalDatasource(Element element) {
MetaClass metaClass = loadMetaClass(element);
if (metaClass == null)
throw new DevelopmentException("'class' attribute is not set for the datasource");
initCollectionDatasourceAttributes(element, metaClass);
HierarchicalDatasource datasource = builder.setDsClass(getDatasourceClass(element)).buildHierarchicalDatasource();
String hierarchyProperty = element.attributeValue("hierarchyProperty");
if (!StringUtils.isEmpty(hierarchyProperty)) {
datasource.setHierarchyPropertyName(hierarchyProperty);
}
if (datasource instanceof CollectionDatasource.Suspendable)
((CollectionDatasource.Suspendable) datasource).setSuspended(true);
loadQuery(element, datasource);
loadDatasources(element, datasource);
return datasource;
}
use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.
the class InstanceUtils method parseNamePattern.
/**
* Parse a name pattern defined by {@link NamePattern} annotation.
* @param metaClass entity meta-class
* @return record containing the name pattern properties, or null if the @NamePattern is not defined for the meta-class
*/
@Nullable
public static NamePatternRec parseNamePattern(MetaClass metaClass) {
Map attributes = (Map) metaClass.getAnnotations().get(NamePattern.class.getName());
if (attributes == null)
return null;
String pattern = (String) attributes.get("value");
if (StringUtils.isBlank(pattern))
return null;
int pos = pattern.indexOf("|");
if (pos < 0)
throw new DevelopmentException("Invalid name pattern: " + pattern);
String format = StringUtils.substring(pattern, 0, pos);
String trimmedFormat = format.trim();
String methodName = trimmedFormat.startsWith("#") ? trimmedFormat.substring(1) : null;
String fieldsStr = StringUtils.substring(pattern, pos + 1);
String[] fields = INSTANCE_NAME_SPLIT_PATTERN.split(fieldsStr);
return new NamePatternRec(format, methodName, fields);
}
Aggregations