Java Code Examples for org.alfresco.service.namespace.QName#toString()

The following examples show how to use org.alfresco.service.namespace.QName#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Return the system container for the specified assoc name.
 * The containers are cached in a thread safe Tenant aware cache.
 *
 * @return System container, <b>which must exist</b>
 */
private NodeRef getSystemContainer(QName assocQName)
{
    final String cacheKey = KEY_SYSTEMCONTAINER_NODEREF + "." + assocQName.toString();
    NodeRef systemContainerRef = (NodeRef)singletonCache.get(cacheKey);
    if (systemContainerRef == null)
    {
        NodeRef rootNodeRef = nodeService.getRootNode(this.storeRef);
        List<ChildAssociationRef> results = nodeService.getChildAssocs(rootNodeRef, RegexQNamePattern.MATCH_ALL, qnameAssocSystem, false);
        if (results.size() == 0)
        {
            throw new AlfrescoRuntimeException("Required system path not found: " + qnameAssocSystem);
        }
        NodeRef sysNodeRef = results.get(0).getChildRef();
        results = nodeService.getChildAssocs(sysNodeRef, RegexQNamePattern.MATCH_ALL, assocQName, false);
        if (results.size() == 0)
        {
            throw new AlfrescoRuntimeException("Required path not found: " + assocQName);
        }
        systemContainerRef = results.get(0).getChildRef();
        singletonCache.put(cacheKey, systemContainerRef);
    }
    return systemContainerRef;
}
 
Example 2
Source File: AbstractCopyBehaviourCallback.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Helper method to transactionally record <code>NodeRef</code> properties so that they
 * can later be fixed up to point to the relative, after-copy locations.
 * <p>
 * When the copy has been completed, the second stage of the process can be applied.
 * 
 * @param sourceNodeRef             the node that is being copied
 * @param properties                the node properties being copied
 * @param propertyQName             the qualified name of the property to check
 * 
 * @see #repointNodeRefs(NodeRef, NodeRef, QName, Map, NodeService)
 */
public void recordNodeRefsForRepointing(
        NodeRef sourceNodeRef,
        Map<QName, Serializable> properties,
        QName propertyQName)
{
    Serializable parameterValue = properties.get(propertyQName);
    if (parameterValue != null &&
            (parameterValue instanceof Collection<?> || parameterValue instanceof NodeRef))
    {
        String key = KEY_NODEREF_REPOINTING_PREFIX + propertyQName.toString();
        // Store it for later
        Map<NodeRef, Serializable> map = TransactionalResourceHelper.getMap(key);
        map.put(sourceNodeRef, parameterValue);
    }
}
 
Example 3
Source File: JSONConversionComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Convert a qname to a string - either full or short prefixed named.
 * 
 * @param qname QName
 * @param isShortName boolean
 * @return qname string.
 */
private String nameToString(final QName qname, final boolean isShortName)
{
    String result;
    if (isShortName)
    {
        final Map<String, String> cache = namespacePrefixCache.get();
        String prefix = cache.get(qname.getNamespaceURI());
        if (prefix == null)
        {
            // first request for this namespace prefix, get and cache result
            Collection<String> prefixes = this.namespaceService.getPrefixes(qname.getNamespaceURI());
            prefix = prefixes.size() != 0 ? prefixes.iterator().next() : "";
            cache.put(qname.getNamespaceURI(), prefix);
        }
        result = prefix + QName.NAMESPACE_PREFIX + qname.getLocalName();
    }
    else
    {
        result = qname.toString();
    }
    return result;
}
 
Example 4
Source File: DocumentNavigator.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getAttributeQName(Object o)
{
    QName qName = ((Property) o).qname;
    String escapedLocalName = ISO9075.encode(qName.getLocalName());
    if (EqualsHelper.nullSafeEquals(escapedLocalName, qName.getLocalName()))        
    {
        return qName.toString();
    }
    else
    {
        return QName.createQName(qName.getNamespaceURI(), escapedLocalName).toString();
    }
}
 
Example 5
Source File: DocumentNavigator.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String getElementQName(Object o)
{
    QName qName = ((ChildAssociationRef) o).getQName();
    if(qName == null)
    {
        return "";
    }
    String escapedLocalName = ISO9075.encode(qName.getLocalName());
    if (EqualsHelper.nullSafeEquals(escapedLocalName, qName.getLocalName()))        
    {
        return qName.toString();
    }
    else
    {
        return QName.createQName(qName.getNamespaceURI(), escapedLocalName).toString();
    }
}
 
Example 6
Source File: RepositoryLocation.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the Lucene query statement for models, based on the path
 *
 * @return  the Lucene query statement
 */
