Java Code Examples for java.util.SortedSet#clear()

The following examples show how to use java.util.SortedSet#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CanonicalizerPhysical.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes()) {
        return null;
    }

    // result will contain all the attrs declared directly on that element
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            result.add(attribute);
        }
    }

    return result.iterator();
}
 
Example 2
Source File: CanonicalizerPhysical.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes()) {
        return null;
    }

    // result will contain all the attrs declared directly on that element
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            result.add(attribute);
        }
    }

    return result.iterator();
}
 
Example 3
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * headSet returns set with keys in requested range
 */
public void testDescendingHeadSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.headSet(m4);
    assertTrue(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertFalse(sm.contains(m4));
    assertFalse(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m1, k);
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, set.size());
    assertEquals(m4, set.first());
}
 
Example 4
Source File: CanonicalizerPhysical.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes()) {
        return null;
    }

    // result will contain all the attrs declared directly on that element
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            result.add(attribute);
        }
    }

    return result.iterator();
}
 
Example 5
Source File: TreeSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * headSet returns set with keys in requested range
 */
public void testHeadSetContents() {
    TreeSet set = set5();
    SortedSet sm = set.headSet(four);
    assertTrue(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, set.size());
    assertEquals(four, set.first());
}
 
Example 6
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * headSet returns set with keys in requested range
 */
public void testHeadSetContents() {
    ConcurrentSkipListSet set = set5();
    SortedSet sm = set.headSet(four);
    assertTrue(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(one, k);
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, set.size());
    assertEquals(four, set.first());
}
 
Example 7
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * headSet returns set with keys in requested range
 */
public void testDescendingHeadSetContents() {
    NavigableSet set = dset5();
    SortedSet sm = set.headSet(m4);
    assertTrue(sm.contains(m1));
    assertTrue(sm.contains(m2));
    assertTrue(sm.contains(m3));
    assertFalse(sm.contains(m4));
    assertFalse(sm.contains(m5));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(m1, k);
    k = (Integer)(i.next());
    assertEquals(m2, k);
    k = (Integer)(i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, set.size());
    assertEquals(m4, set.first());
}
 
Example 8
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * Remove condition from HttpSession list and update page display. As authoring rule, all persist only happen when
    * user submit whole page. So this remove is just impact HttpSession values.
    *
    * @param mapping
    * @param surveyConditionForm
    * @param request
    * @param response
    * @return
    */
   @RequestMapping(value = "/removeCondition")
   public String removeCondition(HttpServletRequest request) {

// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, SurveyConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(SurveyConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<SurveyCondition> conditionSet = getSurveyConditionSet(sessionMap);
    List<SurveyCondition> conditionList = new ArrayList<>(conditionSet);
    SurveyCondition condition = conditionList.remove(orderId);
    for (SurveyCondition otherCondition : conditionSet) {
	if (otherCondition.getOrderId() > orderId) {
	    otherCondition.setOrderId(otherCondition.getOrderId() - 1);
	}
    }
    conditionSet.clear();
    conditionSet.addAll(conditionList);
    // add to delList
    List deletedList = getDeletedSurveyConditionList(sessionMap);
    deletedList.add(condition);
}

request.setAttribute(SurveyConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/conditionList";
   }
 
Example 9
Source File: AuthoringConditionController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, QaAppConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);

int orderId = NumberUtils.stringToInt(request.getParameter(QaAppConstants.PARAM_ORDER_ID), -1);
if (orderId != -1) {
    SortedSet<QaCondition> conditionSet = getQaConditionSet(sessionMap);
    List<QaCondition> conditionList = new ArrayList<>(conditionSet);
    // get current and the target item, and switch their sequnece
    QaCondition condition = conditionList.get(orderId);
    QaCondition repCondition;
    if (up) {
	repCondition = conditionList.get(--orderId);
    } else {
	repCondition = conditionList.get(++orderId);
    }
    int upSeqId = repCondition.getOrderId();
    repCondition.setOrderId(condition.getOrderId());
    condition.setOrderId(upSeqId);

    // put back list, it will be sorted again
    conditionSet.clear();
    conditionSet.addAll(conditionList);
}

request.setAttribute(QaAppConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "authoring/conditionList";
   }
 
Example 10
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP

