Search in sources :

Example 21 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class ChangeLogRecord method writeEventRecord.

/**
     * Write an event record
     *
     * @param event event state
     * @throws JournalException if an error occurs
     */
private void writeEventRecord(EventState event) throws JournalException {
    record.writeChar(EVENT_IDENTIFIER);
    record.writeByte(event.getType());
    record.writeNodeId(event.getParentId());
    record.writePath(event.getParentPath());
    record.writeNodeId(event.getChildId());
    record.writePathElement(event.getChildRelPath());
    record.writeQName(event.getNodeType());
    Set<Name> mixins = event.getMixinNames();
    record.writeInt(mixins.size());
    for (Name mixin : mixins) {
        record.writeQName(mixin);
    }
    record.writeString(event.getUserId());
    if (event.getType() == Event.NODE_MOVED) {
        // write info map
        Map<String, InternalValue> info = event.getInfo();
        record.writeInt(info.size());
        for (Map.Entry<String, InternalValue> entry : info.entrySet()) {
            String key = entry.getKey();
            InternalValue value = entry.getValue();
            record.writeString(key);
            if (value == null) {
                // use undefined for null value
                record.writeInt(PropertyType.UNDEFINED);
            } else {
                record.writeInt(value.getType());
                record.writeString(value.toString());
            }
        }
    }
}
Also used : InternalValue(org.apache.jackrabbit.core.value.InternalValue) HashMap(java.util.HashMap) Map(java.util.Map) Name(org.apache.jackrabbit.spi.Name)

Example 22 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class ChangeLogRecord method readEventRecord.

/**
     * Read an event record.
     *
     * @throws JournalException if an error occurs
     */
private void readEventRecord() throws JournalException {
    int type = record.readByte();
    NodeId parentId = record.readNodeId();
    Path parentPath = record.readPath();
    NodeId childId = record.readNodeId();
    Path childRelPath = record.readPathElement();
    Name ntName = record.readQName();
    Set<Name> mixins = new HashSet<Name>();
    int mixinCount = record.readInt();
    for (int i = 0; i < mixinCount; i++) {
        mixins.add(record.readQName());
    }
    String userId = record.readString();
    Map<String, InternalValue> info = null;
    if (type == Event.NODE_MOVED) {
        info = new HashMap<String, InternalValue>();
        // read info map
        int infoSize = record.readInt();
        for (int i = 0; i < infoSize; i++) {
            String key = record.readString();
            int propType = record.readInt();
            InternalValue value;
            if (propType == PropertyType.UNDEFINED) {
                // indicates null value
                value = null;
            } else {
                value = InternalValue.valueOf(record.readString(), propType);
            }
            info.put(key, value);
        }
    }
    EventState es = createEventState(type, parentId, parentPath, childId, childRelPath, ntName, mixins, userId);
    if (info != null) {
        es.setInfo(info);
    }
    events.add(es);
}
Also used : Path(org.apache.jackrabbit.spi.Path) EventState(org.apache.jackrabbit.core.observation.EventState) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) HashSet(java.util.HashSet)

Example 23 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class IndexingConfigurationImpl method refreshIndexRules.

//---------------------------------< internal >-----------------------------
/**
     * Refreshes the index rules in {@link #configElements} based on the current
     * node types available in the node type registry.
     *
     * @throws Exception if an error occurs while refreshing the rules.
     */
private void refreshIndexRules() throws Exception {
    Map<Name, List<IndexingRule>> nt2rules = new HashMap<Name, List<IndexingRule>>();
    Name[] ntNames = ntReg.getRegisteredNodeTypes();
    NodeList indexingConfigs = configuration.getChildNodes();
    for (int i = 0; i < indexingConfigs.getLength(); i++) {
        Node configNode = indexingConfigs.item(i);
        if (configNode.getNodeName().equals("index-rule")) {
            IndexingRule element = new IndexingRule(configNode);
            // register under node type and all its sub types
            log.debug("Found rule '{}' for NodeType '{}'", element, element.getNodeTypeName());
            for (Name ntName : ntNames) {
                if (ntReg.getEffectiveNodeType(ntName).includesNodeType(element.getNodeTypeName())) {
                    List<IndexingRule> perNtConfig = nt2rules.get(ntName);
                    if (perNtConfig == null) {
                        perNtConfig = new ArrayList<IndexingRule>();
                        nt2rules.put(ntName, perNtConfig);
                    }
                    log.debug("Registering it for name '{}'", ntName);
                    perNtConfig.add(new IndexingRule(element, ntReg.getNodeTypeDef(ntName)));
                }
            }
        }
    }
    configElements = nt2rules;
}
Also used : HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Name(org.apache.jackrabbit.spi.Name)

