Search in sources :

Example 6 with DocumentException

use of org.dom4j.DocumentException in project Openfire by igniterealtime.

the class KrakenPlugin method getOptionsConfig.

/**
     * Returns the web options config for the given transport, if it exists.
     *
     * @param type type of the transport we want the options config for.
     * @return XML document with the options config.
     */
public Document getOptionsConfig(TransportType type) {
    // Load any custom-defined servlets.
    File optConf = new File(this.pluginDirectory, "web" + File.separator + "WEB-INF" + File.separator + "options" + File.separator + type.toString() + ".xml");
    Document optConfXML;
    try {
        FileReader reader = new FileReader(optConf);
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        optConfXML = xmlReader.read(reader);
    } catch (FileNotFoundException e) {
        // Non-existent: Return empty config
        optConfXML = DocumentHelper.createDocument();
        optConfXML.addElement("optionsconfig");
    } catch (DocumentException e) {
        // Bad config: Return empty config
        optConfXML = DocumentHelper.createDocument();
        optConfXML.addElement("optionsconfig");
    }
    return optConfXML;
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) Document(org.dom4j.Document) File(java.io.File)

Example 7 with DocumentException

use of org.dom4j.DocumentException in project hibernate-orm by hibernate.

the class EntitiesConfigurator method configure.

public EntitiesConfigurations configure(MetadataImplementor metadata, ServiceRegistry serviceRegistry, ReflectionManager reflectionManager, MappingCollector mappingCollector, GlobalConfiguration globalConfiguration, AuditEntitiesConfiguration auditEntitiesConfiguration, AuditStrategy auditStrategy, Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
    // Creating a name register to capture all audit entity names created.
    final AuditEntityNameRegister auditEntityNameRegister = new AuditEntityNameRegister();
    // Sorting the persistent class topologically - superclass always beforeQuery subclass
    final Iterator<PersistentClass> classes = GraphTopologicalSort.sort(new PersistentClassGraphDefiner(metadata)).iterator();
    final ClassesAuditingData classesAuditingData = new ClassesAuditingData();
    final Map<PersistentClass, EntityXmlMappingData> xmlMappings = new HashMap<>();
    // Reading metadata from annotations
    while (classes.hasNext()) {
        final PersistentClass pc = classes.next();
        // Ensure we're in POJO, not dynamic model, mapping.
        if (pc.getClassName() != null) {
            // Collecting information from annotations on the persistent class pc
            final AnnotationsMetadataReader annotationsMetadataReader = new AnnotationsMetadataReader(globalConfiguration, reflectionManager, pc);
            final ClassAuditingData auditData = annotationsMetadataReader.getAuditData();
            classesAuditingData.addClassAuditingData(pc, auditData);
        }
    }
    // Now that all information is read we can update the calculated fields.
    classesAuditingData.updateCalculatedFields();
    final AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator(metadata, serviceRegistry, globalConfiguration, auditEntitiesConfiguration, auditStrategy, revisionInfoRelationMapping, auditEntityNameRegister);
    // First pass
    for (Map.Entry<PersistentClass, ClassAuditingData> pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
        final PersistentClass pc = pcDatasEntry.getKey();
        final ClassAuditingData auditData = pcDatasEntry.getValue();
        final EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
        if (auditData.isAudited()) {
            if (!StringTools.isEmpty(auditData.getAuditTable().value())) {
                auditEntitiesConfiguration.addCustomAuditTableName(pc.getEntityName(), auditData.getAuditTable().value());
            }
            auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, true);
        } else {
            auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, false);
        }
        xmlMappings.put(pc, xmlMappingData);
    }
    // Second pass
    for (Map.Entry<PersistentClass, ClassAuditingData> pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
        final EntityXmlMappingData xmlMappingData = xmlMappings.get(pcDatasEntry.getKey());
        if (pcDatasEntry.getValue().isAudited()) {
            auditMetaGen.generateSecondPass(pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData);
            try {
                mappingCollector.addDocument(xmlMappingData.getMainXmlMapping());
                for (Document additionalMapping : xmlMappingData.getAdditionalXmlMappings()) {
                    mappingCollector.addDocument(additionalMapping);
                }
            } catch (DocumentException e) {
                throw new MappingException(e);
            }
        }
    }
    // Only if there are any versioned classes
    if (auditMetaGen.getEntitiesConfigurations().size() > 0) {
        try {
            if (revisionInfoXmlMapping != null) {
                mappingCollector.addDocument(revisionInfoXmlMapping);
            }
        } catch (DocumentException e) {
            throw new MappingException(e);
        }
    }
    return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations(), auditMetaGen.getNotAuditedEntitiesConfigurations());
}
Also used : AuditMetadataGenerator(org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator) HashMap(java.util.HashMap) EntityXmlMappingData(org.hibernate.envers.configuration.internal.metadata.EntityXmlMappingData) Document(org.dom4j.Document) AuditEntityNameRegister(org.hibernate.envers.configuration.internal.metadata.AuditEntityNameRegister) MappingException(org.hibernate.MappingException) AnnotationsMetadataReader(org.hibernate.envers.configuration.internal.metadata.reader.AnnotationsMetadataReader) ClassAuditingData(org.hibernate.envers.configuration.internal.metadata.reader.ClassAuditingData) DocumentException(org.dom4j.DocumentException) HashMap(java.util.HashMap) Map(java.util.Map) PersistentClass(org.hibernate.mapping.PersistentClass) EntitiesConfigurations(org.hibernate.envers.internal.entities.EntitiesConfigurations)

