List of usage examples for org.w3c.dom Element getTagName
public String getTagName();
From source file:com.twinsoft.convertigo.eclipse.editors.connector.HtmlConnectorDesignComposite.java
public void createStatementFromGenerator(Document dom) { // Retrieve selected statement generator xpath String statementGeneratorXpath = xpathEvaluator.getSelectionXpath(); // retrieve element on which generate a statement // every test has been done before activating the button, no need to do them again Element element = (Element) (dom.getDocumentElement().getChildNodes().item(0)); boolean clickable = false, valuable = false, checkable = false, selectable = false, radioable = false, formable = false;/* w w w.j a v a2 s . co m*/ if (element.getTagName().equalsIgnoreCase("A")) { clickable = true; } else if (element.getTagName().equalsIgnoreCase("INPUT")) { String type = element.getAttribute("type"); clickable = Arrays.binarySearch(new String[] { "button", "checkbox", "radio", "submit" }, type) > -1; //warning, must be sort valuable = Arrays.binarySearch(new String[] { "", "password", "text" }, type) > -1; //warning, must be sort checkable = Arrays.binarySearch(new String[] { "checkbox", "radio" }, type) > -1; //warning, must be sort radioable = type.equals("radio"); } else if (element.getTagName().equalsIgnoreCase("TEXTAREA")) { valuable = true; } else if (element.getTagName().equalsIgnoreCase("SELECT")) { selectable = true; } else if (element.getTagName().equalsIgnoreCase("FORM")) { formable = true; } // Retrieve parent Statement StatementWithExpressions parentObject = getParentStatement(); // launch wizard StatementGeneratorWizard statementGeneratorWizard = new StatementGeneratorWizard(parentObject, statementGeneratorXpath, new boolean[] { clickable, valuable, checkable, selectable, radioable, formable }); WizardDialog wzdlg = new WizardDialog(Display.getCurrent().getActiveShell(), statementGeneratorWizard); wzdlg.open(); if (wzdlg.getReturnCode() != Window.CANCEL) { // TODO } }
From source file:eu.aniketos.scpm.userinterface.views.ScpmUI.java
/** * Load the composition plan as Activiti diagram. It is used when user * manually selects composition plans from the table. The method uses system * API to load the *.bpmn20.xml file first. That will create a *.activiti * file automatically. It then close the *.bpmn20.xml file and load the * *.activiti file instead. During the process it also abstracts any * security extensions that embedded in the composition plan by SCF. If * there is any extensions found, it saves them in the activiti file as the * system will not deal with security extensions by default. * /*from w w w.ja v a2 s. c o m*/ * The files are loaded from /AniketosFiles/BPMNdiagrams in the workspace. * * @param fileName * File name with full path to the bpmn file. * * @see saveToWorkspace() * @see moveToWorkspace() * @see getExtensions(); setExtensions() */ private void loadBPMN(String fileName) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); String fileActiviti = ""; String tempFile = fileName.replace("\\", "/"); String filePath[] = tempFile.split("/"); int idx = tempFile.lastIndexOf("/"); if (idx >= 0) fileActiviti = tempFile.substring(idx + 1); else return; fileActiviti.toLowerCase(); idx = fileActiviti.lastIndexOf(".bpmn20.xml"); if (idx >= 0) fileActiviti = fileActiviti.substring(0, idx); fileActiviti = fileActiviti.concat(".activiti"); String bpmnEditorId = "org.activiti.designer.editor.bpmn"; String diagramEditorId = "org.activiti.designer.editor.multiPageEditor"; IFile fileBPMN = null; IFile fileDiagram = null; IFolder folder = null; int pathLength = filePath.length; try { IProject bpmnProject = root.getProject(filePath[pathLength - 5]); if (!bpmnProject.exists()) { System.out.print("xxx project not exists xxx"); bpmnProject.create(null); } if (!bpmnProject.isOpen()) bpmnProject.open(null); folder = bpmnProject.getFolder(filePath[pathLength - 4]); if (!folder.exists()) { System.out.print("xxx Folder not exists xxx"); folder.create(true, true, null); } folder = folder.getFolder(filePath[pathLength - 3]); if (!folder.exists()) { System.out.print("xxx Folder not exists xxx"); folder.create(true, true, null); } folder = folder.getFolder(filePath[pathLength - 2]); if (!folder.exists()) { System.out.print("xxx Folder not exists xxx"); folder.create(true, true, null); } fileBPMN = folder.getFile(filePath[pathLength - 1]); } catch (Exception e1) { // Auto-generated catch block e1.printStackTrace(); } // Get the view IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); IEditorInput bpmnInput = new FileEditorInput(fileBPMN); try { IEditorPart bpmnEditor = page.openEditor(bpmnInput, bpmnEditorId); page.closeEditor(bpmnEditor, true); fileDiagram = folder.getFile(fileActiviti); File bpmnFile = fileBPMN.getRawLocation().makeAbsolute().toFile(); DocumentBuilderFactory bpmnFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder bpmnBuilder = bpmnFactory.newDocumentBuilder(); Document bpmnDoc = bpmnBuilder.parse(bpmnFile); bpmnDoc.getDocumentElement().normalize(); File activitiFile = fileDiagram.getRawLocation().makeAbsolute().toFile(); DocumentBuilderFactory activitiFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder activitiBuilder = activitiFactory.newDocumentBuilder(); Document activitiDoc = activitiBuilder.parse(activitiFile); activitiDoc.getDocumentElement().normalize(); NodeList allList = activitiDoc.getDocumentElement().getChildNodes(); List<org.w3c.dom.Element> bpmn2Element = new Vector<org.w3c.dom.Element>(); for (int index = 0; index < allList.getLength(); index++) { Node bpmn2Node = allList.item(index); if (bpmn2Node.getNodeType() == Node.ELEMENT_NODE) { org.w3c.dom.Element eElement = (org.w3c.dom.Element) bpmn2Node; if (eElement.getTagName().startsWith("bpmn2:")) { bpmn2Element.add(eElement); // System.out.println("bpmn2 ID : " + getAttValue("id", // eElement)); } } } NodeList serviceList = bpmnDoc.getElementsByTagName("serviceTask"); for (int index = 0; index < serviceList.getLength(); index++) { org.w3c.dom.Element serviceElement = (org.w3c.dom.Element) serviceList.item(index); String serviceID = getAttValue("id", serviceElement); List<String> serviceAttributes = new Vector<String>(); serviceAttributes = getExtensions(serviceElement); setExtensions(serviceID, serviceAttributes, bpmn2Element); } for (int index = 0; index < bpmn2Element.size(); index++) System.out.println(getAttValue("expression", bpmn2Element.get(index))); // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(activitiDoc); StreamResult result = new StreamResult(fileDiagram.getRawLocation().makeAbsolute().toFile()); transformer.transform(source, result); IEditorInput diagramInput = new FileEditorInput(fileDiagram); page.openEditor(diagramInput, diagramEditorId); } catch (PartInitException e) { throw new RuntimeException(e); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return; }
From source file:com.enonic.vertical.engine.handlers.PageTemplateHandler.java
private int[] createPageTemplParam(CopyContext copyContext, Document ptpDoc) throws VerticalCreateException { // XML DOM//from w w w . j a va 2 s. com Element root = ptpDoc.getDocumentElement(); // check: does root element exist? if (root == null) { String message = "Root element does not exist."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } // check: if root element is not contentrating, throw create exception if (!"pagetemplateparameter".equals(root.getTagName()) && !"pagetemplateparameters".equals(root.getTagName())) { String message = "Root element is not a pagetemplate or pagetemplates element: %0"; VerticalEngineLogger.errorCreate(this.getClass(), 1, message, root.getTagName(), null); } Node[] node; if ("pagetemplateparameters".equals(root.getTagName())) { node = XMLTool.filterNodes(root.getChildNodes(), Node.ELEMENT_NODE); if (node == null || node.length == 0) { String message = "No page template parameters to create"; VerticalEngineLogger.warn(this.getClass(), 2, message, null); } } else { node = new Node[] { root }; } int[] key = new int[node.length]; // connection variables Connection con = null; PreparedStatement preparedStmt = null; try { con = getConnection(); preparedStmt = con.prepareStatement(PTP_CREATE); for (int i = 0; i < node.length; i++) { Element elem = (Element) node[i]; Map<String, Element> subelems = XMLTool.filterElements(elem.getChildNodes()); // attribute: key (generated in database) key[i] = getNextKey(PTP_TABLE); preparedStmt.setInt(1, key[i]); if (copyContext != null) { String keyStr = elem.getAttribute("key"); if (keyStr != null && keyStr.length() > 0) { copyContext.putPageTemplateParameterKey(Integer.parseInt(keyStr), key[i]); } } // element: stylesheet key String tmp = elem.getAttribute("pagetemplatekey"); preparedStmt.setInt(2, Integer.parseInt(tmp)); tmp = elem.getAttribute("multiple"); preparedStmt.setInt(4, Integer.parseInt(tmp)); tmp = elem.getAttribute("override"); preparedStmt.setInt(6, Integer.parseInt(tmp)); // element: name Element subelem = subelems.get("name"); String name = XMLTool.getElementText(subelem); preparedStmt.setCharacterStream(3, new StringReader(name), name.length()); // element: separator subelem = subelems.get("separator"); String separator = XMLTool.getElementText(subelem); if (separator == null || separator.length() == 0) { separator = ""; } preparedStmt.setCharacterStream(5, new StringReader(separator), separator.length()); // element: timestamp (using the database timestamp at creation) /* no code */ preparedStmt.executeUpdate(); } preparedStmt.close(); preparedStmt = null; } catch (SQLException sqle) { String message = "Failed to create page template parameter because of database error: %t"; VerticalEngineLogger.errorCreate(this.getClass(), 4, message, sqle); } catch (NumberFormatException nfe) { String message = "Failed to parse a key field: %t"; VerticalEngineLogger.errorCreate(this.getClass(), 5, message, nfe); } catch (VerticalKeyException gke) { String message = "Failed to generate page template parameter key: %t"; VerticalEngineLogger.errorCreate(this.getClass(), 6, message, gke); } finally { close(preparedStmt); close(con); } return key; }
From source file:com.enonic.vertical.engine.handlers.PageTemplateHandler.java
public void updatePageTemplParam(Document ptpDoc) throws VerticalUpdateException { Element root = ptpDoc.getDocumentElement(); String tmp;//from w ww.ja v a2 s .c o m // check: does root element exist? if (root == null) { String message = "Root element does not exist"; VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null); } // check: if root element is not contentrating, throw create exception if (!"pagetemplateparameter".equals(root.getTagName()) && !"pagetemplateparameters".equals(root.getTagName())) { String message = "Root element is not the \"pagetemplateparameter\" or \"pagetemplateparameters\" element: %0"; VerticalEngineLogger.errorUpdate(this.getClass(), 1, message, root.getTagName(), null); } Node[] node; if ("pagetemplateparameters".equals(root.getTagName())) { node = XMLTool.filterNodes(root.getChildNodes(), Node.ELEMENT_NODE); if (node == null || node.length == 0) { return; //String message = "No page template parameters to create."; //VerticalEngineLogger.warn(2, message, null); } } else { node = new Node[] { root }; } // connection variables Connection con = null; PreparedStatement preparedStmt = null; //int result = -1; try { con = getConnection(); preparedStmt = con.prepareStatement(PTP_UPDATE); for (Node aNode : node) { Element elem = (Element) aNode; Map<String, Element> subelems = XMLTool.filterElements(elem.getChildNodes()); // attribute: key tmp = elem.getAttribute("key"); int pageTemplParamKey = Integer.parseInt(tmp); preparedStmt.setInt(6, pageTemplParamKey); tmp = elem.getAttribute("pagetemplatekey"); preparedStmt.setInt(1, Integer.parseInt(tmp)); tmp = elem.getAttribute("multiple"); preparedStmt.setInt(3, Integer.parseInt(tmp)); tmp = elem.getAttribute("override"); preparedStmt.setInt(5, Integer.parseInt(tmp)); // element: name Element subelem = subelems.get("name"); String name = XMLTool.getElementText(subelem); preparedStmt.setCharacterStream(2, new StringReader(name), name.length()); subelem = subelems.get("separator"); String separator = XMLTool.getElementText(subelem); if (separator == null || separator.length() == 0) { separator = ""; } preparedStmt.setCharacterStream(4, new StringReader(separator), separator.length()); int result = preparedStmt.executeUpdate(); if (result <= 0) { String message = "Failed to update page template parameters. None updated."; VerticalEngineLogger.errorUpdate(this.getClass(), 3, message, null); } } } catch (SQLException sqle) { String message = "Failed to update page template parameters because of database error: %t"; VerticalEngineLogger.errorUpdate(this.getClass(), 4, message, sqle); } catch (NumberFormatException nfe) { String message = "Failed to parse a key field: %t"; VerticalEngineLogger.errorUpdate(this.getClass(), 5, message, nfe); } finally { close(preparedStmt); close(con); } }
From source file:com.enonic.vertical.engine.handlers.PageTemplateHandler.java
private void updatePageTemplateCOs(Document contentobjectDoc, int pageTemplateKey, int[] paramKeys) throws VerticalCreateException { // XML DOM// w ww .j a v a 2 s .com Element root = contentobjectDoc.getDocumentElement(); // check: does root element exist? if (root == null) { String message = "Root element does not exist."; VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null); } // check: if root element is not contentrating, throw create exception if (!"contentobject".equals(root.getTagName()) && !"contentobjects".equals(root.getTagName())) { String message = "Root element is not a contentobject or contentobjects element: %0"; VerticalEngineLogger.errorCreate(this.getClass(), 1, message, root.getTagName(), null); } Node[] node; if ("contentobjects".equals(root.getTagName())) { node = XMLTool.filterNodes(root.getChildNodes(), Node.ELEMENT_NODE); } else { node = new Node[] { root }; } // connection variables Connection con = null; PreparedStatement createStmt = null; PreparedStatement updateStmt = null; try { con = getConnection(); createStmt = con.prepareStatement(PTC_CREATE); updateStmt = con.prepareStatement(PTC_UPDATE); StringBuffer removeSQLPart = new StringBuffer(); for (int i = 0; i < node.length; i++) { Element elem = (Element) node[i]; Map<String, Element> subelems = XMLTool.filterElements(elem.getChildNodes()); // attribute: templatekey //String tmp = elem.getAttribute("pagetemplatekey"); //pageTemplateKey = Integer.parseInt(tmp); // attribute: conobjkey String tmp = elem.getAttribute("conobjkey"); int contentObjectKey = Integer.parseInt(tmp); if (i > 0) { removeSQLPart.append(','); } removeSQLPart.append(contentObjectKey); // attribute: parameterkey tmp = elem.getAttribute("parameterkey"); int parameterKey; if (tmp.charAt(0) == '_') { parameterKey = paramKeys[Integer.parseInt(tmp.substring(1))]; } else { parameterKey = Integer.parseInt(tmp); } // extract order Element subelem = subelems.get("order"); int order = Integer.parseInt(XMLTool.getElementText(subelem)); updateStmt.setInt(1, order); updateStmt.setInt(2, parameterKey); updateStmt.setInt(3, pageTemplateKey); updateStmt.setInt(4, contentObjectKey); // update page template content object int rowCount = updateStmt.executeUpdate(); // if no page template content object were updated, create a new one if (rowCount == 0) { createStmt.setInt(1, pageTemplateKey); createStmt.setInt(2, contentObjectKey); createStmt.setInt(3, order); createStmt.setInt(4, parameterKey); createStmt.executeUpdate(); } } updateStmt.close(); if (removeSQLPart.length() > 0) { String sql = StringUtil.expandString(PTC_REMOVE_NOT_COB_MANY, removeSQLPart); updateStmt = con.prepareStatement(sql); updateStmt.setInt(1, pageTemplateKey); updateStmt.executeUpdate(); } else if (node.length == 0) { updateStmt = con.prepareStatement(PTC_REMOVE_PAT); updateStmt.setInt(1, pageTemplateKey); updateStmt.executeUpdate(); } } catch (SQLException sqle) { String message = "Failed to link page template to content object because of database error: %t"; VerticalEngineLogger.errorCreate(this.getClass(), 2, message, sqle); } catch (NumberFormatException nfe) { String message = "Failed to parse a key field: %t"; VerticalEngineLogger.errorCreate(this.getClass(), 3, message, nfe); } finally { close(createStmt); close(updateStmt); close(con); } }
From source file:com.enonic.esl.xml.XMLTool.java
/** * <p/> A generic method that builds the xml block of arbitrary depth. All fields starting with a specified prefix and an '_' character * followed element names separated by '_' characters are translated to nested xml elements where the prefix names the top specified * with the root element. The last element can be specified with one of the following prefix and suffixes: <ul> <li>@ (prefix) - * element text will be set as an attribute to the parent element <li>_CDATA (suffix) - element text will be wrapped in a CDATA element * <li>_XHTML (suffix) - element text will be turned into XHTML elements </ul> When reaching one of the prefix and suffixes, the element * creating process will terminate for this field. </p> <p/> <p>Elements already created with the same path will be reused.</p> <p/> * <p>Example:<br> The key 'contentdata_foo_bar_zot_CDATA' with the value '<b>alpha</b>' will transform into the following xml: * <pre>/* ww w . j av a 2 s.co m*/ * <contentdata> * <foo> * <bar> * <zot> * <[!CDATA[<b><b>alpha</b></b>]]> * </zot> * </bar> * </foo> * </contentdata> * </pre> * </p> */ public static void buildSubTree(Document doc, Element rootElement, String prefix, ExtendedMap items) throws XMLToolException { for (Object o : items.keySet()) { String key = (String) o; String[] values = items.getStringArray(key); StringTokenizer keyTokenizer = new StringTokenizer(key, "_"); if (prefix.equals(keyTokenizer.nextToken())) { Element tmpRoot = rootElement; while (keyTokenizer.hasMoreTokens()) { String keyToken = keyTokenizer.nextToken(); if ("CDATA".equals(keyToken)) { String data = values[0]; data = StringUtil.replaceAll(data, "\r\n", "\n"); createCDATASection(doc, tmpRoot, data); break; } else if ("XML".equals(keyToken)) { String xmlDoc = values[0]; Document tempDoc = domparse(xmlDoc); tmpRoot.appendChild(doc.importNode(tempDoc.getDocumentElement(), true)); break; } else if ("XHTML".equals(keyToken)) { createXHTMLNodes(doc, tmpRoot, values[0], true); break; } else if ("FILEITEM".equals(keyToken)) { FileItem fileItem = items.getFileItem(key); tmpRoot.setAttribute("field", fileItem.getFieldName()); } else if (keyToken.charAt(0) == '@') { if (values.length == 1) { tmpRoot.setAttribute(keyToken.substring(1), items.getString(key)); } else { Element parentElem = (Element) tmpRoot.getParentNode(); String elementName = tmpRoot.getTagName(); Element[] elements = getElements(parentElem, elementName); for (int i = 0; i < elements.length && i < values.length; i++) { elements[i].setAttribute(keyToken.substring(1), values[i]); } if (elements.length < values.length) { for (int i = elements.length; i < values.length; i++) { Element element = createElement(doc, parentElem, elementName); element.setAttribute(keyToken.substring(1), values[i]); } } } break; } else { if (!keyTokenizer.hasMoreTokens() && values.length > 1) { Element[] elements = getElements(tmpRoot, keyToken); for (int i = 0; i < elements.length && i < values.length; i++) { createTextNode(doc, elements[i], values[i]); } if (elements.length < values.length) { for (int i = elements.length; i < values.length; i++) { createElement(doc, tmpRoot, keyToken, values[i]); } } } else { Element elem = getElement(tmpRoot, keyToken); if (elem == null) { tmpRoot = createElement(doc, tmpRoot, keyToken); } else { tmpRoot = elem; } if (!keyTokenizer.hasMoreTokens()) { createTextNode(doc, tmpRoot, items.getString(key)); break; } } } } } } }
From source file:com.fujitsu.dc.test.jersey.box.CollectionTest.java
/** * resourcetype?. resourcetype??=1 resourcetype?=1 collectionserviceType?? *//* ww w .j av a 2 s . c o m*/ private void serviceColTypeTest(final Document doc, final String serviceType) { Element root = doc.getDocumentElement(); NodeList resourcetypeList = root.getElementsByTagName("resourcetype"); assertEquals(1, resourcetypeList.getLength()); Element resourcetype = (Element) resourcetypeList.item(0); NodeList children = resourcetype.getChildNodes(); String dc = null; String collection = null; int elementCounut = 0; for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { elementCounut++; Element childElement = (Element) child; if (childElement.getTagName().equals(serviceType)) { dc = childElement.getTagName(); } else if (childElement.getTagName().equals("collection")) { collection = childElement.getTagName(); } } } assertEquals(2, elementCounut); assertNotNull(dc); assertNotNull(collection); }
From source file:autohit.creator.compiler.SimCompiler.java
/** * Every raw element will enter here. Bascially, it dispatches it to it's specific * handler. It will do so for every child in the passed node. *//*from w w w .ja v a 2 s . c o m*/ private void processCode(Element en) throws Exception { Element child; String name; int idx; Node scratchNode; NodeList itemTreeChildren = en.getChildNodes(); //DEBUG //runtimeDebug("ENTER --- " + en.getTagName()); for (idx = 0; idx < itemTreeChildren.getLength(); idx++) { scratchNode = itemTreeChildren.item(idx); // Only process elements if (!(scratchNode instanceof Element)) continue; // Clean it child = (Element) scratchNode; name = child.getTagName().toLowerCase(); // Parse the token and call a handler // Just not enough tokens to justify a state translation if (name.charAt(0) == 'a') { handleAssert(child); } else if (name.charAt(0) == 'b') { if (name.charAt(1) == 'l') { handleBlock(child); } else { handleBuffer(child); } } else if (name.charAt(0) == 'c') { handleCall(child); } else if (name.charAt(0) == 'e') { handleExec(child); } else if (name.charAt(0) == 'f') { handleFor(child); } else if (name.charAt(0) == 'g') { handleGoto(child); } else if (name.charAt(0) == 'i') { if (name.charAt(1) == 'n') { handleInput(child); } else { handleIf(child); } } else if (name.charAt(0) == 'l') { handleLabel(child); } else if (name.charAt(0) == 'm') { if (name.charAt(1) == 'e') { handleMethod(child); } else { handleMath(child); } } else if (name.charAt(0) == 's') { if (name.charAt(1) == 'e') { handleSet(child); } else { handleSubroutine(child); } } else if (name.charAt(0) == 'w') { handleWhile(child); } else if (name.charAt(0) == 'r') { handleReturn(child); } else { runtimeError("Software Detected Fault: autohit.creator.compiler.SimCompiler(). The textual token [" + en.getNodeName() + "] should have NOT reached this code. Check the XML DTD associated with the SimCompiler."); throw (new Exception("Software Detected Fault in creator.compiler.SimCompiler.processItem().")); } } //DEBUG //runtimeDebug("EXIT --- " + en.getTagName()); }
From source file:com.photon.phresco.framework.rest.api.ParameterService.java
/** * Gets the iframe report./* w ww . j ava 2 s . c om*/ * * @param customerId the customer id * @param userId the user id * @param appDirName the app dir name * @param validateAgainst the validate against * @param request the request * @return the iframe report */ @GET @Path("/iFrameReport") @Produces(MediaType.APPLICATION_JSON) public Response getIframeReport(@QueryParam(REST_QUERY_CUSTOMERID) String customerId, @QueryParam(REST_QUERY_USERID) String userId, @QueryParam(REST_QUERY_APPDIR_NAME) String appDirName, @QueryParam(REST_QUERY_VALIDATE_AGAINST) String validateAgainst, @QueryParam(REST_QUERY_MODULE_NAME) String module, @Context HttpServletRequest request) { ResponseInfo<PossibleValues> responseData = new ResponseInfo<PossibleValues>(); StringBuilder sb = new StringBuilder(); String rootModulePath = ""; String subModuleName = ""; String textContent = ""; try { if (StringUtils.isNotEmpty(module)) { rootModulePath = Utility.getProjectHome() + appDirName; subModuleName = module; } else { rootModulePath = Utility.getProjectHome() + appDirName; } ProjectInfo projectInfo = Utility.getProjectInfo(rootModulePath, subModuleName); ApplicationInfo applicationInfo = projectInfo.getAppInfos().get(0); PomProcessor processor = Utility.getPomProcessor(rootModulePath, subModuleName); File pomFile = Utility.getPomFileLocation(rootModulePath, subModuleName); String validateReportUrl = ""; String infoFileDir = getInfoFileDir(Constants.PHASE_VALIDATE_CODE, Constants.PHASE_VALIDATE_CODE, rootModulePath, subModuleName); MojoProcessor mojoProcessor = new MojoProcessor(new File(infoFileDir)); Parameter srcParameter = mojoProcessor.getParameter(Constants.PHASE_VALIDATE_CODE, "src"); if (srcParameter != null && srcParameter.getPossibleValues() != null && CollectionUtils.isNotEmpty(srcParameter.getPossibleValues().getValue())) { List<String> againsts = new ArrayList<String>(); List<Value> srcValues = srcParameter.getPossibleValues().getValue(); for (Value srcValue : srcValues) { againsts.add(srcValue.getKey()); } if (CollectionUtils.isNotEmpty(againsts) && !FUNCTIONALTEST.equals(validateAgainst) && !againsts.contains(validateAgainst)) { validateReportUrl = processor.getProperty(Constants.POM_PROP_KEY_VALIDATE_REPORT); } } else { validateReportUrl = processor.getProperty(Constants.POM_PROP_KEY_VALIDATE_REPORT); } FrameworkConfiguration frameworkConfig = PhrescoFrameworkFactory.getFrameworkConfig(); ServiceManager serviceManager = CONTEXT_MANAGER_MAP.get(userId); Customer customer = serviceManager.getCustomer(customerId); // Check whether iphone Technology or not Properties sysProps = System.getProperties(); String phrescoFileServerNumber = sysProps.getProperty(PHRESCO_FILE_SERVER_PORT_NO); if (StringUtils.isNotEmpty(validateReportUrl)) { StringBuilder codeValidatePath = new StringBuilder(pomFile.getParent()); codeValidatePath.append(validateReportUrl); codeValidatePath.append(validateAgainst); codeValidatePath.append(File.separatorChar); codeValidatePath.append(INDEX_HTML); File indexPath = new File(codeValidatePath.toString()); if (indexPath.isFile() && StringUtils.isNotEmpty(phrescoFileServerNumber)) { sb.append(HTTP_PROTOCOL); sb.append(PROTOCOL_POSTFIX); InetAddress thisIp = InetAddress.getLocalHost(); sb.append(thisIp.getHostAddress()); sb.append(FrameworkConstants.COLON); sb.append(phrescoFileServerNumber); sb.append(FrameworkConstants.FORWARD_SLASH); sb.append(appDirName); String splitPhrDir = processor.getProperty(Constants.POM_PROP_KEY_SPLIT_PHRESCO_DIR); String splitSrcDir = processor.getProperty(Constants.POM_PROP_KEY_SPLIT_SRC_DIR); if (StringUtils.isNotEmpty(applicationInfo.getPhrescoPomFile()) && StringUtils.isNotEmpty(splitPhrDir)) { sb.append(FrameworkConstants.FORWARD_SLASH); sb.append(splitPhrDir); } else if (StringUtils.isNotEmpty(splitSrcDir)) { sb.append(FrameworkConstants.FORWARD_SLASH); sb.append(splitSrcDir); } sb.append(validateReportUrl); sb.append(validateAgainst); sb.append(FrameworkConstants.FORWARD_SLASH); sb.append(INDEX_HTML); ResponseInfo<String> finalOutput = responseDataEvaluation(responseData, null, sb.toString(), RESPONSE_STATUS_SUCCESS, PHR500003); return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER).build(); } else { ResponseInfo<PossibleValues> finalOutput = responseDataEvaluation(responseData, null, null, RESPONSE_STATUS_SUCCESS, PHR500005); return Response.status(Status.OK).entity(finalOutput) .header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER).build(); } } String serverUrl = ""; FrameworkUtil frameworkUtil = new FrameworkUtil(request); serverUrl = frameworkUtil.getSonarHomeURL(); StringBuilder reportPath = new StringBuilder(); if (StringUtils.isNotEmpty(validateAgainst) && FUNCTIONALTEST.equals(validateAgainst)) { File testFolderLocation = Utility.getTestFolderLocation(projectInfo, rootModulePath, subModuleName); String funcDir = processor.getProperty(Constants.POM_PROP_KEY_FUNCTEST_DIR); reportPath.append(testFolderLocation.toString()); reportPath.append(funcDir); reportPath.append(File.separatorChar); reportPath.append(Constants.POM_NAME); } else { reportPath.append(pomFile.getPath()); } File file = new File(reportPath.toString()); processor = new PomProcessor(file); String groupId = processor.getModel().getGroupId(); String artifactId = processor.getModel().getArtifactId(); sb.append(serverUrl); sb.append(frameworkConfig.getSonarReportPath()); sb.append(groupId); sb.append(FrameworkConstants.COLON); sb.append(artifactId); if (StringUtils.isNotEmpty(validateAgainst) && !REQ_SRC.equals(validateAgainst)) { textContent = validateAgainst + projectInfo.getAppInfos().get(0).getId(); } else { PomProcessor pomPro = new PomProcessor(pomFile); Profile profile = pomPro.getProfile(validateAgainst); if (profile != null) { List<Element> properties = profile.getProperties().getAny(); for (Element element : properties) { if (element.getTagName().equalsIgnoreCase("sonar.branch")) { textContent = element.getTextContent(); } } } else { textContent = validateAgainst + projectInfo.getAppInfos().get(0).getId(); } } sb.append(FrameworkConstants.COLON); sb.append(textContent); int responseCode = 0; URL sonarURL = new URL(sb.toString()); String protocol = sonarURL.getProtocol(); HttpURLConnection connection = null; if (protocol.equals(HTTP_PROTOCOL)) { connection = (HttpURLConnection) sonarURL.openConnection(); responseCode = connection.getResponseCode(); } else if (protocol.equals("https")) { responseCode = FrameworkUtil.getHttpsResponse(sb.toString()); } if (responseCode != 200) { ResponseInfo<PossibleValues> finalOutput = responseDataEvaluation(responseData, null, null, RESPONSE_STATUS_FAILURE, PHR510003); return Response.status(Status.OK).entity(finalOutput) .header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER).build(); } else if (!frameworkUtil.checkReportForHigherVersion(serverUrl, textContent)) { ResponseInfo<PossibleValues> finalOutput = responseDataEvaluation(responseData, null, null, RESPONSE_STATUS_FAILURE, PHR510003); return Response.status(Status.OK).entity(finalOutput) .header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER).build(); } Map<String, String> theme = customer.getFrameworkTheme(); if (MapUtils.isNotEmpty(theme)) { sb.append("?"); sb.append(CUST_BASE_COLOR + theme.get("customerBaseColor")); sb.append("&" + CSS_PHRESCO_STYLE); } else { sb.append("?"); sb.append(CSS_PHRESCO_STYLE); } } catch (PhrescoException e) { ResponseInfo<PossibleValues> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHR510009); return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER) .build(); } catch (PhrescoPomException e) { ResponseInfo<PossibleValues> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHR510006); return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER) .build(); } catch (UnknownHostException e) { ResponseInfo<PossibleValues> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHR510007); return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER) .build(); } catch (IOException e) { ResponseInfo<PossibleValues> finalOutput = responseDataEvaluation(responseData, e, null, RESPONSE_STATUS_ERROR, PHR510008); return Response.status(Status.OK).entity(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER) .build(); } ResponseInfo<String> finalOutput = responseDataEvaluation(responseData, null, sb.toString(), RESPONSE_STATUS_SUCCESS, PHR500003); return Response.ok(finalOutput).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL_HEADER).build(); }