List of usage examples for java.util.regex Matcher appendReplacement
public Matcher appendReplacement(StringBuilder sb, String replacement)
From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.WfsFilterDelegate.java
/** * The WKT passed into the spatial methods has the coordinates ordered in LON/LAT. This method * will convert the WKT to LAT/LON ordering. *//*from ww w . j a v a2s.c o m*/ private String convertWktToLatLonOrdering(String wktInLonLat) { if (Wfs20Constants.LAT_LON_ORDER.equals(coordinateOrder)) { LOGGER.debug("Converting WKT from LON/LAT coordinate ordering to LAT/LON coordinate ordering."); // Normalize all whitespace in WKT before processing. wktInLonLat = normalizeWhitespaceInWkt(wktInLonLat); Matcher matcher = COORD_PATTERN.matcher(wktInLonLat); StringBuffer stringBuffer = new StringBuffer(); while (matcher.find()) { String lonLatCoord = matcher.group(); String latLonCoord = StringUtils.reverseDelimited(lonLatCoord, ' '); LOGGER.debug("Converted LON/LAT coord: ({}) to LAT/LON coord: ({}).", lonLatCoord, latLonCoord); matcher.appendReplacement(stringBuffer, latLonCoord); } matcher.appendTail(stringBuffer); String wktInLatLon = stringBuffer.toString(); LOGGER.debug("Original WKT with coords in LON/LAT ordering: {}", wktInLonLat); LOGGER.debug("Converted WKT with coords in LAT/LON ordering: {}", wktInLatLon); return wktInLatLon; } else { LOGGER.debug("The configured CSW source requires coordinates in LON/LAT ordering."); return wktInLonLat; } }
From source file:org.intermine.bio.dataconversion.FlyBaseProcessor.java
/** * Return a map from feature_id to seqlen * @throws SQLException if somethign goes wrong *//*from ww w.ja v a 2 s . c o m*/ // private Map<Integer, Integer> makeCDNALengthMap(Connection connection) // throws SQLException { // Map<Integer, Integer> retMap = new HashMap(); // // ResultSet res = getCDNALengthResultSet(connection); // while (res.next()) { // Integer featureId = new Integer(res.getInt("feature_id")); // Integer seqlen = new Integer(res.getInt("seqlen")); // retMap.put(featureId, seqlen); // } // return retMap; // } private Item makePhenotypeAnnotation(String alleleItemIdentifier, String value, Item dataSetItem, List<String> publicationsItemIdList) throws ObjectStoreException { Item phenotypeAnnotation = getChadoDBConverter().createItem("PhenotypeAnnotation"); phenotypeAnnotation.addToCollection("dataSets", dataSetItem); Pattern p = Pattern.compile(FLYBASE_PROP_ATTRIBUTE_PATTERN); Matcher m = p.matcher(value); StringBuffer sb = new StringBuffer(); List<String> dbAnatomyTermIdentifiers = new ArrayList<String>(); List<String> dbDevelopmentTermIdentifiers = new ArrayList<String>(); List<String> dbCVTermIdentifiers = new ArrayList<String>(); while (m.find()) { String field = m.group(1); int colonPos = field.indexOf(':'); if (colonPos == -1) { m.appendReplacement(sb, field); } else { String identifier = field.substring(0, colonPos); if (identifier.startsWith(FLYBASE_ANATOMY_TERM_PREFIX)) { dbAnatomyTermIdentifiers.add(addCVTermColon(identifier)); } else { if (identifier.startsWith("FBdv")) { dbDevelopmentTermIdentifiers.add(addCVTermColon(identifier)); } else { if (identifier.startsWith("FBcv")) { dbCVTermIdentifiers.add(addCVTermColon(identifier)); } } } String text = field.substring(colonPos + 1); m.appendReplacement(sb, text); } } m.appendTail(sb); /* * ignore with for now because the with text is wrong in chado - see ticket #889 List<String> withAlleleIdentifiers = findWithAllele(value); if (withAlleleIdentifiers.size() > 0) { phenotypeAnnotation.setCollection("with", withAlleleIdentifiers); } */ String valueNoRefs = sb.toString(); String valueNoUps = valueNoRefs.replaceAll("<up>", "[").replaceAll("</up>", "]"); phenotypeAnnotation.setAttribute("description", valueNoUps); phenotypeAnnotation.setReference("allele", alleleItemIdentifier); if (publicationsItemIdList != null && publicationsItemIdList.size() > 0) { ReferenceList pubReferenceList = new ReferenceList("publications", publicationsItemIdList); phenotypeAnnotation.addCollection(pubReferenceList); } if (dbAnatomyTermIdentifiers.size() == 1) { String anatomyIdentifier = dbAnatomyTermIdentifiers.get(0); String anatomyTermItemId = makeAnatomyTerm(anatomyIdentifier); phenotypeAnnotation.setReference("anatomyTerm", anatomyTermItemId); } else { if (dbAnatomyTermIdentifiers.size() > 1) { throw new RuntimeException("more than one anatomy term: " + dbAnatomyTermIdentifiers); } } if (dbDevelopmentTermIdentifiers.size() == 1) { String developmentTermIdentifier = dbDevelopmentTermIdentifiers.get(0); String developmentTermItemId = makeDevelopmentTerm(developmentTermIdentifier); phenotypeAnnotation.setReference("developmentTerm", developmentTermItemId); } else { if (dbAnatomyTermIdentifiers.size() > 1) { throw new RuntimeException("more than one anatomy term: " + dbAnatomyTermIdentifiers); } } if (dbCVTermIdentifiers.size() > 0) { for (String cvTermIdentifier : dbCVTermIdentifiers) { String cvTermItemId = makeCVTerm(cvTermIdentifier); phenotypeAnnotation.addToCollection("cvTerms", cvTermItemId); } } return phenotypeAnnotation; }
From source file:com.g3net.tool.StringUtils.java
/** * src?regex??????? ?(handler)// ww w .j ava 2 s . co m * ????? * * @param src * @param regex * ??:&(\\d+;)([a-z)+) * @param handleGroupIndex * ??? * @param hander * ? * @param reservesGroups * ???,?hander?handleGroupIndex * ?reservesGroups?hander?regex? * @return */ public static String replaceAll(String src, String regex, int handleGroupIndex, GroupHandler hander, int[] reservesGroups) { if (src == null || src.trim().length() == 0) { return ""; } Matcher m = Pattern.compile(regex).matcher(src); StringBuffer sbuf = new StringBuffer(); String replacementFirst = ""; String replacementTail = ""; if (reservesGroups != null && reservesGroups.length > 0) { Arrays.sort(reservesGroups); for (int i = 0; i < reservesGroups.length; i++) { if (reservesGroups[i] < handleGroupIndex) { replacementFirst = replacementFirst + "$" + reservesGroups[i]; } else { replacementTail = replacementTail + "$" + reservesGroups[i]; } } } // perform the replacements: while (m.find()) { String value = m.group(handleGroupIndex); String group = m.group(); String handledStr = hander.handler(value); String replacement = ""; if (reservesGroups == null) { int start0 = m.start(); int end0 = m.end(); int start = m.start(handleGroupIndex); int end = m.end(handleGroupIndex); int relativeStart = start - start0; int relativeEnd = end - start0; StringBuilder sbgroup = new StringBuilder(group); sbgroup = sbgroup.replace(relativeStart, relativeEnd, handledStr); replacement = sbgroup.toString(); } else { replacement = replacementFirst + handledStr + replacementTail; } m.appendReplacement(sbuf, replacement); } // Put in the remainder of the text: m.appendTail(sbuf); return sbuf.toString(); // return null; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * Parses the text and if embed media found then translates the path and adds the file to the zip package. * /*from w w w .java2s . c o m*/ * @param zip * The zip package * @param text * Text * @param mediaFiles * List of embedded files found * @return The translated Text */ protected String translateEmbedData(ZipOutputStream zip, String subFolder, String writeSubFolder, String text, List<String> mediaFiles) { Pattern p = Pattern.compile("(src|href)[\\s]*=[\\s]*\"([^#\"]*)([#\"])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); StringBuffer sb = new StringBuffer(); subFolder = (subFolder == null || subFolder.length() == 0) ? "Resources/" : subFolder; Matcher m = p.matcher(text); // security advisor pushAdvisor(); while (m.find()) { if (m.groupCount() != 3) continue; String ref = m.group(2); if (!ref.contains("/access/mneme/content/")) continue; String resource_id = ref.replace("/access/mneme", ""); String resource_name = ref.substring(ref.lastIndexOf("/") + 1); resource_name = resource_name.replaceAll("%20", " "); resource_name = Validator.escapeResourceName(resource_name); mediaFiles.add(subFolder + resource_name); m.appendReplacement(sb, m.group(1) + "= \"" + writeSubFolder + resource_name + "\""); writeContentResourceToZip(zip, subFolder, resource_id, resource_name); } popAdvisor(); m.appendTail(sb); return sb.toString(); }
From source file:org.etudes.util.XrefHelper.java
/** * Replace any embedded references in the html data with the translated, new references listed in translations. * //w w w . j a v a 2 s .co m * @param data * the html data. * @param translations * The translations. * @param siteId * The site id. * @param parentRef * Reference of the resource that has data as body. * @return The translated html data. */ @SuppressWarnings("unchecked") public static String translateEmbeddedReferences(String data, Collection<Translation> translations, String siteId, String parentRef) { if (data == null) return data; if (translations == null) return data; // get our thread-local list of translations made in this thread (if any) List<Translation> threadTranslations = (List<Translation>) ThreadLocalManager.get(THREAD_TRANSLATIONS_KEY); Pattern p = getPattern(); Matcher m = p.matcher(data); StringBuffer sb = new StringBuffer(); // process each "harvested" string (avoiding like strings that are not in src= or href= patterns) while (m.find()) { if (m.groupCount() == 3) { String ref = m.group(2); String terminator = m.group(3); if (ref != null) ref = ref.trim(); // expand to a full reference if relative ref = adjustRelativeReference(ref, parentRef); // harvest any content hosting reference int index = indexContentReference(ref); if (index != -1) { // except those we don't want to harvest if (exception(ref, siteId)) index = -1; } if (index != -1) { // save just the reference part (i.e. after the /access); String normal = ref.substring(index + 7); // deal with %20, &, and other encoded URL stuff normal = decodeUrl(normal); // translate the normal form String translated = normal; for (Translation translation : translations) { translated = translation.translate(translated); } // also translate with our global list if (threadTranslations != null) { for (Translation translation : threadTranslations) { translated = translation.translate(translated); } } // URL encode translated String escaped = escapeUrl(translated); // if changed, replace if (!normal.equals(translated)) { m.appendReplacement(sb, Matcher.quoteReplacement( m.group(1) + "=\"" + ref.substring(0, index + 7) + escaped + terminator)); } } } } m.appendTail(sb); return sb.toString(); }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * /*from w ww . j av a2 s .co m*/ * @param questionDocument * @param itemBody * @param question * @param questionParts * @return */ public Element getFillBlanksResponseChoices(Document questionDocument, Element itemBody, FillBlanksQuestionImpl question, Map<String, Element> questionParts) { if (question == null) return itemBody; // itemBody String text = question.getText(); Pattern p_fillBlanks_curly = Pattern.compile("([^{]*.?)(\\{)([^}]*.?)(\\})", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); Matcher m_fillBlanks = p_fillBlanks_curly.matcher(text); StringBuffer sb = new StringBuffer(); // in each part look for {} fill in the blank symbol and create render_fib tag int count = 1; while (m_fillBlanks.find()) { String fib = m_fillBlanks.group(1); Element textDiv = questionDocument.createElement("div"); textDiv.setTextContent(fib); itemBody.appendChild(textDiv); String fib_curly = m_fillBlanks.group(2); Element fbInteraction = questionDocument.createElement("textEntryInteraction"); fbInteraction.setAttribute("responseIdentifier", "RESPONSE" + (count++)); fbInteraction.setAttribute("expectedLength", Integer.toString(fib_curly.length())); itemBody.appendChild(fbInteraction); m_fillBlanks.appendReplacement(sb, ""); } m_fillBlanks.appendTail(sb); if (sb.length() > 0) { Element textDiv = questionDocument.createElement("div"); textDiv.setTextContent(sb.toString()); itemBody.appendChild(textDiv); } // answer List<String> correctAnswers = new ArrayList<String>(); question.parseCorrectAnswers(correctAnswers); int responseCount = 1; for (String answer : correctAnswers) { Element responseDeclaration = createResponseDeclaration(questionDocument, "RESPONSE" + responseCount, "single", "string"); Element correctResponse = questionDocument.createElement("correctResponse"); Element correctResponseValue = questionDocument.createElement("value"); answer = FormattedText.unEscapeHtml(answer); correctResponseValue.setTextContent(answer); correctResponse.appendChild(correctResponseValue); responseDeclaration.appendChild(correctResponse); questionParts.put("responseDeclaration" + responseCount, responseDeclaration); responseCount++; } Element countDiv = questionDocument.createElement("div"); countDiv.setTextContent(Integer.toString(responseCount)); questionParts.put("responseDeclarationCount", countDiv); questionParts.put("itemBody", itemBody); return itemBody; }
From source file:org.nuclos.client.wizard.steps.NuclosEntityAttributeCommonPropertiesStep.java
@Override public void prepare() { super.prepare(); cbMandatory.setEnabled(true);//from w ww.j av a 2s. c o m fillCalcFunctionBox(); if (!this.parentWizardModel.isStateModel()) { cbxAttributeGroup.setEnabled(false); } else { fillAttributeGroupBox(); } if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Integer")) { final NumericFormatDocument nfd = new NumericFormatDocument(); nfd.addDocumentListener(new DefaultValueDocumentListener()); tfDefaultValue.setDocument(nfd); final NumericFormatDocument nfdMandatory = new NumericFormatDocument(); nfdMandatory.addDocumentListener(new MandatoryValueDocumentListener()); tfMandatory.setDocument(nfdMandatory); } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Double")) { final DoubleFormatDocument dfd = new DoubleFormatDocument(); dfd.addDocumentListener(new DefaultValueDocumentListener()); tfDefaultValue.setDocument(dfd); final DoubleFormatDocument dfdMandatory = new DoubleFormatDocument(); dfdMandatory.addDocumentListener(new MandatoryValueDocumentListener()); tfMandatory.setDocument(dfdMandatory); } if (getModel().isEditMode()) { tfLabel.setText(getModel().getAttribute().getInternalName()); cbxCalcFunction.setSelectedItem(getModel().getAttribute().getCalcFunction()); cbxAttributeGroup.setSelectedItem(getModel().getAttribute().getAttributeGroup()); cbDistinct.setSelected(getModel().getAttribute().isDistinct()); ItemListener ilArray[] = cbMandatory.getItemListeners(); for (ItemListener il : ilArray) { cbMandatory.removeItemListener(il); } cbMandatory.setSelected(getModel().getAttribute().isMandatory()); for (ItemListener il : ilArray) { cbMandatory.addItemListener(il); } cbLogBook.setSelected(getModel().getAttribute().isLogBook()); cbIndexed.setSelected(getModel().getAttribute().isIndexed()); if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.util.Date")) { String str = getModel().getAttribute().getDefaultValue(); if (RelativeDate.today().toString().equals(str)) { dateDefaultValue.setDate(new Date(System.currentTimeMillis())); dateDefaultValue.getJTextField().setText("Heute"); } else if ("Heute".equalsIgnoreCase(str)) { dateDefaultValue.setDate(new Date(System.currentTimeMillis())); dateDefaultValue.getJTextField().setText("Heute"); } else { SimpleDateFormat result = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY); result.setLenient(false); try { dateDefaultValue.setDate(result.parse(str)); } catch (Exception e) { // set no day LOG.warn("prepare failed: " + e, e); } } } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Boolean")) { String value = getModel().getAttribute().getDefaultValue(); if (value != null && value.equalsIgnoreCase("ja")) { cbDefaultValue.setSelected(true); } else { cbDefaultValue.setSelected(false); } } else { tfDefaultValue.setText(getModel().getAttribute().getDefaultValue()); } if (getModel().getAttribute().getDbName() != null) { String sModifiedDBName = new String(getModel().getAttribute().getDbName()); tfDBFieldName.setText(sModifiedDBName.replaceFirst("^STRVALUE_", "").replaceFirst("^INTID_", "")); if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() != null) { tfDBFieldNameComplete.setText("STRVALUE_" + getModel().getAttribute().getDbName()); } else if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() == null) { tfDBFieldNameComplete.setText("INTID_" + getModel().getAttribute().getDbName()); } } } else { if (!blnLabelModified) tfLabel.setText(getModel().getName().toLowerCase()); if (getModel().getAttributeCount() == 0 && !blnDefaultSelected) { cbDistinct.setSelected(true); cbMandatory.setSelected(true); blnDefaultSelected = true; } cbDistinct.setEnabled(!this.parentWizardModel.hasRows()); cbIndexed.setSelected(getModel().isRefernzTyp()); if (cbxAttributeGroup.getModel().getSize() > 1) { if (this.parentWizardModel.isStateModel()) cbxAttributeGroup.setSelectedIndex(1); } if (getModel().getAttribute().getDbName() != null) { String sModifiedDBName = new String(getModel().getAttribute().getDbName()); tfDBFieldName.setText(sModifiedDBName.replaceFirst("^STRVALUE_", "").replaceFirst("^INTID_", "")); if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() != null) { tfDBFieldNameComplete.setText("STRVALUE_" + getModel().getAttribute().getDbName()); } else if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() == null) { tfDBFieldNameComplete.setText("INTID_" + getModel().getAttribute().getDbName()); } } } Object objMandatoryValue = getModel().getAttribute().getMandatoryValue(); if (getModel().isRefernzTyp() || getModel().isLookupTyp()) { ItemListener listener[] = cbxDefaultValue.getItemListeners(); for (ItemListener il : listener) { cbxDefaultValue.removeItemListener(il); } ItemListener listenerMandatory[] = cbxDefaultValue.getItemListeners(); for (ItemListener il : listenerMandatory) { cbxMandatory.removeItemListener(il); } boolean isValueList = getModel().getAttribute().isValueListProvider(); cbxDefaultValue.setVisible(!isValueList); lovDefaultValue.setVisible(isValueList); tfDefaultValue.setVisible(false); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxMandatory.setVisible(!isValueList && this.parentWizardModel.isEditMode()); lovMandatory.setVisible(isValueList && this.parentWizardModel.isEditMode()); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); List<DefaultValue> defaultModel = new ArrayList<DefaultValue>(); List<DefaultValue> mandatoryModel = new ArrayList<DefaultValue>(); DefaultValue mandatoryValue = null; final String sEntity = !getModel().isLookupTyp() ? getModel().getAttribute().getMetaVO().getEntity() : getModel().getAttribute().getLookupMetaVO().getEntity(); if (!isValueList) { Collection<MasterDataVO> colVO = MasterDataDelegate.getInstance().getMasterData(sEntity); for (MasterDataVO vo : colVO) { String sField = getModel().getAttribute().getField(); if (sField == null) break; Pattern referencedEntityPattern = Pattern.compile("[$][{][\\w\\[\\]]+[}]"); Matcher referencedEntityMatcher = referencedEntityPattern.matcher(sField); StringBuffer sb = new StringBuffer(); while (referencedEntityMatcher.find()) { Object value = referencedEntityMatcher.group().substring(2, referencedEntityMatcher.group().length() - 1); String sName = value.toString(); Object fieldValue = vo.getField(sName); if (fieldValue != null) referencedEntityMatcher.appendReplacement(sb, fieldValue.toString()); else referencedEntityMatcher.appendReplacement(sb, ""); } // complete the transfer to the StringBuffer referencedEntityMatcher.appendTail(sb); sField = sb.toString(); DefaultValue dv = new DefaultValue(vo.getIntId(), sField); defaultModel.add(dv); mandatoryModel.add(dv); if (dv.getId().equals(objMandatoryValue)) { mandatoryValue = dv; } } Collections.sort(defaultModel); Collections.sort(mandatoryModel); defaultModel.add(0, new DefaultValue(null, null)); mandatoryModel.add(0, new DefaultValue(null, null)); cbxDefaultValue.setModel(new ListComboBoxModel<DefaultValue>(defaultModel)); cbxDefaultValue.setSelectedItem(getModel().getAttribute().getIdDefaultValue()); cbxMandatory.setModel(new ListComboBoxModel<DefaultValue>(mandatoryModel)); if (mandatoryValue != null) { cbxMandatory.setSelectedItem(mandatoryValue); } for (ItemListener il : listener) { cbxDefaultValue.addItemListener(il); } for (ItemListener il : listenerMandatory) { cbxMandatory.addItemListener(il); } } else { final EntityFieldMetaDataVO efMetaDataVO = new EntityFieldMetaDataVO(); efMetaDataVO.setField(sEntity); efMetaDataVO.setDataType(String.class.getName()); efMetaDataVO.setForeignEntity(sEntity); efMetaDataVO.setForeignEntityField(getModel().getAttribute().getField()); lovDefaultValue.setModel(getModel()); lovDefaultValue.setEfMetaDataVO(efMetaDataVO); lovDefaultValue.setSelectedListener(new ListOfValues.SelectedListener() { @Override public void actionPerformed(CollectableValueIdField itemSelected) { if (itemSelected == null) { getModel().getAttribute().setIdDefaultValue(new DefaultValue(null, null)); } else { getModel().getAttribute().setIdDefaultValue( new DefaultValue(IdUtils.unsafeToId(itemSelected.getValueId()), (String) itemSelected.getValue())); } } }); lovMandatory.setModel(getModel()); lovMandatory.setEfMetaDataVO(efMetaDataVO); lovMandatory.setSelectedListener(new ListOfValues.SelectedListener() { @Override public void actionPerformed(CollectableValueIdField itemSelected) { if (itemSelected == null) { getModel().getAttribute().setMandatoryValue(new DefaultValue(null, null).getId()); } else { getModel().getAttribute().setMandatoryValue( new DefaultValue(IdUtils.unsafeToId(itemSelected.getValueId()), (String) itemSelected.getValue()).getId()); } } }); } } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.util.Date")) { dateDefaultValue.setVisible(true); cbxDefaultValue.setVisible(false); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(false); dateMandatory.setVisible(this.parentWizardModel.isEditMode()); if (objMandatoryValue != null && objMandatoryValue instanceof Date) { dateMandatory.setDate((Date) objMandatoryValue); } cbMandatoryValue.setVisible(false); } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Boolean")) { cbxDefaultValue.setVisible(false); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(false); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(true); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(this.parentWizardModel.isEditMode()); if (objMandatoryValue != null && objMandatoryValue instanceof Boolean) { cbMandatoryValue.setSelected((Boolean) objMandatoryValue); } } else if (getModel().getAttribute().isValueList()) { ItemListener listener[] = cbxDefaultValue.getItemListeners(); for (ItemListener il : listener) { cbxDefaultValue.removeItemListener(il); } cbxCalcFunction.setEnabled(false); cbxDefaultValue.setVisible(true); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(false); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxDefaultValue.removeAllItems(); cbxDefaultValue.addItem(new DefaultValue(null, null)); cbxMandatory.addItem(new DefaultValue(null, null)); for (ValueList valueList : getModel().getAttribute().getValueList()) { cbxDefaultValue.addItem(new DefaultValue( valueList.getId() != null ? valueList.getId().intValue() : null, valueList.getLabel())); } cbxDefaultValue.setSelectedItem(getModel().getAttribute().getDefaultValue()); for (ItemListener il : listener) { cbxDefaultValue.addItemListener(il); } listener = cbxMandatory.getItemListeners(); for (ItemListener il : listener) { cbxMandatory.removeItemListener(il); } for (ValueList valueList : getModel().getAttribute().getValueList()) { DefaultValue dv = new DefaultValue(valueList.getId() != null ? valueList.getId().intValue() : null, valueList.getLabel()); cbxMandatory.addItem(dv); if (dv.getId() != null && dv.getId().equals(objMandatoryValue)) { cbxMandatory.setSelectedItem(dv); } } for (ItemListener il : listener) { cbxMandatory.addItemListener(il); } cbMandatory.setEnabled(getModel().getAttribute().getId() != null); cbxMandatory.setVisible(true); lovMandatory.setVisible(parentWizardModel.isEditMode() && getModel().getAttribute().getId() != null); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); } else if (getModel().getAttribute().isImage() || getModel().getAttribute().isPasswordField() || getModel().getAttribute().isFileType()) { cbMandatory.setEnabled(false); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); } else { cbxDefaultValue.setVisible(false); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(true); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(this.parentWizardModel.isEditMode()); if (objMandatoryValue != null) { tfMandatory.setText(objMandatoryValue.toString()); } dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); } Attribute attr = NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute(); if (NuclosEntityAttributeCommonPropertiesStep.this.parentWizardModel.hasRows() && attr.getId() != null) { boolean blnAllowed = StringUtils.isEmpty(attr.getInternalName()) ? false : MetaDataDelegate.getInstance().isChangeDatabaseColumnToUniqueAllowed( NuclosEntityAttributeCommonPropertiesStep.this.parentWizardModel.getEntityName(), attr.getInternalName()); if (!blnAllowed && !attr.isDistinct()) { cbDistinct.setSelected(false); cbDistinct.setEnabled(false); cbDistinct.setToolTipText(SpringLocaleDelegate.getInstance().getMessage( "wizard.step.entitysqllayout.6", "Das Feld {0} kann nicht auf ein eindeutiges Feld umgestellt werden.", attr.getLabel())); } } if (parentWizardModel.isVirtual()) { cbDistinct.setSelected(false); cbDistinct.setEnabled(false); tfMandatory.setEnabled(false); dateMandatory.setEnabled(false); cbMandatory.setEnabled(false); cbxMandatory.setEnabled(false); cbMandatoryValue.setEnabled(false); cbxCalcFunction.setEnabled(false); tfDBFieldName.setEnabled(false); cbIndexed.setEnabled(false); tfDefaultValue.setEnabled(false); dateDefaultValue.setEnabled(false); cbxDefaultValue.setEnabled(false); cbDefaultValue.setEnabled(false); cbLogBook.setEnabled(false); } }
From source file:uk.ac.ebi.intact.editor.controller.misc.MyNotesController.java
private String replaceACs(String line, Pattern pattern) { Matcher matcher = pattern.matcher(line); StringBuffer sb = new StringBuffer(line.length() * 2); while (matcher.find()) { String ac = matcher.group(); String replacement;//from ww w .j a v a 2 s .co m Class aoClass = getMyNotesService().loadClassFromAc(ac); if (aoClass == null) { addWarningMessage("Accession problem: " + ac, "Some accession numbers in the note could not be auto-linked because there is no object type for " + "that accession, or it does not exist in the database"); replacement = ac; } String urlFolderName = null; if (IntactPublication.class.isAssignableFrom(aoClass)) { urlFolderName = "publication"; } else if (IntactExperiment.class.isAssignableFrom(aoClass)) { urlFolderName = "experiment"; } else if (IntactInteractionEvidence.class.isAssignableFrom(aoClass)) { urlFolderName = "interaction"; } else if (IntactComplex.class.isAssignableFrom(aoClass)) { urlFolderName = "complex"; } else if (IntactInteractor.class.isAssignableFrom(aoClass)) { urlFolderName = "interactor"; } else if (IntactModelledParticipant.class.isAssignableFrom(aoClass)) { urlFolderName = "complex participant"; } else if (IntactParticipantEvidence.class.isAssignableFrom(aoClass)) { urlFolderName = "participant"; } else if (IntactModelledFeature.class.isAssignableFrom(aoClass)) { urlFolderName = "complex feature"; } else if (IntactFeatureEvidence.class.isAssignableFrom(aoClass)) { urlFolderName = "feature"; } else if (IntactOrganism.class.isAssignableFrom(aoClass)) { urlFolderName = "organism"; } else if (IntactCvTerm.class.isAssignableFrom(aoClass)) { urlFolderName = "cvobject"; } else if (IntactSource.class.isAssignableFrom(aoClass)) { urlFolderName = "institution"; } replacement = "<a href=\"" + absoluteContextPath + "/" + urlFolderName + "/" + ac + "\">" + ac + "</a>"; matcher.appendReplacement(sb, replacement); } matcher.appendTail(sb); return sb.toString(); }
From source file:com.ibm.jaggr.service.impl.AggregatorImpl.java
@Override public String substituteProps(String str, SubstitutionTransformer transformer) { if (str == null) { return null; }//from ww w. ja va 2 s .co m StringBuffer buf = new StringBuffer(); Matcher matcher = pattern.matcher(str); while (matcher.find()) { String propName = matcher.group(1); String propValue = null; if (getBundleContext() != null) { propValue = getBundleContext().getProperty(propName); } else { propValue = System.getProperty(propName); } if (propValue == null && variableResolverServiceTracker != null) { ServiceReference[] refs = variableResolverServiceTracker.getServiceReferences(); if (refs != null) { for (ServiceReference sr : refs) { IVariableResolver resolver = (IVariableResolver) getBundleContext().getService(sr); try { propValue = resolver.resolve(propName); if (propValue != null) { break; } } finally { getBundleContext().ungetService(sr); } } } } if (propValue != null) { if (transformer != null) { propValue = transformer.transform(propName, propValue); } matcher.appendReplacement(buf, propValue.replace("\\", "\\\\") //$NON-NLS-1$ //$NON-NLS-2$ .replace("$", "\\$") //$NON-NLS-1$ //$NON-NLS-2$ ); } else { matcher.appendReplacement(buf, "\\${" + propName + "}"); //$NON-NLS-1$ //$NON-NLS-2$ } } matcher.appendTail(buf); return buf.toString(); }
From source file:info.magnolia.module.admininterface.SaveHandlerImpl.java
/** * Update the links in a string returned by a rich text editor. If there are links to temporary files created due * the fckeditor upload mechanism those filese are written to the node. * @param node node saving to. used to save the files and fileinfod to * @param name the name of the field. used to make a subnode for the files * @param valueStr the value containing the links * @return the cleaned value//ww w .j av a2s . c o m * @throws AccessDeniedException * @throws RepositoryException * @throws PathNotFoundException */ private String updateLinks(Content node, String name, String valueStr) throws AccessDeniedException, RepositoryException, PathNotFoundException { // process the images and uploaded files HierarchyManager hm = MgnlContext.getHierarchyManager(this.getRepository()); Pattern imagePattern = Pattern.compile("(<(a|img)[^>]+(href|src)[ ]*=[ ]*\")([^\"]*)(\"[^>]*>)"); Pattern uuidPattern = Pattern.compile(MgnlContext.getContextPath() + "/tmp/fckeditor/([^/]*)/[^\"]*"); Content filesNode = ContentUtil.getOrCreateContent(node, name + "_files", ItemType.CONTENTNODE); String pageName = StringUtils.substringAfterLast(this.getPath(), "/"); // adapt img urls Matcher srcMatcher = imagePattern.matcher(valueStr); StringBuffer res = new StringBuffer(); while (srcMatcher.find()) { String src = srcMatcher.group(4); // the editor creates relative links after moving an absolute path: ../../../ replace them src = StringUtils.replace(src, "../../../", MgnlContext.getContextPath() + "/"); String link = src; // process the tmporary uploaded files Matcher uuidMatcher = uuidPattern.matcher(src); if (uuidMatcher.find()) { String uuid = uuidMatcher.group(1); Document doc = FCKEditorTmpFiles.getDocument(uuid); String fileNodeName = Path.getUniqueLabel(hm, filesNode.getHandle(), "file"); SaveHandlerImpl.saveDocument(filesNode, doc, fileNodeName, "", ""); String subpath = StringUtils.removeStart(filesNode.getHandle(), this.getPath() + "/"); link = pageName + "/" + subpath + "/" + fileNodeName + "/" + doc.getFileNameWithExtension(); doc.delete(); try { FileUtils.deleteDirectory(new java.io.File(Path.getTempDirectory() + "/fckeditor/" + uuid)); } catch (IOException e) { log.error("can't delete tmp file [" + Path.getTempDirectory() + "/fckeditor/" + uuid + "]"); } } // make internal links relative else if (src.startsWith(MgnlContext.getContextPath())) { link = pageName + StringUtils.removeStart(src, MgnlContext.getContextPath() + this.getPath()); } // internal uuid links have a leading $ link = StringUtils.replace(link, "$", "\\$"); srcMatcher.appendReplacement(res, "$1" + link + "$5"); //$NON-NLS-1$ } srcMatcher.appendTail(res); valueStr = res.toString(); return valueStr; }