use of com.enonic.xp.form.FormItem in project xp by enonic.
the class ContentTypeMapper method serializeFormItemSet.
private void serializeFormItemSet(final MapGenerator gen, final FormItemSet itemSet) {
gen.map();
gen.value("formItemType", "ItemSet");
gen.value("name", itemSet.getName());
gen.value("label", itemSet.getLabel());
gen.value("customText", itemSet.getCustomText());
gen.value("helpText", itemSet.getHelpText());
serializeOccurrences(gen, itemSet.getOccurrences());
gen.array("items");
for (FormItem formItem : itemSet) {
serializeItem(gen, formItem);
}
gen.end();
gen.end();
}
use of com.enonic.xp.form.FormItem in project xp by enonic.
the class ContentTypeMapper method serializeLayout.
private void serializeLayout(final MapGenerator gen, final FieldSet fieldSet) {
gen.map();
gen.value("formItemType", "Layout");
gen.value("name", fieldSet.getName());
gen.value("label", fieldSet.getLabel());
gen.array("items");
for (FormItem formItem : fieldSet) {
serializeItem(gen, formItem);
}
gen.end();
gen.end();
}
use of com.enonic.xp.form.FormItem in project xp by enonic.
the class XmlMacroDescriptorParserTest method assertResult.
private void assertResult() throws Exception {
final MacroDescriptor result = this.builder.build();
assertEquals("myapplication:mymacro", result.getKey().toString());
assertEquals("My macro", result.getDisplayName());
assertEquals("key.display-name", result.getDisplayNameI18nKey());
assertEquals("key.description", result.getDescriptionI18nKey());
assertEquals("This macro is a test", result.getDescription());
assertEquals(3, result.getForm().size());
final FormItem item = result.getForm().getFormItem("myDate");
assertNotNull(item);
final Input input = (Input) item;
assertEquals(InputTypeName.DATE.toString(), input.getInputType().toString());
assertEquals("key.label", input.getLabelI18nKey());
assertEquals("key.help-text", input.getHelpTextI18nKey());
final FormItem contentSelectorItem = result.getForm().getFormItem("someonesParent");
assertNotNull(contentSelectorItem);
final Input contentSelectorInput = (Input) contentSelectorItem;
assertEquals(InputTypeName.CONTENT_SELECTOR.toString(), contentSelectorInput.getInputType().toString());
assertEquals("key.parent", contentSelectorInput.getLabelI18nKey());
assertEquals("mytype", contentSelectorInput.getInputTypeConfig().getProperty("allowContentType").getValue());
assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowContentType").size());
assertEquals("path1", contentSelectorInput.getInputTypeConfig().getProperty("allowPath").getValue());
assertEquals(2, contentSelectorInput.getInputTypeConfig().getProperties("allowPath").size());
assertEquals("system:reference", contentSelectorInput.getInputTypeConfig().getProperty("relationshipType").getValue());
final InputTypeConfig config = input.getInputTypeConfig();
assertNotNull(config);
}
use of com.enonic.xp.form.FormItem in project xp by enonic.
the class ImageContentProcessor method extractMetadata.
private ExtraDatas extractMetadata(final MediaInfo mediaInfo, final XDatas xDatas, final CreateAttachment sourceAttachment) {
final ExtraDatas.Builder extradatasBuilder = ExtraDatas.create();
final Map<XDataName, ExtraData> metadataMap = new HashMap<>();
final ExtraData geoData = extractGeoLocation(mediaInfo, xDatas);
if (geoData != null) {
metadataMap.put(MediaInfo.GPS_INFO_METADATA_NAME, geoData);
extradatasBuilder.add(geoData);
}
for (Map.Entry<String, Collection<String>> entry : mediaInfo.getMetadata().asMap().entrySet()) {
for (XData xData : xDatas) {
final String formItemName = getConformityName(entry.getKey());
final FormItem formItem = xData.getForm().getFormItems().getItemByName(formItemName);
if (formItem == null) {
continue;
}
ExtraData extraData = metadataMap.get(xData.getName());
if (extraData == null) {
extraData = new ExtraData(xData.getName(), new PropertyTree());
metadataMap.put(xData.getName(), extraData);
extradatasBuilder.add(extraData);
}
if (FormItemType.INPUT.equals(formItem.getType())) {
Input input = (Input) formItem;
if (InputTypeName.DATE_TIME.equals(input.getInputType())) {
extraData.getData().addLocalDateTime(formItemName, ValueTypes.LOCAL_DATE_TIME.convert(entry.getValue().toArray()[0]));
} else if (InputTypeName.LONG.equals(input.getInputType())) {
final Long[] longValues = entry.getValue().stream().map(Long::parseLong).toArray(Long[]::new);
extraData.getData().addLongs(formItemName, longValues);
} else {
extraData.getData().addStrings(formItemName, entry.getValue());
}
}
}
}
fillComputedFormItems(metadataMap.values(), mediaInfo, sourceAttachment);
return extradatasBuilder.build();
}
use of com.enonic.xp.form.FormItem in project xp by enonic.
the class ImageContentProcessor method extractGeoLocation.
private ExtraData extractGeoLocation(final MediaInfo mediaInfo, final XDatas xDatas) {
final ImmutableMultimap<String, String> mediaItems = mediaInfo.getMetadata();
final Double geoLat = parseDouble(mediaItems.get(GEO_LATITUDE).stream().findFirst().orElse(null));
final Double geoLong = parseDouble(mediaItems.get(GEO_LONGITUDE).stream().findFirst().orElse(null));
if (geoLat == null || geoLong == null) {
return null;
}
final XData geoMixin = xDatas.getXData(MediaInfo.GPS_INFO_METADATA_NAME);
if (geoMixin == null) {
return null;
}
final ExtraData extraData = new ExtraData(geoMixin.getName(), new PropertyTree());
final FormItem formItem = geoMixin.getForm().getFormItems().getItemByName(MediaInfo.GPS_INFO_GEO_POINT);
if (FormItemType.INPUT.equals(formItem.getType())) {
final Input input = (Input) formItem;
if (InputTypeName.GEO_POINT.equals(input.getInputType())) {
final GeoPoint geoPoint = new GeoPoint(geoLat, geoLong);
extraData.getData().addGeoPoint(formItem.getName(), ValueTypes.GEO_POINT.convert(geoPoint));
}
}
return extraData;
}
Aggregations