Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

In this page you can find the example usage for org.dom4j Element attribute.

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractComponentLoader.java

License:Apache License

protected void loadDescription(Component.HasCaption component, Element element) {
    if (element.attribute("description") != null) {
        String description = element.attributeValue("description");

        description = loadResourceString(description);
        component.setDescription(description);
    }//from ww w  .  j  a va2 s .  com
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractComponentLoader.java

License:Apache License

protected void loadIcon(Component.HasIcon component, Element element) {
    if (element.attribute("icon") != null) {
        String icon = element.attributeValue("icon");
        component.setIcon(getIconPath(icon));
    }//from ww  w  .j ava  2  s.c  o m
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.AbstractComponentLoader.java

License:Apache License

protected void loadActionConstraint(Action action, Element element) {
    if (action instanceof Action.HasSecurityConstraint) {
        Action.HasSecurityConstraint itemTrackingAction = (Action.HasSecurityConstraint) action;

        Attribute operationTypeAttribute = element.attribute("constraintOperationType");
        if (operationTypeAttribute != null) {
            ConstraintOperationType operationType = ConstraintOperationType
                    .fromId(operationTypeAttribute.getValue());
            itemTrackingAction.setConstraintOperationType(operationType);
        }//  w w  w.ja v  a2s  .  com

        String constraintCode = element.attributeValue("constraintCode");
        itemTrackingAction.setConstraintCode(constraintCode);
    }
}

From source file:com.haulmont.cuba.gui.xml.layout.loaders.DataGridLoader.java

License:Apache License

protected String loadCaption(Element element) {
    if (element.attribute("caption") != null) {
        String caption = element.attributeValue("caption");

        return loadResourceString(caption);
    }/*from w w w  .  jav a  2 s  .  c  om*/
    return null;
}

From source file:com.haulmont.cuba.security.app.UserSettingServiceBean.java

License:Apache License

@Override
public void copySettings(User fromUser, User toUser) {
    MetaClass metaClass = metadata.getClassNN(UserSetting.class);

    Security security = AppBeans.get(Security.NAME);
    if (!security.isEntityOpPermitted(metaClass, EntityOp.CREATE)) {
        throw new AccessDeniedException(PermissionType.ENTITY_OP, metaClass.getName());
    }/*ww  w . j  a v  a  2s. c o m*/

    Map<UUID, Presentation> presentationsMap = copyPresentations(fromUser, toUser);
    copyUserFolders(fromUser, toUser, presentationsMap);
    Map<UUID, FilterEntity> filtersMap = copyFilters(fromUser, toUser);

    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();

        Query deleteSettingsQuery = em.createQuery("delete from sec$UserSetting s where s.user.id = ?1");
        deleteSettingsQuery.setParameter(1, toUser);
        deleteSettingsQuery.executeUpdate();
        tx.commitRetaining();
        em = persistence.getEntityManager();

        TypedQuery<UserSetting> q = em.createQuery("select s from sec$UserSetting s where s.user.id = ?1",
                UserSetting.class);
        q.setParameter(1, fromUser);
        List<UserSetting> fromUserSettings = q.getResultList();

        for (UserSetting currSetting : fromUserSettings) {
            UserSetting newSetting = metadata.create(UserSetting.class);
            newSetting.setUser(toUser);
            newSetting.setClientType(currSetting.getClientType());
            newSetting.setName(currSetting.getName());

            try {
                Document doc = Dom4j.readDocument(currSetting.getValue());

                List<Element> components = doc.getRootElement().element("components").elements("component");
                for (Element component : components) {
                    Attribute presentationAttr = component.attribute("presentation");
                    if (presentationAttr != null) {
                        UUID presentationId = UuidProvider.fromString(presentationAttr.getValue());
                        Presentation newPresentation = presentationsMap.get(presentationId);
                        if (newPresentation != null) {
                            presentationAttr.setValue(newPresentation.getId().toString());
                        }
                    }
                    Element defaultFilterEl = component.element("defaultFilter");
                    if (defaultFilterEl != null) {
                        Attribute idAttr = defaultFilterEl.attribute("id");
                        if (idAttr != null) {
                            UUID filterId = UuidProvider.fromString(idAttr.getValue());
                            FilterEntity newFilter = filtersMap.get(filterId);
                            if (newFilter != null) {
                                idAttr.setValue(newFilter.getId().toString());
                            }
                        }
                    }
                }

                newSetting.setValue(Dom4j.writeDocument(doc, true));
            } catch (Exception e) {
                newSetting.setValue(currSetting.getValue());
            }
            em.persist(newSetting);
        }

        tx.commit();
    }
}

From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java

License:Apache License

@Override
public Report parseXml(String xml) throws IOException {
    try {/*  ww  w  .  j  a v a2 s  .c  om*/
        SAXReader reader = null;
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();

            SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

            factory.setSchema(schemaFactory.newSchema(new Source[] { new StreamSource(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream("reporting.xsd")) }));

            SAXParser parser = factory.newSAXParser();

            reader = new SAXReader(parser.getXMLReader());
        } catch (SAXException e) {
            throw new ReportingXmlException(
                    String.format("An error occurred during loading reporting xsd. \\n[%s]", xml), e);
        } catch (ParserConfigurationException e) {
            throw new ReportingXmlException(
                    String.format("An error occurred during loading reporting xsd. \\n[%s]", xml), e);
        }

        Document document = reader.read(new StringReader(xml));
        Element rootElement = document.getRootElement();
        Map<String, ReportTemplate> templateMap = parseTemplates(rootElement);
        List<ReportParameter> reportParameters = parseInputParameters(rootElement);
        List<ReportFieldFormat> reportFieldFormats = parseValueFormats(rootElement);
        BandBuilder rootBandDefinitionBuilder = new BandBuilder().name(BandData.ROOT_BAND_NAME);
        parseQueries(rootElement.element("rootBand"), rootBandDefinitionBuilder);
        parseChildBandDefinitions(rootElement.element("rootBand"), rootBandDefinitionBuilder);
        ReportBand rootBandDefinition = rootBandDefinitionBuilder.build();
        String reportName = rootElement.attribute("name").getText();
        ReportImpl report = new ReportImpl(reportName, templateMap, rootBandDefinition, reportParameters,
                reportFieldFormats);
        return report;
    } catch (DocumentException e) {
        throw new ReportingXmlException(
                String.format("An error occurred while parsing report xml. \\n[%s]", xml), e);
    } catch (FileNotFoundException e) {
        throw new ReportingXmlException(String.format("Could not find report template. \\n[%s]", xml), e);
    } catch (ClassNotFoundException e) {
        throw new ReportingXmlException(String.format("Report parameter class not found. \\n[%s]", xml), e);
    }
}

