Skip to content

Commit

Permalink
[HCT-14] Added new transformer input element <hct:tags/>
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Feb 6, 2014
1 parent 1e8b3d7 commit a6bdb62
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
7 changes: 5 additions & 2 deletions core/src/main/java/net/tirasa/hct/cocoon/sax/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.commons.lang3.StringUtils;
import org.hippoecm.hst.content.beans.standard.HippoAsset;
import org.hippoecm.hst.content.beans.standard.HippoAvailableTranslations;
import org.hippoecm.hst.content.beans.standard.HippoAvailableTranslationsBean;
import org.hippoecm.hst.content.beans.standard.HippoDirectory;
import org.hippoecm.hst.content.beans.standard.HippoDocument;
import org.hippoecm.hst.content.beans.standard.HippoFacetSelect;
Expand Down Expand Up @@ -139,6 +138,7 @@ public static Element fromName(final String name) {

}
}

public static final EnumSet<Element> FILTER_ELEMENTS = EnumSet.of(
Element.EQUALTO, Element.NOT_EQUALTO, Element.CONTAINS, Element.NOT_CONTAINS,
Element.LIKE, Element.NOT_LIKE, Element.ISNULL, Element.NOT_NULL,
Expand All @@ -154,6 +154,8 @@ public static Element fromName(final String name) {

public static final String XSD_LONG = "xsd:long";

public static final String XSD_DOUBLE = "xsd:double";

public static final String XSD_DATETIME = "xsd:dateTime";

public static final String NS_EMPTY = "";
Expand Down Expand Up @@ -220,7 +222,8 @@ public static enum Attribute {
SIZE_KB("sizeKb"),
LAST_MOD("lastModified"),
INCLUDE_FOLDERS("includeFolders"),
DATE_FORMAT("dateFormat");
DATE_FORMAT("dateFormat"),
SCORE("score");

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import org.hippoecm.hst.content.beans.standard.HippoHtml;
import org.hippoecm.hst.content.beans.standard.HippoItem;
import org.hippoecm.repository.api.HippoNodeType;
import org.onehippo.forge.ecmtagging.Tag;
import org.onehippo.forge.ecmtagging.TagCollection;
import org.onehippo.forge.ecmtagging.TaggingNodeType;
import org.onehippo.taxonomy.api.TaxonomyNodeTypes;
import org.xml.sax.InputSource;
Expand Down Expand Up @@ -321,6 +323,26 @@ public void dumpRelatedDocs(final List<HippoDocument> relDocs, final String elem
}
}

public void dumpTags(final TagCollection tags) throws SAXException {
saxConsumer.startElement(NS_HCT, Element.TAGS.getName(),
PREFIX_HCT + ":" + Element.TAGS.getName(), EMPTY_ATTRS);

for (Tag tag : tags.values()) {
final AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(NS_EMPTY, Attribute.SCORE.getName(),
Attribute.SCORE.getName(), XSD_DOUBLE, String.valueOf(tag.getScore()));

saxConsumer.startElement(NS_HCT, Element.TAG.getName(),
PREFIX_HCT + ":" + Element.TAG.getName(), attrs);
saxConsumer.characters(tag.getName().toCharArray(), 0, tag.getName().length());
saxConsumer.endElement(NS_HCT, Element.TAG.getName(),
PREFIX_HCT + ":" + Element.TAG.getName());
}

saxConsumer.endElement(NS_HCT, Element.TAGS.getName(),
PREFIX_HCT + ":" + Element.TAGS.getName());
}

public void dumpTags(final String[] tags) throws SAXException {
saxConsumer.startElement(NS_HCT, Element.TAGS.getName(),
PREFIX_HCT + ":" + Element.TAGS.getName(), EMPTY_ATTRS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.hippoecm.hst.content.beans.standard.HippoMirror;
import org.hippoecm.repository.api.HippoNodeType;
import org.onehippo.forge.ecmtagging.TaggingNodeType;
import org.onehippo.forge.ecmtagging.providers.AllTagsProvider;
import org.onehippo.taxonomy.api.TaxonomyNodeTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -270,6 +271,12 @@ private void document(final HCTConnManager connManager)
dumper.endHippoItem(doc);
}

private void tags(final HCTConnManager connManager) throws RepositoryException, SAXException {
final HippoItemXMLDumper dumper = new HippoItemXMLDumper(this.getSAXConsumer());

dumper.dumpTags(AllTagsProvider.getTags(connManager.getSession(), "tags"));
}

private <T extends HippoItem> void recursiveTraversal(final HippoItem item, final Class<T> traversalType,
final int depth, final HippoItemXMLDumper dumper) throws SAXException, RepositoryException {

Expand Down Expand Up @@ -581,11 +588,13 @@ public void startElement(final String uri, final String localName, final String
}

if (element == Element.TAGS) {
if (state != State.INSIDE_RETURN) {
if (state == State.INSIDE_RETURN) {
hctQuery.setReturnTags(true);
} else if (state == State.OUTSIDE) {
LOG.debug("Requiring tags, no processing needed here");
} else {
throw new InvalidHCTRequestException(localName, state);
}

hctQuery.setReturnTags(true);
}

if (element == Element.TAXONOMIES) {
Expand Down Expand Up @@ -636,8 +645,8 @@ public void endElement(final String uri, final String localName, final String na
state = State.INSIDE_QUERY;

LOG.debug("Fields to be returned: {}; images: {}; relatedDocs: {}",
new Object[]{hctQuery.getReturnFields(), hctQuery.isReturnImages(),
hctQuery.isReturnRelatedDocs()});
new Object[] { hctQuery.getReturnFields(), hctQuery.isReturnImages(),
hctQuery.isReturnRelatedDocs() });
}

if (element == Element.ORDERBY) {
Expand Down Expand Up @@ -668,7 +677,7 @@ public void endElement(final String uri, final String localName, final String na
}
state = State.OUTSIDE;

HCTConnManager connManager = HCTConnManager.getContentInstance();
final HCTConnManager connManager = HCTConnManager.getContentInstance();
try {
query(connManager);
} catch (Exception e) {
Expand All @@ -683,7 +692,7 @@ public void endElement(final String uri, final String localName, final String na
throw new InvalidHCTRequestException(localName, state);
}

HCTConnManager connManager = HCTConnManager.getContentInstance();
final HCTConnManager connManager = HCTConnManager.getContentInstance();
try {
traverse(connManager);
} catch (Exception e) {
Expand All @@ -694,12 +703,27 @@ public void endElement(final String uri, final String localName, final String na

}

if (element == Element.TAGS) {
if (state != State.OUTSIDE) {
throw new InvalidHCTRequestException(localName, state);
}

final HCTConnManager connManager = HCTConnManager.getContentInstance();
try {
tags(connManager);
} catch (Exception e) {
throw new ProcessingException("While fetching tags", e);
} finally {
connManager.logout();
}
}

if (element == Element.DOCUMENT) {
if (state != State.OUTSIDE) {
throw new InvalidHCTRequestException(localName, state);
}

HCTConnManager connManager = HCTConnManager.getContentInstance();
final HCTConnManager connManager = HCTConnManager.getContentInstance();
try {
document(connManager);
} catch (Exception e) {
Expand Down

0 comments on commit a6bdb62

Please sign in to comment.