String sessionMapID = WebUtil.readStrParam(request, ImageGalleryConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

int imageIdx = NumberUtils.stringToInt(request.getParameter(ImageGalleryConstants.PARAM_IMAGE_INDEX), -1);
if (imageIdx != -1) {
    SortedSet<ImageGalleryItem> taskListList = getImageList(sessionMap);
    List<ImageGalleryItem> rList = new ArrayList<>(taskListList);
    // get current and the target item, and switch their sequnece
    ImageGalleryItem image = rList.get(imageIdx);
    ImageGalleryItem repImage;
    if (up) {
	repImage = rList.get(--imageIdx);
    } else {
	repImage = rList.get(++imageIdx);
    }
    int upSeqId = repImage.getSequenceId();
    repImage.setSequenceId(image.getSequenceId());
    image.setSequenceId(upSeqId);

    // put back list, it will be sorted again
    taskListList.clear();
    taskListList.addAll(rList);
}

request.setAttribute(ImageGalleryConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/parts/itemlist";
   }
 
Example 11
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String switchItem(HttpServletRequest request, boolean up) {
// get back sessionMAP
String sessionMapID = WebUtil.readStrParam(request, TaskListConstants.ATTR_SESSION_MAP_ID);
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);

int itemIdx = NumberUtils.stringToInt(request.getParameter(TaskListConstants.PARAM_ITEM_INDEX), -1);
if (itemIdx != -1) {
    SortedSet<TaskListItem> taskListList = getTaskListItemList(sessionMap);
    List<TaskListItem> rList = new ArrayList<>(taskListList);
    // get current and the target item, and switch their sequnece
    TaskListItem item = rList.get(itemIdx);
    TaskListItem repItem;
    if (up) {
	repItem = rList.get(--itemIdx);
    } else {
	repItem = rList.get(++itemIdx);
    }
    int upSeqId = repItem.getSequenceId();
    repItem.setSequenceId(item.getSequenceId());
    item.setSequenceId(upSeqId);

    // put back list, it will be sorted again
    taskListList.clear();
    taskListList.addAll(rList);
}

request.setAttribute(TaskListConstants.ATTR_SESSION_MAP_ID, sessionMapID);
return "pages/authoring/parts/itemlist";
   }
 
Example 12
Source File: Canonicalizer11.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well --
 * subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes() && !firstCall) {
        return null;
    }
    // result will contain the attrs which have to be output
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            String NUri = attribute.getNamespaceURI();
            String NName = attribute.getLocalName();
            String NValue = attribute.getValue();

            if (!XMLNS_URI.equals(NUri)) {
                // It's not a namespace attr node. Add to the result and continue.
                result.add(attribute);
            } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
                // The default mapping for xml must not be output.
                Node n = ns.addMappingAndRender(NName, NValue, attribute);

                if (n != null) {
                    // Render the ns definition
                    result.add((Attr)n);
                    if (C14nHelper.namespaceIsRelative(attribute)) {
                        Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
                        throw new CanonicalizationException(
                            "c14n.Canonicalizer.RelativeNamespace", exArgs
                        );
                    }
                }
            }
        }
    }

    if (firstCall) {
        // It is the first node of the subtree
        // Obtain all the namespaces defined in the parents, and added to the output.
        ns.getUnrenderedNodes(result);
        // output the attributes in the xml namespace.
        xmlattrStack.getXmlnsAttr(result);
        firstCall = false;
    }

    return result.iterator();
}
 
Example 13
Source File: Canonicalizer20010315.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes() && !firstCall) {
        return null;
    }
    // result will contain the attrs which have to be output
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            String NUri = attribute.getNamespaceURI();
            String NName = attribute.getLocalName();
            String NValue = attribute.getValue();

            if (!XMLNS_URI.equals(NUri)) {
                //It's not a namespace attr node. Add to the result and continue.
                result.add(attribute);
            } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
                //The default mapping for xml must not be output.
                Node n = ns.addMappingAndRender(NName, NValue, attribute);

                if (n != null) {
                    //Render the ns definition
                    result.add((Attr)n);
                    if (C14nHelper.namespaceIsRelative(attribute)) {
                        Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
                        throw new CanonicalizationException(
                            "c14n.Canonicalizer.RelativeNamespace", exArgs
                        );
                    }
                }
            }
        }
    }

    if (firstCall) {
        //It is the first node of the subtree
        //Obtain all the namespaces defined in the parents, and added to the output.
        ns.getUnrenderedNodes(result);
        //output the attributes in the xml namespace.
        xmlattrStack.getXmlnsAttr(result);
        firstCall = false;
    }

    return result.iterator();
}
 