From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java

License:Apache License

protected Map<String, ReportTemplate> parseTemplates(Element rootElement) throws IOException {
    Element templatesElement = rootElement.element("templates");
    List<Element> templates = templatesElement.elements("template");
    Map<String, ReportTemplate> templateMap = new HashMap<String, ReportTemplate>();
    for (Element template : templates) {
        String code = template.attribute("code").getText();
        String documentName = template.attribute("documentName").getText();
        String documentPath = template.attribute("documentPath").getText();
        String outputType = template.attribute("outputType").getText();
        String outputNamePattern = template.attribute("outputNamePattern").getText();

        ReportTemplate reportTemplate = new ReportTemplateBuilder().code(code).documentName(documentName)
                .documentPath(documentPath).documentContent(getDocumentContent(documentPath))
                .outputType(ReportOutputType.getOutputTypeById(outputType)).outputNamePattern(outputNamePattern)
                .build();/*from  w  w w .j  av a 2 s  . c  o m*/

        templateMap.put(reportTemplate.getCode(), reportTemplate);
    }

    return templateMap;
}

From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java

License:Apache License

protected List<ReportParameter> parseInputParameters(Element rootElement)
        throws FileNotFoundException, ClassNotFoundException {
    List<ReportParameter> reportParameters = new ArrayList<ReportParameter>();

    Element inputParametersElement = rootElement.element("parameters");
    if (inputParametersElement != null) {
        List<Element> parameters = inputParametersElement.elements("parameter");
        for (Element parameter : parameters) {
            String name = parameter.attribute("name").getText();
            String alias = parameter.attribute("alias").getText();
            Boolean required = Boolean.valueOf(parameter.attribute("required").getText());
            Class type = Class.forName(parameter.attribute("class").getText());
            Attribute defaultValueAttr = parameter.attribute("defaultValue");
            String defaultValue = null;
            if (defaultValueAttr != null) {
                defaultValue = defaultValueAttr.getText();
            }/*from   w w w  .  j a v a  2  s .co m*/

            ReportParameterImpl reportParameter = new ReportParameterImpl(name, alias, required, type,
                    defaultValue);
            reportParameters.add(reportParameter);
        }
    }

    return reportParameters;
}

From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java

License:Apache License

protected List<ReportFieldFormat> parseValueFormats(Element rootElement)
        throws FileNotFoundException, ClassNotFoundException {
    List<ReportFieldFormat> reportParameters = new ArrayList<ReportFieldFormat>();
    Element formatsElement = rootElement.element("formats");

    if (formatsElement != null) {
        List<Element> parameters = formatsElement.elements("format");
        for (Element parameter : parameters) {
            String name = parameter.attribute("name").getText();
            String format = parameter.attribute("format").getText();
            reportParameters.add(new ReportFieldFormatImpl(name, format));
        }//from w ww.ja  v a2 s  . c  om
    }

    return reportParameters;
}

From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java

License:Apache License

protected void parseChildBandDefinitions(Element bandDefinitionElement, BandBuilder parentBandDefinitionBuilder)
        throws FileNotFoundException, ClassNotFoundException {
    Element childrenBandsElement = bandDefinitionElement.element("bands");
    if (childrenBandsElement != null) {
        List<Element> childrenBands = childrenBandsElement.elements("band");
        for (Element childBandElement : childrenBands) {
            String childBandName = childBandElement.attribute("name").getText();
            BandOrientation orientation = BandOrientation
                    .fromId(childBandElement.attribute("orientation").getText());
            BandBuilder childBandDefinitionBuilder = new BandBuilder().name(childBandName)
                    .orientation(orientation);

            parseQueries(childBandElement, childBandDefinitionBuilder);
            parseChildBandDefinitions(childBandElement, childBandDefinitionBuilder);
            ReportBand childBandDefinition = childBandDefinitionBuilder.build();
            parentBandDefinitionBuilder.child(childBandDefinition);
        }//from   w  w  w  .j  a  v  a  2 s  . c  o  m
    }
}