List of usage examples for org.w3c.dom Element getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:org.apereo.portal.layout.dlm.PositionManager.java
/** This method applies the ordering specified in the passed in order list to the child nodes of the compViewParent. Nodes specified in the list but located elsewhere are pulled in./* w w w. j a v a2 s. c o m*/ */ static void applyToNodes(List<NodeInfo> order, Element compViewParent) { // first set up a bogus node to assist with inserting Node insertPoint = compViewParent.getOwnerDocument().createElement("bogus"); Node first = compViewParent.getFirstChild(); if (first != null) compViewParent.insertBefore(insertPoint, first); else compViewParent.appendChild(insertPoint); // now pass through the order list inserting the nodes as you go for (int i = 0; i < order.size(); i++) compViewParent.insertBefore(order.get(i).getNode(), insertPoint); compViewParent.removeChild(insertPoint); }
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 www . jav a 2 s .c om */ 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.PositionManager.java
/** This method locates the position set element in the child list of the passed in plfParent or if not found it will create one automatically and return it if the passed in create flag is true. *///from w w w.j a v a 2 s.c o m private static Element getPositionSet(Element plfParent, IPerson person, boolean create) throws PortalException { Node child = plfParent.getFirstChild(); while (child != null) { if (child.getNodeName().equals(Constants.ELM_POSITION_SET)) return (Element) child; child = child.getNextSibling(); } if (create == false) return null; String ID = null; try { ID = getDLS().getNextStructDirectiveId(person); } catch (Exception e) { throw new PortalException("Exception encountered while " + "generating new position set node " + "Id for userId=" + person.getID(), e); } Document plf = plfParent.getOwnerDocument(); Element positions = plf.createElement(Constants.ELM_POSITION_SET); positions.setAttribute(Constants.ATT_TYPE, Constants.ELM_POSITION_SET); positions.setAttribute(Constants.ATT_ID, ID); plfParent.appendChild(positions); return positions; }
From source file:org.apereo.portal.layout.dlm.PositionManager.java
/** Create, append to the passed in position set, and return a position element that references the passed in elementID. *///from w w w. j a v a2s . co m private static Element createAndAppendPosition(String elementID, Element positions, IPerson person) throws PortalException { if (LOG.isDebugEnabled()) LOG.debug("Adding Position Set entry " + elementID + "."); String ID = null; try { ID = getDLS().getNextStructDirectiveId(person); } catch (Exception e) { throw new PortalException("Exception encountered while " + "generating new position node " + "Id for userId=" + person.getID(), e); } Document plf = positions.getOwnerDocument(); Element position = plf.createElement(Constants.ELM_POSITION); position.setAttribute(Constants.ATT_TYPE, Constants.ELM_POSITION); position.setAttribute(Constants.ATT_ID, ID); position.setAttributeNS(Constants.NS_URI, Constants.ATT_NAME, elementID); positions.appendChild(position); return position; }
From source file:org.apereo.portal.layout.dlm.RDBMDistributedLayoutStore.java
/** * Returns the layout for a user. This method overrides the same * method in the superclass to return a composite layout for non * fragment owners and a regular layout for layout owners. A * composite layout is made up of layout pieces from potentially * multiple incorporated layouts. If no layouts are defined then * the composite layout will be the same as the user's personal * layout fragment or PLF, the one holding only those UI elements * that they own or incorporated elements that they have been * allowed to changed./*from ww w . ja va2 s . c o m*/ **/ private DistributedUserLayout _getUserLayout(IPerson person, IUserProfile profile) { final String userName = (String) person.getAttribute("username"); final FragmentDefinition ownedFragment = this.fragmentUtils.getFragmentDefinitionByOwner(person); final boolean isLayoutOwnerDefault = this.isLayoutOwnerDefault(person); final Set<String> fragmentNames = new LinkedHashSet<String>(); final Document ILF; final Document PLF = this.getPLF(person, profile); // If this user is an owner then ownedFragment will be non null. For // fragment owners and owners of any default layout from which a // fragment owners layout is copied there should not be any imported // distributed layouts. Instead, load their PLF, mark as an owned // if a fragment owner, and return. if (ownedFragment != null || isLayoutOwnerDefault) { ILF = (Document) PLF.cloneNode(true); final Element layoutNode = ILF.getDocumentElement(); final Element ownerDocument = layoutNode.getOwnerDocument().getDocumentElement(); final NodeList channelNodes = ownerDocument.getElementsByTagName("channel"); for (int i = 0; i < channelNodes.getLength(); i++) { Element channelNode = (Element) channelNodes.item(i); final Node chanIdNode = channelNode.getAttributeNode("chanID"); if (chanIdNode == null || MissingPortletDefinition.CHANNEL_ID.equals(chanIdNode.getNodeValue())) { channelNode.getParentNode().removeChild(channelNode); } } if (ownedFragment != null) { fragmentNames.add(ownedFragment.getName()); layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_FRAGMENT_NAME, ownedFragment.getName()); logger.debug("User '{}' is owner of '{}' fragment.", userName, ownedFragment.getName()); } else if (isLayoutOwnerDefault) { layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_IS_TEMPLATE_USER, "true"); layoutNode.setAttributeNS(Constants.NS_URI, Constants.ATT_TEMPLATE_LOGIN_ID, (String) person.getAttribute("username")); } } else { final Locale locale = profile.getLocaleManager().getLocales()[0]; final List<FragmentDefinition> applicableFragmentDefinitions = this.fragmentUtils .getFragmentDefinitionsApplicableToPerson(person); final List<Document> applicableLayouts = this.fragmentUtils .getFragmentDefinitionUserViewLayouts(applicableFragmentDefinitions, locale); final IntegrationResult integrationResult = new IntegrationResult(); ILF = this.createCompositeILF(person, PLF, applicableLayouts, integrationResult); // push optimizations made during merge back into db. if (integrationResult.isChangedPLF()) { if (logger.isDebugEnabled()) { logger.debug("Saving PLF for {} due to changes during merge.", person.getAttribute(IPerson.USERNAME)); } super.setUserLayout(person, profile, PLF, false); } fragmentNames.addAll(this.fragmentUtils.getFragmentNames(applicableFragmentDefinitions)); } return this.createDistributedUserLayout(person, profile, ILF, fragmentNames); }
From source file:org.asimba.idp.profile.catalog.saml2.SAML2Catalog.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s. c o m*/ */ public void service(HttpServletRequest oRequest, HttpServletResponse oResponse) throws OAException { // Prepare requestors first: List<IRequestor> lRequestors = getRequestors(oRequest); // low-cost // Prepare identity providers next: List<IIDP> lIDPs = getIDPs(oRequest); // Build catalog in EntitiesDescriptor CatalogEntitiesDescriptorBuilder oCatalogRoot = new CatalogEntitiesDescriptorBuilder(_oConfigManager, Engine.getInstance().getServer()); // Establish our local EntityDescriptor that is the endpoint // on behalf of the proxied system EntityDescriptor oTheAsimbaEntityDescriptor = SAML2Exchange.getEntityDescriptor(_sLinkedSAML2IDPProfileID); // Add SP's for (IRequestor r : lRequestors) { SAML2Requestor s2req = getSAML2Requestor(r); // In transparant mode, we just echo the endpoints of the SP if (_sPublishMode.equals(PUBLISHMODE_TRANSPARANT)) { if (s2req == null) { _oLogger.info("Skipping SP '" + r.getID() + "' in SAML2 Catalog because it is not a SAML2 SP"); continue; } EntityDescriptor oED = getTransparantSPEntityDescriptor(s2req); if (oED != null) { oCatalogRoot.addEntityDescriptor(oED); } continue; } // In proxy-mode, we rewrite the endpoints to the linked SAML SP profile (authmethod) if (_sPublishMode.equals(PUBLISHMODE_PROXY)) { EntityDescriptor oED = getProxiedSPEntityDescriptor(r, oTheAsimbaEntityDescriptor); if (oED != null) { oCatalogRoot.addEntityDescriptor(oED); } continue; } } // Add IDP's for (IIDP idp : lIDPs) { SAML2IDP oSAML2IDP = getSAML2IDP(idp); if (_sPublishMode.equals(PUBLISHMODE_TRANSPARANT)) { if (oSAML2IDP == null) { _oLogger.warn( "Skipping IDP '" + idp.getID() + "' in SAML2 Catalog because it is not a SAML2 IDP"); continue; } EntityDescriptor oED = getTransparantIDPEntityDescriptor(oSAML2IDP); if (oED != null) { oCatalogRoot.addEntityDescriptor(oED); } continue; } // In proxy-mode, we rewrite the endpoints to the linked SAML SP profile (authmethod) if (_sPublishMode.equals(PUBLISHMODE_PROXY)) { EntityDescriptor oED = getProxiedIDPEntityDescriptor(idp, oTheAsimbaEntityDescriptor); if (oED != null) { oCatalogRoot.addEntityDescriptor(oED); } continue; } } EntitiesDescriptor o = oCatalogRoot.getEntitiesDescriptor(); // Now marshall this to XML try { MarshallerFactory marshallerFactory = Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(o); Element e = marshaller.marshall(o); PrintWriter oPW = oResponse.getWriter(); String s = XMLUtils.getStringFromDocument(e.getOwnerDocument()); oPW.write(s); oPW.close(); return; } catch (MarshallingException e) { _oLogger.error("Could not marshall EntitiesDescriptor catalog to DOM: " + e.getMessage()); throw new OAException(SystemErrors.ERROR_INTERNAL); } catch (IOException e) { _oLogger.error("Could not write output: " + e.getMessage()); throw new OAException(SystemErrors.ERROR_INTERNAL); } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
private void addAttributeSet(Document xForm, Element modelSection, Element formSection, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, boolean checkIfExtension) { XSObjectList attrUses = controlType.getAttributeUses(); if (attrUses != null) { int nbAttr = attrUses.getLength(); for (int i = 0; i < nbAttr; i++) { XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i); XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration(); //test if extended ! if (checkIfExtension && this.doesAttributeComeFromExtension(currentAttributeUse, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(/* w ww.j a v a 2 s . co m*/ "This attribute comes from an extension: recopy form controls. \n Model section: "); DOMUtil.prettyPrintDOM(modelSection); } String attributeName = currentAttributeUse.getName(); if (attributeName == null || attributeName.equals("")) attributeName = currentAttributeUse.getAttrDeclaration().getName(); //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int j = 0; int nb = binds.getLength(); String bindId = null; while (j < nb && bindId == null) { Element bind = (Element) binds.item(j); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null) { String name = nodeset.substring(1); //remove "@" in nodeset if (name.equals(attributeName)) bindId = bind.getAttributeNS(XFORMS_NS, "id"); } j++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); formSection.appendChild(newControl); } } else { String newPathToRoot; if ((pathToRoot == null) || pathToRoot.equals("")) { newPathToRoot = "@" + currentAttribute.getName(); } else if (pathToRoot.endsWith("/")) { newPathToRoot = pathToRoot + "@" + currentAttribute.getName(); } else { newPathToRoot = pathToRoot + "/@" + currentAttribute.getName(); } XSSimpleTypeDefinition simpleType = currentAttribute.getTypeDefinition(); //TODO SRA: UrType ? /*if(simpleType==null){ simpleType=new UrType(); }*/ addSimpleType(xForm, modelSection, formSection, simpleType, currentAttributeUse, newPathToRoot); } } } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
/** * checkIfExtension: if false, addElement is called wether it is an extension or not * if true, if it is an extension, element is recopied (and no additional bind) *//*from w ww . ja v a 2 s . c o m*/ private void addGroup(Document xForm, Element modelSection, Element formSection, XSModelGroup group, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, int minOccurs, int maxOccurs, boolean checkIfExtension) { if (group != null) { Element repeatSection = addRepeatIfNecessary(xForm, modelSection, formSection, owner.getTypeDefinition(), minOccurs, maxOccurs, pathToRoot); Element repeatContentWrapper = repeatSection; if (repeatSection != formSection) { //selector -> no more needed? //this.addSelector(xForm, repeatSection); //group wrapper repeatContentWrapper = _wrapper.createGroupContentWrapper(repeatSection); } if (LOGGER.isDebugEnabled()) LOGGER.debug( "addGroup from owner=" + owner.getName() + " and controlType=" + controlType.getName()); XSObjectList particles = group.getParticles(); for (int counter = 0; counter < particles.getLength(); counter++) { XSParticle currentNode = (XSParticle) particles.item(counter); XSTerm term = currentNode.getTerm(); if (LOGGER.isDebugEnabled()) LOGGER.debug(" : next term = " + term.getName()); int childMaxOccurs = currentNode.getMaxOccurs(); if (currentNode.getMaxOccursUnbounded()) childMaxOccurs = -1; int childMinOccurs = currentNode.getMinOccurs(); if (term instanceof XSModelGroup) { if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is a group"); addGroup(xForm, modelSection, repeatContentWrapper, ((XSModelGroup) term), controlType, owner, pathToRoot, childMinOccurs, childMaxOccurs, checkIfExtension); } else if (term instanceof XSElementDeclaration) { XSElementDeclaration element = (XSElementDeclaration) term; if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is an element declaration: " + term.getName()); //special case for types already added because used in an extension //do not add it when it comes from an extension !!! //-> make a copy from the existing form control if (checkIfExtension && this.doesElementComeFromExtension(element, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "This element comes from an extension: recopy form controls.\n Model Section="); DOMUtil.prettyPrintDOM(modelSection); } //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int i = 0; int nb = binds.getLength(); String bindId = null; while (i < nb && bindId == null) { Element bind = (Element) binds.item(i); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null && nodeset.equals(element.getName())) bindId = bind.getAttributeNS(XFORMS_NS, "id"); i++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); repeatContentWrapper.appendChild(newControl); } } else { //add it normally String elementName = getElementName(element, xForm); String path = pathToRoot + "/" + elementName; if (pathToRoot.equals("")) { //relative path = elementName; } addElement(xForm, modelSection, repeatContentWrapper, element, element.getTypeDefinition(), path); } } else { //XSWildcard -> ignore ? //LOGGER.warn("XSWildcard found in group from "+owner.getName()+" for pathToRoot="+pathToRoot); } } if (LOGGER.isDebugEnabled()) LOGGER.debug("--- end of addGroup from owner=" + owner.getName()); } }
From source file:org.chiba.xml.xforms.connector.ConnectorFactory.java
protected ChibaBean getProcessor(Element e) { ElementNSImpl elementNS = (ElementNSImpl) e.getOwnerDocument().getDocumentElement(); Object o = elementNS.getUserData(); if (o instanceof Container) { return ((Container) o).getProcessor(); }//from w w w . jav a 2 s.c om return null; }
From source file:org.chiba.xml.xforms.constraints.RelevanceSelector.java
private static void addElement(Element relevantParent, NodeImpl instanceNode) { Document relevantDocument = relevantParent.getOwnerDocument(); Element relevantElement;//from w ww .j a v a 2 s .c o m if (instanceNode.getNamespaceURI() == null) { relevantElement = relevantDocument.createElement(instanceNode.getNodeName()); } else { relevantElement = relevantDocument.createElementNS(instanceNode.getNamespaceURI(), instanceNode.getNodeName()); } // needed in instance serializer ... ((NodeImpl) relevantElement).setUserData(instanceNode.getUserData()); relevantParent.appendChild(relevantElement); addAttributes(relevantElement, instanceNode); addChildren(relevantElement, instanceNode); }