List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast
public static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator.
From source file:com.thed.launcher.EggplantZBotScriptLauncher.java
@Override public void testcaseExecutionResult() { String scriptPath = LauncherUtils.getFilePathFromCommand(currentTestcaseExecution.getScriptPath()); logger.info("Script Path is " + scriptPath); File scriptFile = new File(scriptPath); String scriptName = scriptFile.getName().split("\\.")[0]; logger.info("Script Name is " + scriptName); File resultsFolder = new File( scriptFile.getParentFile().getParentFile().getAbsolutePath() + File.separator + "Results"); File statisticalFile = resultsFolder.listFiles(new FilenameFilter() { @Override/* w w w. j ava 2s .com*/ public boolean accept(File file, String s) { return StringUtils.endsWith(s, "Statistics.xml"); } })[0]; try { XPath xpath = XPathFactory.newInstance().newXPath(); Document statisticalDoc = getDoc(statisticalFile); String result = xpath.compile("/statistics/script[@name='" + scriptName + "']/LastStatus/text()") .evaluate(statisticalDoc, XPathConstants.STRING).toString(); logger.info("Result is " + result); String comments; if (StringUtils.equalsIgnoreCase(result, "Success")) { logger.info("Test success detected"); status = currentTestcaseExecution.getTcId() + ": " + currentTestcaseExecution.getScriptId() + " STATUS: Script Successfully Executed"; currentTcExecutionResult = new Integer(1); comments = " Successfully executed on " + agent.getAgentHostAndIp(); } else { logger.info("Test failure detected, getting error message"); status = currentTestcaseExecution.getTcId() + ": " + currentTestcaseExecution.getScriptId() + " STATUS: Script Successfully Executed"; currentTcExecutionResult = new Integer(2); comments = " Error in test: "; String lastRunDateString = xpath .compile("/statistics/script[@name='" + scriptName + "']/LastRun/text()") .evaluate(statisticalDoc); //Date lastRunDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse(lastRunDateString); File historyFile = new File(resultsFolder.getAbsolutePath() + File.separator + scriptName + File.separator + "RunHistory.xml"); Document historyDoc = getDoc(historyFile); //xpath = XPathFactory.newInstance().newXPath(); String xpathExpr = "/runHistory[@script='" + scriptName + "']/run[contains(RunDate, '" + StringUtils.substringBeforeLast(lastRunDateString, " ") + "')]/ErrorMessage/text()"; logger.info("Using xPath to find errorMessage " + xpathExpr); comments += xpath.compile(xpathExpr).evaluate(historyDoc, XPathConstants.STRING); logger.info("Sending comments: " + comments); } if (currentTcExecutionResult != null) { ScriptUtil.updateTestcaseExecutionResult(url, currentTestcaseExecution, currentTcExecutionResult, comments); } } catch (Exception e) { logger.log(Level.SEVERE, "Error in reading process steams \n", e); } }
From source file:info.magnolia.cms.servlets.RequestInterceptor.java
/** * Request and Response here is same as receivced by the original page so it includes all post/get data. Sub action * could be called from here once this action finishes, it will continue loading the requested page. *//* w ww . j a v a 2 s .co m*/ public void doGet(HttpServletRequest request, HttpServletResponse response) { String action = request.getParameter(EntryServlet.INTERCEPT); String repository = request.getParameter(PARAM_REPOSITORY); if (repository == null) { repository = ContentRepository.WEBSITE; } HierarchyManager hm = MgnlContext.getHierarchyManager(repository); synchronized (ExclusiveWrite.getInstance()) { if (action.equals(ACTION_PREVIEW)) { // preview mode (button in main bar) String preview = request.getParameter(Resource.MGNL_PREVIEW_ATTRIBUTE); if (preview != null) { // @todo IMPORTANT remove use of http session HttpSession httpsession = request.getSession(true); if (BooleanUtils.toBoolean(preview)) { httpsession.setAttribute(Resource.MGNL_PREVIEW_ATTRIBUTE, Boolean.TRUE); } else { httpsession.removeAttribute(Resource.MGNL_PREVIEW_ATTRIBUTE); } } } else if (action.equals(ACTION_NODE_DELETE)) { // delete paragraph try { String path = request.getParameter(PARAM_PATH); // deactivate updatePageMetaData(request, hm); hm.delete(path); hm.save(); } catch (RepositoryException e) { log.error("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$ } } else if (action.equals(ACTION_NODE_SORT)) { // sort paragrpahs try { String pathSelected = request.getParameter(PARAM_PATH_SELECTED); String pathSortAbove = request.getParameter(PARAM_PATH_SORT_ABOVE); String pathParent = StringUtils.substringBeforeLast(pathSelected, "/"); //$NON-NLS-1$ String srcName = StringUtils.substringAfterLast(pathSelected, "/"); String destName = StringUtils.substringAfterLast(pathSortAbove, "/"); if (StringUtils.equalsIgnoreCase(destName, "mgnlNew")) { destName = null; } hm.getContent(pathParent).orderBefore(srcName, destName); hm.save(); } catch (RepositoryException e) { if (log.isDebugEnabled()) log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$ } } } }
From source file:eionet.cr.web.util.VoIDXmlWriter.java
/** * Writes sitemap xml into stream based of the uploads data. * * @param uploads/*from w w w. ja va 2 s.c om*/ * @throws XMLStreamException */ public void writeVoIDXml(List<UploadDTO> uploads) throws XMLStreamException { writer.writeStartDocument(ENCODING, "1.0"); writer.writeStartElement(RDF_NS_PREFIX, ROOT_ELEMENT, RDF_NS); writer.writeNamespace(RDF_NS_PREFIX, RDF_NS); writer.writeNamespace(RDFS_NS_PREFIX, RDFS_NS); writer.writeNamespace(OWL_NS_PREFIX, OWL_NS); writer.writeNamespace(DCT_NS_PREFIX, DCT_NS); writer.writeNamespace(VOID_NS_PREFIX, VOID_NS); for (UploadDTO upload : uploads) { writer.writeStartElement(VOID_NS_PREFIX, "Dataset", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "about", upload.getSubjectUri()); if (StringUtils.isNotEmpty(upload.getLabel())) { writer.writeStartElement(DCT_NS_PREFIX, "title", DCT_NS); writer.writeCharacters(upload.getLabel()); writer.writeEndElement(); writer.writeStartElement(RDFS_NS_PREFIX, "label", RDFS_NS); writer.writeCharacters(upload.getLabel()); writer.writeEndElement(); } writer.writeStartElement(VOID_NS_PREFIX, "sparqlEndpoint", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "resource", contextRoot + "/sparql"); writer.writeEndElement(); writer.writeStartElement(VOID_NS_PREFIX, "dataDump", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "resource", contextRoot + "/exportTriples.action?uri=" + upload.getSubjectUri()); writer.writeEndElement(); writer.writeStartElement(VOID_NS_PREFIX, "triples", VOID_NS); writer.writeCharacters(upload.getTriples()); writer.writeEndElement(); writer.writeStartElement(DCT_NS_PREFIX, "modified", DCT_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "datatype", "http://www.w3.org/2001/XMLSchema#dateTime"); writer.writeCharacters(StringUtils.substringBeforeLast(upload.getDateModified(), ".")); writer.writeEndElement(); writer.writeEndElement(); } writer.writeEndDocument(); }
From source file:com.ewcms.web.pubsub.PubsubServlet.java
private PubsubSenderable createPubsubSender(String path) { String name = null;/*w w w . j av a2 s . co m*/ if (StringUtils.indexOf(path, '/') == -1) { name = pathSender.get(path); } else { String root = StringUtils.substringBeforeLast(path, "/"); name = pathSender.get(root); if (name == null) { String middle = StringUtils.substringAfter(root, "/"); name = pathSender.get(middle); } } if (StringUtils.isNotBlank(name)) { try { Class<?> clazz = Class.forName(name); Class<?>[] argsClass = new Class<?>[] { String.class, ServletContext.class }; Constructor<?> cons = clazz.getConstructor(argsClass); return (PubsubSenderable) cons.newInstance(new Object[] { path, this.getServletContext() }); } catch (Exception e) { logger.error("PubsubSender create error:{}", e.toString()); } } return new NoneSender(); }
From source file:jp.techlier.extensions.velocity.directive.Import.java
protected String getAbstructTemplateName(final InternalContextAdapter context, final String templateName) { if (templateName == null || templateName.startsWith("/")) { return templateName; }/*from w ww . j a va2 s . c o m*/ final String currentTemplateName = context.getCurrentTemplateName(); String currentTemplatePath = "."; if (currentTemplateName.indexOf('/') >= 0) { currentTemplatePath = StringUtils.substringBeforeLast(currentTemplateName, "/"); } return currentTemplatePath + "/" + templateName; }
From source file:edu.mayo.qdm.webapp.rest.controller.TranslatorController.java
/** * Gets the exceuction.//from w ww. j a v a 2 s .c o m * * @param request the request * @param executionId the execution id * @return the exceuction * @throws Exception the exception */ @RequestMapping(value = "executor/execution/{executionId}", method = RequestMethod.GET) public Object getExceuction(HttpServletRequest request, @PathVariable String executionId) throws Exception { String requestUrl = request.getRequestURL().toString(); requestUrl = StringUtils.substringBeforeLast(requestUrl, "/execution/") + "/execution/{id}/{resource}"; UriTemplate template = new UriTemplate(requestUrl); Execution execution = new Execution(this.fileSystemResolver.getExecutionInfo(executionId), template); String xml = xmlProcessor.executionToXml(execution); return this.buildResponse(request, "executor/execution", execution, xml); }
From source file:eionet.web.action.SchemasJsonApiActionBean.java
/** * Converts business objects to JSON result. * * @param datasetTables// w w w.j av a2s . c o m * List of DataSetTable objects. * @param schemas * List of Schema objects. * @return JSON string */ private String convertToJson(List<DataSetTable> datasetTables, List<Schema> schemas) { String webAppUrl = Props.getRequiredProperty(PropsIF.DD_URL); if (webAppUrl.endsWith("/")) { webAppUrl = StringUtils.substringBeforeLast(webAppUrl, "/"); } JSONArray itemList = new JSONArray(); if (CollectionUtils.isNotEmpty(datasetTables)) { for (DataSetTable dsTable : datasetTables) { JSONObject ci = new JSONObject(); ci.put("url", webAppUrl + "/GetSchema?id=TBL" + dsTable.getId()); ci.put("identifier", dsTable.getIdentifier()); ci.put("name", dsTable.getName()); ci.put("status", dsTable.getDataSetStatus()); itemList.add(ci); } } if (CollectionUtils.isNotEmpty(schemas)) { for (Schema schema : schemas) { JSONObject ci = new JSONObject(); String relPath = schemaRepository.getSchemaRelativePath(schema.getFileName(), schema.getSchemaSetIdentifier(), false); ci.put("url", webAppUrl + DownloadServlet.SCHEMAS_PATH + "/" + relPath); ci.put("identifier", schema.getSchemaSetIdentifier()); ci.put("name", schema.getNameAttribute()); ci.put("status", schema.getSchemaSetRegStatus().toString()); itemList.add(ci); } } return itemList.toString(2); }
From source file:eionet.cr.dao.virtuoso.VirtuosoFolderDAO.java
@Override public void createFolder(String parentFolderUri, String folderName, String folderLabel, String homeUri) throws DAOException { // Make sure we have valid inputs. if (StringUtils.isBlank(parentFolderUri) || StringUtils.isBlank(folderName)) { throw new IllegalArgumentException("Parent folder URI and folder name must not be blank!"); }/* www. j av a 2s . co m*/ // Remove trailing "/" from parent URI, if such exists if (parentFolderUri.endsWith("/")) { parentFolderUri = StringUtils.substringBeforeLast(parentFolderUri, "/"); } // If the new folder URI is reserved, exit silently. String newFolderUri = parentFolderUri + "/" + URLUtil.escapeIRI(folderName); if (FolderUtil.isUserReservedUri(newFolderUri)) { LOGGER.debug("Cannot create reserved folder, exiting silently!"); return; } Connection sqlConn = null; RepositoryConnection repoConn = null; try { sqlConn = SesameUtil.getSQLConnection(); sqlConn.setAutoCommit(false); repoConn = SesameUtil.getRepositoryConnection(); repoConn.setAutoCommit(false); ValueFactory vf = repoConn.getValueFactory(); URI homeFolder = vf.createURI(homeUri); URI parentFolder = vf.createURI(parentFolderUri); URI hasFolder = vf.createURI(Predicates.CR_HAS_FOLDER); URI newFolder = vf.createURI(newFolderUri); URI rdfType = vf.createURI(Predicates.RDF_TYPE); URI rdfsLabel = vf.createURI(Predicates.RDFS_LABEL); URI allowSubObjectType = vf.createURI(Predicates.CR_ALLOW_SUBOBJECT_TYPE); Literal folderLabelLiteral = vf.createLiteral(folderLabel); URI folder = vf.createURI(Subjects.CR_FOLDER); URI file = vf.createURI(Subjects.CR_FILE); ArrayList<Statement> statements = new ArrayList<Statement>(); statements.add(new ContextStatementImpl(parentFolder, hasFolder, newFolder, homeFolder)); statements.add(new ContextStatementImpl(newFolder, rdfType, folder, homeFolder)); if (StringUtils.isNotEmpty(folderLabel)) { statements.add(new ContextStatementImpl(newFolder, rdfsLabel, folderLabelLiteral, homeFolder)); } statements.add(new ContextStatementImpl(newFolder, allowSubObjectType, folder, homeFolder)); statements.add(new ContextStatementImpl(newFolder, allowSubObjectType, file, homeFolder)); repoConn.add(statements); // if a new project is created add subfolders if (FolderUtil.isProjectRootFolder(parentFolderUri)) { repoConn.add(getProjectFolderCreationStatements(folderName, vf)); } createNeverHarvestedSources(sqlConn, statements); repoConn.commit(); sqlConn.commit(); } catch (OpenRDFException e) { SesameUtil.rollback(repoConn); throw new DAOException(e.getMessage(), e); } catch (SQLException e) { SQLUtil.rollback(sqlConn); throw new DAOException(e.getMessage(), e); } finally { SQLUtil.close(sqlConn); SesameUtil.close(repoConn); } }
From source file:eionet.meta.exports.rdf.VoIDXmlWriter.java
/** * Writes data element's VoID xml.//from w ww .j a va 2s . c o m * * @param dataElements * @throws XMLStreamException */ public void writeVoIDXml(List<DataElement> dataElements, Vector tables) throws XMLStreamException { String dataElementsBaseUri = Props.getRequiredProperty(PropsIF.RDF_DATAELEMENTS_BASE_URI); String tablesBaseUri = Props.getRequiredProperty(PropsIF.RDF_TABLES_BASE_URI); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); writer.writeStartDocument(ENCODING, "1.0"); writer.writeStartElement(RDF_NS_PREFIX, ROOT_ELEMENT, RDF_NS); writer.writeNamespace(RDF_NS_PREFIX, RDF_NS); writer.writeNamespace(RDFS_NS_PREFIX, RDFS_NS); writer.writeNamespace(OWL_NS_PREFIX, OWL_NS); writer.writeNamespace(DCT_NS_PREFIX, DCT_NS); writer.writeNamespace(VOID_NS_PREFIX, VOID_NS); for (int i = 0; tables != null && i < tables.size(); i++) { DsTable table = (DsTable) tables.get(i); String tableId = table.getID(); String tableRdfUrl = MessageFormat.format(tablesBaseUri, Integer.parseInt(tableId)); writer.writeStartElement(VOID_NS_PREFIX, "Dataset", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "ID", "TBL" + tableId); writer.writeStartElement(RDFS_NS_PREFIX, "label", RDFS_NS); writer.writeCharacters(table.getName()); writer.writeEndElement(); writer.writeStartElement(VOID_NS_PREFIX, "dataDump", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "resource", tableRdfUrl); writer.writeEndElement(); if (StringUtils.isNotEmpty(table.getDstDate())) { Long milliseconds = Long.parseLong(table.getDstDate()); writer.writeStartElement(DCT_NS_PREFIX, "modified", DCT_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "datatype", "http://www.w3.org/2001/XMLSchema#dateTime"); writer.writeCharacters(dateFormat.format(new Date(milliseconds))); writer.writeEndElement(); } writer.writeEndElement(); } for (DataElement de : dataElements) { String dataelementUri = MessageFormat.format(dataElementsBaseUri, de.getId()); writer.writeStartElement(VOID_NS_PREFIX, "Dataset", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "about", StringUtils.substringBeforeLast(dataelementUri, "/rdf")); writer.writeStartElement(RDFS_NS_PREFIX, "label", RDFS_NS); writer.writeCharacters(de.getShortName()); writer.writeEndElement(); writer.writeStartElement(VOID_NS_PREFIX, "dataDump", VOID_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "resource", dataelementUri); writer.writeEndElement(); if (de.getModified() != null) { writer.writeStartElement(DCT_NS_PREFIX, "modified", DCT_NS); writer.writeAttribute(RDF_NS_PREFIX, RDF_NS, "datatype", "http://www.w3.org/2001/XMLSchema#dateTime"); writer.writeCharacters(dateFormat.format(de.getModified())); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndDocument(); }
From source file:com.bsb.cms.commons.template.freemarker.FreemarkerGenerator.java
@Override public void createFile(String ftlTemplateFile, Map<String, Object> dataMap, String filePath) throws TemplateRuntimeException { Writer out = null;//from ww w . j av a2 s . c o m try { Template temp = getTemplate(ftlTemplateFile); FreemarkerUtils.getMap(dataMap); filePath = filePath.replace("\\", "/"); String savePath = StringUtils.substringBeforeLast(filePath, "/"); // String realPath = PublishUtils.getPublistHomeDir() + savePath; File file = new File(savePath); if (!file.exists()) { file.mkdirs(); } out = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8"); temp.process(dataMap, out); // Merge data model with template } catch (Exception e) { throw new TemplateRuntimeException(e.getMessage()); } finally { if (out != null) { try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } } log.debug(">>>>create file:" + filePath); }