Search in sources :

Example 1 with DevelopmentException

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 2 with DevelopmentException

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;
}
Also used : StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 3 with DevelopmentException

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);
        }
    }
}
Also used : Element(org.dom4j.Element) Datatype(com.haulmont.chile.core.datatypes.Datatype) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 4 with DevelopmentException

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;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 5 with DevelopmentException

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);
}
Also used : Map(java.util.Map) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException) Nullable(javax.annotation.Nullable)

Aggregations

DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)16 MetaClass (com.haulmont.chile.core.model.MetaClass)4 Element (org.dom4j.Element)3 InputStream (java.io.InputStream)2 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 View (com.haulmont.cuba.core.global.View)1 ViewProperty (com.haulmont.cuba.core.global.ViewProperty)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 Component (com.haulmont.cuba.gui.components.Component)1 Window (com.haulmont.cuba.gui.components.Window)1 AppWorkArea (com.haulmont.cuba.gui.components.mainwindow.AppWorkArea)1 FoldersPane (com.haulmont.cuba.gui.components.mainwindow.FoldersPane)1 TopLevelWindowAttachListener (com.haulmont.cuba.gui.components.mainwindow.TopLevelWindowAttachListener)1 UserIndicator (com.haulmont.cuba.gui.components.mainwindow.UserIndicator)1 WebWindow (com.haulmont.cuba.web.gui.WebWindow)1 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)1 PresentationEditor (com.haulmont.cuba.web.gui.components.presentations.PresentationEditor)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1