Example 14
Source File: UnicodeSetTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
void pick(int bits, Object[] examples, SortedSet output) {
    output.clear();
    for (int k = 0; k < 32; ++k) {
        if (((1<<k) & bits) != 0) output.add(examples[k]);
    }
}
 
Example 15
Source File: Canonicalizer20010315.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes() && !firstCall) {
        return null;
    }
    // result will contain the attrs which have to be output
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            String NUri = attribute.getNamespaceURI();
            String NName = attribute.getLocalName();
            String NValue = attribute.getValue();

            if (!XMLNS_URI.equals(NUri)) {
                //It's not a namespace attr node. Add to the result and continue.
                result.add(attribute);
            } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
                //The default mapping for xml must not be output.
                Node n = ns.addMappingAndRender(NName, NValue, attribute);

                if (n != null) {
                    //Render the ns definition
                    result.add((Attr)n);
                    if (C14nHelper.namespaceIsRelative(attribute)) {
                        Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
                        throw new CanonicalizationException(
                            "c14n.Canonicalizer.RelativeNamespace", exArgs
                        );
                    }
                }
            }
        }
    }

    if (firstCall) {
        //It is the first node of the subtree
        //Obtain all the namespaces defined in the parents, and added to the output.
        ns.getUnrenderedNodes(result);
        //output the attributes in the xml namespace.
        xmlattrStack.getXmlnsAttr(result);
        firstCall = false;
    }

    return result.iterator();
}
 
Example 16
Source File: Canonicalizer20010315.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes() && !firstCall) {
        return null;
    }
    // result will contain the attrs which have to be output
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            String NUri = attribute.getNamespaceURI();
            String NName = attribute.getLocalName();
            String NValue = attribute.getValue();

            if (!XMLNS_URI.equals(NUri)) {
                //It's not a namespace attr node. Add to the result and continue.
                result.add(attribute);
            } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
                //The default mapping for xml must not be output.
                Node n = ns.addMappingAndRender(NName, NValue, attribute);

                if (n != null) {
                    //Render the ns definition
                    result.add((Attr)n);
                    if (C14nHelper.namespaceIsRelative(attribute)) {
                        Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
                        throw new CanonicalizationException(
                            "c14n.Canonicalizer.RelativeNamespace", exArgs
                        );
                    }
                }
            }
        }
    }

    if (firstCall) {
        //It is the first node of the subtree
        //Obtain all the namespaces defined in the parents, and added to the output.
        ns.getUnrenderedNodes(result);
        //output the attributes in the xml namespace.
        xmlattrStack.getXmlnsAttr(result);
        firstCall = false;
    }

    return result.iterator();
}
 
Example 17
Source File: SortedSetRelation.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Utility that could be on SortedSet. Allows faster implementation than
 * what is in Java for doing addAll, removeAll, retainAll, (complementAll).
 * @param a first set
 * @param relation the relation filter, using ANY, CONTAINS, etc.
 * @param b second set
 * @return the new set
 */    
public static <T extends Object & Comparable<? super T>> SortedSet<? extends T> doOperation(SortedSet<T> a, int relation, SortedSet<T> b) {
    // TODO: optimize this as above
    TreeSet<? extends T> temp;
    switch (relation) {
        case ADDALL:
            a.addAll(b); 
            return a;
        case A:
            return a; // no action
        case B:
            a.clear(); 
            a.addAll(b); 
            return a;
        case REMOVEALL: 
            a.removeAll(b);
            return a;
        case RETAINALL: 
            a.retainAll(b);
            return a;
        // the following is the only case not really supported by Java
        // although all could be optimized
        case COMPLEMENTALL:
            temp = new TreeSet<T>(b);
            temp.removeAll(a);
            a.removeAll(b);
            a.addAll(temp);
            return a;
        case B_REMOVEALL:
            temp = new TreeSet<T>(b);
            temp.removeAll(a);
            a.clear();
            a.addAll(temp);
            return a;
        case NONE:
            a.clear();
            return a;
        default: 
            throw new IllegalArgumentException("Relation " + relation + " out of range");
    }
}
 
Example 18
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected String starting(@ModelAttribute("authoringForm") DacoForm authoringForm, HttpServletRequest request)
    throws ServletException {

// save toolContentID into HTTPSession
Long contentId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID));

// get back the daco and question list and display them on page