public String getLuceneQueryStatement(QName contentModelType)
{
    String result = "+TYPE:\"" + contentModelType.toString() + "\"";
    
    if ((this.path != null) && (! this.path.equals("")))
    {
        result += " +PATH:\"" + this.path + "\"";
    }
   
    return result;
}
 
Example 7
Source File: RenditionServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Given a QName this method returns the long-form String with the braces
 * escaped.
 */
private String getLongNameWithEscapedBraces(QName qn)
{
    String longName = qn.toString();
    String escapedBraces = longName.replace("{", "\\{").replace("}", "\\}");
    return escapedBraces;
}
 
Example 8
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return The array of aspects applied to this node as fully qualified qname strings
 */
public Scriptable getAspects()
{
    Set<QName> aspects = getAspectsSet();
    Object[] result = new Object[aspects.size()];
    int count = 0;
    for (QName qname : aspects)
    {
        result[count++] = qname.toString();
    }
    return Context.getCurrentContext().newArray(this.scope, result);
}
 
Example 9
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Return all the property names defined for this node as an array.
 * 
 * @param useShortQNames if true short-form qnames will be returned, else long-form.
 * @return Array of property names for this node type and optionally parent properties.
 */
public Scriptable getPropertyNames(boolean useShortQNames)
{
    Set<QName> props = this.nodeService.getProperties(this.nodeRef).keySet();
    Object[] result = new Object[props.size()];
    int count = 0;
    for (QName qname : props)
    {
        result[count++] = useShortQNames ? getShortQName(qname).toString() : qname.toString();
    }
    return Context.getCurrentContext().newArray(this.scope, result);
}
 
Example 10
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Return all the property names defined for this node's type as an array.
 * 
 * @param useShortQNames if true short-form qnames will be returned, else long-form.
 * @return Array of property names for this node's type.
 */
public Scriptable getTypePropertyNames(boolean useShortQNames)
{
    Set<QName> props = this.services.getDictionaryService().getClass(this.getQNameType()).getProperties().keySet();
    Object[] result = new Object[props.size()];
    int count = 0;
    for (QName qname : props)
    {
        result[count++] = useShortQNames ? getShortQName(qname).toString() : qname.toString();
    }
    return Context.getCurrentContext().newArray(this.scope, result);
}
 
Example 11
Source File: WorkflowQNameConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String convertQNameToName(QName name, NamespacePrefixResolver prefixResolver)
{
    // NOTE: Map names using old conversion scheme (i.e. : -> _) as well as new scheme (i.e. } -> _)
    String nameStr = name.toPrefixString(prefixResolver);
    if (nameStr.indexOf('_') != -1 && nameStr.indexOf('_') < nameStr.indexOf(':'))
    {
        // Return full QName string.
        return name.toString();
    }
    // Return prefixed QName string.
    return nameStr.replace(':', '_');
}
 
Example 12
Source File: AbstractVersionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Invoke the calculate version label policy behaviour
 * 
 * @param classRef QName
 * @param preceedingVersion Version
 * @param versionNumber int
 * @return String
 */
protected String invokeCalculateVersionLabel(
		QName classRef,
		Version preceedingVersion, 
		int versionNumber, 
		Map<String, Serializable>versionProperties)
{
	String versionLabel = null;
	
	Collection<CalculateVersionLabelPolicy> behaviours = this.calculateVersionLabelDelegate.getList(classRef);
	if (behaviours.size() == 0)
	{
           // Default the version label to the SerialVersionLabelPolicy
           SerialVersionLabelPolicy defaultVersionLabelPolicy = new SerialVersionLabelPolicy();
           versionLabel = defaultVersionLabelPolicy.calculateVersionLabel(classRef, preceedingVersion, versionNumber, versionProperties);
	}
	else if (behaviours.size() == 1)
	{
		// Call the policy behaviour
		CalculateVersionLabelPolicy[] arr = behaviours.toArray(new CalculateVersionLabelPolicy[]{});
		versionLabel = arr[0].calculateVersionLabel(classRef, preceedingVersion, versionNumber, versionProperties);
	}
	else
	{
		// Error since we can only deal with a single caculate version label policy
		throw new VersionServiceException("More than one CalculateVersionLabelPolicy behaviour has been registered for the type " + classRef.toString());
	}
	
	return versionLabel;
}
 
Example 13
Source File: Site.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get a map of the sites custom properties
 * 
 * @return map of names and values
 */