Example 8 with DocumentException

use of org.dom4j.DocumentException in project tdi-studio-se by Talend.

the class AlfrescoOutputModelManager method addModel.

/**
     * Adds an Alfresco model definition file.
     * 
     * @param newModelFilePath
     * @throws AlfrescoOutputException if already added or error reading it
     */
public void addModel(String newModelFilePath) throws AlfrescoOutputException {
    if (this.availableModels.contains(newModelFilePath)) {
        //$NON-NLS-1$
        throw new AlfrescoOutputException(Messages.getString("AlfrescoOutputModelManager.alreadyAdded"));
    }
    this.availableModels.add(newModelFilePath);
    // parsing the model
    org.dom4j.Document modelDoc = null;
    try {
        modelDoc = new SAXReader().read(new File(newModelFilePath));
    } catch (DocumentException dex) {
        throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("AlfrescoOutputModelManager.errorReadingModel") + " " + newModelFilePath, dex);
    }
    Element modelElt = modelDoc.getRootElement();
    //$NON-NLS-1$
    Element namespacesElt = modelElt.element("namespaces");
    if (namespacesElt != null) {
        //$NON-NLS-1$
        List<Element> namespaces = (List<Element>) namespacesElt.elements("namespace");
        HashMap<String, String> availablePrefixToNamespaceMapTmp = new HashMap<String, String>(3);
        for (Element namespace : namespaces) {
            //$NON-NLS-1$
            String namespacePrefix = namespace.attributeValue("prefix");
            if (this.availablePrefixToNamespaceMap.containsKey(namespacePrefix)) {
                throw new AlfrescoOutputException(//$NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("AlfrescoOutputModelManager.prefixConflict") + " " + namespacePrefix + " " + //$NON-NLS-1$
                this.availablePrefixToNamespaceMap.get(namespacePrefix));
            }
            //$NON-NLS-1$
            String namespaceUri = namespace.attributeValue("uri");
            availablePrefixToNamespaceMapTmp.put(namespacePrefix, namespaceUri);
        }
        this.availablePrefixToNamespaceMap.putAll(availablePrefixToNamespaceMapTmp);
    }
    //$NON-NLS-1$
    Element typesElt = modelElt.element("types");
    if (typesElt != null) {
        //$NON-NLS-1$
        List<Element> types = (List<Element>) typesElt.elements("type");
        this.availableTypes.addAllAlfrescoModelElement(types);
    }
    //$NON-NLS-1$
    Element aspectsElt = modelElt.element("aspects");
    if (aspectsElt != null) {
        //$NON-NLS-1$
        List<Element> aspects = (List<Element>) aspectsElt.elements("aspect");
        this.availableAspects.addAllAlfrescoModelElement(aspects);
    }
}
Also used : HashMap(java.util.HashMap) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List) AlfrescoOutputException(org.talend.designer.alfrescooutput.util.AlfrescoOutputException) File(java.io.File)

