Search in sources :

Example 61 with Document

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

the class RevisionInfoConfiguration method configure.

public RevisionInfoConfigurationResult configure(MetadataImplementor metadata, ReflectionManager reflectionManager) {
    boolean revisionEntityFound = false;
    RevisionInfoGenerator revisionInfoGenerator = null;
    Class<?> revisionInfoClass = null;
    for (PersistentClass persistentClass : metadata.getEntityBindings()) {
        // Ensure we're in POJO, not dynamic model, mapping.
        if (persistentClass.getClassName() != null) {
            XClass clazz;
            try {
                clazz = reflectionManager.classForName(persistentClass.getClassName());
            } catch (ClassLoadingException e) {
                throw new MappingException(e);
            }
            final RevisionEntity revisionEntity = clazz.getAnnotation(RevisionEntity.class);
            if (revisionEntity != null) {
                if (revisionEntityFound) {
                    throw new MappingException("Only one entity may be annotated with @RevisionEntity!");
                }
                // Checking if custom revision entity isn't audited
                if (clazz.getAnnotation(Audited.class) != null) {
                    throw new MappingException("An entity annotated with @RevisionEntity cannot be audited!");
                }
                revisionEntityFound = true;
                final MutableBoolean revisionNumberFound = new MutableBoolean();
                final MutableBoolean revisionTimestampFound = new MutableBoolean();
                final MutableBoolean modifiedEntityNamesFound = new MutableBoolean();
                searchForRevisionInfoCfg(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound, modifiedEntityNamesFound);
                if (!revisionNumberFound.isSet()) {
                    throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " + "with @RevisionNumber!");
                }
                if (!revisionTimestampFound.isSet()) {
                    throw new MappingException("An entity annotated with @RevisionEntity must have a field annotated " + "with @RevisionTimestamp!");
                }
                revisionInfoEntityName = persistentClass.getEntityName();
                revisionInfoClass = persistentClass.getMappedClass();
                final Class<? extends RevisionListener> revisionListenerClass = getRevisionListenerClass(revisionEntity.value());
                revisionInfoTimestampType = persistentClass.getProperty(revisionInfoTimestampData.getName()).getType();
                if (globalCfg.isTrackEntitiesChangedInRevision() || (globalCfg.isUseRevisionEntityWithNativeId() && DefaultTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass)) || (!globalCfg.isUseRevisionEntityWithNativeId() && SequenceIdTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass)) || modifiedEntityNamesFound.isSet()) {
                    // If tracking modified entities parameter is enabled, custom revision info entity is a subtype
                    // of DefaultTrackingModifiedEntitiesRevisionEntity class, or @ModifiedEntityNames annotation is used.
                    revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData, metadata.getMetadataBuildingOptions().getServiceRegistry());
                    globalCfg.setTrackEntitiesChangedInRevision(true);
                } else {
                    revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), metadata.getMetadataBuildingOptions().getServiceRegistry());
                }
            }
        }
    }
    // In case of a custom revision info generator, the mapping will be null.
    Document revisionInfoXmlMapping = null;
    final Class<? extends RevisionListener> revisionListenerClass = getRevisionListenerClass(RevisionListener.class);
    if (revisionInfoGenerator == null) {
        if (globalCfg.isTrackEntitiesChangedInRevision()) {
            revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultTrackingModifiedEntitiesRevisionEntity.class : SequenceIdTrackingModifiedEntitiesRevisionEntity.class;
            revisionInfoEntityName = revisionInfoClass.getName();
            revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData, metadata.getMetadataBuildingOptions().getServiceRegistry());
        } else {
            revisionInfoClass = globalCfg.isUseRevisionEntityWithNativeId() ? DefaultRevisionEntity.class : SequenceIdRevisionEntity.class;
            revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass, revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), metadata.getMetadataBuildingOptions().getServiceRegistry());
        }
        revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
    }
    return new RevisionInfoConfigurationResult(revisionInfoGenerator, revisionInfoXmlMapping, new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdData.getName(), revisionInfoTimestampData.getName(), isTimestampAsDate()), generateRevisionInfoRelationMapping(), new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData, metadata.getMetadataBuildingOptions().getServiceRegistry()), globalCfg.isTrackEntitiesChangedInRevision() ? new ModifiedEntityNamesReader(revisionInfoClass, modifiedEntityNamesData, metadata.getMetadataBuildingOptions().getServiceRegistry()) : null, revisionInfoEntityName, revisionInfoClass, revisionInfoTimestampData);
}
Also used : ClassLoadingException(org.hibernate.annotations.common.reflection.ClassLoadingException) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) MutableBoolean(org.hibernate.envers.internal.tools.MutableBoolean) ModifiedEntityNamesReader(org.hibernate.envers.internal.revisioninfo.ModifiedEntityNamesReader) DefaultRevisionInfoGenerator(org.hibernate.envers.internal.revisioninfo.DefaultRevisionInfoGenerator) Document(org.dom4j.Document) XClass(org.hibernate.annotations.common.reflection.XClass) RevisionInfoNumberReader(org.hibernate.envers.internal.revisioninfo.RevisionInfoNumberReader) SequenceIdTrackingModifiedEntitiesRevisionEntity(org.hibernate.envers.enhanced.SequenceIdTrackingModifiedEntitiesRevisionEntity) MappingException(org.hibernate.MappingException) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) RevisionEntity(org.hibernate.envers.RevisionEntity) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) SequenceIdTrackingModifiedEntitiesRevisionEntity(org.hibernate.envers.enhanced.SequenceIdTrackingModifiedEntitiesRevisionEntity) DefaultTrackingModifiedEntitiesRevisionEntity(org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity) Audited(org.hibernate.envers.Audited) DefaultTrackingModifiedEntitiesRevisionInfoGenerator(org.hibernate.envers.internal.revisioninfo.DefaultTrackingModifiedEntitiesRevisionInfoGenerator) DefaultRevisionInfoGenerator(org.hibernate.envers.internal.revisioninfo.DefaultRevisionInfoGenerator) RevisionInfoGenerator(org.hibernate.envers.internal.revisioninfo.RevisionInfoGenerator) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) DefaultTrackingModifiedEntitiesRevisionInfoGenerator(org.hibernate.envers.internal.revisioninfo.DefaultTrackingModifiedEntitiesRevisionInfoGenerator) DefaultTrackingModifiedEntitiesRevisionEntity(org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity) RevisionInfoQueryCreator(org.hibernate.envers.internal.revisioninfo.RevisionInfoQueryCreator) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 62 with Document

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

