You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2015/03/30 17:43:33 UTC
[04/59] [abbrv] isis git commit: ISIS-720: mothballing scimpi
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/FormFieldBlock.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/FormFieldBlock.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/FormFieldBlock.java
new file mode 100644
index 0000000..294a239
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/FormFieldBlock.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.edit;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.viewer.scimpi.dispatcher.view.field.InclusionList;
+import org.apache.isis.viewer.scimpi.dispatcher.view.form.InputField;
+
+public class FormFieldBlock extends InclusionList {
+ private final Map<String, String> content = new HashMap<String, String>();
+ private final Map<String, String> values = new HashMap<String, String>();
+
+ public void replaceContent(final String field, final String htmlString) {
+ content.put(field, htmlString);
+ }
+
+ public boolean hasContent(final String name) {
+ return content.containsKey(name);
+ }
+
+ public String getContent(final String name) {
+ return content.get(name);
+ }
+
+ public boolean isVisible(final String name) {
+ return true;
+ }
+
+ public boolean isNullable(final String name) {
+ return true;
+ }
+
+ public ObjectAdapter getCurrent(final String name) {
+ return null;
+ }
+
+ public void value(final String field, final String value) {
+ values.put(field, value);
+ }
+
+ public void setUpValues(final InputField[] inputFields) {
+ for (final InputField inputField : inputFields) {
+ final String name = inputField.getName();
+ inputField.setValue(values.get(name));
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/HiddenField.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/HiddenField.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/HiddenField.java
new file mode 100644
index 0000000..71019ea
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/HiddenField.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.edit;
+
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.BlockContent;
+import org.apache.isis.viewer.scimpi.dispatcher.TagOrderException;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class HiddenField extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ final BlockContent blockContent = request.getBlockContent();
+ if (!(blockContent instanceof FormFieldBlock)) {
+ throw new TagOrderException(request);
+ }
+
+ final String field = request.getOptionalProperty("name");
+ final String value = request.getRequiredProperty("value");
+ final FormFieldBlock block = (FormFieldBlock) blockContent;
+ block.value(field, value);
+ block.exclude(field);
+ }
+
+ @Override
+ public String getName() {
+ return "hidden-field";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/RadioListField.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/RadioListField.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/RadioListField.java
new file mode 100644
index 0000000..7b3c1e6
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/RadioListField.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.edit;
+
+import java.util.Iterator;
+
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class RadioListField extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ final FormFieldBlock block = (FormFieldBlock) request.getBlockContent();
+ final String field = request.getRequiredProperty(FIELD);
+ if (block.isVisible(field)) {
+ final String id = request.getRequiredProperty(COLLECTION);
+ final String exclude = request.getOptionalProperty("exclude");
+
+ final ObjectAdapter collection = request.getContext().getMappedObjectOrResult(id);
+
+ final RequestContext context = request.getContext();
+ final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
+ final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
+
+ final StringBuffer buffer = new StringBuffer();
+
+ while (iterator.hasNext()) {
+ final ObjectAdapter element = iterator.next();
+ final Scope scope = Scope.INTERACTION;
+ final String elementId = context.mapObject(element, scope);
+ if (exclude != null && context.getMappedObject(exclude) == element) {
+ continue;
+ }
+ final String title = element.titleString();
+ final String checked = "";
+ buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"" + elementId + "\"" + checked + " />" + title + "</input><br/>\n");
+ }
+
+ block.replaceContent(field, buffer.toString());
+ }
+ }
+
+ @Override
+ public String getName() {
+ return "radio-list";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/Selector.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/Selector.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/Selector.java
new file mode 100644
index 0000000..e814f28
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/edit/Selector.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.edit;
+
+import java.util.Iterator;
+
+import org.apache.isis.core.commons.exceptions.UnknownTypeException;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.facets.collections.modify.CollectionFacet;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+import org.apache.isis.viewer.scimpi.dispatcher.util.MethodsUtils;
+import org.apache.isis.viewer.scimpi.dispatcher.view.action.ActionForm;
+import org.apache.isis.viewer.scimpi.dispatcher.view.action.CreateFormParameter;
+
+public class Selector extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ final FormFieldBlock block = (FormFieldBlock) request.getBlockContent();
+ final String field = request.getRequiredProperty(FIELD);
+ if (block.isVisible(field)) {
+ processElement(request, block, field);
+ }
+ request.skipUntilClose();
+ }
+
+ private void processElement(final Request request, final FormFieldBlock block, final String field) {
+ final String type = request.getOptionalProperty(TYPE, "dropdown");
+ if (!request.isPropertySpecified(METHOD) && request.isPropertySpecified(COLLECTION)) {
+ final String id = request.getRequiredProperty(COLLECTION, Request.NO_VARIABLE_CHECKING);
+ final String selector = showSelectionList(request, id, block.getCurrent(field), block.isNullable(field), type);
+ block.replaceContent(field, selector);
+ } else {
+ final String objectId = request.getOptionalProperty(OBJECT);
+ final String methodName = request.getRequiredProperty(METHOD);
+ final ObjectAdapter object = MethodsUtils.findObject(request.getContext(), objectId);
+ final ObjectAction action = MethodsUtils.findAction(object, methodName);
+ if (action.getParameterCount() == 0) {
+ final ObjectAdapter collection = action.execute(object, new ObjectAdapter[0]);
+ final String selector = showSelectionList(request, collection, block.getCurrent(field), block.isNullable(field), type);
+ block.replaceContent(field, selector);
+ } else {
+ final String id = "selector_options";
+ final String id2 = (String) request.getContext().getVariable(id);
+ final String selector = showSelectionList(request, id2, block.getCurrent(field), block.isNullable(field), type);
+
+ final CreateFormParameter parameters = new CreateFormParameter();
+ parameters.objectId = objectId;
+ parameters.methodName = methodName;
+ parameters.buttonTitle = request.getOptionalProperty(BUTTON_TITLE, "Search");
+ parameters.formTitle = request.getOptionalProperty(FORM_TITLE);
+ parameters.className = request.getOptionalProperty(CLASS, "selector");
+ parameters.id = request.getOptionalProperty(ID);
+
+ parameters.resultName = id;
+ parameters.forwardResultTo = request.getContext().getResourceFile();
+ parameters.forwardVoidTo = "error";
+ parameters.forwardErrorTo = parameters.forwardResultTo;
+ parameters.scope = Scope.REQUEST.name();
+ request.pushNewBuffer();
+ ActionForm.createForm(request, parameters);
+ block.replaceContent(field, selector);
+
+ request.appendHtml(request.popBuffer());
+ }
+ }
+ }
+
+ private String showSelectionList(final Request request, final String collectionId, final ObjectAdapter selectedItem, final boolean allowNotSet, final String type) {
+ if (collectionId != null && !collectionId.equals("")) {
+ final ObjectAdapter collection = request.getContext().getMappedObjectOrResult(collectionId);
+ return showSelectionList(request, collection, selectedItem, allowNotSet, type);
+ } else {
+ return null;
+ }
+ }
+
+ private String showSelectionList(final Request request, final ObjectAdapter collection, final ObjectAdapter selectedItem, final boolean allowNotSet, final String type) {
+ final String field = request.getRequiredProperty(FIELD);
+ final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
+
+ if (type.equals("radio")) {
+ return radioButtonList(request, field, allowNotSet, collection, selectedItem, facet);
+ } else if (type.equals("list")) {
+ final String size = request.getOptionalProperty("size", "5");
+ return dropdownList(request, field, allowNotSet, collection, selectedItem, size, facet);
+ } else if (type.equals("dropdown")) {
+ return dropdownList(request, field, allowNotSet, collection, selectedItem, null, facet);
+ } else {
+ throw new UnknownTypeException(type);
+ }
+ }
+
+ private String radioButtonList(final Request request, final String field, final boolean allowNotSet, final ObjectAdapter collection, final ObjectAdapter selectedItem, final CollectionFacet facet) {
+ final RequestContext context = request.getContext();
+ final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
+ final StringBuffer buffer = new StringBuffer();
+ if (allowNotSet) {
+ buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"null\"></input><br/>\n");
+ }
+ while (iterator.hasNext()) {
+ final ObjectAdapter element = iterator.next();
+ final String elementId = context.mapObject(element, Scope.INTERACTION);
+ final String title = element.titleString();
+ final String checked = element == selectedItem ? "checked=\"checked\"" : "";
+ buffer.append("<input type=\"radio\" name=\"" + field + "\" value=\"" + elementId + "\"" + checked + ">" + title + "</input><br/>\n");
+ }
+
+ return buffer.toString();
+ }
+
+ private String dropdownList(final Request request, final String field, final boolean allowNotSet, final ObjectAdapter collection, final ObjectAdapter selectedItem, String size, final CollectionFacet facet) {
+ final RequestContext context = request.getContext();
+ final Iterator<ObjectAdapter> iterator = facet.iterator(collection);
+ final StringBuffer buffer = new StringBuffer();
+ size = size == null ? "" : " size =\"" + size + "\"";
+ buffer.append("<select name=\"" + field + "\"" + size + " >\n");
+ if (allowNotSet) {
+ buffer.append(" <option value=\"null\"></option>\n");
+ }
+ while (iterator.hasNext()) {
+ final ObjectAdapter element = iterator.next();
+ final String elementId = context.mapObject(element, Scope.INTERACTION);
+ final String title = element.titleString();
+ final String checked = element == selectedItem ? "selected=\"selected\"" : "";
+ buffer.append(" <option value=\"" + elementId + "\"" + checked + ">" + title + "</option>\n");
+ }
+ buffer.append("</select>\n");
+ return buffer.toString();
+ }
+
+ @Override
+ public String getName() {
+ return "selector";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/ExcludeField.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/ExcludeField.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/ExcludeField.java
new file mode 100644
index 0000000..0c12990
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/ExcludeField.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.field;
+
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class ExcludeField extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ final String field = request.getOptionalProperty(NAME);
+ final InclusionList block = (InclusionList) request.getBlockContent();
+ block.exclude(field);
+ }
+
+ @Override
+ public String getName() {
+ return "exclude";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/IncludeField.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/IncludeField.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/IncludeField.java
new file mode 100644
index 0000000..bff9858
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/IncludeField.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.field;
+
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class IncludeField extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ final String field = request.getOptionalProperty(NAME);
+ final InclusionList block = (InclusionList) request.getBlockContent();
+ block.include(field);
+ }
+
+ @Override
+ public String getName() {
+ return "include";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/InclusionList.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/InclusionList.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/InclusionList.java
new file mode 100644
index 0000000..1fdc2f6
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/InclusionList.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.field;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.Lists;
+
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+import org.apache.isis.viewer.scimpi.dispatcher.BlockContent;
+import org.apache.isis.viewer.scimpi.dispatcher.view.form.InputField;
+
+public class InclusionList implements BlockContent {
+ private final Set<String> includedList = new HashSet<String>();
+ private final Set<String> excludedList = new HashSet<String>();
+
+ private boolean inIncludedList(final String fieldName) {
+ return includedList.size() == 0 || includedList.contains(fieldName) || includedList.contains("all");
+ }
+
+ private boolean inExcludedList(final String fieldName) {
+ return excludedList.contains(fieldName) || excludedList.contains("all");
+ }
+
+ public void include(final String field) {
+ includedList.add(field);
+ }
+
+ public void exclude(final String field) {
+ excludedList.add(field);
+ }
+
+ public List<ObjectAssociation> includedFields(final List<ObjectAssociation> originalFields) {
+ final List<ObjectAssociation> includedFields = Lists.newArrayList();
+ for (int i = 0; i < originalFields.size(); i++) {
+ final String id2 = originalFields.get(i).getId();
+ if (includes(id2)) {
+ includedFields.add(originalFields.get(i));
+ }
+ }
+
+ return includedFields;
+ }
+
+ public void hideExcludedParameters(final InputField[] inputFields) {
+ for (final InputField inputField : inputFields) {
+ final String id2 = inputField.getName();
+ if (!includes(id2)) {
+ inputField.setHidden(true);
+ }
+ }
+ }
+
+ public boolean includes(final String id) {
+ return inIncludedList(id) && !inExcludedList(id);
+ }
+
+ public List<ObjectAction> includedActions(final List<ObjectAction> originalActions) {
+ final List<ObjectAction> includedActions = Lists.newArrayList();
+ for (int i = 0; i < originalActions.size(); i++) {
+ final String id2 = originalActions.get(i).getId();
+ if (includes(id2)) {
+ includedActions.add(originalActions.get(i));
+ }
+ }
+
+ return includedActions;
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkField.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkField.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkField.java
new file mode 100644
index 0000000..74a24e6
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkField.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.field;
+
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.Dispatcher;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class LinkField extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ final String field = request.getOptionalProperty(NAME);
+ final String variable = request.getOptionalProperty(REFERENCE_NAME, RequestContext.RESULT);
+ final String scope = request.getOptionalProperty(SCOPE, Scope.INTERACTION.toString());
+ final String forwardView = request.getOptionalProperty(VIEW, "_generic." + Dispatcher.EXTENSION);
+ final LinkedFieldsBlock tag = (LinkedFieldsBlock) request.getBlockContent();
+ tag.link(field, variable, scope, forwardView);
+ }
+
+ @Override
+ public String getName() {
+ return "link";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedFieldsBlock.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedFieldsBlock.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedFieldsBlock.java
new file mode 100644
index 0000000..5049a3d
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedFieldsBlock.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.field;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
+
+public class LinkedFieldsBlock extends InclusionList {
+ private final Map<String, LinkedObject> linkedFields = new HashMap<String, LinkedObject>();
+
+ public void link(final String field, final String variable, final String scope, final String forwardView) {
+ include(field);
+ linkedFields.put(field, new LinkedObject(variable, scope, forwardView));
+ }
+
+ public LinkedObject[] linkedFields(final List<ObjectAssociation> fields) {
+ final LinkedObject[] includedFields = new LinkedObject[fields.size()];
+ for (int i = 0; i < fields.size(); i++) {
+ final String id2 = fields.get(i).getId();
+ if (fields.get(i).isOneToOneAssociation() && linkedFields.containsKey(id2)) {
+ includedFields[i] = linkedFields.get(id2);
+ }
+ }
+ return includedFields;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedObject.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedObject.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedObject.java
new file mode 100644
index 0000000..d2c8548
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/field/LinkedObject.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.field;
+
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
+
+public class LinkedObject {
+ private final String variable;
+ private final String scope;
+ private String forwardView;
+
+ public LinkedObject(final String variable, final String scope, final String forwardView) {
+ this.variable = variable;
+ this.scope = scope;
+ this.forwardView = forwardView;
+ }
+
+ public LinkedObject(final String forwardView) {
+ this.forwardView = forwardView;
+ scope = Scope.INTERACTION.toString();
+ variable = RequestContext.RESULT;
+ }
+
+ public String getVariable() {
+ return variable;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public String getForwardView() {
+ return forwardView;
+ }
+
+ public void setForwardView(final String path) {
+ forwardView = path;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HiddenInputField.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HiddenInputField.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HiddenInputField.java
new file mode 100644
index 0000000..9245bc6
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HiddenInputField.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.form;
+
+import org.apache.commons.lang.StringEscapeUtils;
+
+public class HiddenInputField {
+ private final String value;
+ private final String name;
+
+ public HiddenInputField(final String name, final String value) {
+ this.value = value;
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return StringEscapeUtils.escapeHtml(value);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HtmlFormBuilder.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HtmlFormBuilder.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HtmlFormBuilder.java
new file mode 100644
index 0000000..fd44cc8
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/HtmlFormBuilder.java
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.form;
+
+import org.apache.isis.core.commons.exceptions.UnknownTypeException;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+import org.apache.isis.viewer.scimpi.dispatcher.view.HelpLink;
+
+public class HtmlFormBuilder {
+
+ public static void createForm(
+ final Request request,
+ final String action,
+ final HiddenInputField[] hiddenFields,
+ final InputField[] fields,
+ final String className,
+ final String id,
+ final String formTitle,
+ final String labelDelimiter,
+ final String description,
+ final String helpReference,
+ final String buttonTitle,
+ final String errors,
+ final String cancelTo) {
+
+ String classSegment = " class=\"" + className + (id == null ? "\"" : "\" id=\"" + id + "\"");
+ request.appendHtml("<form " + classSegment + " action=\"" + action + "\" method=\"post\" accept-charset=\"UTF-8\">\n");
+ if (formTitle != null && formTitle.trim().length() > 0) {
+ classSegment = " class=\"title\"";
+ request.appendHtml("<div" + classSegment + ">");
+ request.appendAsHtmlEncoded(formTitle);
+ request.appendHtml("</div>\n");
+ }
+
+ // TODO reinstate fieldsets when we can specify them
+ // request.appendHtml("<fieldset>\n");
+
+ final String cls = "errors";
+ if (errors != null) {
+ request.appendHtml("<div class=\"" + cls + "\">");
+ request.appendAsHtmlEncoded(errors);
+ request.appendHtml("</div>");
+ }
+ for (final HiddenInputField hiddenField : hiddenFields) {
+ if (hiddenField == null) {
+ continue;
+ }
+ request.appendHtml(" <input type=\"hidden\" name=\"" + hiddenField.getName() + "\" value=\"");
+ request.appendAsHtmlEncoded(hiddenField.getValue());
+ request.appendHtml("\" />\n");
+ }
+ request.appendHtml(request.getContext().interactionFields());
+ for (final InputField fld : fields) {
+ if (fld.isHidden()) {
+ request.appendHtml(" <input type=\"hidden\" name=\"" + fld.getName() + "\" value=\"");
+ request.appendAsHtmlEncoded(fld.getValue());
+ request.appendHtml("\" />\n");
+ } else {
+ final String errorSegment = fld.getErrorText() == null ? "" : "<span class=\"error\">" + fld.getErrorText() + "</span>";
+ final String fieldSegment = createField(fld);
+ final String helpSegment = HelpLink.createHelpSegment(fld.getDescription(), fld.getHelpReference());
+ final String title = fld.getDescription().equals("") ? "" : " title=\"" + fld.getDescription() + "\"";
+ request.appendHtml(" <div class=\"field " + fld.getName() + "\"><label class=\"label\" " + title + ">");
+ request.appendAsHtmlEncoded(fld.getLabel());
+ request.appendHtml(labelDelimiter + "</label>" + fieldSegment + errorSegment + helpSegment + "</div>\n");
+ }
+ }
+
+ request.appendHtml(" <input class=\"button\" type=\"submit\" value=\"");
+ request.appendAsHtmlEncoded(buttonTitle);
+ request.appendHtml("\" name=\"execute\" />\n");
+ HelpLink.append(request, description, helpReference);
+ // TODO alllow forms to be cancelled, returning to previous page.
+ // request.appendHtml(" <div class=\"action\"><a class=\"button\" href=\"reset\">Cancel</a></div>");
+
+ if (cancelTo != null) {
+ request.appendHtml(" <input class=\"button\" type=\"button\" value=\"");
+ request.appendAsHtmlEncoded("Cancel");
+ request.appendHtml("\" onclick=\"window.location = '" + cancelTo + "'\" name=\"cancel\" />\n");
+ }
+
+ // TODO reinstate fieldsets when we can specify them
+ // request.appendHtml("</fieldset>\n");
+ request.appendHtml("</form>\n");
+ }
+
+ private static String createField(final InputField field) {
+ if (field.isHidden()) {
+ if (field.getType() == InputField.REFERENCE) {
+ return createObjectField(field, "hidden");
+ } else {
+ return "";
+ }
+ } else {
+ if (field.getType() == InputField.HTML) {
+ return "<span class=\"value\">" + field.getHtml() + "</span>";
+ } else if (field.getOptionsText() != null) {
+ return createOptions(field);
+ } else if (field.getType() == InputField.REFERENCE) {
+ return createObjectField(field, "text");
+ } else if (field.getType() == InputField.CHECKBOX) {
+ return createCheckbox(field);
+ } else if (field.getType() == InputField.PASSWORD) {
+ return createPasswordField(field);
+ } else if (field.getType() == InputField.TEXT) {
+ if (field.getHeight() > 1) {
+ return createTextArea(field);
+ } else {
+ return createTextField(field);
+ }
+ } else {
+ throw new UnknownTypeException(field.toString());
+ }
+ }
+ }
+
+ private static String createObjectField(final InputField field, final String type) {
+ return field.getHtml();
+ }
+
+ private static String createTextArea(final InputField field) {
+ final String columnsSegment = field.getWidth() == 0 ? "" : " cols=\"" + field.getWidth() / field.getHeight() + "\"";
+ final String rowsSegment = field.getHeight() == 0 ? "" : " rows=\"" + field.getHeight() + "\"";
+ final String wrapSegment = !field.isWrapped() ? "" : " wrap=\"off\"";
+ final String requiredSegment = !field.isRequired() ? "" : " class=\"required\"";
+ final String disabled = field.isEditable() ? "" : " disabled=\"disabled\"";
+ final String maxLength = field.getMaxLength() == 0 ? "" : " maxlength=\"" + field.getMaxLength() + "\"";
+ return "<textarea" + requiredSegment + " name=\"" + field.getName() + "\"" + columnsSegment + rowsSegment + wrapSegment
+ + maxLength + disabled + ">" + Request.getEncoder().encoder(field.getValue()) + "</textarea>";
+ }
+
+ private static String createPasswordField(final InputField field) {
+ final String extra = " autocomplete=\"off\"";
+ return createTextField(field, "password", extra);
+ }
+
+ private static String createTextField(final InputField field) {
+ return createTextField(field, "text", "");
+ }
+
+ private static String createTextField(final InputField field, final String type, final String additionalAttributes) {
+ final String value = field.getValue();
+ final String valueSegment = value == null ? "" : " value=\"" + Request.getEncoder().encoder(value) + "\"";
+ final String lengthSegment = field.getWidth() == 0 ? "" : " size=\"" + field.getWidth() + "\"";
+ final String maxLengthSegment = field.getMaxLength() == 0 ? "" : " maxlength=\"" + field.getMaxLength() + "\"";
+ final String requiredSegment = !field.isRequired() ? "" : " required";
+ final String disabled = field.isEditable() ? "" : " disabled=\"disabled\"";
+ return "<input class=\"" + field.getDataType() + requiredSegment + "\" type=\"" + type + "\" name=\"" + field.getName() + "\"" +
+ valueSegment + lengthSegment + maxLengthSegment + disabled + additionalAttributes + " />";
+ }
+
+ private static String createCheckbox(final InputField field) {
+ final String entryText = field.getValue();
+ final String valueSegment = entryText != null && entryText.toLowerCase().equals("true") ? " checked=\"checked\"" : "";
+ final String disabled = field.isEditable() ? "" : " disabled=\"disabled\"";
+ return "<input type=\"checkbox\" name=\"" + field.getName() + "\" value=\"true\" " + valueSegment + disabled + " />";
+ }
+
+ private static String createOptions(final InputField field) {
+ final String[] options = field.getOptionsText();
+ final String[] ids = field.getOptionValues();
+ final int length = options.length;
+ final String classSegment = field.isRequired() && length == 0 ? " class=\"required\"" : "";
+ final String disabled = field.isEditable() ? "" : " disabled=\"disabled\"";
+ final StringBuffer str = new StringBuffer();
+ str.append("\n <select name=\"" + field.getName() + "\"" + disabled + classSegment + ">\n");
+ boolean offerOther = false;
+ for (int i = 0; i < length; i++) {
+ final String selectedSegment = field.getValue() == null || ids[i].equals(field.getValue()) ? " selected=\"selected\"" : "";
+ if (field.getType() == InputField.TEXT && options[i].equals("__other")) {
+ offerOther = true;
+ } else {
+ str.append(" <option value=\"" + Request.getEncoder().encoder(ids[i]) + "\"" + selectedSegment + ">" + Request.getEncoder().encoder(options[i]) + "</option>\n");
+ }
+ }
+ if (!field.isRequired() || length == 0) {
+ final String selectedSegment = field.getValue() == null || field.getValue().equals("") ? " selected=\"selected\"" : "";
+ str.append(" <option value=\"null\"" + selectedSegment + "></option>\n");
+ }
+ if (offerOther) {
+ str.append(" <option value=\"-OTHER-\">Other:</option>\n");
+ }
+ str.append(" </select>");
+ if (field.getType() == InputField.TEXT) {
+ final String lengthSegment = field.getWidth() == 0 ? "" : " size=\"" + field.getWidth() + "\"";
+ final String hideSegment = " style=\"display: none;\" "; // TODO
+ // only
+ // hide
+ // when JS
+ // enabled
+ str.append(" <input type=\"text\" name=\"" + field.getName() + "-other\"" + hideSegment + lengthSegment + disabled + " />");
+ }
+ str.append("\n");
+ return str.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/InputField.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/InputField.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/InputField.java
new file mode 100644
index 0000000..0382cc4
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/form/InputField.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.form;
+
+import org.apache.isis.core.commons.util.ToString;
+
+public class InputField {
+ public static final int REFERENCE = 1;
+ public static final int TEXT = 2;
+ public static final int PASSWORD = 3;
+ public static final int CHECKBOX = 4;
+ public static final int HTML = 5;
+
+ private int type;
+
+ private String label;
+ private String description = "";
+ private String helpReference;
+ private String errorText;
+ private final String name;
+ private String dataType;
+
+ private int maxLength = 0;
+ private int width;
+ private int height = 1;
+ private boolean isWrapped = false;
+
+ private boolean isRequired = true;
+ private boolean isEditable = true;
+ private boolean isHidden = false;
+
+ private String[] optionsText;
+ private String[] optionValues;
+
+ private String value;
+ private String html;
+
+ public InputField(final String name) {
+ this.name = name;
+ }
+
+ public String getErrorText() {
+ return errorText;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getDataType() {
+ return dataType;
+ }
+
+ public String getHelpReference() {
+ return helpReference;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isEditable() {
+ return isEditable;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public String getHtml() {
+ return html;
+ }
+
+ public boolean isHidden() {
+ return isHidden;
+ }
+
+ public String[] getOptionsText() {
+ return optionsText;
+ }
+
+ public String[] getOptionValues() {
+ return optionValues;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public boolean isWrapped() {
+ return isWrapped;
+ }
+
+ public boolean isRequired() {
+ return isRequired;
+ }
+
+ public int getMaxLength() {
+ return maxLength;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setErrorText(final String errorText) {
+ this.errorText = errorText;
+ }
+
+ public void setDescription(final String description) {
+ this.description = description;
+ }
+
+ public void setHelpReference(final String helpReference) {
+ this.helpReference = helpReference;
+ }
+
+ public void setLabel(final String label) {
+ this.label = label;
+ }
+
+ public void setEditable(final boolean isEditable) {
+ this.isEditable = isEditable;
+ isRequired = isRequired && isEditable;
+ }
+
+ public void setValue(final String entryText) {
+ this.value = entryText;
+ }
+
+ public void setHtml(final String html) {
+ this.html = html;
+ }
+
+ public void setHidden(final boolean isHidden) {
+ this.isHidden = isHidden;
+ }
+
+ public void setWidth(final int width) {
+ this.width = width;
+ }
+
+ public void setOptions(final String[] optionsText, final String[] optionValues) {
+ this.optionsText = optionsText;
+ this.optionValues = optionValues;
+ }
+
+ public void setHeight(final int height) {
+ this.height = height;
+ }
+
+ public void setWrapped(final boolean isWrapped) {
+ this.isWrapped = isWrapped;
+ }
+
+ public void setRequired(final boolean isRequired) {
+ this.isRequired = isRequired;
+ }
+
+ public void setMaxLength(final int maxLength) {
+ this.maxLength = maxLength;
+ }
+
+ public void setType(final int type) {
+ this.type = type;
+ }
+
+ public void setDataType(String dataType) {
+ this.dataType = dataType;
+ }
+
+ @Override
+ public String toString() {
+ final ToString str = new ToString(this);
+ str.append("name", name);
+ String typeName;
+ switch (type) {
+ case CHECKBOX:
+ typeName = "checkbox";
+ break;
+ case REFERENCE:
+ typeName = "reference";
+ break;
+ case TEXT:
+ typeName = "text";
+ break;
+ default:
+ typeName = "unset";
+ break;
+ }
+ str.append("type", typeName);
+ str.append("datatype", dataType);
+ str.append("editable", isEditable);
+ str.append("hidden", isHidden);
+ str.append("required", isRequired);
+ return str.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logoff.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logoff.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logoff.java
new file mode 100644
index 0000000..1632f5d
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logoff.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.logon;
+
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.logon.LogoutAction;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class Logoff extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ LogoutAction.logoutUser(request.getContext());
+ }
+
+ @Override
+ public String getName() {
+ return "logoff";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
new file mode 100644
index 0000000..facd79d
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Logon.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.logon;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.isis.core.commons.authentication.AnonymousSession;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext;
+import org.apache.isis.viewer.scimpi.dispatcher.context.RequestContext.Scope;
+import org.apache.isis.viewer.scimpi.dispatcher.edit.FieldEditState;
+import org.apache.isis.viewer.scimpi.dispatcher.edit.FormState;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+import org.apache.isis.viewer.scimpi.dispatcher.view.form.HiddenInputField;
+import org.apache.isis.viewer.scimpi.dispatcher.view.form.HtmlFormBuilder;
+import org.apache.isis.viewer.scimpi.dispatcher.view.form.InputField;
+
+public class Logon extends AbstractElementProcessor {
+
+ @Override
+ public void process(final Request request) {
+ String view = request.getOptionalProperty(VIEW);
+ RequestContext context = request.getContext();
+ if (view == null) {
+ view = (String) context.getVariable("login-path");
+ }
+
+ final boolean isNotLoggedIn = IsisContext.getSession().getAuthenticationSession() instanceof AnonymousSession;
+ if (isNotLoggedIn) {
+ loginForm(request, view);
+ }
+ }
+
+ public static void loginForm(final Request request, final String view) {
+ final String object = request.getOptionalProperty(OBJECT);
+ final String method = request.getOptionalProperty(METHOD, "logon");
+ final String result = request.getOptionalProperty(RESULT_NAME, "_user");
+ final String resultScope = request.getOptionalProperty(SCOPE, Scope.SESSION.name());
+ final String role = request.getOptionalProperty("field", "roles");
+// final String isisUser = request.getOptionalProperty("isis-user", "_web_default");
+ final String formId = request.getOptionalProperty(FORM_ID, request.nextFormId());
+ final String labelDelimiter = request.getOptionalProperty(LABEL_DELIMITER, ":");
+
+ // TODO error if all values are not set (not if use type is not set and all others are still defaults);
+
+ if (object != null) {
+ RequestContext context = request.getContext();
+ context.addVariable(LOGON_OBJECT, object, Scope.SESSION);
+ context.addVariable(LOGON_METHOD, method, Scope.SESSION);
+ context.addVariable(LOGON_RESULT_NAME, result, Scope.SESSION);
+ context.addVariable(LOGON_SCOPE, resultScope, Scope.SESSION);
+ context.addVariable(PREFIX + "roles-field", role, Scope.SESSION);
+// context.addVariable(PREFIX + "isis-user", isisUser, Scope.SESSION);
+ context.addVariable(LOGON_FORM_ID, formId, Scope.SESSION);
+ }
+
+ final String error = request.getOptionalProperty(ERROR, request.getContext().getRequestedFile());
+ final List<HiddenInputField> hiddenFields = new ArrayList<HiddenInputField>();
+ hiddenFields.add(new HiddenInputField(ERROR, error));
+ if (view != null) {
+ hiddenFields.add(new HiddenInputField(VIEW, view));
+ }
+ hiddenFields.add(new HiddenInputField("_" + FORM_ID, formId));
+
+ final FormState entryState = (FormState) request.getContext().getVariable(ENTRY_FIELDS);
+ boolean isforThisForm = entryState != null && entryState.isForForm(formId);
+ if (entryState != null && entryState.isForForm(formId)) {
+ }
+ final InputField nameField = createdField("username", "User Name", InputField.TEXT, isforThisForm ? entryState : null);
+ final String width = request.getOptionalProperty("width");
+ if (width != null) {
+ final int w = Integer.valueOf(width).intValue();
+ nameField.setWidth(w);
+ }
+ final InputField passwordField = createdField("password", "Password", InputField.PASSWORD, isforThisForm ? entryState : null);
+ final InputField[] fields = new InputField[] { nameField, passwordField, };
+
+ final String formTitle = request.getOptionalProperty(FORM_TITLE);
+ final String loginButtonTitle = request.getOptionalProperty(BUTTON_TITLE, "Log in");
+ final String className = request.getOptionalProperty(CLASS, "login");
+ final String id = request.getOptionalProperty(ID, "logon");
+
+ HtmlFormBuilder.createForm(request, "logon.app", hiddenFields.toArray(new HiddenInputField[hiddenFields.size()]), fields,
+ className, id, formTitle, labelDelimiter, null, null, loginButtonTitle,
+ isforThisForm && entryState != null ? entryState.getError() : null , null);
+ }
+
+ protected static InputField createdField(final String fieldName, final String fieldLabel, final int type, final FormState entryState) {
+ final InputField nameField = new InputField(fieldName);
+ nameField.setType(type);
+ nameField.setLabel(fieldLabel);
+ if (entryState != null) {
+ final FieldEditState fieldState = entryState.getField(fieldName);
+ final String entry = fieldState == null ? "" : fieldState.getEntry();
+ nameField.setValue(entry);
+ final String error = fieldState == null ? "" : fieldState.getError();
+ nameField.setErrorText(error);
+ }
+ return nameField;
+ }
+
+ @Override
+ public String getName() {
+ return "logon";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/RestrictAccess.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/RestrictAccess.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/RestrictAccess.java
new file mode 100644
index 0000000..83f2597
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/RestrictAccess.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.viewer.scimpi.dispatcher.view.logon;
+
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.Dispatcher;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class RestrictAccess extends AbstractElementProcessor {
+ private static final String LOGIN_VIEW = "login-view";
+ private static final String DEFAULT_LOGIN_VIEW = "login." + Dispatcher.EXTENSION;
+
+ public String getName() {
+ return "restrict-access";
+ }
+
+ public void process(Request request) {
+ if (!request.getContext().isUserAuthenticated()) {
+ final String view = request.getOptionalProperty(LOGIN_VIEW, DEFAULT_LOGIN_VIEW);
+ request.getContext().redirectTo(view);
+ }
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java
new file mode 100644
index 0000000..17cd472
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/Secure.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.logon;
+
+import org.apache.isis.core.commons.authentication.AnonymousSession;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class Secure extends AbstractElementProcessor {
+ private static final String LOGIN_VIEW = "login-view";
+
+ @Override
+ public void process(final Request request) {
+ final boolean isLoggedIn = !(IsisContext.getSession().getAuthenticationSession() instanceof AnonymousSession);
+ if (!isLoggedIn) {
+ IsisContext.getMessageBroker().addWarning("You are not currently logged in! Please log in so you can continue.");
+ final String view = request.getOptionalProperty(LOGIN_VIEW, "/login.shtml");
+ request.getContext().redirectTo(view);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return "secure";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/2c7cfbfe/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java
----------------------------------------------------------------------
diff --git a/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java
new file mode 100644
index 0000000..4254746
--- /dev/null
+++ b/mothballed/component/viewer/scimpi/dispatcher/src/main/java/org/apache/isis/viewer/scimpi/dispatcher/view/logon/User.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.viewer.scimpi.dispatcher.view.logon;
+
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.viewer.scimpi.dispatcher.AbstractElementProcessor;
+import org.apache.isis.viewer.scimpi.dispatcher.Dispatcher;
+import org.apache.isis.viewer.scimpi.dispatcher.processor.Request;
+
+public class User extends AbstractElementProcessor {
+ private static final String LOGIN_VIEW = "login-view";
+ private static final String DEFAULT_LOGIN_VIEW = "login." + Dispatcher.EXTENSION;
+ private static final String LOGOUT_VIEW = "logout-view";
+ private static final String DEFAULT_LOGOUT_VIEW = "logout." + Dispatcher.EXTENSION;
+
+ @Override
+ public void process(final Request request) {
+ final boolean isAuthenticatedn = request.getContext().isUserAuthenticated();
+ request.appendHtml("<div class=\"user\">");
+ if (isAuthenticatedn) {
+ displayUserAndLogoutLink(request);
+ } else {
+ displayLoginForm(request);
+ }
+ request.appendHtml("</div>");
+ }
+
+ public void displayLoginForm(final Request request) {
+ String loginView = request.getOptionalProperty(LOGIN_VIEW);
+ if (loginView == null) {
+ Logon.loginForm(request, ".");
+ } else {
+ if (loginView.trim().length() == 0) {
+ loginView = DEFAULT_LOGIN_VIEW;
+ }
+ request.appendHtml("<a div class=\"link\" href=\"" + loginView + "\">Log in</a>");
+ }
+ }
+
+ public void displayUserAndLogoutLink(final Request request) {
+ String user = request.getOptionalProperty(NAME);
+ if (user == null) {
+ user = (String) request.getContext().getVariable("_username");
+ }
+ if (user == null) {
+ user = IsisContext.getAuthenticationSession().getUserName();
+ }
+ request.appendHtml("Welcome <span class=\"name\">");
+ request.appendAsHtmlEncoded(user);
+ request.appendHtml("</span>, ");
+ final String logoutView = request.getOptionalProperty(LOGOUT_VIEW, DEFAULT_LOGOUT_VIEW);
+ request.appendHtml("<a class=\"link\" href=\"logout.app?view=" + logoutView + "\">Log out</a>");
+ }
+
+ @Override
+ public String getName() {
+ return "user";
+ }
+
+}