List of usage examples for org.w3c.dom Document getFirstChild
public Node getFirstChild();
From source file:org.sakaiproject.lessonbuildertool.service.LessonBuilderEntityProducer.java
public void init() { logger.info("init()"); try {/*from w ww . j av a 2 s.c o m*/ EntityManager.registerEntityProducer(this, REFERENCE_ROOT); } catch (Exception e) { logger.warn("Error registering Link Tool Entity Producer", e); } lessonBuilderAccessAPI.setToolApi(this); // LinkMigrationHelper is not present before 2.10. So this code can compile on older systems, // find it via introspection. try { linkMigrationHelper = RequestFilter.class.getClassLoader() .loadClass("org.sakaiproject.util.api.LinkMigrationHelper"); // this is in the kernel, so it should already be loaded linkMigrationHelperInstance = ComponentManager.get(linkMigrationHelper); if (linkMigrationHelper != null) migrateAllLinks = linkMigrationHelper.getMethod("migrateAllLinks", new Class[] { Set.class, String.class }); } catch (Exception e) { System.out.println("Exception in introspection " + e); System.out.println("loader " + RequestFilter.class.getClassLoader()); } // Builds a Regexp selector. StringBuilder regexp = new StringBuilder("("); for (String attribute : attributes) { regexp.append(attribute); regexp.append("|"); } if (regexp.length() > 1) { regexp.deleteCharAt(regexp.length() - 1); } regexp.append(")[\\s]*=[\\s]*([\"'|])([^\"']*)(\\2|#)"); attributePattern = Pattern.compile(regexp.toString(), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); pathPattern = Pattern.compile("/(?:access/content/group|web|dav|xsl-portal/site|portal/site)/([^/]+)/.*"); dummyPattern = Pattern.compile(ITEMDUMMY + "\\d+"); // Add the server name to the list of servers String serverName = ServerConfigurationService.getString("serverName", null); String serverId = ServerConfigurationService.getString("serverId", null); servers = new HashSet<String>(); // prefer servername to serverid, by doing it first if (serverName != null) servers.add(serverName); if (serverId != null) servers.add(serverId); try { String hostName = InetAddress.getLocalHost().getHostName(); servers.add(hostName); hostName = InetAddress.getLocalHost().getCanonicalHostName(); servers.add(hostName); } catch (Exception ignore) { } servers.add("localhost"); // if neither is defined we're in trouble; if (servers.size() == 0) System.out.println( "LessonBuilderEntityProducer ERROR: neither servername nor serverid defined in sakai.properties"); // this slightly odd code is for testing. It lets us test by reloading just lesson builder. // otherwise we have to restart sakai, since the entity stuff can't be restarted if (false) { try { Document doc = Xml.createDocument(); Stack stack = new Stack(); Element root = doc.createElement("archive"); doc.appendChild(root); root.setAttribute("source", "45d48248-ba23-4829-914a-7219c3ced2dd"); root.setAttribute("server", "foo"); root.setAttribute("date", "now"); root.setAttribute("system", "sakai"); stack.push(root); archive("45d48248-ba23-4829-914a-7219c3ced2dd", doc, stack, "/tmp/archive", null); stack.pop(); Xml.writeDocument(doc, "/tmp/xmlout"); // we don't have an actual user at this point, so need to force checks to work securityService.pushAdvisor(new SecurityAdvisor() { public SecurityAdvice isAllowed(String userId, String function, String reference) { return SecurityAdvice.ALLOWED; } }); merge("0134937b-ce16-440c-80a6-fb088d79e5ad", (Element) doc.getFirstChild().getFirstChild(), "/tmp/archive", "45d48248-ba23-4829-914a-7219c3ced2dd", null, null, null); } catch (Exception e) { System.out.println(e); } finally { securityService.popAdvisor(); } } try { ComponentManager.loadComponent("org.sakaiproject.lessonbuildertool.service.LessonBuilderEntityProducer", this); } catch (Exception e) { logger.warn( "Error registering Lesson Builder Entity Producer with Spring. Lessonbuilder will work, but Lesson Builder instances won't be imported from site archives. This normally happens only if you redeploy Lessonbuilder. Suggest restarting Sakai", e); } }
From source file:org.sakaiproject.lessonbuildertool.service.LessonBuilderEntityProducer.java
public Map<String, String> transferCopyEntitiesImpl(String fromContext, String toContext, List ids, boolean cleanup) { Map<String, String> entityMap = new HashMap<String, String>(); try {//w w w .ja va 2 s. com if (cleanup == true) { Site toSite = siteService.getSite(toContext); List toSitePages = toSite.getPages(); if (toSitePages != null && !toSitePages.isEmpty()) { Vector removePageIds = new Vector(); Iterator pageIter = toSitePages.iterator(); while (pageIter.hasNext()) { SitePage currPage = (SitePage) pageIter.next(); List<String> toolIds = myToolList(); List toolList = currPage.getTools(); Iterator toolIter = toolList.iterator(); while (toolIter.hasNext()) { ToolConfiguration toolConfig = (ToolConfiguration) toolIter.next(); if (toolIds.contains(toolConfig.getToolId())) { removePageIds.add(toolConfig.getPageId()); } } } for (int i = 0; i < removePageIds.size(); i++) { String removeId = (String) removePageIds.get(i); SitePage sitePage = toSite.getPage(removeId); toSite.removePage(sitePage); } } siteService.save(toSite); ToolSession session = sessionManager.getCurrentToolSession(); if (session != null && session.getAttribute(ATTR_TOP_REFRESH) == null) { session.setAttribute(ATTR_TOP_REFRESH, Boolean.TRUE); } SimplePageBean simplePageBean = makeSimplePageBean(fromContext); List<SimplePage> sitePages = simplePageToolDao.getSitePages(toContext); if (sitePages != null && !sitePages.isEmpty()) { for (SimplePage page : sitePages) simplePageBean.deletePage(toContext, page.getPageId()); } } logger.debug("lesson builder transferCopyEntities"); Document doc = Xml.createDocument(); Stack stack = new Stack(); Element root = doc.createElement("archive"); doc.appendChild(root); root.setAttribute("source", fromContext); root.setAttribute("server", "foo"); root.setAttribute("date", "now"); root.setAttribute("system", "sakai"); stack.push(root); archive(fromContext, doc, stack, "/tmp/archive", null); stack.pop(); merge(toContext, (Element) doc.getFirstChild().getFirstChild(), "/tmp/archive", fromContext, null, null, null, entityMap); ToolSession session = sessionManager.getCurrentToolSession(); if (session != null && session.getAttribute(ATTR_TOP_REFRESH) == null) { session.setAttribute(ATTR_TOP_REFRESH, Boolean.TRUE); } // We've done the fixups but still need to do group adjustments Site site = siteService.getSite(toContext); ResourcePropertiesEdit rp = site.getPropertiesEdit(); rp.removeProperty("lessonbuilder-needsfixup"); siteService.save(site); // unfortunately in duplicate site, site-admin has the site open, so this doesn't actually do anything // site-manage will stomp on it. So we need a different way to say that group fixup is needed } catch (Exception e) { logger.error(e.getMessage(), e); } try { Site toSite = siteService.getSite(toContext); } catch (Exception e) { logger.error(e.getMessage(), e); } // set this flag for the group update, which we really do need in duplicate simplePageToolDao.setNeedsGroupFixup(toContext, 2); return entityMap; }
From source file:org.sonar.plugins.gosu.sqale.RemediationEffortExtractor.java
public void extractFromSqaleFile(String sqaleModelLocation) throws Exception { Document sqaleModel = parseXml(new File(sqaleModelLocation)); Node sqale = sqaleModel.getFirstChild(); NodeList categories = sqale.getChildNodes(); handleCategories(categories);//from w w w . ja v a2s.c o m }
From source file:org.wso2.carbon.dashboard.migratetool.DSCarFileMigrationTool.java
/** * Process unzipped car file in order to migrate to carbon-dashboards version 1.0.15+ * * @param tempDirectory tempDirectory of unzipped car file directory *///from ww w. j av a 2 s . com private void migrateUnZippedCarFile(File tempDirectory) { for (int i = 0; i < tempDirectory.listFiles().length; i++) { File[] listOfFiles = tempDirectory.listFiles(); File artifactPath = listOfFiles[i]; File artifactXML = new File(artifactPath.getPath() + File.separator + ARTIFACT_XML); if (listOfFiles[i].isDirectory() && artifactXML.exists()) { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse(artifactXML); doc.getDocumentElement().normalize(); if (doc.getFirstChild().getAttributes().getNamedItem("type").getTextContent() .equals(GADGET_ARTIFACT)) { Node file = doc.getElementsByTagName("file").item(0); file.setTextContent(file.getTextContent().toLowerCase()); saveArtifactXML(doc, artifactXML); gadgetJSONUpdater(artifactPath); } else if (doc.getFirstChild().getAttributes().getNamedItem("type").getTextContent() .equals(DASHBOARD_ARTIFACT)) { Node file = doc.getElementsByTagName("file").item(0); if (isDashboardArtifact(artifactPath, file.getTextContent())) { dashboardUpdater(new File(artifactPath.getPath() + "/resources")); } } else if (doc.getFirstChild().getAttributes().getNamedItem("type").getTextContent() .equals("dashboards/dashboard")) { dashboardUpdater(new File(artifactPath.getPath())); } } catch (ParserConfigurationException e) { log.error("Error in parsing artifact.xml of " + listOfFiles[i].getName(), e); } catch (IOException e) { log.error("Error in opening artifact.xml of " + listOfFiles[i].getName(), e); } catch (SAXException e) { log.error("Error in parsing artifact.xml of " + listOfFiles[i].getName(), e); } } } }
From source file:org.wso2.carbon.dataservices.core.WSDLToDataService.java
private static ModelBean createModelBean(Map<QName, Document> modelMap, Document doc) { ModelBean bean = new ModelBean(); if (doc == null) { return null; }// w w w. ja v a2s.c o m Node beanEl = doc.getFirstChild(); /* populate bean attributes */ NamedNodeMap beanAttrs = beanEl.getAttributes(); bean.setName(beanAttrs.getNamedItem("originalName").getNodeValue()); bean.setNsURI(beanAttrs.getNamedItem("nsuri").getNodeValue()); Node isSimpleNode = beanAttrs.getNamedItem("simple"); if (isSimpleNode != null) { bean.setSimple("yes".equals(isSimpleNode.getNodeValue())); } else { bean.setSimple(false); } /* populate child elements / properties */ NodeList propsElList = beanEl.getChildNodes(); int count = propsElList.getLength(); Node propEl; for (int i = 0; i < count; i++) { propEl = propsElList.item(i); bean.addProperty(createModelProperty(modelMap, propEl)); } return bean; }
From source file:org.wso2.carbon.pc.core.ProcessStore.java
public String getSucessorPredecessorSubprocessList(String resourcePath) { String resourceString = ""; try {/* w ww . ja va 2 s . c o m*/ RegistryService registryService = ProcessCenterServerHolder.getInstance().getRegistryService(); if (registryService != null) { UserRegistry reg = registryService.getGovernanceSystemRegistry(); resourcePath = resourcePath.substring("/_system/governance/".length()); Resource resourceAsset = reg.get(resourcePath); String resourceContent = new String((byte[]) resourceAsset.getContent()); JSONObject conObj = new JSONObject(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(resourceContent))); JSONArray subprocessArray = new JSONArray(); JSONArray successorArray = new JSONArray(); JSONArray predecessorArray = new JSONArray(); conObj.put("subprocesses", subprocessArray); conObj.put("successors", successorArray); conObj.put("predecessors", predecessorArray); NodeList subprocessElements = ((Element) document.getFirstChild()) .getElementsByTagName("subprocess"); NodeList successorElements = ((Element) document.getFirstChild()).getElementsByTagName("successor"); NodeList predecessorElements = ((Element) document.getFirstChild()) .getElementsByTagName("predecessor"); if (subprocessElements.getLength() != 0) { for (int i = 0; i < subprocessElements.getLength(); i++) { Element subprocessElement = (Element) subprocessElements.item(i); String subprocessName = subprocessElement.getElementsByTagName("name").item(0) .getTextContent(); String subprocessPath = subprocessElement.getElementsByTagName("path").item(0) .getTextContent(); String subprocessId = subprocessElement.getElementsByTagName("id").item(0).getTextContent(); String subprocessVersion = subprocessPath.substring(subprocessPath.lastIndexOf("/") + 1) .trim(); JSONObject subprocess = new JSONObject(); subprocess.put("name", subprocessName); subprocess.put("path", subprocessPath); subprocess.put("id", subprocessId); subprocess.put("version", subprocessVersion); subprocessArray.put(subprocess); } } if (successorElements.getLength() != 0) { for (int i = 0; i < successorElements.getLength(); i++) { Element successorElement = (Element) successorElements.item(i); String successorName = successorElement.getElementsByTagName("name").item(0) .getTextContent(); String successorPath = successorElement.getElementsByTagName("path").item(0) .getTextContent(); String successorId = successorElement.getElementsByTagName("id").item(0).getTextContent(); String successorVersion = successorPath.substring(successorPath.lastIndexOf("/") + 1) .trim(); JSONObject successor = new JSONObject(); successor.put("name", successorName); successor.put("path", successorPath); successor.put("id", successorId); successor.put("version", successorVersion); successorArray.put(successor); } } if (predecessorElements.getLength() != 0) { for (int i = 0; i < predecessorElements.getLength(); i++) { Element predecessorElement = (Element) predecessorElements.item(i); String predecessorName = predecessorElement.getElementsByTagName("name").item(0) .getTextContent(); String predecessorPath = predecessorElement.getElementsByTagName("path").item(0) .getTextContent(); String predecessorId = predecessorElement.getElementsByTagName("id").item(0) .getTextContent(); String predecessorVersion = predecessorPath.substring(predecessorPath.lastIndexOf("/") + 1) .trim(); JSONObject predecessor = new JSONObject(); predecessor.put("name", predecessorName); predecessor.put("path", predecessorPath); predecessor.put("id", predecessorId); predecessor.put("version", predecessorVersion); predecessorArray.put(predecessor); } } resourceString = conObj.toString(); } } catch (Exception e) { log.error("Failed to fetch Successor Predecessor and Subprocess information: " + resourcePath); } return resourceString; }
From source file:org.wso2.carbon.pc.core.ProcessStore.java
public String deleteSubprocess(String deleteSubprocess) { try {/* w w w . j av a 2 s . c o m*/ RegistryService registryService = ProcessCenterServerHolder.getInstance().getRegistryService(); if (registryService != null) { UserRegistry reg = registryService.getGovernanceSystemRegistry(); JSONObject processInfo = new JSONObject(deleteSubprocess); String processName = processInfo.getString("processName"); String processVersion = processInfo.getString("processVersion"); JSONObject subprocess = processInfo.getJSONObject("deleteSubprocess"); String processAssetPath = "processes/" + processName + "/" + processVersion; Resource resource = reg.get(processAssetPath); String processContent = new String((byte[]) resource.getContent()); Document doc = stringToXML(processContent); if (subprocess != null) { NodeList subprocessElements = ((Element) doc.getFirstChild()) .getElementsByTagName("subprocess"); for (int i = 0; i < subprocessElements.getLength(); i++) { Element subprocessElement = (Element) subprocessElements.item(i); String subprocessName = subprocessElement.getElementsByTagName("name").item(0) .getTextContent(); String subprocessPath = subprocessElement.getElementsByTagName("path").item(0) .getTextContent(); String subprocessId = subprocessElement.getElementsByTagName("id").item(0).getTextContent(); if (subprocessName.equals(subprocess.getString("name")) && subprocessPath.equals(subprocess.getString("path")) && subprocessId.equals(subprocess.getString("id"))) { subprocessElement.getParentNode().removeChild(subprocessElement); break; } } String newProcessContent = xmlToString(doc); resource.setContent(newProcessContent); reg.put(processAssetPath, resource); } } } catch (Exception e) { log.error(e); } return "OK"; }
From source file:org.wso2.carbon.pc.core.ProcessStore.java
public String deleteSuccessor(String deleteSuccessor) { try {//from w ww.ja v a2 s . c om RegistryService registryService = ProcessCenterServerHolder.getInstance().getRegistryService(); if (registryService != null) { UserRegistry reg = registryService.getGovernanceSystemRegistry(); JSONObject processInfo = new JSONObject(deleteSuccessor); String processName = processInfo.getString("processName"); String processVersion = processInfo.getString("processVersion"); JSONObject successor = processInfo.getJSONObject("deleteSuccessor"); String processAssetPath = "processes/" + processName + "/" + processVersion; Resource resource = reg.get(processAssetPath); String processContent = new String((byte[]) resource.getContent()); Document doc = stringToXML(processContent); if (successor != null) { NodeList successorElements = ((Element) doc.getFirstChild()).getElementsByTagName("successor"); for (int i = 0; i < successorElements.getLength(); i++) { Element successorElement = (Element) successorElements.item(i); String successorName = successorElement.getElementsByTagName("name").item(0) .getTextContent(); String successorPath = successorElement.getElementsByTagName("path").item(0) .getTextContent(); String successorId = successorElement.getElementsByTagName("id").item(0).getTextContent(); if (successorName.equals(successor.getString("name")) && successorPath.equals(successor.getString("path")) && successorId.equals(successor.getString("id"))) { successorElement.getParentNode().removeChild(successorElement); break; } } String newProcessContent = xmlToString(doc); resource.setContent(newProcessContent); reg.put(processAssetPath, resource); } } } catch (Exception e) { log.error(e); } return "OK"; }
From source file:org.wso2.carbon.pc.core.ProcessStore.java
public String deletePredecessor(String deletePredecessor) { try {//from ww w.j a va 2s.com RegistryService registryService = ProcessCenterServerHolder.getInstance().getRegistryService(); if (registryService != null) { UserRegistry reg = registryService.getGovernanceSystemRegistry(); JSONObject processInfo = new JSONObject(deletePredecessor); String processName = processInfo.getString("processName"); String processVersion = processInfo.getString("processVersion"); JSONObject predecessor = processInfo.getJSONObject("deletePredecessor"); String processAssetPath = "processes/" + processName + "/" + processVersion; Resource resource = reg.get(processAssetPath); String processContent = new String((byte[]) resource.getContent()); Document doc = stringToXML(processContent); if (predecessor != null) { NodeList predecessorElements = ((Element) doc.getFirstChild()) .getElementsByTagName("predecessor"); for (int i = 0; i < predecessorElements.getLength(); i++) { Element predecessorElement = (Element) predecessorElements.item(i); String predecessorName = predecessorElement.getElementsByTagName("name").item(0) .getTextContent(); String predecessorPath = predecessorElement.getElementsByTagName("path").item(0) .getTextContent(); String predecessorId = predecessorElement.getElementsByTagName("id").item(0) .getTextContent(); if (predecessorName.equals(predecessor.getString("name")) && predecessorPath.equals(predecessor.getString("path")) && predecessorId.equals(predecessor.getString("id"))) { predecessorElement.getParentNode().removeChild(predecessorElement); break; } } String newProcessContent = xmlToString(doc); resource.setContent(newProcessContent); reg.put(processAssetPath, resource); } } } catch (Exception e) { log.error(e); } return "OK"; }
From source file:org.xwoot.wikiContentManager.XWikiSwizzleClient.XwikiSwizzleClient.java
public static List<String> PageListFromXmlStatic(Document doc) { if (doc == null) { return null; }//from w w w .ja v a2 s. co m if (doc.getFirstChild() == null) { return null; } // get entries NodeList entries = doc.getFirstChild().getChildNodes(); if (entries == null || entries.getLength() == 0) { return null; } if (doc.getFirstChild().getAttributes() == null || doc.getFirstChild().getAttributes() .getNamedItem(WikiContentManager.XML_ATTRIBUTE_NAME_LISTSIZE) == null) { return null; } NodeList entriesList = doc.getFirstChild().getChildNodes(); Integer listSize = Integer.valueOf(doc.getFirstChild().getAttributes() .getNamedItem(WikiContentManager.XML_ATTRIBUTE_NAME_LISTSIZE).getNodeValue()); List<String> result = new ArrayList<String>(); if (listSize.intValue() == 0) { return result; } for (int i = 0; i < listSize.intValue(); i++) { if (entriesList != null && entriesList.item(i) != null && entriesList.item(i).getAttributes() != null && entriesList.item(i).getAttributes() .getNamedItem(WikiContentManager.XML_ATTRIBUTE_NAME_XWIKIPAGEID) != null) { result.add(entriesList.item(i).getAttributes() .getNamedItem(WikiContentManager.XML_ATTRIBUTE_NAME_XWIKIPAGEID).getTextContent()); } } return result; }