the class ConfigManager method saveSettings.

/**
     * Saves settings from options screen.
     *
     * @param transportName Name of the transport to have it's options saved (type of transport)
     * @param options Options passed from options form.
     */
public void saveSettings(String transportName, HashMap<String, String> options) {
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
    Document optConfig = plugin.getOptionsConfig(TransportType.valueOf(transportName));
    Element leftPanel = optConfig.getRootElement().element("leftpanel");
    if (leftPanel != null && leftPanel.nodeCount() > 0) {
        for (Object nodeObj : leftPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element rightPanel = optConfig.getRootElement().element("rightpanel");
    if (rightPanel != null && rightPanel.nodeCount() > 0) {
        for (Object nodeObj : rightPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element bottomPanel = optConfig.getRootElement().element("bottompanel");
    if (bottomPanel != null && bottomPanel.nodeCount() > 0) {
        for (Object nodeObj : bottomPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) Element(org.dom4j.Element) KrakenPlugin(net.sf.kraken.KrakenPlugin) Document(org.dom4j.Document)

Example 63 with Document

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

the class PluginCacheConfigurator method configure.

public void configure(String pluginName) {
    try {
        SAXReader saxReader = new SAXReader();
        saxReader.setEncoding("UTF-8");
        Document cacheXml = saxReader.read(configDataStream);
        List<Node> mappings = cacheXml.selectNodes("/cache-config/cache-mapping");
        for (Node mapping : mappings) {
            registerCache(pluginName, mapping);
        }
    } catch (DocumentException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Node(org.dom4j.Node) DocumentException(org.dom4j.DocumentException) Document(org.dom4j.Document)

Example 64 with Document

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

the class UpdateManager method loadLatestServerInfo.

private void loadLatestServerInfo() {
    Document xmlResponse;
    File file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf", "server-update.xml");
    if (!file.exists()) {
        return;
    }
    // Check read privs.
    if (!file.canRead()) {
        Log.warn("Cannot retrieve server updates. File must be readable: " + file.getName());
        return;
    }
    try (FileReader reader = new FileReader(file)) {
        SAXReader xmlReader = new SAXReader();
        xmlReader.setEncoding("UTF-8");
        xmlResponse = xmlReader.read(reader);
    } catch (Exception e) {
        Log.error("Error reading server-update.xml", e);
        return;
    }
    // Parse info and recreate update information (if still required)
    Element openfire = xmlResponse.getRootElement().element("openfire");
    if (openfire != null) {
        Version latestVersion = new Version(openfire.attributeValue("latest"));
        String changelog = openfire.attributeValue("changelog");
        String url = openfire.attributeValue("url");
        // Check if current server version is correct
        Version currentServerVersion = XMPPServer.getInstance().getServerInfo().getVersion();
        if (latestVersion.isNewerThan(currentServerVersion)) {
            serverUpdate = new Update("Openfire", latestVersion.getVersionString(), changelog, url);
        }
    }
}
Also used : Version(org.jivesoftware.util.Version) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) FileReader(java.io.FileReader) Document(org.dom4j.Document) File(java.io.File) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException)

Example 65 with Document

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

the class ChatTranscriptManager method getTextTranscriptFromSessionID.

/**
     * Return the plain text version of a chat transcript.
     *
     * @param sessionID the sessionID of the <code>ChatSession</code>
     * @return the plain text version of a chat transcript.
     */
public static String getTextTranscriptFromSessionID(String sessionID) {
    String transcript = null;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_SESSION_TRANSCRIPT);
        pstmt.setString(1, sessionID);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            transcript = DbConnectionManager.getLargeTextField(rs, 1);
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    if (transcript == null || "".equals(transcript)) {
        return "";
    }
    // Define time zone used in the transcript.
    SimpleDateFormat UTC_FORMAT = new SimpleDateFormat(XMPPDateTimeFormat.XMPP_DELAY_DATETIME_FORMAT);
    UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
    final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
    Document element = null;
    try {
        element = DocumentHelper.parseText(transcript);
    } catch (DocumentException e) {
        Log.error(e.getMessage(), e);
    }
    StringBuilder buf = new StringBuilder();
    // Add the Messages and Presences contained in the retrieved transcript element
    for (Iterator<Element> it = element.getRootElement().elementIterator(); it.hasNext(); ) {
        Element packet = it.next();
        String name = packet.getName();
        String message = "";
        String from = "";
        if ("presence".equals(name)) {
            String type = packet.attributeValue("type");
            from = new JID(packet.attributeValue("from")).getResource();
            if (type == null) {
                message = from + " has joined the room";
            } else {
                message = from + " has left the room";
            }
        } else if ("message".equals(name)) {
            from = new JID(packet.attributeValue("from")).getResource();
            message = packet.elementText("body");
            message = StringUtils.escapeHTMLTags(message);
        }
        List<Element> el = packet.elements("x");
        for (Element ele : el) {
            if ("jabber:x:delay".equals(ele.getNamespaceURI())) {
                String stamp = ele.attributeValue("stamp");
                try {
                    String formattedDate;
                    synchronized (UTC_FORMAT) {
                        Date d = UTC_FORMAT.parse(stamp);
                        formattedDate = formatter.format(d);
                    }
                    if ("presence".equals(name)) {
                        buf.append("[").append(formattedDate).append("] ").append(message).append("\n");
                    } else {
                        buf.append("[").append(formattedDate).append("] ").append(from).append(": ").append(message).append("\n");
                    }
                } catch (ParseException e) {
                    Log.error(e.getMessage(), e);
                }
            }
        }
    }
    return buf.toString();
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException) ParseException(java.text.ParseException) Date(java.util.Date) DocumentException(org.dom4j.DocumentException) ResultSet(java.sql.ResultSet) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Document (org.dom4j.Document)288 Element (org.dom4j.Element)192 SAXReader (org.dom4j.io.SAXReader)143 Test (org.junit.Test)102 StringReader (java.io.StringReader)88 File (java.io.File)57 ArrayList (java.util.ArrayList)47 List (java.util.List)40 IOException (java.io.IOException)27 DocumentException (org.dom4j.DocumentException)25 XMLWriter (org.dom4j.io.XMLWriter)22 HashMap (java.util.HashMap)19 Map (java.util.Map)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 LinkedList (java.util.LinkedList)16 Attribute (org.dom4j.Attribute)15 Node (org.dom4j.Node)14 FileOutputStream (java.io.FileOutputStream)11 DavException (com.zimbra.cs.dav.DavException)10 OutputFormat (org.dom4j.io.OutputFormat)9