List of usage examples for java.io Serializable toString
public String toString()
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileUtils.java
public static RepositoryFile createFolder(final Session session, final CredentialsStrategySessionFactory sessionFactory, final RepositoryFile parentFolder, final RepositoryFile folder, final boolean inheritAces, final RepositoryFileSid ownerSid, final IPathConversionHelper pathConversionHelper, final String versionMessage) throws RepositoryException { Serializable parentFolderId = parentFolder == null ? null : parentFolder.getId(); PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId);/*from w ww . j a va2 s. c om*/ Node folderNode = createFolderNode(session, pentahoJcrConstants, parentFolderId, folder); session.save(); JcrRepositoryFileAclUtils.createAcl(session, pentahoJcrConstants, folderNode.getIdentifier(), new RepositoryFileAcl.Builder(ownerSid).entriesInheriting(inheritAces).build()); session.save(); if (folder.isVersioned()) { JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants, folderNode, versionMessage); } JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, parentFolderId, Messages.getInstance().getString("JcrRepositoryFileDao.USER_0001_VER_COMMENT_ADD_FOLDER", folder.getName(), (parentFolderId == null ? "root" : parentFolderId.toString()))); //$NON-NLS-1$ //$NON-NLS-2$ return JcrRepositoryFileUtils.getFileById(session, pentahoJcrConstants, pathConversionHelper, null, folderNode.getIdentifier()); }
From source file:org.nuxeo.ecm.core.storage.sql.Model.java
/** * Turns an id that may be a String or a Long into a String for high-level * Nuxeo APIs./* w ww .java 2s .c om*/ * * @param the serializable id * @return the string */ public String idToString(Serializable id) { return id.toString(); }
From source file:org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache.java
/** * Returns true if the removal was succesful; or false if there is nothing to remove. Current * implementation always result in a disk orphan. * <p>/*from www .ja v a2 s . c o m*/ * @return true if at least one item was removed. * @param key */ public boolean doRemove(Serializable key) { if (!alive) { log.error(logCacheName + "No longer alive so returning false for key = " + key); return false; } if (key == null) { return false; } boolean reset = false; boolean removed = false; try { storageLock.writeLock().acquire(); if (key instanceof String && key.toString().endsWith(CacheConstants.NAME_COMPONENT_DELIMITER)) { removed = performPartialKeyRemoval((String) key); } else if (key instanceof GroupId) { removed = performGroupRemoval((GroupId) key); } else { removed = performSingleKeyRemoval(key); } } catch (Exception e) { log.error(logCacheName + "Problem removing element.", e); reset = true; } finally { storageLock.writeLock().release(); } if (reset) { reset(); } // this increments the removecount. // there is no reason to call this if an item was not removed. if (removed) { doOptimizeRealTime(); } return removed; }
From source file:org.alfresco.repo.node.NodeServiceTest.java
/** * Looks for a key that contains the toString() of the value *//*from w w w . j a v a2 s . c o m*/ private Object findCacheValue(SimpleCache<Serializable, ValueHolder<Serializable>> cache, Serializable key) { Collection<Serializable> keys = cache.getKeys(); for (Serializable keyInCache : keys) { String keyInCacheStr = keyInCache.toString(); String keyStr = key.toString(); if (keyInCacheStr.endsWith(keyStr)) { Object value = TransactionalCache.getSharedCacheValue(cache, keyInCache); return value; } } return null; }
From source file:it.doqui.index.ecmengine.business.job.backup.MetaDataBackupJob.java
private void generaXmlMetaDati(NodeRef nodeRef, Map<QName, Serializable> propertyMap) throws JiBXException, FileNotFoundException, DictionaryRuntimeException { logger.debug("[MetaDatiManager::generaXmlMetaDati] BEGIN"); String nomeFile;/*from www .jav a 2s . com*/ //String folderFileMetaDati = "/usr/prod/fs/alfresco2/metadati"; //contentDir //dir.contenstore = /usr/prod/fs/alfresco2/content/contentstore String folderContent = this.contentDir; logger.debug("[MetaDatiManager::generaXmlMetaDati] Directory Contenuti: " + folderContent); try { nomeFile = nodeRef.getId() + ".xml"; logger.debug("[MetaDatiManager::generaXmlMetaDati] Nome file xml da ricercare : " + nomeFile); String urlRelative = getContentUrl(propertyMap); if (urlRelative != null) { // Se il file xml dei metadati deve essere memorizzato nella stessa cartella dove e` memorizzato // il content ,allora bisogna individiare il path dove tale content e` memorizzato e controllare se // il file xml e` presente o no in questa cartella; urlRelative contiene il path relativo // del content; bisogna sapere il path fisico su fs di partenza che e` contenuto nel file di property // custom-data-location.properties logger.debug("[MetaDatiManager::generaXmlMetaDati] Path relativo content : " + urlRelative); // store://2007/11/14/14/5/53d84b63-92b2-11dc-bd5f-372cc7f30666.bin // /usr/prod/fs/alfresco2/content/contentstore/2007/11/14/14/5 // store:/ urlRelative = urlRelative.substring(7); logger.debug("[MetaDatiManager::generaXmlMetaDati] Url relativo senza store: " + urlRelative); // /usr/prod/fs/alfresco2/content/contentstore/2007/11/14/14/5/53d84b63-92b2-11dc-bd5f-372cc7f30666.bin folderContent = folderContent + urlRelative; logger.debug("[MetaDatiManager::generaXmlMetaDati] Url comprensivo del binario : " + folderContent); int idLength = nodeRef.getId().length() + 4; int l = folderContent.length(); l = l - idLength; folderContent = folderContent.substring(0, l); // /usr/prod/fs/alfresco2/content/contentstore/2007/11/14/14/5/ logger.debug("[MetaDatiManager::generaXmlMetaDati] Path cartella content : " + folderContent); } else { logger.debug("[MetaDatiManager::generaXmlMetaDati] Il content modificato non e' un documento"); logger.debug("[MetaDatiManager::generaXmlMetaDati] Esco dal Job di backup"); return; } boolean creato = false; final File file = new File(folderContent); if (!file.exists()) { file.mkdir(); } if (file.isDirectory()) { final File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { if (nomeFile.equalsIgnoreCase(files[i].getName())) { creato = true; logger.debug("[MetaDatiManager::generaXmlMetaDati] File xml gia creato."); break; } } } final IBindingFactory factory = BindingDirectory.getFactory(MetaDati.class); IMarshallingContext mctx = null; MetaDati metaDati = null; MetaDatiOggettoValore oggetto = null; MetaDatiAutoreValore autore = null; final String path = folderContent + nomeFile; if (!creato) { //file xml dei metadati per il nodo in esame deve ancora essere creato logger.debug("[MetaDatiManager::generaXmlMetaDati] File xml da generare"); mctx = factory.createMarshallingContext(); mctx.setIndent(1); metaDati = new MetaDati(); //Ciclo sulle proprieta` for (Map.Entry<QName, Serializable> entry : propertyMap.entrySet()) { final QName propName = entry.getKey(); final Serializable valore = entry.getValue(); PropertyDefinition propDef = this.dictionaryService.getProperty(propName); if (logger.isDebugEnabled()) { logger.debug( "[MetaDatiManager::generaXmlMetaDati] Nome Proprieta : " + propName.toString()); logger.debug("[MetaDatiManager::generaXmlMetaDati] Valore Proprieta : " + (valore != null ? valore.toString() : "null")); } //MetaDatiAutoreValore valoreAutore = null; //MetaDatiOggettoValore valoreOggetto = null; if (propDef.isMultiValued()) { //valore multiplo logger.debug("[MetaDatiManager::generaXmlMetaDati] Property multivalue"); String[] values = null; String value = null; if (valore instanceof Collection<?>) { final Collection<?> valuesCollection = (Collection<?>) valore; values = new String[valuesCollection.size()]; int j = 0; for (Object o : valuesCollection) { values[j] = o.toString(); j++; } } else { value = "Type not supported: " + valore.getClass().getName(); logger.debug("[MetaDatiManager::generaXmlMetaDati] " + value); } if ("side-doc:autore".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { if (values != null) { for (int i = 0; i < values.length; i++) { autore = new MetaDatiAutoreValore(); autore.setCognome(values[i]); autore.setNome(values[i]); autore.setDataInizio(new Date()); metaDati.addAutore(autore); } } else { autore = new MetaDatiAutoreValore(); autore.setCognome("Type not supported"); autore.setNome("Type not supported"); autore.setDataInizio(new Date()); metaDati.addAutore(autore); } } else if ("cm:name".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { logger.debug("[MetaDatiManager::generaXmlMetaDati] Property cm:name multivalue"); if (values != null) { for (int i = 0; i < values.length; i++) { oggetto = new MetaDatiOggettoValore(); oggetto.setCampo(values[i]); oggetto.setDataInizio(new Date()); metaDati.addOggetto(oggetto); } } else { oggetto = new MetaDatiOggettoValore(); oggetto.setCampo("Type not supported"); oggetto.setDataInizio(new Date()); metaDati.addOggetto(oggetto); } } } else { //singolo valore logger.debug("[MetaDatiManager::generaXmlMetaDati] Property single value"); if ("side-doc:oggetto".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { oggetto = new MetaDatiOggettoValore(); if (valore == null) { oggetto.setCampo("- null -"); oggetto.setDataInizio(new Date()); } else if (valore instanceof String || valore instanceof Long || valore instanceof Integer || valore instanceof Date || valore instanceof MLText || valore instanceof ContentData || valore instanceof Boolean || valore instanceof NodeRef) { oggetto.setCampo(valore.toString()); oggetto.setDataInizio(new Date()); } else { oggetto.setCampo("Type not supported: " + valore.getClass().getName()); oggetto.setDataInizio(new Date()); } metaDati.addOggetto(oggetto); } else { if ("cm:name".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { logger.debug( "[MetaDatiManager::generaXmlMetaDati] " + "Property cm:name single value"); oggetto = new MetaDatiOggettoValore(); if (valore == null) { oggetto.setCampo("- null -"); oggetto.setDataInizio(new Date()); } else if (valore instanceof String || valore instanceof Long || valore instanceof Integer || valore instanceof Date || valore instanceof MLText || valore instanceof ContentData || valore instanceof Boolean || valore instanceof NodeRef) { oggetto.setCampo(valore.toString()); logger.debug("[MetaDatiManager::generaXmlMetaDati] " + "Property cm:name --> value : " + valore.toString()); oggetto.setDataInizio(new Date()); } else { oggetto.setCampo("Type not supported: " + valore.getClass().getName()); oggetto.setDataInizio(new Date()); } metaDati.addOggetto(oggetto); } else if ("sys:node-uuid".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { logger.debug("[MetaDatiManager::generaXmlMetaDati] " + "Property sys:node-uuid single value"); oggetto = new MetaDatiOggettoValore(); if (valore == null) { oggetto.setCampo("- null -"); oggetto.setDataInizio(new Date()); } else if (valore instanceof String || valore instanceof Long || valore instanceof Integer || valore instanceof Date || valore instanceof MLText || valore instanceof ContentData || valore instanceof Boolean || valore instanceof NodeRef) { oggetto.setCampo(valore.toString()); logger.debug("[MetaDatiManager::generaXmlMetaDati] " + "Property sys:node-uuid --> valore : " + valore.toString()); oggetto.setDataInizio(new Date()); } else { oggetto.setCampo("Type not supported: " + valore.getClass().getName()); oggetto.setDataInizio(new Date()); } metaDati.addOggetto(oggetto); } } } } mctx.marshalDocument(metaDati, "UTF-8", null, new FileOutputStream(path)); logger.debug("[MetaDatiManager::generaXmlMetaDati] Marshall file xml : " + path); } else { logger.debug("[MetaDatiManager::generaXmlMetaDati] File xml gia` creato, devo prima leggerlo"); final IUnmarshallingContext uctx = factory.createUnmarshallingContext(); final Object obj = uctx.unmarshalDocument(new FileInputStream(path), null); if (obj instanceof MetaDati) { logger.debug( "[MetaDatiManager::generaXmlMetaDati] OK : obj e' un'istanza della classe MetaDati"); metaDati = (MetaDati) obj; for (Map.Entry<QName, Serializable> entry : propertyMap.entrySet()) { final QName propName = entry.getKey(); final Serializable valore = entry.getValue(); PropertyDefinition propDef = dictionaryService.getProperty(propName); if (logger.isDebugEnabled()) { logger.debug( "[MetaDatiManager::generaXmlMetaDati] Nome Proprieta`: " + propName.toString()); logger.debug("[MetaDatiManager::generaXmlMetaDati] Valore Proprieta`: " + ((valore != null) ? valore.toString() : "null")); } if (propDef.isMultiValued()) { //multi value logger.debug("[MetaDatiManager::generaXmlMetaDati] property multivalue"); String[] values = null; String value = null; if (valore instanceof Collection<?>) { Collection<?> valuesCollection = (Collection<?>) valore; values = new String[valuesCollection.size()]; int j = 0; for (Object o : valuesCollection) { values[j] = o.toString(); j++; } } else { value = "Type not supported: " + valore.getClass().getName(); logger.debug("[MetaDatiManager::generaXmlMetaDati] " + value); } if ("side-doc:autore".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { if (values != null) { for (int i = 0; i < values.length; i++) { autore = new MetaDatiAutoreValore(); autore.setCognome(values[i]); autore.setNome(values[i]); autore.setDataInizio(new Date()); metaDati.addAutore(autore); } } else { autore = new MetaDatiAutoreValore(); autore.setCognome("Type not supported"); autore.setNome("Type not supported"); autore.setDataInizio(new Date()); metaDati.addAutore(autore); } } else if ("cm:name".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { logger.debug("[MetaDatiManager::generaXmlMetaDati] Property cm:name multivalue"); if (values != null) { for (int i = 0; i < values.length; i++) { oggetto = new MetaDatiOggettoValore(); oggetto.setCampo(values[i]); oggetto.setDataInizio(new Date()); metaDati.addOggetto(oggetto); } } else { oggetto = new MetaDatiOggettoValore(); oggetto.setCampo("Type not supported"); oggetto.setDataInizio(new Date()); metaDati.addOggetto(oggetto); } } } else { //single value logger.debug("[MetaDatiManager::generaXmlMetaDati] property single value"); if ("side-doc:oggetto".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { oggetto = new MetaDatiOggettoValore(); if (valore == null) { oggetto.setCampo("- null -"); oggetto.setDataInizio(new Date()); } else if (valore instanceof String || valore instanceof Long || valore instanceof Integer || valore instanceof Date || valore instanceof MLText || valore instanceof ContentData || valore instanceof Boolean || valore instanceof NodeRef) { oggetto.setCampo(valore.toString()); oggetto.setDataInizio(new Date()); } else { oggetto.setCampo("Type not supported: " + valore.getClass().getName()); oggetto.setDataInizio(new Date()); } metaDati.addOggetto(oggetto); } else { if ("cm:name".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { logger.debug("[MetaDatiManager::generaXmlMetaDati] Property cm:name " + "single value"); oggetto = new MetaDatiOggettoValore(); if (valore == null) { oggetto.setCampo("- null -"); oggetto.setDataInizio(new Date()); } else if (valore instanceof String || valore instanceof Long || valore instanceof Integer || valore instanceof Date || valore instanceof MLText || valore instanceof ContentData || valore instanceof Boolean || valore instanceof NodeRef) { oggetto.setCampo(valore.toString()); oggetto.setDataInizio(new Date()); logger.debug("[MetaDatiManager::generaXmlMetaDati] " + "Property cm:name --> value : " + valore.toString()); } else { oggetto.setCampo("Type not supported: " + valore.getClass().getName()); oggetto.setDataInizio(new Date()); } metaDati.addOggetto(oggetto); } else if ("sys:node-uuid".equalsIgnoreCase(resolveQNameToPrefixName(propName))) { logger.debug("[MetaDatiManager::generaXmlMetaDati] Property sys:node-uuid"); oggetto = new MetaDatiOggettoValore(); if (valore == null) { oggetto.setCampo("- null -"); oggetto.setDataInizio(new Date()); } else if (valore instanceof String || valore instanceof Long || valore instanceof Integer || valore instanceof Date || valore instanceof MLText || valore instanceof ContentData || valore instanceof Boolean || valore instanceof NodeRef) { oggetto.setCampo(valore.toString()); logger.debug("[MetaDatiManager::generaXmlMetaDati] " + "Property sys:node-uuid --> valore : " + valore.toString()); oggetto.setDataInizio(new Date()); } else { oggetto.setCampo("Type not supported: " + valore.getClass().getName()); oggetto.setDataInizio(new Date()); } metaDati.addOggetto(oggetto); } } } } mctx = factory.createMarshallingContext(); mctx.setIndent(1); mctx.marshalDocument(metaDati, "UTF-8", null, new FileOutputStream(path)); logger.debug("[MetaDatiManager::generaXmlMetaDati] Marshall file xml : " + path); } else { logger.error("[MetaDatiManager::generaXmlMetaDati] Errore :" + " obj non e` una istanza della classe Metadati"); throw new JiBXException( "UnmarshalDocument Errato: " + "obj non e' una istanza della classe Metadati"); } } } finally { logger.debug("[MetaDatiManager::generaXmlMetaDati] END"); } }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDao.java
private RepositoryFile internalGetFileById(final Serializable fileId, final boolean loadMaps, final IPentahoLocale locale) { Assert.notNull(fileId);//from w w w.ja v a 2s .c o m return (RepositoryFile) jcrTemplate.execute(new JcrCallback() { @Override public Object doInJcr(final Session session) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); Node fileNode = session.getNodeByIdentifier(fileId.toString()); RepositoryFile file = fileNode != null ? JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper, fileNode, loadMaps, locale) : null; if (file != null) { RepositoryFileAcl acl = aclDao.getAcl(file.getId()); // Invoke accessVoterManager to see if we have access to perform this operation if (!accessVoterManager.hasAccess(file, RepositoryFilePermission.READ, acl, PentahoSessionHolder.getSession())) { return null; } } return file; } }); }
From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDao.java
@Override @SuppressWarnings("unchecked") public List<RepositoryFile> getReferrers(final Serializable fileId) { if (fileId == null) { return new ArrayList<RepositoryFile>(); }/*from w w w .j a va2s. c om*/ return (List<RepositoryFile>) jcrTemplate.execute(new JcrCallback() { @Override public Object doInJcr(final Session session) throws RepositoryException, IOException { PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session); Node fileNode = session.getNodeByIdentifier(fileId.toString()); // guard against using a file retrieved from a more lenient session inside a more strict session Assert.notNull(fileNode); Set<RepositoryFile> referrers = new HashSet<RepositoryFile>(); PropertyIterator refIter = fileNode.getReferences(); if (refIter.hasNext()) { while (refIter.hasNext()) { // for each referrer property, march up the tree until we find the file node to which the property // belongs RepositoryFile referrer = getReferrerFile(session, pentahoJcrConstants, refIter.nextProperty()); if (referrer != null) { referrers.add(referrer); } } } session.save(); return Arrays.asList(referrers.toArray()); } }); }
From source file:org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditServiceImpl.java
/** * Writes an audit trail entry to the given writer * * @param writer The writer to write to/*from w ww .jav a2 s .co m*/ * @param entry The entry to write * @param reportFormat The format to write the header in * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void writeAuditTrailEntry(Writer writer, RecordsManagementAuditEntry entry, ReportFormat reportFormat) throws IOException { if (writer == null) { return; } if (reportFormat == ReportFormat.HTML) { writer.write("<div class=\"audit-entry\">\n"); writer.write("<div class=\"audit-entry-header\">"); writer.write("<span class=\"label\">Timestamp:</span>"); writer.write("<span class=\"value\">"); writer.write(StringEscapeUtils.escapeHtml(entry.getTimestamp().toString())); writer.write("</span>"); writer.write("<span class=\"label\">User:</span>"); writer.write("<span class=\"value\">"); writer.write(entry.getFullName() != null ? StringEscapeUtils.escapeHtml(entry.getFullName()) : StringEscapeUtils.escapeHtml(entry.getUserName())); writer.write("</span>"); if (entry.getUserRole() != null && entry.getUserRole().length() > 0) { writer.write("<span class=\"label\">Role:</span>"); writer.write("<span class=\"value\">"); writer.write(StringEscapeUtils.escapeHtml(entry.getUserRole())); writer.write("</span>"); } if (entry.getEvent() != null && entry.getEvent().length() > 0) { writer.write("<span class=\"label\">Event:</span>"); writer.write("<span class=\"value\">"); writer.write(StringEscapeUtils.escapeHtml(getAuditEventLabel(entry.getEvent()))); writer.write("</span>\n"); } writer.write("</div>\n"); writer.write("<div class=\"audit-entry-node\">"); if (entry.getIdentifier() != null && entry.getIdentifier().length() > 0) { writer.write("<span class=\"label\">Identifier:</span>"); writer.write("<span class=\"value\">"); writer.write(StringEscapeUtils.escapeHtml(entry.getIdentifier())); writer.write("</span>"); } if (entry.getNodeType() != null && entry.getNodeType().length() > 0) { writer.write("<span class=\"label\">Type:</span>"); writer.write("<span class=\"value\">"); writer.write(StringEscapeUtils.escapeHtml(entry.getNodeType())); writer.write("</span>"); } if (entry.getPath() != null && entry.getPath().length() > 0) { // we need to strip off the first part of the path String path = entry.getPath(); String displayPath = path; int idx = path.indexOf('/', 1); if (idx != -1) { displayPath = "/File Plan" + path.substring(idx); } writer.write("<span class=\"label\">Location:</span>"); writer.write("<span class=\"value\">"); writer.write(StringEscapeUtils.escapeHtml(displayPath)); writer.write("</span>"); } writer.write("</div>\n"); if (entry.getChangedProperties() != null) { writer.write("<table class=\"changed-values-table\" cellspacing=\"0\">"); writer.write("<tr><th>Property</th><th>Previous Value</th><th>New Value</th></tr>"); // create an entry for each property that changed for (QName valueName : entry.getChangedProperties().keySet()) { Pair<Serializable, Serializable> values = entry.getChangedProperties().get(valueName); writer.write("<tr><td>"); writer.write(getPropertyLabel(valueName)); writer.write("</td><td>"); // inspect the property to determine it's data type QName propDataType = DataTypeDefinition.TEXT; PropertyDefinition propDef = dictionaryService.getProperty(valueName); if (propDef != null) { propDataType = propDef.getDataType().getName(); } if (DataTypeDefinition.MLTEXT.equals(propDataType)) { writer.write(values.getFirst() == null ? "<none>" : StringEscapeUtils .escapeHtml(convertToMlText((Map) values.getFirst()).getDefaultValue())); writer.write("</td><td>"); writer.write(values.getSecond() == null ? "<none>" : StringEscapeUtils .escapeHtml(convertToMlText((Map) values.getSecond()).getDefaultValue())); } else { Serializable oldValue = values.getFirst(); writer.write(oldValue == null ? "<none>" : StringEscapeUtils.escapeHtml(oldValue.toString())); writer.write("</td><td>"); Serializable newValue = values.getSecond(); writer.write(newValue == null ? "<none>" : StringEscapeUtils.escapeHtml(newValue.toString())); } writer.write("</td></tr>"); } writer.write("</table>\n"); } writer.write("</div>"); } else { try { JSONObject json = new JSONObject(); json.put("timestamp", entry.getTimestampString()); json.put("userName", entry.getUserName()); json.put("userRole", entry.getUserRole() == null ? "" : entry.getUserRole()); json.put("fullName", entry.getFullName() == null ? "" : entry.getFullName()); json.put("nodeRef", entry.getNodeRef() == null ? "" : entry.getNodeRef()); // TODO: Find another way for checking the event if (entry.getEvent().equals("Create Person") && entry.getNodeRef() != null) { NodeRef nodeRef = entry.getNodeRef(); String userName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME); json.put("nodeName", userName == null ? "" : userName); json.put("createPerson", true); } else { json.put("nodeName", entry.getNodeName() == null ? "" : entry.getNodeName()); } // TODO: Find another way for checking the event if (entry.getEvent().equals("Delete RM Object")) { json.put("deleteObject", true); } json.put("nodeType", entry.getNodeType() == null ? "" : entry.getNodeType()); json.put("event", entry.getEvent() == null ? "" : getAuditEventLabel(entry.getEvent())); json.put("identifier", entry.getIdentifier() == null ? "" : entry.getIdentifier()); json.put("path", entry.getPath() == null ? "" : entry.getPath()); JSONArray changedValues = new JSONArray(); if (entry.getChangedProperties() != null) { // create an entry for each property that changed for (QName valueName : entry.getChangedProperties().keySet()) { Pair<Serializable, Serializable> values = entry.getChangedProperties().get(valueName); JSONObject changedValue = new JSONObject(); changedValue.put("name", getPropertyLabel(valueName)); // inspect the property to determine it's data type QName propDataType = DataTypeDefinition.TEXT; PropertyDefinition propDef = dictionaryService.getProperty(valueName); if (propDef != null) { propDataType = propDef.getDataType().getName(); } // handle output of mltext properties if (DataTypeDefinition.MLTEXT.equals(propDataType)) { changedValue.put("previous", values.getFirst() == null ? "" : convertToMlText((Map) values.getFirst()).getDefaultValue()); changedValue.put("new", values.getSecond() == null ? "" : convertToMlText((Map) values.getSecond()).getDefaultValue()); } else { changedValue.put("previous", values.getFirst() == null ? "" : values.getFirst().toString()); changedValue.put("new", values.getSecond() == null ? "" : values.getSecond().toString()); } changedValues.put(changedValue); } } json.put("changedValues", changedValues); writer.write(json.toString()); } catch (JSONException je) { writer.write("{}"); } } }
From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.DataLayer.java
/** * Builds a label for the given node from values of its properties or * associations. The format//from w ww .java 2 s. c o m * is a list of tokens separated by the view token separator. A token is * either a property value * (the name of the property is directly given as a placeholder for the * value) or some static * text (enclosed in curly braces). * * @param pattern * the format pattern, in plain text (meaning non URL-encoded) * @param nodeRef * @param properties * the set of properties from which to find property tokens * @param includeSystemProps * <code>true</code> if the * @return */ private String getNameForNode(String pattern, NodeRef nodeRef, Map<QName, Serializable> properties, boolean includeSystemProps) { String result = ""; String view = pattern; StringTokenizer st = new StringTokenizer(view, VIEW_TOKEN_SEPARATOR); boolean lastTokenWasText = false; boolean first = true; while (st.hasMoreTokens()) { String token = st.nextToken().trim(); if (token.startsWith("{") && token.endsWith("}")) { result += token.substring(1, token.length() - 1); first = false; lastTokenWasText = true; } else if (token.contains(VIEW_FIELD_SEPARATOR)) { StringTokenizer st2 = new StringTokenizer(token, VIEW_FIELD_SEPARATOR); String clazz = null; String attribute = null; String association = null; if (st2.hasMoreTokens()) { clazz = st2.nextToken(); } if (st2.hasMoreTokens()) { attribute = st2.nextToken(); } if (st2.hasMoreTokens()) { association = st2.nextToken(); } if (clazz != null) { // QName nodeType = nodeService.getType(nodeRef); if (nodeType.getLocalName().endsWith("_" + clazz)) { if (association == null) { if (attribute != null) { for (QName qname : properties.keySet()) { String key = qname.getLocalName(); if (key.endsWith("_" + attribute)) { Serializable value = properties.get(qname); if (value != null && value.toString().length() > 0) { if (lastTokenWasText == false) { result += " "; } result += value; lastTokenWasText = false; first = false; } } } } } else { if (attribute != null) { Map<String, List<AssociationRef>> nodeAssos = collectAssociations(nodeRef); String associationFirstPartName = nodeType.toString() + "_" + association; String associationName = getAssociationNameStartingBy(associationFirstPartName, nodeAssos); if (associationName.length() > 0) { List<?> assocs = nodeAssos.get(associationName); for (Object o : assocs) { if (o instanceof AssociationRef) { AssociationRef ref = (AssociationRef) o; Map<QName, Serializable> targetProperties = nodeService .getProperties(ref.getTargetRef()); QName targetType = nodeService.getType(ref.getTargetRef()); if (lastTokenWasText == false) { result += " "; } result += getPropertyValue(targetProperties, targetType, attribute); lastTokenWasText = false; first = false; } } } } } } else { logger.error("The class " + clazz + " is not appropriate for this node ('" + nodeRef.toString() + "')."); } } } else { // simple attribute for (QName qname : properties.keySet()) { String key = qname.getLocalName(); if (key.endsWith("_" + token) || (includeSystemProps == true && (key.endsWith(token)))) {// #1529 Serializable value = properties.get(qname); if (value != null && value.toString().length() > 0) { if (lastTokenWasText == false && first == false) { result += " "; } result += value; lastTokenWasText = false; first = false; } } } } } if (result.length() == 0) { return nodeRef.getId(); } // return result.substring(0, result.length() - 1); return result; }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.JDBCMapper.java
public int setToPreparedStatement(PreparedStatement ps, int i, Serializable object) throws SQLException { if (object instanceof Calendar) { Calendar cal = (Calendar) object; ps.setTimestamp(i, dialect.getTimestampFromCalendar(cal), cal); } else if (object instanceof java.sql.Date) { ps.setDate(i, (java.sql.Date) object); } else if (object instanceof Long) { ps.setLong(i, ((Long) object).longValue()); } else if (object instanceof WrappedId) { dialect.setId(ps, i, object.toString()); } else if (object instanceof Object[]) { int jdbcType; if (object instanceof String[]) { jdbcType = dialect.getJDBCTypeAndString(ColumnType.STRING).jdbcType; } else if (object instanceof Boolean[]) { jdbcType = dialect.getJDBCTypeAndString(ColumnType.BOOLEAN).jdbcType; } else if (object instanceof Long[]) { jdbcType = dialect.getJDBCTypeAndString(ColumnType.LONG).jdbcType; } else if (object instanceof Double[]) { jdbcType = dialect.getJDBCTypeAndString(ColumnType.DOUBLE).jdbcType; } else if (object instanceof java.sql.Date[]) { jdbcType = Types.DATE; } else if (object instanceof java.sql.Clob[]) { jdbcType = Types.CLOB; } else if (object instanceof Calendar[]) { jdbcType = dialect.getJDBCTypeAndString(ColumnType.TIMESTAMP).jdbcType; object = dialect.getTimestampFromCalendar((Calendar) object); } else if (object instanceof Integer[]) { jdbcType = dialect.getJDBCTypeAndString(ColumnType.INTEGER).jdbcType; } else {/*from w ww . jav a2 s . c o m*/ jdbcType = dialect.getJDBCTypeAndString(ColumnType.CLOB).jdbcType; } Array array = dialect.createArrayOf(jdbcType, (Object[]) object, connection); ps.setArray(i, array); } else { ps.setObject(i, object); } return i; }