Skip to main content
summaryrefslogtreecommitdiffstats
blob: 157a5ce61d63ebcc691581f7562daa3af9e58716 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.app;

import static org.eclipse.osee.framework.core.enums.BranchState.CREATED;
import static org.eclipse.osee.framework.core.enums.BranchState.MODIFIED;
import static org.eclipse.osee.framework.core.enums.BranchType.BASELINE;
import static org.eclipse.osee.framework.core.enums.BranchType.WORKING;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.jdk.core.type.ClassBasedResourceToken;
import org.eclipse.osee.framework.jdk.core.type.IResourceRegistry;
import org.eclipse.osee.framework.jdk.core.type.ResourceToken;
import org.eclipse.osee.orcs.data.BranchReadable;
import org.eclipse.osee.orcs.search.BranchQuery;
import org.eclipse.osee.template.engine.AppendableRule;
import org.eclipse.osee.template.engine.CompositeRule;
import org.eclipse.osee.template.engine.IdentifiableLongOptionsRule;
import org.eclipse.osee.template.engine.PageCreator;
import org.eclipse.osee.template.engine.PageFactory;

/**
 * @author Ryan D. Brooks
 * @author David W. Miller
 */
public class OseeAppletPage {

   //example input for pattern:  <input id="selected_branch" type="text" list="baselineBranches" required/><br />
   private static final Pattern listAttributePattern = Pattern.compile("<input[^>]+?list=\"([^\"]+)");
   private final BranchQuery query;

   public OseeAppletPage(BranchQuery query) {
      this.query = query;
   }

   public String realizeApplet(String name, Class<?> clazz) {
      ResourceToken valuesToken = new ClassBasedResourceToken(name, clazz);
      return realizeApplet(null, valuesToken);
   }

   public String realizeApplet(IResourceRegistry registry, String name, Class<?> clazz) {
      ResourceToken valuesToken = new ClassBasedResourceToken(name, clazz);
      return realizeApplet(registry, valuesToken);
   }

   public String realizeApplet(IResourceRegistry registry, String name, Class<?> clazz, AppendableRule<?>... rules) {
      ResourceToken valuesToken = new ClassBasedResourceToken(name, clazz);
      PageCreator page = PageFactory.newPageCreatorWithRules(registry, valuesToken, rules);

      return realizeApplet(page);
   }

   public String realizeApplet(IResourceRegistry registry, ResourceToken valuesToken) {
      PageCreator page = PageFactory.newPageCreator(registry, valuesToken);
      return realizeApplet(page);
   }

   public String realizeApplet(PageCreator page) {
      CharSequence widgets = page.getValue("widgets");
      Matcher matcher = listAttributePattern.matcher(widgets);

      CompositeRule<BranchReadable> dataListsRule = new CompositeRule<>("dataLists");
      while (matcher.find()) {
         String listId = matcher.group(1);
         if (listId.equals("baselineBranches") || listId.equals("workingAndBaselineBranches")) {
            if (!dataListsRule.ruleExists(listId)) {
               Iterable<BranchReadable> options = getBranchOptions(query, listId);
               dataListsRule.addRule(new IdentifiableLongOptionsRule<BranchReadable>("", options, listId));
            }
         }
      }
      page.addSubstitution(dataListsRule);

      return page.realizePage(OseeAppResourceTokens.OseeAppHtml);
   }

   private Iterable<BranchReadable> getBranchOptions(BranchQuery query, String listId) {
      BranchType[] branchTypes =
         listId.equals("baselineBranches") ? new BranchType[] {BASELINE} : new BranchType[] {BASELINE, WORKING};
      query.andIsOfType(branchTypes);
      query.andStateIs(CREATED, MODIFIED);

      return query.getResults();
   }
}

Back to the top