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.jasig.portal.layout.dlm.PLFIntegrator.java
private static void mergeChannel(Element plfChild, Element plfParent, Element ilfParent, IntegrationResult result) {/*from ww w . j a v a2 s.co m*/ 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.changedPLF = true; 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); if (attributeChanged == false && childChanges.changedILF == false) { // no changes were used so remove this guy from plf. plfParent.removeChild(plfChild); result.changedPLF = true; } else result.changedILF = true; // need to pass on up whether PLF changed in called methods if (childChanges.changedPLF) result.changedPLF = 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.changedPLF = true; } else { appendChild(plfChild, ilfParent, true); result.changedILF = true; } } }
From source file:org.jasig.portal.layout.dlm.PLFIntegrator.java
private static void mergeFolder(Element plfChild, Element plfParent, Element ilfParent, IntegrationResult result) 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.changedPLF = true;/*from ww w .j a v a 2 s. 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); if (attributeChanged == false && childChanges.changedILF == false) { // no changes were used so remove this guy from plf. plfParent.removeChild(plfChild); result.changedPLF = true; } else result.changedILF = true; // need to pass on up whether PLF changed in called methods if (childChanges.changedPLF) result.changedPLF = 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.changedPLF = true; return; } Element ilfChild = appendChild(plfChild, ilfParent, false); result.changedILF = true; IntegrationResult childChanges = new IntegrationResult(); applyChildChanges(plfChild, ilfChild, childChanges); if (childChanges.changedPLF) result.changedPLF = true; } }
From source file:org.jasig.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./*w w w . j av a 2s . c o m*/ */ static void applyOrdering(List<NodeInfo> order, Element compViewParent, Element positionSet) { // 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++); final NodeInfo prevNode = available.put(nodeInfo.id, nodeInfo); if (prevNode != null) { throw new IllegalStateException("Infinite loop detected in layout. Triggered by " + nodeInfo.id + " 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); } ni.positionDirective = 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.kuali.test.handlers.parameter.SelectEditDocumentLookupHandler.java
protected Element findLookupTable(Document htmlDocument) { Element retval = null;//from www. j ava 2s .c om retval = htmlDocument.getElementById(Constants.LOOKUP_RESULTS_TABLE_ID); if (retval == null) { NodeList l = htmlDocument.getDocumentElement().getElementsByTagName(Constants.HTML_TAG_TYPE_TABLE); for (int i = 0; i < l.getLength(); ++i) { Node node = l.item(i); Node classatt = node.getAttributes().getNamedItem(Constants.HTML_TAG_ATTRIBUTE_CLASS); Node idatt = node.getAttributes().getNamedItem(Constants.HTML_TAG_ATTRIBUTE_ID); if ((idatt != null) && (classatt != null) && idatt.getNodeValue().equals(Constants.LOOKUP_RESULTS_TABLE_ID) && classatt.getNodeValue().equals(Constants.LOOKUP_RESULTS_TABLE_CLASS)) { retval = (Element) node; break; } } } return retval; }
From source file:org.pentaho.di.ui.spoon.Spoon.java
public void addMenuLast() { org.pentaho.ui.xul.dom.Document doc = mainSpoonContainer.getDocumentRoot(); JfaceMenupopup recentFilesPopup = (JfaceMenupopup) doc.getElementById("file-open-recent-popup"); recentFilesPopup.removeChildren();//from w ww . j av a2 s. com // Previously loaded files... List<LastUsedFile> lastUsedFiles = props.getLastUsedFiles(); for (int i = 0; i < lastUsedFiles.size(); i++) { final LastUsedFile lastUsedFile = lastUsedFiles.get(i); char chr = (char) ('1' + i); String accessKey = "ctrl-" + chr; String accessText = "CTRL-" + chr; String text = lastUsedFile.toString(); String id = "last-file-" + i; if (i > 8) { accessKey = null; accessText = null; } final String lastFileId = Integer.toString(i); Action action = new Action("open-last-file-" + (i + 1), Action.AS_DROP_DOWN_MENU) { public void run() { lastFileSelect(lastFileId); } }; // shorten the filename if necessary int targetLength = 40; if (text.length() > targetLength) { int lastSep = text.replace('\\', '/').lastIndexOf('/'); if (lastSep != -1) { String fileName = "..." + text.substring(lastSep); if (fileName.length() < targetLength) { // add the start of the file path int leadSize = targetLength - fileName.length(); text = text.substring(0, leadSize) + fileName; } else { text = fileName; } } } JfaceMenuitem miFileLast = new JfaceMenuitem(null, recentFilesPopup, mainSpoonContainer, text, 0, action); miFileLast.setLabel(text); miFileLast.setId(id); if (accessText != null && accessKey != null) { miFileLast.setAcceltext(accessText); miFileLast.setAccesskey(accessKey); } if (lastUsedFile.isTransformation()) { miFileLast.setImage(GUIResource.getInstance().getImageTransGraph()); } else if (lastUsedFile.isJob()) { miFileLast.setImage(GUIResource.getInstance().getImageJobGraph()); } miFileLast.setCommand("spoon.lastFileSelect('" + i + "')"); } }
From source file:org.pentaho.di.ui.spoon.Spoon.java
public void enableMenus() { boolean disableTransMenu = getActiveTransformation() == null; boolean disableJobMenu = getActiveJob() == null; boolean disableMetaMenu = getActiveMeta() == null; boolean isRepositoryRunning = rep != null; boolean disablePreviewButton = true; String activePerspectiveId = null; SpoonPerspectiveManager manager = SpoonPerspectiveManager.getInstance(); if (manager != null && manager.getActivePerspective() != null) { activePerspectiveId = manager.getActivePerspective().getId(); }/*from w w w . j av a 2 s .c o m*/ boolean etlPerspective = false; if (activePerspectiveId != null && activePerspectiveId.length() > 0) { etlPerspective = activePerspectiveId.equals(MainSpoonPerspective.ID); } TransGraph transGraph = getActiveTransGraph(); if (transGraph != null) { disablePreviewButton = !(transGraph.isRunning() && !transGraph.isHalting()); } boolean disableSave = true; TabItemInterface currentTab = getActiveTabitem(); if (currentTab != null && currentTab.canHandleSave()) { disableSave = !currentTab.hasContentChanged(); } EngineMetaInterface meta = getActiveMeta(); if (meta != null) { disableSave = !meta.canSave(); } org.pentaho.ui.xul.dom.Document doc; if (mainSpoonContainer != null) { doc = mainSpoonContainer.getDocumentRoot(); if (doc != null) { if (etlPerspective) { doc.getElementById("file").setVisible(etlPerspective); doc.getElementById("edit").setVisible(etlPerspective); doc.getElementById("view").setVisible(etlPerspective); doc.getElementById("action").setVisible(etlPerspective); doc.getElementById("tools").setVisible(etlPerspective); doc.getElementById("help").setVisible(etlPerspective); doc.getElementById("help-tip").setVisible(etlPerspective); doc.getElementById("help-welcome").setVisible(etlPerspective); doc.getElementById("help-plugins").setVisible(true); } // Only enable certain menu-items if we need to. disableMenuItem(doc, "file-new-database", disableTransMenu && disableJobMenu || !isRepositoryRunning); disableMenuItem(doc, "file-save", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave); disableMenuItem(doc, "toolbar-file-save", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave); disableMenuItem(doc, "file-save-as", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave); disableMenuItem(doc, "toolbar-file-save-as", disableTransMenu && disableJobMenu && disableMetaMenu || disableSave); disableMenuItem(doc, "file-save-as-vfs", disableTransMenu && disableJobMenu && disableMetaMenu); disableMenuItem(doc, "file-close", disableTransMenu && disableJobMenu && disableMetaMenu); disableMenuItem(doc, "file-print", disableTransMenu && disableJobMenu); disableMenuItem(doc, "file-export-to-xml", disableTransMenu && disableJobMenu); disableMenuItem(doc, "file-export-all-to-xml", disableTransMenu && disableJobMenu); // Disable the undo and redo menus if there is no active transformation // or active job // DO NOT ENABLE them otherwise ... leave that to the undo/redo settings // disableMenuItem(doc, UNDO_MENU_ITEM, disableTransMenu && disableJobMenu); disableMenuItem(doc, REDO_MENU_ITEM, disableTransMenu && disableJobMenu); disableMenuItem(doc, "edit-clear-selection", disableTransMenu && disableJobMenu); disableMenuItem(doc, "edit-select-all", disableTransMenu && disableJobMenu); updateSettingsMenu(doc, disableTransMenu, disableJobMenu); disableMenuItem(doc, "edit-settings", disableTransMenu && disableJobMenu && disableMetaMenu); // View Menu ((XulMenuitem) doc.getElementById("view-results")).setSelected(isExecutionResultsPaneVisible()); disableMenuItem(doc, "view-results", transGraph == null && disableJobMenu); disableMenuItem(doc, "view-zoom-in", disableTransMenu && disableJobMenu); disableMenuItem(doc, "view-zoom-out", disableTransMenu && disableJobMenu); disableMenuItem(doc, "view-zoom-100pct", disableTransMenu && disableJobMenu); // Transformations disableMenuItem(doc, "process-run", disableTransMenu && disablePreviewButton && disableJobMenu); disableMenuItem(doc, "trans-replay", disableTransMenu && disablePreviewButton); disableMenuItem(doc, "trans-preview", disableTransMenu && disablePreviewButton); disableMenuItem(doc, "trans-debug", disableTransMenu && disablePreviewButton); disableMenuItem(doc, "trans-verify", disableTransMenu); disableMenuItem(doc, "trans-impact", disableTransMenu); disableMenuItem(doc, "trans-get-sql", disableTransMenu); disableMenuItem(doc, "trans-last-impact", disableTransMenu); // Tools disableMenuItem(doc, "repository-connect", isRepositoryRunning); disableMenuItem(doc, "repository-disconnect", !isRepositoryRunning); disableMenuItem(doc, "repository-explore", !isRepositoryRunning); disableMenuItem(doc, "repository-clear-shared-object-cache", !isRepositoryRunning); disableMenuItem(doc, "toolbar-expore-repository", !isRepositoryRunning); disableMenuItem(doc, "repository-export-all", !isRepositoryRunning); disableMenuItem(doc, "repository-import-directory", !isRepositoryRunning); disableMenuItem(doc, "trans-last-preview", !isRepositoryRunning || disableTransMenu); // Wizard disableMenuItem(doc, "wizard-connection", disableTransMenu && disableJobMenu); disableMenuItem(doc, "wizard-copy-table", disableTransMenu && disableJobMenu); disableMenuItem(doc, "wizard-copy-tables", isRepositoryRunning && disableTransMenu && disableJobMenu); disableMenuItem(doc, "database-inst-dependancy", !isRepositoryRunning); SpoonPluginManager.getInstance().notifyLifecycleListeners(SpoonLifeCycleEvent.MENUS_REFRESHED); MenuManager menuManager = getMenuBarManager(); menuManager.updateAll(true); // What steps & plugins to show? refreshCoreObjects(); fireMenuControlers(); } } }
From source file:org.pentaho.di.ui.spoon.Spoon.java
/** * @param doc//from w w w . j a v a 2s . c o m * @param disableJobMenu * @param disableTransMenu */ private void updateSettingsMenu(org.pentaho.ui.xul.dom.Document doc, boolean disableTransMenu, boolean disableJobMenu) { XulMenuitem settingsItem = (XulMenuitem) doc.getElementById("edit-settings"); if (settingsItem != null) { if (disableTransMenu && !disableJobMenu) { settingsItem.setAcceltext("CTRL-J"); settingsItem.setAccesskey("ctrl-j"); } else if (!disableTransMenu && disableJobMenu) { settingsItem.setAcceltext("CTRL-T"); settingsItem.setAccesskey("ctrl-t"); } else { settingsItem.setAcceltext(""); settingsItem.setAccesskey(""); } } }
From source file:org.pentaho.di.ui.spoon.Spoon.java
private void disableMenuItem(org.pentaho.ui.xul.dom.Document doc, String itemId, boolean disable) { XulComponent menuItem = doc.getElementById(itemId); if (menuItem != null) { menuItem.setDisabled(disable);//from ww w . j a v a2 s . co m } else { log.logError( "Non-Fatal error : Menu Item with id = " + itemId + " does not exist! Check 'menubar.xul'"); } }
From source file:org.pentaho.reporting.engine.classic.core.RotationTest.java
@Test public void testHandleRotatedTextHTML() throws Exception { URL url = getClass().getResource("BACKLOG-10064.prpt"); MasterReport report = (MasterReport) new ResourceManager().createDirectly(url, MasterReport.class) .getResource();/*from w w w . java 2 s . c o m*/ report.getReportConfiguration().setConfigProperty(HtmlTableModule.INLINE_STYLE, "true"); List<String> elementsIdList = Arrays.asList("topLeft90", "topCenter90", "topRight90", "topJustify90", "topLeft-90", "topCenter-90", "topRight-90", "topJustify-90", "middleLeft90", "middleCenter90", "middleRight90", "middleJustify90", "middleLeft-90", "middleCenter-90", "middleRight-90", "middleJustify-90", "bottomLeft90", "bottomCenter90", "bottomRight90", "bottomJustify90", "bottomLeft-90", "bottomCenter-90", "bottomRight-90", "bottomJustify-90"); XPathFactory xpathFactory = XPathFactory.newInstance(); try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { HtmlReportUtil.createStreamHTML(report, stream); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(stream.toByteArray())); for (String elementId : elementsIdList) { org.w3c.dom.Element element = document.getElementById(elementId); Node rotatedTextStyle = element.getFirstChild().getAttributes().getNamedItem("style"); Node trSryle = element.getParentNode().getParentNode().getAttributes().getNamedItem("style"); assertTrue(isStyleValid(rotatedTextStyle.getNodeValue(), trSryle.getNodeValue(), elementId.contains("middle"))); } } catch (final IOException | ReportProcessingException e) { fail(); } }
From source file:org.sakaiproject.citation.impl.BaseConfigurationService.java
protected void saveServletClientMappings(Document document) { Element clientElement = document.getElementById("saveciteClients"); if (clientElement == null) { NodeList mapNodes = document.getElementsByTagName("map"); if (mapNodes != null) { for (int i = 0; i < mapNodes.getLength(); i++) { Element mapElement = (Element) mapNodes.item(i); if (mapElement.hasAttribute("id") && mapElement.getAttribute("id").equals("saveciteClients")) { clientElement = mapElement; break; }//from www . ja v a2s. com } } } if (clientElement != null) { try { XStream xstream = new XStream(); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(clientElement), new StreamResult(buffer)); String str = buffer.toString(); // DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); // LSSerializer serializer = domImplLS.createLSSerializer(); // String str = serializer.writeToString(clientElement); this.saveciteClients = (Map<String, List<Map<String, String>>>) xstream.fromXML(str); } catch (Exception e) { m_log.warn("Exception trying to read saveciteClients from config XML", e); } } }