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());
}
}
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);
}
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());
}
}
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;
}
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;
}
Aggregations