Search in sources :

Example 91 with Node

use of org.dom4j.Node in project core by craftercms.

the class ContentStoreServiceImplTest method assertContentFrDescriptorItem.

private void assertContentFrDescriptorItem(Item item, boolean processorSpecified) {
    assertNotNull(item);
    assertEquals(CONTENT_FR_DESCRIPTOR_NAME, item.getName());
    assertEquals(CONTENT_FR_DESCRIPTOR_PATH, item.getUrl());
    assertFalse(item.isFolder());
    assertEquals(CONTENT_FR_DESCRIPTOR_PATH, item.getDescriptorUrl());
    assertNotNull(item.getDescriptorDom());
    assertSystemInfoProperties(item);
    if (processorSpecified) {
        assertEquals(FIRST_QUOTE_EN, item.getProperty("//first-quote"));
        assertEquals(SECOND_QUOTE_FR, item.getProperty("//second-quote"));
        assertEquals(THIRD_QUOTE_FR, item.getProperty("//third-quote"));
    } else {
        Node firstQuote = item.getDescriptorDom().selectSingleNode("//first-quote");
        assertNotNull(firstQuote);
        assertEquals(FIRST_QUOTE_EN, firstQuote.getText());
        Node secondQuote = item.getDescriptorDom().selectSingleNode("//second-quote");
        assertNotNull(secondQuote);
        assertEquals(SECOND_QUOTE_FR, secondQuote.getText());
        Node thirdQuote = item.getDescriptorDom().selectSingleNode("//third-quote");
        assertNotNull(thirdQuote);
        assertEquals(THIRD_QUOTE_FR, thirdQuote.getText());
    }
}
Also used : Node(org.dom4j.Node)

Example 92 with Node

use of org.dom4j.Node in project core by craftercms.

the class MetaDataMergeStrategyResolverTest method setUpTestDescriptorDoms.

private void setUpTestDescriptorDoms() {
    Node strategy1MergeStrategyElement = mock(Node.class);
    when(strategy1MergeStrategyElement.getText()).thenReturn(STRATEGY1_ELEMENT_VALUE);
    descriptorDomStrategy1 = mock(Document.class);
    when(descriptorDomStrategy1.selectSingleNode(MERGE_STRATEGY_ELEMENT_XPATH_QUERY)).thenReturn(strategy1MergeStrategyElement);
    Node strategy2MergeStrategyElement = mock(Node.class);
    when(strategy2MergeStrategyElement.getText()).thenReturn(STRATEGY2_ELEMENT_VALUE);
    descriptorDomStrategy2 = mock(Document.class);
    when(descriptorDomStrategy2.selectSingleNode(MERGE_STRATEGY_ELEMENT_XPATH_QUERY)).thenReturn(strategy2MergeStrategyElement);
}
Also used : Node(org.dom4j.Node) Document(org.dom4j.Document)

Example 93 with Node

use of org.dom4j.Node in project core by craftercms.

the class IncludeDescriptorsProcessor method doInclude.

@SuppressWarnings("unchecked")
protected void doInclude(Item item, Element includeElement, Item itemToInclude) throws ItemProcessingException {
    List<Node> includeElementParentChildren = includeElement.getParent().content();
    int includeElementIdx = includeElementParentChildren.indexOf(includeElement);
    Element itemToIncludeRootElement = itemToInclude.getDescriptorDom().getRootElement().createCopy();
    // Remove the <include> element
    includeElementParentChildren.remove(includeElementIdx);
    // Add the item's root element
    includeElementParentChildren.add(includeElementIdx, itemToIncludeRootElement);
    // Add dependency key
    item.addDependencyKey(itemToInclude.getKey());
    if (logger.isDebugEnabled()) {
        logger.debug("Item " + itemToInclude.getDescriptorUrl() + " included into " + item.getDescriptorUrl());
    }
}
Also used : Node(org.dom4j.Node) Element(org.dom4j.Element)

Example 94 with Node

use of org.dom4j.Node in project core by craftercms.

the class Dom4jDocumentJsonSerializer method getTextContentFromMixedContent.

@SuppressWarnings("unchecked")
private List<String> getTextContentFromMixedContent(Element element) {
    List<Node> content = element.content();
    List<String> textContent = new ArrayList<String>();
    for (Node node : content) {
        if (node.getNodeType() == Node.TEXT_NODE) {
            String text = node.getText();
            if (StringUtils.isNotBlank(text)) {
                textContent.add(text);
            }
        }
    }
    return textContent;
}
Also used : Node(org.dom4j.Node) ArrayList(java.util.ArrayList)

Example 95 with Node

use of org.dom4j.Node in project core by craftercms.

the class ExplicitParentMergeStrategy method getDescriptors.

@Override
public List<MergeableDescriptor> getDescriptors(Context context, CachingOptions cachingOptions, String mainDescriptorUrl, Document mainDescriptorDom, boolean mainDescriptorOptional) throws XmlMergeException {
    Node parentDescriptorElem = mainDescriptorDom.selectSingleNode(parentDescriptorElementXPathQuery);
    List<MergeableDescriptor> descriptors = new ArrayList<>();
    if (parentDescriptorElem != null) {
        String parentDescriptorUrl = parentDescriptorElem.getText();
        Document parentDescriptorDom = getDescriptorDom(context, cachingOptions, parentDescriptorUrl);
        if (parentDescriptorDom != null) {
            DescriptorMergeStrategy parentMergeStrategy = mergeStrategyResolver.getStrategy(parentDescriptorUrl, parentDescriptorDom);
            if (parentMergeStrategy != null) {
                descriptors.addAll(parentMergeStrategy.getDescriptors(context, cachingOptions, parentDescriptorUrl, parentDescriptorDom, true));
            }
        } else {
            throw new XmlMergeException("No parent descriptor found at " + parentDescriptorUrl);
        }
    } else {
        throw new XmlMergeException("No parent descriptor element specified");
    }
    descriptors.add(new MergeableDescriptor(mainDescriptorUrl, mainDescriptorOptional));
    return descriptors;
}
Also used : DescriptorMergeStrategy(org.craftercms.core.xml.mergers.DescriptorMergeStrategy) Node(org.dom4j.Node) ArrayList(java.util.ArrayList) MergeableDescriptor(org.craftercms.core.xml.mergers.MergeableDescriptor) Document(org.dom4j.Document) XmlMergeException(org.craftercms.core.exception.XmlMergeException)

Aggregations

Node (org.dom4j.Node)253 Document (org.dom4j.Document)83 Element (org.dom4j.Element)61 ArrayList (java.util.ArrayList)56 List (java.util.List)54 Test (org.junit.Test)40 SAXReader (org.dom4j.io.SAXReader)28 File (java.io.File)25 Iterator (java.util.Iterator)18 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)18 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)18 HashMap (java.util.HashMap)16 URL (java.net.URL)15 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)15 InputStream (java.io.InputStream)14 Attribute (org.dom4j.Attribute)14 Image (java.awt.Image)12 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)11 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10