List of usage examples for org.w3c.dom Document getElementById
public Element getElementById(String elementId);
Element
that has an ID attribute with the given value. From source file:org.apereo.portal.layout.dlm.PLFIntegrator.java
private static void mergeChannel(Element plfChild, Element plfParent, Element ilfParent, IntegrationResult result, NodeInfoTracker tracker) { String id = plfChild.getAttribute(Constants.ATT_ID); if (id.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) { // incorporated channel - if a copy of an inc'd channel is in the // plf it is because either it has attribute edits. It does not // imply movement. // That is accomplished by the position set. So see if it still // exists in the ilf for applying changes Document ilf = ilfParent.getOwnerDocument(); Element original = ilf.getElementById(id); if (original == null) { // not there anymore, discard from plf plfParent.removeChild(plfChild); result.setChangedPLF(true);//from w w w. ja v a2 s. c o m return; } // found it, apply changes and see if they had any affect boolean attributeChanged = false; IntegrationResult childChanges = new IntegrationResult(); attributeChanged = EditManager.applyEditSet(plfChild, original); applyChildChanges(plfChild, original, childChanges, tracker); if (attributeChanged == false && !childChanges.isChangedILF()) { // no changes were used so remove this guy from plf. plfParent.removeChild(plfChild); result.setChangedPLF(true); } else result.setChangedILF(true); // need to pass on up whether PLF changed in called methods if (childChanges.isChangedPLF()) result.setChangedPLF(true); } else // plf channel { if (LOG.isInfoEnabled()) LOG.info("merging into ilf channel " + id); if (ilfParent.getAttribute(Constants.ATT_ADD_CHILD_ALLOWED).equals("false")) { if (LOG.isInfoEnabled()) LOG.info("removing from plf disallowed add of channel " + id); plfParent.removeChild(plfChild); result.setChangedPLF(true); } else { appendChild(plfChild, ilfParent, true); result.setChangedILF(true); } } }
From source file:org.apereo.portal.layout.dlm.PLFIntegrator.java
private static void mergeFolder(Element plfChild, Element plfParent, Element ilfParent, IntegrationResult result, NodeInfoTracker tracker) throws PortalException { String id = plfChild.getAttribute(Constants.ATT_ID); if (id.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) { // incorporated folder - if a copy of an inc'd folder is in the // plf it is because either it has attribute edits or there are // nested child changes to be applied. It does not imply movement. // That is accomplished by the position set. So see if it still // exists in the ilf for applying changes Document ilf = ilfParent.getOwnerDocument(); Element original = ilf.getElementById(id); if (original == null) { // not there anymore, discard from plf plfParent.removeChild(plfChild); result.setChangedPLF(true);/* w w w . java 2s . c om*/ return; } // found it, apply changes and see if they had any affect boolean attributeChanged = false; IntegrationResult childChanges = new IntegrationResult(); attributeChanged = EditManager.applyEditSet(plfChild, original); applyChildChanges(plfChild, original, childChanges, tracker); if (attributeChanged == false && !childChanges.isChangedILF()) { // no changes were used so remove this guy from plf. plfParent.removeChild(plfChild); result.setChangedPLF(true); } else result.setChangedILF(true); // need to pass on up whether PLF changed in called methods if (childChanges.isChangedPLF()) result.setChangedPLF(true); } else { // plf folder - the real node. What is being portrayed in this // case is a plf node that is supposed to be added into the ilf // parent if (ilfParent.getAttribute(Constants.ATT_ADD_CHILD_ALLOWED).equals("false")) { // nope, delete directive from plf if (LOG.isInfoEnabled()) LOG.info("removing folder from plf " + id); plfParent.removeChild(plfChild); result.setChangedPLF(true); return; } Element ilfChild = appendChild(plfChild, ilfParent, false); result.setChangedILF(true); IntegrationResult childChanges = new IntegrationResult(); applyChildChanges(plfChild, ilfChild, childChanges, tracker); if (childChanges.isChangedPLF()) result.setChangedPLF(true); } }
From source file:org.apereo.portal.layout.dlm.PositionManager.java
/** This method assembles in the passed in order object a list of NodeInfo objects ordered first by those specified in the position set and whose nodes still exist in the composite view and then by any remaining children in the compViewParent.//from ww w . ja va 2s. c o m */ static void applyOrdering(List<NodeInfo> order, Element compViewParent, Element positionSet, NodeInfoTracker tracker) { // first pull out all visible channel or visible folder children and // put their id's in a list of available children and record their // relative order in the CVP. final Map<String, NodeInfo> available = new LinkedHashMap<String, NodeInfo>(); Element child = (Element) compViewParent.getFirstChild(); Element next = null; int indexInCVP = 0; while (child != null) { next = (Element) child.getNextSibling(); if (child.getAttribute("hidden").equals("false") && (!child.getAttribute("chanID").equals("") || child.getAttribute("type").equals("regular"))) { final NodeInfo nodeInfo = new NodeInfo(child, indexInCVP++); tracker.track(nodeInfo, order, compViewParent, positionSet); final NodeInfo prevNode = available.put(nodeInfo.getId(), nodeInfo); if (prevNode != null) { throw new IllegalStateException("Infinite loop detected in layout. Triggered by " + nodeInfo.getId() + " with already visited node ids: " + available.keySet()); } } child = next; } // now fill the order list using id's from the position set if nodes // having those ids exist in the composite view. Otherwise discard // that position directive. As they are added to the list remove them // from the available nodes in the parent. Document CV = compViewParent.getOwnerDocument(); Element directive = (Element) positionSet.getFirstChild(); while (directive != null) { next = (Element) directive.getNextSibling(); // id of child to move is in the name attrib on the position nodes String id = directive.getAttribute("name"); child = CV.getElementById(id); if (child != null) { // look for the NodeInfo for this node in the available // nodes and if found use that one. Otherwise use a new that // does not include an index in the CVP parent. In either case // indicate the position directive responsible for placing this // NodeInfo object in the list. final String childId = child.getAttribute(Constants.ATT_ID); NodeInfo ni = available.remove(childId); if (ni == null) { ni = new NodeInfo(child); tracker.track(ni, order, compViewParent, positionSet); } ni.setPositionDirective(directive); order.add(ni); } directive = next; } // now append any remaining ids from the available list maintaining // the order that they have there. order.addAll(available.values()); }
From source file:org.apereo.portal.layout.dlm.TabColumnPrefsHandler.java
/** Handles user requests to delete UI elements. For ILF owned nodes it delegates to the DeleteManager to add a delete directive. For PLF owned nodes it deletes the node outright. */// w w w . ja va 2s. com public static void deleteNode(Element compViewNode, Element compViewParent, IPerson person) throws PortalException { String ID = compViewNode.getAttribute(Constants.ATT_ID); if (ID.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) // ilf node DeleteManager.addDeleteDirective(compViewNode, ID, person); else { // plf node Document plf = (Document) person.getAttribute(Constants.PLF); Element node = plf.getElementById(ID); if (node == null) return; Element parent = (Element) node.getParentNode(); if (parent == null) return; parent.removeChild(node); } }
From source file:org.chiba.xml.xforms.connector.file.FileURIResolver.java
/** * Performs link traversal of the <code>file</code> URI and returns the * result as a DOM document./*w ww . j av a 2s . c o m*/ * * @return a DOM node parsed from the <code>file</code> URI. * @throws XFormsException if any error occurred during link traversal. */ public Object resolve() throws XFormsException { try { // create uri URI uri = new URI(getURI()); // use scheme specific part in order to handle UNC names String fileName = uri.getSchemeSpecificPart(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading file '" + fileName + "'"); } // create file File file = new File(fileName); // check for directory if (file.isDirectory()) { return FileURIResolver.buildDirectoryListing(file); } // parse file DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); Document document = factory.newDocumentBuilder().parse(file); // check for fragment identifier if (uri.getFragment() != null) { return document.getElementById(uri.getFragment()); } return document; } catch (Exception e) { throw new XFormsException(e); } }
From source file:org.chiba.xml.xforms.connector.http.HTTPURIResolver.java
/** * Performs link traversal of the <code>http</code> URI and returns the result * as a DOM document./*from w w w. ja v a 2 s . co m*/ * * @return a DOM node parsed from the <code>http</code> URI. * @throws XFormsException if any error occurred during link traversal. */ public Object resolve() throws XFormsException { try { URI uri = new URI(getURI()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("getting '" + uri + "'"); } get(getURIWithoutFragment()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("converting response stream to XML"); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); Document document = factory.newDocumentBuilder().parse(getResponseBody()); if (uri.getFragment() != null) { return document.getElementById(uri.getFragment()); } return document; } catch (Exception e) { throw new XFormsException(e); } }
From source file:org.etudes.component.app.melete.SectionServiceImpl.java
public SectionObjService getNextSection(String curr_id, String seqXML) throws Exception { SubSectionUtilImpl SectionUtil = new SubSectionUtilImpl(); org.w3c.dom.Document sectionDocument = SectionUtil.getSubSectionW3CDOM(seqXML); org.w3c.dom.Element currItem = sectionDocument.getElementById(curr_id); org.w3c.dom.Element nextItem = SectionUtil.getNextSection(currItem); if (nextItem != null) { SectionObjService nextSection = getSection(Integer.parseInt(nextItem.getAttribute("id"))); return nextSection; }/*from w ww . ja va 2 s.c om*/ return null; }
From source file:org.etudes.component.app.melete.SectionServiceImpl.java
public SectionObjService getPrevSection(String curr_id, String seqXML) throws Exception { SubSectionUtilImpl SectionUtil = new SubSectionUtilImpl(); org.w3c.dom.Document sectionDocument = SectionUtil.getSubSectionW3CDOM(seqXML); org.w3c.dom.Element currItem = sectionDocument.getElementById(curr_id); org.w3c.dom.Element prevItem = SectionUtil.getPrevSection(sectionDocument, currItem); if (prevItem != null) { SectionObjService prevSection = getSection(Integer.parseInt(prevItem.getAttribute("id"))); return prevSection; }/*from www . ja va 2s . co m*/ return null; }
From source file:org.jasig.portal.layout.dlm.DistributedLayoutManager.java
protected boolean canMoveNode(IUserLayoutNodeDescription node, IUserLayoutNodeDescription parent, String nextSiblingId) throws PortalException { // are we moving to a new parent? if (!getParentId(node.getId()).equals(parent.getId())) return node.isMoveAllowed() && canAddNode(node, parent, nextSiblingId); // same parent. which direction are we moving? Document uld = this.getUserLayoutDOM(); Element parentE = uld.getElementById(parent.getId()); Element child = (Element) parentE.getFirstChild(); int idx = 0;//from w w w. j av a 2 s.c om int nodeIdx = -1; int sibIdx = -1; while (child != null) { String id = child.getAttribute(Constants.ATT_ID); if (id.equals(node.getId())) nodeIdx = idx; if (id.equals(nextSiblingId)) sibIdx = idx; idx++; child = (Element) child.getNextSibling(); } if (nodeIdx == -1 || // couldn't find node (nextSiblingId != null && sibIdx == -1)) // couldn't find sibling return false; if (nodeIdx < sibIdx || // moving right sibIdx == -1) // appending to end return canMoveRight(node.getId(), nextSiblingId); return canMoveLeft(node.getId(), nextSiblingId); }
From source file:org.jasig.portal.layout.dlm.DistributedLayoutManager.java
/** * Returns the localized name of a folder node or null if none is available. * This method also implements enforcement of user label overrides to * fragment folders purging those overrides if they are no longer allowed * or needed. /*from w ww . j a v a 2 s . co m*/ */ public String getFolderLabel(String nodeId) { IUserLayoutNodeDescription ndesc = getNode(nodeId); if (!(ndesc instanceof IUserLayoutFolderDescription)) return null; IUserLayoutFolderDescription desc = (IUserLayoutFolderDescription) ndesc; boolean editAllowed = desc.isEditAllowed(); String label = desc.getName(); // assume user owned to begin with which means plfId equals nodeId String plfId = nodeId; if (nodeId.startsWith(org.jasig.portal.layout.dlm.Constants.FRAGMENT_ID_USER_PREFIX)) { Document plf = RDBMDistributedLayoutStore.getPLF(owner); Element plfNode = plf.getElementById(nodeId); if (plfNode != null) plfId = plfNode.getAttribute(Constants.ATT_PLF_ID); else plfId = null; // no user mods exist for this node } return label; }