Search in sources :

Example 1 with Document

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

the class RevisionInfoConfiguration method generateRevisionInfoRelationMapping.

private Element generateRevisionInfoRelationMapping() {
    final Document document = globalCfg.getEnversService().getXmlHelper().getDocumentFactory().createDocument();
    final Element revRelMapping = document.addElement("key-many-to-one");
    revRelMapping.addAttribute("type", revisionPropType);
    revRelMapping.addAttribute("class", revisionInfoEntityName);
    if (revisionPropSqlType != null) {
        // Putting a fake name to make Hibernate happy. It will be replaced later anyway.
        MetadataTools.addColumn(revRelMapping, "*", null, null, null, revisionPropSqlType, null, null, false);
    }
    return revRelMapping;
}
Also used : Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 2 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 3 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 4 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)

Example 5 with Document

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

the class ContentFilterTest method testFilterChatMessage.

@Test
public void testFilterChatMessage() throws DocumentException, IOException, XmlPullParserException {
    String chatXML = "<message to=\"doe@127.0.0.1/Adium\" type=\"chat\" id=\"iChat_E8B5ED64\" from=\"bob@127.0.0.1/frodo\">" + "<body>fox</body>" + "<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" + "<body xmlns=\"http://www.w3.org/1999/xhtml\" style=\"background-color:#E8A630;color:#000000\">fox</body>" + "</html>" + "<x xmlns=\"jabber:x:event\">" + "<composing/>" + "</x>" + "</message>";
    XPPReader packetReader = new XPPReader();
    Document doc = packetReader.read(new StringReader(chatXML));
    Message m = new Message(doc.getRootElement());
    // filter on the word "fox" and "dog"
    filter.setPatterns("fox,dog,message");
    filter.setMask("**");
    String expectedXML = chatXML.replaceAll("fox", filter.getMask());
    // do filter
    boolean matched = filter.filter(m);
    assertTrue(matched);
    assertEquals(expectedXML, expectedXML, m.toXML());
}
Also used : Message(org.xmpp.packet.Message) StringReader(java.io.StringReader) XPPReader(org.dom4j.io.XPPReader) Document(org.dom4j.Document) Test(org.junit.Test)

Aggregations

Document (org.dom4j.Document)891 Element (org.dom4j.Element)492 SAXReader (org.dom4j.io.SAXReader)252 File (java.io.File)135 IOException (java.io.IOException)135 StringReader (java.io.StringReader)111 ArrayList (java.util.ArrayList)110 List (java.util.List)107 Test (org.junit.Test)101 DocumentException (org.dom4j.DocumentException)93 HashMap (java.util.HashMap)90 InputStream (java.io.InputStream)82 Node (org.dom4j.Node)80 Test (org.junit.jupiter.api.Test)80 XMLWriter (org.dom4j.io.XMLWriter)53 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)48 FileInputStream (java.io.FileInputStream)45 Map (java.util.Map)41 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)40 XMLParser (org.olat.core.util.xml.XMLParser)40