Example 24 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class IndexingConfigurationImpl method getApplicableIndexingRule.

/**
     * Returns the first indexing rule that applies to the given node
     * <code>state</code>.
     *
     * @param state a node state.
     * @param propertyName the property name to check.
     * @return the indexing rule or <code>null</code> if none applies.
     */
private IndexingRule getApplicableIndexingRule(NodeState state, Name propertyName) {
    List<IndexingRule> rules = null;
    List<IndexingRule> r = configElements.get(state.getNodeTypeName());
    if (r != null) {
        rules = new ArrayList<IndexingRule>();
        rules.addAll(r);
    }
    for (Name name : state.getMixinTypeNames()) {
        r = configElements.get(name);
        if (r != null) {
            if (rules == null) {
                rules = new ArrayList<IndexingRule>();
            }
            rules.addAll(r);
        }
    }
    if (rules != null) {
        for (IndexingRule rule : rules) {
            if (rule.appliesTo(state, propertyName)) {
                return rule;
            }
        }
    }
    // no applicable rule
    return null;
}
Also used : Name(org.apache.jackrabbit.spi.Name)

Example 25 with Name

use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.

the class IndexingConfigurationImpl method createPropertyConfigs.

/**
     * Creates property configurations defined in the <code>config</code>.
     *
     * @param config the fulltext indexing configuration.
     * @param propConfigs will be filled with exact <code>Name</code> to
     *                    <code>PropertyConfig</code> mappings.
     * @param namePatterns will be filled with <code>NamePattern</code>s.
     * @throws IllegalNameException   if the node type name contains illegal
     *                                characters.
     * @throws NamespaceException if the node type contains an unknown
     *                                prefix.
     */
private void createPropertyConfigs(Node config, Map<Name, PropertyConfig> propConfigs, List<NamePattern> namePatterns) throws IllegalNameException, NamespaceException {
    NodeList childNodes = config.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node n = childNodes.item(i);
        if (n.getNodeName().equals("property")) {
            NamedNodeMap attributes = n.getAttributes();
            // get boost value
            float boost = 1.0f;
            Node boostAttr = attributes.getNamedItem("boost");
            if (boostAttr != null) {
                try {
                    boost = Float.parseFloat(boostAttr.getNodeValue());
                } catch (NumberFormatException e) {
                // use default
                }
            }
            // get nodeScopeIndex flag
            boolean nodeScopeIndex = true;
            Node nsIndex = attributes.getNamedItem("nodeScopeIndex");
            if (nsIndex != null) {
                nodeScopeIndex = Boolean.valueOf(nsIndex.getNodeValue());
            }
            // get isRegexp flag
            boolean isRegexp = false;
            Node regexp = attributes.getNamedItem("isRegexp");
            if (regexp != null) {
                isRegexp = Boolean.valueOf(regexp.getNodeValue());
            }
            // get useInExcerpt flag
            boolean useInExcerpt = true;
            Node excerpt = attributes.getNamedItem("useInExcerpt");
            if (excerpt != null) {
                useInExcerpt = Boolean.valueOf(excerpt.getNodeValue());
            }
            PropertyConfig pc = new PropertyConfig(boost, nodeScopeIndex, useInExcerpt);
            if (isRegexp) {
                namePatterns.add(new NamePattern(getTextContent(n), pc, resolver));
            } else {
                Name propName = resolver.getQName(getTextContent(n));
                propConfigs.put(propName, pc);
            }
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Name(org.apache.jackrabbit.spi.Name)

Aggregations

Name (org.apache.jackrabbit.spi.Name)382 RepositoryException (javax.jcr.RepositoryException)101 ArrayList (java.util.ArrayList)57 QValue (org.apache.jackrabbit.spi.QValue)42 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)39 HashSet (java.util.HashSet)38 Path (org.apache.jackrabbit.spi.Path)38 NodeId (org.apache.jackrabbit.core.id.NodeId)37 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)33 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)32 NodeId (org.apache.jackrabbit.spi.NodeId)32 PropertyId (org.apache.jackrabbit.core.id.PropertyId)29 HashMap (java.util.HashMap)28 NamespaceException (javax.jcr.NamespaceException)28 NodeState (org.apache.jackrabbit.core.state.NodeState)28 Value (javax.jcr.Value)25 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)25 InternalValue (org.apache.jackrabbit.core.value.InternalValue)23 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)22 PropertyState (org.apache.jackrabbit.core.state.PropertyState)22