List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.google.gdt.eclipse.designer.core.GTestUtils.java
/** * Creates new GWT module./* w ww .j a va 2s . co m*/ * * @param moduleId * the id of module, such as <code>com.mycompany.project.ImageViewer</code>. * * @return the module {@link IFile}. */ public static IFile createModule(TestProject testProject, String moduleId) throws Exception { IProject project = testProject.getProject(); Assert.isTrue(moduleId.contains("."), "Given module name '%s' is not fully qualifed.", moduleId); String packageName = StringUtils.substringBeforeLast(moduleId, "."); String shortModuleName = StringUtils.substringAfterLast(moduleId, "."); String publicFolderPath = WebUtils.getWebFolderName(project) + "/"; IPackageFragment modulePackage = testProject.getPackage(packageName); // *.gwt.xml IFile moduleFile; { String entryPointTypeName = packageName + ".client." + shortModuleName; String source = DesignerTestCase .getDoubleQuotes2(new String[] { "<module>", " <inherits name='com.google.gwt.user.User'/>", //" <inherits name='com.google.gwt.user.theme.standard.Standard'/>", " <entry-point class='" + entryPointTypeName + "'/>", "</module>" }); moduleFile = testProject.createFile(modulePackage, shortModuleName + ".gwt.xml", source); } // "client" package { IPackageFragment clientPackage = testProject.getPackage(packageName + ".client"); testProject.createUnit(clientPackage, shortModuleName + ".java", DesignerTestCase.getSourceDQ("package " + clientPackage.getElementName() + ";", "import com.google.gwt.core.client.EntryPoint;", "import com.google.gwt.user.client.ui.RootPanel;", "public class " + shortModuleName + " implements EntryPoint {", " public void onModuleLoad() {", " RootPanel rootPanel = RootPanel.get();", " }", "}")); } // "public" resources { // HTML { String docType = ""; if (Utils.getVersion(project).isHigherOrSame(Utils.GWT_2_0)) { docType += "<!doctype html>"; } // String html = DesignerTestCase.getSourceDQ(docType, "<html>", " <head>", " <title>Wrapper HTML for GWT module</title>", " <meta name='gwt:module' content='" + moduleId + "'/>", " <link type='text/css' rel='stylesheet' href='" + shortModuleName + ".css'/>", " </head>", " <body>", " <script language='javascript' src='" + moduleId + ".nocache.js'></script>", " <iframe id='__gwt_historyFrame' style='width:0;height:0;border:0'></iframe>", " </body>", "</html>"); setFileContent(project, publicFolderPath + "/" + shortModuleName + ".html", html); } // CSS { String css = DesignerTestCase.getSourceDQ("body {", " background-color: white;", " font: 18px Arial;", "}", ".gwt-Button {", " overflow: visible;", "}", "td {", " font: 18px Arial;", " padding: 0px;", "}", "a {", " color: darkblue;", "}", ".gwt-TabLayoutPanelTab {", " float: left;", " border: 1px solid #87b3ff;", " padding: 2px;", " cursor: hand;", "}", ".gwt-TabLayoutPanelTab-selected {", " font-weight: bold;", " background-color: #e8eef7;", " cursor: default;", "}"); setFileContent(project, publicFolderPath + "/" + shortModuleName + ".css", css); } // images { TestUtils.createImagePNG(testProject, publicFolderPath + "/1.png", 16, 16); TestUtils.createImagePNG(testProject, publicFolderPath + "/2.png", 16, 16); } } // web.xml { String content = DesignerTestCase.getSourceDQ(new String[] { "<?xml version='1.0' encoding='UTF-8'?>", "<!DOCTYPE web-app", " PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'", " 'http://java.sun.com/dtd/web-app_2_3.dtd'>", "", "<web-app>", "", " <!-- Default page to serve -->", " <welcome-file-list>", " <welcome-file>" + shortModuleName + ".html</welcome-file>", " </welcome-file-list>", "", "</web-app>" }); setFileContent(project, publicFolderPath + "/WEB-INF/web.xml", content); } // "server" package testProject.getPackage(packageName + ".server"); // done return moduleFile; }
From source file:net.di2e.ecdr.commons.util.SearchUtils.java
private static SortTypeConfiguration getSortConfiguration(String sortKey, List<SortTypeConfiguration> sortTypeConfigurationList, boolean supportWildcard) { for (SortTypeConfiguration sortType : sortTypeConfigurationList) { String configSortKey = sortType.getSortKey(); LOGGER.trace("Comparing incoming sort key of {} with configuration of key {}", sortKey, configSortKey); if (supportWildcard) { if (configSortKey.startsWith(SortTypeConfiguration.SORT_WILDCARD)) { configSortKey = StringUtils.substringAfterLast(configSortKey, SortTypeConfiguration.SORT_XPATH_DELIMITTER); if (sortKey.contains(SortTypeConfiguration.SORT_XPATH_DELIMITTER)) { sortKey = StringUtils.substringAfterLast(sortKey, SortTypeConfiguration.SORT_XPATH_DELIMITTER); }//from w ww . j av a2s. co m } LOGGER.trace( "SortKeys being compated after wildcard normalization query sortKey=[{}] and configuration sortKey=[{}]", sortKey, configSortKey); } if (StringUtils.equalsIgnoreCase(configSortKey, sortKey)) { return sortType; } } return null; }
From source file:info.magnolia.cms.core.HierarchyManager.java
/** * Like getContent() but creates the node if not yet existing. Attention save is not called! * @param path the path of the node// ww w . ja v a 2s .co m * @param create true if the node should get created * @param type the node type of the created node * @return the node * @throws AccessDeniedException * @throws RepositoryException */ public Content getContent(String path, boolean create, ItemType type) throws AccessDeniedException, RepositoryException { Content node; try { node = getContent(path); } catch (PathNotFoundException e) { if (create) { node = this.createContent(StringUtils.substringBeforeLast(path, "/"), StringUtils.substringAfterLast(path, "/"), type.toString()); } else { throw e; } } return node; }
From source file:it.latraccia.dss.util.builder.SignatureBuilder.java
/** * Suggest the target file name.//from w ww . ja v a 2s.c o m * Original code in {@link eu.europa.ec.markt.dss.applet.wizard.signature.SaveStep#prepareTargetFileName(java.io.File, * eu.europa.ec.markt.dss.signature.SignaturePackaging, String)} * * @param file The selected file to sign * @param signaturePackaging The selected packaging * @param signatureFormat The complete signature format (e.g. "CAdES") * @return The suggested target File */ private File prepareTargetFileName(final File file, final SignaturePackaging signaturePackaging, final String signatureFormat) { final File parentDir = file.getParentFile(); final String originalName = StringUtils.substringBeforeLast(file.getName(), "."); final String originalExtension = "." + StringUtils.substringAfterLast(file.getName(), "."); final String format = signatureFormat.toUpperCase(); if ((SignaturePackaging.ENVELOPING == signaturePackaging || SignaturePackaging.DETACHED == signaturePackaging) && format.startsWith("XADES")) { return new File(parentDir, originalName + "-signed" + ".xml"); } if (format.startsWith("CADES") && !originalExtension.toLowerCase().equals(".p7m")) { return new File(parentDir, originalName + originalExtension + ".p7m"); } if (format.startsWith("ASIC")) { return new File(parentDir, originalName + originalExtension + ".asics"); } return new File(parentDir, originalName + "-signed" + originalExtension); }
From source file:edu.ku.brc.af.ui.forms.formatters.UIFormatterEditorDlg.java
@Override public void createUI() { super.createUI(); CellConstraints cc = new CellConstraints(); orderUpBtn = createIconBtn("ReorderUp", "TCGD_MOVE_UP", new ActionListener() { public void actionPerformed(ActionEvent ae) { int inx = fieldsTbl.getSelectedRow(); UIFieldFormatterField item = (UIFieldFormatterField) fields.get(inx); fields.remove(inx);/*www . ja va 2 s .co m*/ fields.insertElementAt(item, inx - 1); fieldsTbl.getSelectionModel().setSelectionInterval(inx - 1, inx - 1); selectedFormat.resetLength(); updateEnabledState(); updateUIEnabled(); } }); orderDwnBtn = createIconBtn("ReorderDown", "TCGD_MOVE_DOWN", new ActionListener() { public void actionPerformed(ActionEvent ae) { int inx = fieldsTbl.getSelectedRow(); UIFieldFormatterField item = (UIFieldFormatterField) fields.get(inx); fields.remove(inx); fields.insertElementAt(item, inx + 1); fieldsTbl.getSelectionModel().setSelectionInterval(inx + 1, inx + 1); selectedFormat.resetLength(); updateEnabledState(); updateUIEnabled(); } }); // get formatters for field List<UIFieldFormatterIFace> fmtrs = new Vector<UIFieldFormatterIFace>(uiFieldFormatterMgrCache .getFormatterList(fieldInfo.getTableInfo().getClassObj(), fieldInfo.getName())); Collections.sort(fmtrs, new Comparator<UIFieldFormatterIFace>() { public int compare(UIFieldFormatterIFace o1, UIFieldFormatterIFace o2) { return o1.toPattern().compareTo(o2.toPattern()); } }); // table and field titles PanelBuilder tblInfoPB = new PanelBuilder( new FormLayout("r:p,2px,f:p:g", "p,2px,p,2px,p,10px")/*, new FormDebugPanel()*/); String typeStr = fieldInfo.getType(); typeStr = typeStr.indexOf('.') > -1 ? StringUtils.substringAfterLast(fieldInfo.getType(), ".") : typeStr; JLabel tableTitleLbl = createI18NFormLabel("FFE_TABLE"); JLabel tableTitleValueLbl = createLabel(fieldInfo.getTableInfo().getTitle()); tableTitleValueLbl.setBackground(Color.WHITE); tableTitleValueLbl.setOpaque(true); JLabel fieldTitleLbl = createI18NFormLabel("FFE_FIELD"); JLabel fieldTitleValueLbl = createLabel(fieldInfo.getTitle()); fieldTitleValueLbl.setBackground(Color.WHITE); fieldTitleValueLbl.setOpaque(true); JLabel fieldLengthLbl = createI18NFormLabel("FFE_LENGTH"); JLabel fieldLengthValueLbl = createLabel(Integer.toString(fieldInfo.getLength())); fieldLengthValueLbl.setBackground(Color.WHITE); fieldLengthValueLbl.setOpaque(true); int y = 1; tblInfoPB.add(tableTitleLbl, cc.xy(1, y)); tblInfoPB.add(tableTitleValueLbl, cc.xy(3, y)); y += 2; tblInfoPB.add(fieldTitleLbl, cc.xy(1, y)); tblInfoPB.add(fieldTitleValueLbl, cc.xy(3, y)); y += 2; tblInfoPB.add(fieldLengthLbl, cc.xy(1, y)); tblInfoPB.add(fieldLengthValueLbl, cc.xy(3, y)); y += 2; // sample panel sampleLabel = createLabel("", SwingConstants.LEFT); JPanel samplePanel = new JPanel(); samplePanel.setBorder(BorderFactory.createTitledBorder(getResourceString("FFE_SAMPLE"))); //$NON-NLS-1$ samplePanel.add(sampleLabel); // name text field nameTF = createTextField(20); // title text field titleTF = createTextField(20); byYearCB = createCheckBox(getResourceString("FFE_BY_YEAR_CHECKBOX")); //$NON-NLS-1$ hookByYearCheckBoxListener(); fieldsPanel = new EditDeleteAddPanel(getSaveAL(), getDelAL(), getAddAL()); fieldsTbl = new JTable(fieldsModel = new FieldsTableModel()); fieldTypeCbx = new JComboBox(FieldType.values()); // I18N fieldTxt = createTextField(20); fieldsPanel.getAddBtn().setEnabled(true); fieldsPanel.getEditBtn().setIcon(IconManager.getIcon("Green Arrow Up", IconManager.IconSize.Std16)); UIHelper.makeTableHeadersCentered(fieldsTbl, true); fieldTxt.setDocument(new FieldDocument()); fieldsTbl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); int width = fieldTypeCbx.getPreferredSize().width; y = 1; PanelBuilder subPB = new PanelBuilder(new FormLayout("r:p,2px,p", "p,4px, p,4px, p,4px, p,4px")); subPB.add(createI18NFormLabel("FFE_NAME"), cc.xy(1, y)); subPB.add(nameTF, cc.xy(3, y)); y += 2; subPB.add(createI18NFormLabel("FFE_TITLE"), cc.xy(1, y)); subPB.add(titleTF, cc.xy(3, y)); y += 2; subPB.add(byYearCB, cc.xy(3, y)); y += 2; // CardLayout for Editor Panels SpinnerModel retModel = new SpinnerNumberModel(1, //initial value 1, //min fieldInfo.getLength(), //max 1); //step sizeSpinner = new JSpinner(retModel); isIncChk = new JCheckBox("Is Incrementer"); // I18N String colDefs = "f:p:g,p,2px," + width + "px,2px,p"; closeBtn = createClose(0); PanelBuilder numPB = new PanelBuilder(new FormLayout(colDefs, "p,2px,p,2px,p")); numPB.add(createI18NFormLabel("FFE_LENGTH"), cc.xy(2, 1)); numPB.add(sizeSpinner, cc.xy(4, 1)); //numPB.add(closeBtn, cc.xy(6, 1)); numPB.add(isIncChk, cc.xy(4, 3)); sepCbx = new JComboBox(new String[] { "-", ".", "/", "(space)", "_" }); closeBtn = createClose(1); PanelBuilder sepPB = new PanelBuilder(new FormLayout(colDefs, "p,2px,p")); sepPB.add(createI18NFormLabel("FFE_SEP"), cc.xy(2, 1)); sepPB.add(sepCbx, cc.xy(4, 1)); //sepPB.add(closeBtn, cc.xy(6, 1)); closeBtn = createClose(2); PanelBuilder txtPB = new PanelBuilder(new FormLayout(colDefs, "p,2px,p")); txtPB.add(createI18NFormLabel("FFE_TEXT"), cc.xy(2, 1)); txtPB.add(fieldTxt, cc.xy(4, 1)); cardPanel = new JPanel(cardLayout); cardPanel.add("size", numPB.getPanel()); cardPanel.add("text", txtPB.getPanel()); cardPanel.add("sep", sepPB.getPanel()); cardPanel.add("none", new JLabel(" ")); y = 1; PanelBuilder leftPB = new PanelBuilder(new FormLayout("f:p:g", "t:p,10px,p,f:p:g")); leftPB.add(tblInfoPB.getPanel(), cc.xy(1, y)); y += 2; leftPB.add(subPB.getPanel(), cc.xy(1, y)); y += 2; PanelBuilder upDownPanel = new PanelBuilder(new FormLayout("p", "f:p:g, p, 2px, p, f:p:g")); upDownPanel.add(orderUpBtn, cc.xy(1, 2)); upDownPanel.add(orderDwnBtn, cc.xy(1, 4)); totLenLbl = createLabel("XXXXX"); y = 1; PanelBuilder rightPB = new PanelBuilder(new FormLayout("p:g,2px,p,2px,p", "200px,2px,p,2px,p,2px,p")); rightPB.add(createScrollPane(fieldsTbl), cc.xywh(1, y, 3, 1)); rightPB.add(upDownPanel.getPanel(), cc.xywh(5, y, 1, 1)); y += 2; rightPB.add(totLenLbl, cc.xy(1, y)); rightPB.add(fieldsPanel, cc.xywh(3, y, 1, 1)); y += 2; rightPB.add(fieldTypeLbl = createI18NFormLabel("FFE_TYPE"), cc.xy(1, y)); rightPB.add(fieldTypeCbx, cc.xy(3, y)); rightPB.add(closeBtn, cc.xy(5, y)); y += 2; rightPB.add(cardPanel, cc.xyw(1, y, 3)); y += 2; y = 1; PanelBuilder pb = new PanelBuilder(new FormLayout("p:g,10px,p,10px,p:g,10px,p", "f:p:g,10px,p")); Color bg = getBackground(); pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xywh(3, 1, 1, 1)); pb.add(leftPB.getPanel(), cc.xy(1, y)); pb.add(rightPB.getPanel(), cc.xy(5, y)); //pb.add(keyPanel, cc.xy(7, y)); y += 2; pb.add(samplePanel, cc.xyw(1, y, 7)); y += 2; setByYearSelected(selectedFormat); nameTF.setEditable(isNew); nameTF.setText(selectedFormat.getName()); titleTF.setText(selectedFormat.getTitle()); updateSample(); hookTextChangeListener(nameTF, "FFE_NO_NAME", 32); hookTextChangeListener(titleTF, "FFE_NO_TITLE", 32); pb.setDefaultDialogBorder(); contentPanel = pb.getPanel(); mainPanel.add(contentPanel, BorderLayout.CENTER); updateUIEnabled(); pack(); enabledEditorUI(false); hookFieldsTblSelectionListener(); fieldTypeCbx.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { typeChanged(); } }); sepCbx.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { fieldHasChanged = true; updateEnabledState(); hasChanged = true; updateUIEnabled(); } }); fieldTxt.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { fieldHasChanged = true; updateEnabledState(); hasChanged = true; updateUIEnabled(); } }); sizeSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { fieldHasChanged = true; updateEnabledState(); hasChanged = true; updateUIEnabled(); } }); isIncChk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fieldHasChanged = true; if (!isIncChk.isSelected()) { byYearCB.setSelected(false); } updateEntry(); updateUIEnabled(); updateEnabledState(); fieldsTbl.repaint(); } }); fieldTypeCbx.setSelectedIndex(-1); fieldHasChanged = false; updateEnabledState(); }
From source file:it.openutils.mgnlaws.magnolia.datastore.S3DataStore.java
public DataIdentifier getDataIdentifier(String key) { return new DataIdentifier(StringUtils.substringAfterLast(key, "/")); }
From source file:info.magnolia.link.LinkUtil.java
/** * Make a absolute path relative. It adds ../ until the root is reached * @param absolutePath absolute path// w ww . j a v a2s .c o m * @param url page to be relative to * @return relative path */ public static String makePathRelative(String url, String absolutePath) { String fromPath = StringUtils.substringBeforeLast(url, "/"); String toPath = StringUtils.substringBeforeLast(absolutePath, "/"); // reference to parent folder if (StringUtils.equals(fromPath, toPath) && StringUtils.endsWith(absolutePath, "/")) { return "."; } String[] fromDirectories = StringUtils.split(fromPath, "/"); String[] toDirectories = StringUtils.split(toPath, "/"); int pos = 0; while (pos < fromDirectories.length && pos < toDirectories.length && fromDirectories[pos].equals(toDirectories[pos])) { pos++; } StringBuilder rel = new StringBuilder(); for (int i = pos; i < fromDirectories.length; i++) { rel.append("../"); } for (int i = pos; i < toDirectories.length; i++) { rel.append(toDirectories[i] + "/"); } rel.append(StringUtils.substringAfterLast(absolutePath, "/")); return rel.toString(); }
From source file:gov.nih.nci.caarray.security.SecurityUtils.java
static InstanceLevelMappingElement findMappingElement(String className, String attributeName) { final String packageName = StringUtils.substringBeforeLast(className, "."); final String objectName = StringUtils.substringAfterLast(className, "."); for (final InstanceLevelMappingElement elt : Arrays.asList(projectMapping, sampleMapping)) { if (packageName.equals(elt.getObjectPackageName()) && objectName.equals(elt.getObjectName()) && attributeName.equals(elt.getAttributeName())) { return elt; }/* w w w . j av a 2s . c o m*/ } return null; }
From source file:info.magnolia.cms.core.DefaultHierarchyManager.java
/** * Like getContent() but creates the node if not yet existing. Attention save is not called! * @param path the path of the node/* w w w.j a v a 2 s.co m*/ * @param create true if the node should get created * @param type the node type of the created node * @return the node * @throws AccessDeniedException * @throws RepositoryException */ @Override public Content getContent(String path, boolean create, ItemType type) throws AccessDeniedException, RepositoryException { Content node; try { node = getContent(path); } catch (PathNotFoundException e) { if (create) { node = this.createContent(StringUtils.substringBeforeLast(path, "/"), StringUtils.substringAfterLast(path, "/"), type.toString()); AuditLoggingUtil.log(AuditLoggingUtil.ACTION_CREATE, getWorkspaceName(), node.getItemType(), node.getHandle()); } else { throw e; } } return node; }
From source file:eionet.cr.web.action.HarvestSourceActionBean.java
/** * * @return Resolution// ww w . j av a2s. co m */ public Resolution export() throws DAOException { Resolution resolution = new ForwardResolution("/pages/export.jsp"); // process further only if exportType has been specified if (!StringUtils.isBlank(exportType)) { // process further only if source URL has been specified if (harvestSource != null && !StringUtils.isBlank(harvestSource.getUrl())) { // if exporting to file, generate and stream RDF into servlet // response if (ExportType.FILE.toString().equals(exportType)) { resolution = (new StreamingResolution("application/rdf+xml") { @Override public void stream(HttpServletResponse response) throws Exception { RDFGenerator.generate(harvestSource.getUrl(), response.getOutputStream()); } }).setFilename("rdf.xml"); } else if (ExportType.HOMESPACE.toString().equals(exportType)) { try { // If datasetName not provided, then extract it from source url if (StringUtils.isBlank(datasetName)) { datasetName = StringUtils.substringAfterLast(harvestSource.getUrl(), "/"); } // Construct dataset uri if (!StringUtils.isBlank(datasetName) && !StringUtils.isBlank(folder)) { String dataset = folder + "/" + StringUtils.replace(datasetName, " ", "%20"); List<String> selectedFiles = new ArrayList<String>(); selectedFiles.add(harvestSource.getUrl()); CreateDataset cd = new CreateDataset(null, getUser()); cd.create(datasetName, dataset, folder, selectedFiles, overwriteDataset, null); return new RedirectResolution(FactsheetActionBean.class).addParameter("uri", dataset); } } catch (Exception e) { throw new DAOException(e.getMessage(), e); } } else { throw new IllegalArgumentException("Unknown export type: " + exportType); } } } else if (getUser() != null) { folders = FolderUtil.getUserAccessibleFolders(getUser()); } return resolution; }