Example 9 with DocumentException

use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.

the class XMLChartConfig method load.

/**
     * Loads chart settings from the specified XML file.
     *
     * @throws IOException
     *             if there was an error reading the file
     * @throws DocumentException
     *             if there was an error parsing the file
     * @throws XmlParseException
     * @throws IllegalArgumentException
     *             if any attribute has invalid value
     */
public static List<ChartSettings> load(File xmlFile) throws IOException, DocumentException, XmlParseException {
    List<ChartSettings> charts = new ArrayList<ChartSettings>();
    Document document;
    try (FileInputStream fis = new FileInputStream(xmlFile)) {
        document = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(fis);
    }
    Element chartsElem = document.getRootElement();
    if (!chartsElem.getName().equals(E_CHARTS)) {
        throw new DocumentException("Missing <" + E_CHARTS + "> root element");
    }
    for (Iterator iter = chartsElem.elementIterator(E_CHART); iter.hasNext(); ) {
        Element chartElem = (Element) iter.next();
        String chartTitle = getAttr(chartElem, A_CHART_TITLE);
        String category = getAttr(chartElem, A_CHART_CATEGORY, "unknown");
        String outfile = getAttr(chartElem, A_CHART_OUTFILE);
        // inheritable attributes
        String xAxis = getInheritedAttr(chartElem, A_CHART_XAXIS, ChartSettings.DEFAULT_CHART_XAXIS);
        String yAxis = getInheritedAttr(chartElem, A_CHART_YAXIS, "");
        boolean allowLogScale = getInheritedAttrBoolean(chartElem, A_CHART_ALLOW_LOG_SCALE, ChartSettings.DEFAULT_CHART_ALLOW_LOG_SCALE);
        boolean plotZero = getInheritedAttrBoolean(chartElem, A_CHART_PLOT_ZERO, ChartSettings.DEFAULT_CHART_PLOT_ZERO);
        if (!allowLogScale)
            plotZero = true;
        int width = getInheritedAttrInt(chartElem, A_CHART_WIDTH, ChartSettings.DEFAULT_CHART_WIDTH);
        int height = getInheritedAttrInt(chartElem, A_CHART_HEIGHT, ChartSettings.DEFAULT_CHART_HEIGHT);
        String outDoc = getAttr(chartElem, A_CHART_DOCUMENT, null);
        String topPlotStr = getAttr(chartElem, A_CHART_TOP_PLOTS, null);
        int topPlots = -1;
        if (topPlotStr != null)
            topPlots = Integer.parseInt(topPlotStr);
        topPlotStr = getAttr(chartElem, A_CHART_TOP_PLOTS_TYPE, "max");
        ChartSettings.TopPlotsType topPlotsType = ChartSettings.TopPlotsType.valueOf(topPlotStr.toUpperCase());
        ChartSettings chart = new ChartSettings(chartTitle, category, outfile, xAxis, yAxis, allowLogScale, plotZero, width, height, outDoc, topPlots, topPlotsType);
        for (Iterator plotIter = chartElem.elementIterator(E_PLOT); plotIter.hasNext(); ) {
            Element plotElem = (Element) plotIter.next();
            String dataCol = getAttr(plotElem, A_PLOT_DATA_COLUMN, null);
            // inheritable attributes
            String legend = getInheritedAttr(plotElem, A_PLOT_LEGEND, null);
            String infile = getInheritedAttr(plotElem, A_PLOT_INFILE, null);
            boolean showRaw = getInheritedAttrBoolean(plotElem, A_PLOT_SHOW_RAW, PlotSettings.DEFAULT_PLOT_SHOW_RAW);
            boolean showMovingAvg = getInheritedAttrBoolean(plotElem, A_PLOT_SHOW_MOVING_AVG, PlotSettings.DEFAULT_PLOT_SHOW_MOVING_AVG);
            int movingAvgPoints = getInheritedAttrInt(plotElem, A_PLOT_MOVING_AVG_POINTS, PlotSettings.DEFAULT_PLOT_MOVING_AVG_POINTS);
            double multiplier = getInheritedAttrDouble(plotElem, A_PLOT_MULTIPLIER, PlotSettings.DEFAULT_PLOT_MULTIPLIER);
            double divisor = getInheritedAttrDouble(plotElem, A_PLOT_DIVISOR, PlotSettings.DEFAULT_PLOT_DIVISOR);
            boolean nonNegative = getInheritedAttrBoolean(plotElem, A_PLOT_NON_NEGATIVE, PlotSettings.DEFAULT_PLOT_NON_NEGATIVE);
            boolean percentTime = getInheritedAttrBoolean(plotElem, A_PLOT_PERCENT_TIME, PlotSettings.DEFAULT_PLOT_PERCENT_TIME);
            String dataFunction = getAttr(plotElem, A_PLOT_DATA_FUNCTION, PlotSettings.DEFAULT_PLOT_DATA_FUNCTION);
            String aggFunction = getAttr(plotElem, A_PLOT_AGGREGATE_FUNCTION, PlotSettings.DEFAULT_PLOT_AGGREGATE_FUNCTION);
            String ratioTop = getAttr(plotElem, A_PLOT_RATIO_TOP, null);
            String ratioBottom = getAttr(plotElem, A_PLOT_RATIO_BOTTOM, null);
            if ((ratioTop == null && ratioBottom != null) || (ratioTop != null && ratioBottom == null)) {
                throw new DocumentException("Both ratioTop/ratioBottom need to be specified");
            }
            if ((ratioTop == null && dataCol == null) || (ratioTop != null && dataCol != null)) {
                throw new DocumentException("Specify either ratio or data");
            }
            boolean optional = getInheritedAttrBoolean(plotElem, A_PLOT_OPTIONAL, PlotSettings.DEFAULT_PLOT_OPTIONAL);
            PlotSettings plot = new PlotSettings(legend, infile, dataCol, showRaw, showMovingAvg, movingAvgPoints, multiplier, divisor, nonNegative, percentTime, dataFunction, aggFunction, optional, ratioTop, ratioBottom);
            chart.addPlot(plot);
        }
        for (Iterator plotIter = chartElem.elementIterator(E_GROUP_PLOT); plotIter.hasNext(); ) {
            Element plotElem = (Element) plotIter.next();
            String dataCol = getAttr(plotElem, A_PLOT_DATA_COLUMN);
            // inheritable attributes
            String infile = getInheritedAttr(plotElem, A_PLOT_INFILE, null);
            boolean showRaw = getInheritedAttrBoolean(plotElem, A_PLOT_SHOW_RAW, PlotSettings.DEFAULT_PLOT_SHOW_RAW);
            boolean showMovingAvg = getInheritedAttrBoolean(plotElem, A_PLOT_SHOW_MOVING_AVG, PlotSettings.DEFAULT_PLOT_SHOW_MOVING_AVG);
            int movingAvgPoints = getInheritedAttrInt(plotElem, A_PLOT_MOVING_AVG_POINTS, PlotSettings.DEFAULT_PLOT_MOVING_AVG_POINTS);
            double multiplier = getInheritedAttrDouble(plotElem, A_PLOT_MULTIPLIER, PlotSettings.DEFAULT_PLOT_MULTIPLIER);
            double divisor = getInheritedAttrDouble(plotElem, A_PLOT_DIVISOR, PlotSettings.DEFAULT_PLOT_DIVISOR);
            boolean nonNegative = getInheritedAttrBoolean(plotElem, A_PLOT_NON_NEGATIVE, PlotSettings.DEFAULT_PLOT_NON_NEGATIVE);
            boolean percentTime = getInheritedAttrBoolean(plotElem, A_PLOT_PERCENT_TIME, PlotSettings.DEFAULT_PLOT_PERCENT_TIME);
            String dataFunction = getAttr(plotElem, A_PLOT_DATA_FUNCTION, PlotSettings.DEFAULT_PLOT_DATA_FUNCTION);
            String aggFunction = getAttr(plotElem, A_PLOT_AGGREGATE_FUNCTION, PlotSettings.DEFAULT_PLOT_AGGREGATE_FUNCTION);
            String groupBy = getAttr(plotElem, A_PLOT_GROUP_BY);
            String ignore = getAttr(plotElem, A_PLOT_IGNORE, null);
            boolean optional = getInheritedAttrBoolean(plotElem, A_PLOT_OPTIONAL, PlotSettings.DEFAULT_PLOT_OPTIONAL);
            GroupPlotSettings plot = new GroupPlotSettings(groupBy, ignore, infile, dataCol, showRaw, showMovingAvg, movingAvgPoints, multiplier, divisor, nonNegative, percentTime, dataFunction, aggFunction, optional);
            chart.addPlot(plot);
        }
        charts.add(chart);
    }
    return charts;
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Document(org.dom4j.Document) FileInputStream(java.io.FileInputStream) DocumentException(org.dom4j.DocumentException) Iterator(java.util.Iterator)

Example 10 with DocumentException

use of org.dom4j.DocumentException in project zm-mailbox by Zimbra.

the class XMLChartConfig method getInheritedAttrDouble.

// allows 'k', 'm', 'g' suffix for kilo, mega and giga
private static double getInheritedAttrDouble(Element elem, String name, double defaultValue) throws DocumentException {
    String val = getInheritedAttr(elem, name, null);
    if (val != null) {
        int len = val.length();
        if (len == 0)
            return defaultValue;
        char unit = val.toLowerCase().charAt(len - 1);
        int multiplier = 1;
        if (unit == 'k')
            multiplier = 1024;
        else if (unit == 'm')
            multiplier = 1024 * 1024;
        else if (unit == 'g')
            multiplier = 1024 * 1024 * 1024;
        String digits;
        if (multiplier == 1)
            digits = val;
        else
            digits = val.substring(0, len - 1);
        try {
            double d = Double.parseDouble(digits);
            return d * multiplier;
        } catch (NumberFormatException ex) {
            throw new DocumentException("Invalid double value " + val + " for attribute " + name + " in element " + elem.getName());
        }
    } else
        return defaultValue;
}
Also used : DocumentException(org.dom4j.DocumentException)

Aggregations

DocumentException (org.dom4j.DocumentException)36 Document (org.dom4j.Document)20 SAXReader (org.dom4j.io.SAXReader)19 Element (org.dom4j.Element)13 IOException (java.io.IOException)8 StringReader (java.io.StringReader)8 File (java.io.File)7 ConfigException (com.zimbra.common.localconfig.ConfigException)4 ArrayList (java.util.ArrayList)4 LocalConfig (com.zimbra.common.localconfig.LocalConfig)3 ServiceException (com.zimbra.common.service.ServiceException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Server (com.zimbra.cs.account.Server)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 XMLWriter (org.dom4j.io.XMLWriter)2 LoginCms (afip.wsaa.wsdl.LoginCms)1 NonNull (com.android.annotations.NonNull)1 DirectoryInput (com.android.build.api.transform.DirectoryInput)1