List<DacoQuestion> questions = null;
Daco daco = null;

// initial Session Map
SessionMap<String, Object> sessionMap = new SessionMap<>();
request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap);
authoringForm.setSessionMapID(sessionMap.getSessionID());

// Get contentFolderID and save to form.
String contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID);
authoringForm.setContentFolderID(contentFolderID);
sessionMap.put(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID);

try {
    daco = dacoService.getDacoByContentId(contentId);
    // if daco does not exist, try to use default content instead.
    if (daco == null) {
	daco = dacoService.getDefaultContent(contentId);
	if (daco.getDacoQuestions() == null) {
	    questions = null;
	} else {

	    questions = new ArrayList<>(daco.getDacoQuestions());
	}
    } else {

	questions = new ArrayList<>(daco.getDacoQuestions());
    }

    authoringForm.setDaco(daco);
} catch (Exception e) {
    AuthoringController.log.error(e);
    throw new ServletException(e);
}

// init it to avoid null exception in following handling
if (questions == null) {
    questions = new ArrayList<>();
} else {
    DacoUser dacoUser = null;
    // handle system default question: createBy is null, now set it to
    // current user
    for (DacoQuestion question : questions) {
	if (question.getCreateBy() == null) {
	    if (dacoUser == null) {
		// get back login user DTO
		HttpSession ss = SessionManager.getSession();
		UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
		dacoUser = new DacoUser(user, daco);
	    }
	    question.setCreateBy(dacoUser);
	}
    }
}

// init daco question list
SortedSet<DacoQuestion> dacoQuestionList = getQuestionList(sessionMap);
dacoQuestionList.clear();
dacoQuestionList.addAll(questions);

sessionMap.put(DacoConstants.ATTR_DACO_FORM, authoringForm);
request.getSession().setAttribute(AttributeNames.PARAM_NOTIFY_CLOSE_URL,
	request.getParameter(AttributeNames.PARAM_NOTIFY_CLOSE_URL));

return "pages/authoring/start";
   }
 
Example 19
Source File: Canonicalizer11.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well --
 * subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes() && !firstCall) {
        return null;
    }
    // result will contain the attrs which have to be output
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            String NUri = attribute.getNamespaceURI();
            String NName = attribute.getLocalName();
            String NValue = attribute.getValue();

            if (!XMLNS_URI.equals(NUri)) {
                // It's not a namespace attr node. Add to the result and continue.
                result.add(attribute);
            } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
                // The default mapping for xml must not be output.
                Node n = ns.addMappingAndRender(NName, NValue, attribute);

                if (n != null) {
                    // Render the ns definition
                    result.add((Attr)n);
                    if (C14nHelper.namespaceIsRelative(attribute)) {
                        Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
                        throw new CanonicalizationException(
                            "c14n.Canonicalizer.RelativeNamespace", exArgs
                        );
                    }
                }
            }
        }
    }

    if (firstCall) {
        // It is the first node of the subtree
        // Obtain all the namespaces defined in the parents, and added to the output.
        ns.getUnrenderedNodes(result);
        // output the attributes in the xml namespace.
        xmlattrStack.getXmlnsAttr(result);
        firstCall = false;
    }

    return result.iterator();
}
 
Example 20
Source File: Canonicalizer20010315.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes() && !firstCall) {
        return null;
    }
    // result will contain the attrs which have to be output
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            String NUri = attribute.getNamespaceURI();
            String NName = attribute.getLocalName();
            String NValue = attribute.getValue();

            if (!XMLNS_URI.equals(NUri)) {
                //It's not a namespace attr node. Add to the result and continue.
                result.add(attribute);
            } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
                //The default mapping for xml must not be output.
                Node n = ns.addMappingAndRender(NName, NValue, attribute);

                if (n != null) {
                    //Render the ns definition
                    result.add((Attr)n);
                    if (C14nHelper.namespaceIsRelative(attribute)) {
                        Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
                        throw new CanonicalizationException(
                            "c14n.Canonicalizer.RelativeNamespace", exArgs
                        );
                    }
                }
            }
        }
    }

    if (firstCall) {
        //It is the first node of the subtree
        //Obtain all the namespaces defined in the parents, and added to the output.
        ns.getUnrenderedNodes(result);
        //output the attributes in the xml namespace.
        xmlattrStack.getXmlnsAttr(result);
        firstCall = false;
    }

    return result.iterator();
}