public ScriptableQNameMap<String, CustomProperty> getCustomProperties()
{
    if (this.customProperties == null)
    {
        // create the custom properties map
        ScriptNode siteNode = new ScriptNode(this.siteInfo.getNodeRef(), this.serviceRegistry);
        // set the scope, for use when converting props to javascript objects
        siteNode.setScope(scope);
        this.customProperties = new ContentAwareScriptableQNameMap<String, CustomProperty>(siteNode, this.serviceRegistry);
        
        Map<QName, Serializable> props = siteInfo.getCustomProperties();
        for (QName qname : props.keySet())
        {
            // get the property value
            Serializable propValue = props.get(qname);
            
            // convert the value
            NodeValueConverter valueConverter = siteNode.new NodeValueConverter();
            Serializable value = valueConverter.convertValueForScript(qname, propValue);
            
            // get the type and label information from the dictionary
            String title = null;
            String type = null;
            PropertyDefinition propDef = this.serviceRegistry.getDictionaryService().getProperty(qname);
            if (propDef != null)
            {
                type = propDef.getDataType().getName().toString();
                title = propDef.getTitle(this.serviceRegistry.getDictionaryService());
            }
            
            // create the custom property and add to the map
            CustomProperty customProp = new CustomProperty(qname.toString(), value, type, title);
            this.customProperties.put(qname.toString(), customProp);
        }
    }
    return this.customProperties;
}
 
Example 14
Source File: NodeResourceHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the QName in the format prefix:local, but in the exceptional case where there is no registered prefix
 * returns it in the form {uri}local.
 *
 * @param   k QName
 * @return  a String representing the QName in the format prefix:local or {uri}local.
 */
public String getQNamePrefixString(QName k)
{
    String key;
    try
    {
        key = k.toPrefixString(namespaceService);
    }
    catch (NamespaceException e)
    {
        key = k.toString();
    }
    return key;
}
 
Example 15
Source File: XMLTransferReportWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String formatQName(QName qname)
{
    return qname.toString();
}
 
Example 16
Source File: XMLTransferManifestWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String formatQName(QName qname)
{
    return qname.toString();
}
 
Example 17
Source File: AlfrescoModelDiff.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public AlfrescoModelDiff(QName modelName, TYPE type, Long oldChecksum, Long newChecksum)
{
   this(modelName.toString(), type, oldChecksum, newChecksum);
}
 
Example 18
Source File: ContentStreamer.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Streams the content on a given node's content property to the response of the web script.
 *
 * @param req            Request
 * @param res            Response
 * @param nodeRef        The node reference
 * @param propertyQName  The content property name
 * @param attach         Indicates whether the content should be streamed as an attachment or not
 * @param attachFileName Optional file name to use when attach is <code>true</code>
 * @throws IOException
 */
public void streamContent(WebScriptRequest req,
            WebScriptResponse res,
            NodeRef nodeRef,
            QName propertyQName,
            boolean attach,
            String attachFileName,
            Map<String, Object> model) throws IOException
{
    if (logger.isDebugEnabled())
        logger.debug("Retrieving content from node ref " + nodeRef.toString() + " (property: " + propertyQName.toString() + ") (attach: " + attach + ")");

    // TODO
    // This was commented out to accomadate records management permissions.  We need to review how we cope with this
    // hard coded permission checked.

    // check that the user has at least READ_CONTENT access - else redirect to the login page
    //        if (permissionService.hasPermission(nodeRef, PermissionService.READ_CONTENT) == AccessStatus.DENIED)
    //        {
    //            throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Permission denied");
    //        }

    // check If-Modified-Since header and set Last-Modified header as appropriate
    Date modified = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
    if (modified != null)
    {
        long modifiedSince = -1;
        String modifiedSinceStr = req.getHeader("If-Modified-Since");
        if (modifiedSinceStr != null)
        {
            try
            {
                modifiedSince = dateFormat.parse(modifiedSinceStr).getTime();
            }
            catch (Throwable e)
            {
                if (logger.isInfoEnabled())
                    logger.info("Browser sent badly-formatted If-Modified-Since header: " + modifiedSinceStr);
            }

            if (modifiedSince > 0L)
            {
                // round the date to the ignore millisecond value which is not supplied by header
                long modDate = (modified.getTime() / 1000L) * 1000L;
                if (modDate <= modifiedSince)
                {
                    res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
            }
        }
    }

    // get the content reader
    ContentReader reader = contentService.getReader(nodeRef, propertyQName);
    if (reader == null || !reader.exists())
    {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to locate content for node ref " + nodeRef + " (property: " + propertyQName.toString() + ")");
    }

    // Stream the content
    streamContentImpl(req, res, reader, nodeRef, propertyQName, attach, modified, modified == null ? null : Long.toString(modified.getTime()), attachFileName, model);
}
 
Example 19
Source File: QueryBuilder.java    From alfresco-mvc with Apache License 2.0 4 votes vote down vote up
public static String escapeQName(final String language, final QName qName) {
	String string = qName.toString();
	return escape(language, string);
}