Search in sources :

Example 11 with NamespaceResolver

use of org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver in project jackrabbit by apache.

the class ClusterSyncTest method createClusterNode.

/**
     * Create a cluster node, with a memory journal referencing a list of records.
     *
     * @param id cluster node id
     * @param records memory journal's list of records
     * @param disableAutoSync if <code>true</code> background synchronization is disabled
     */
private ClusterNode createClusterNode(String id, boolean disableAutoSync) throws Exception {
    final MemoryJournal journal = new MemoryJournal() {

        protected boolean syncAgainOnNewRecords() {
            return true;
        }
    };
    JournalFactory jf = new JournalFactory() {

        public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
            return journal;
        }
    };
    ClusterConfig cc = new ClusterConfig(id, SYNC_DELAY, jf);
    SimpleClusterContext context = new SimpleClusterContext(cc);
    journal.setRepositoryHome(context.getRepositoryHome());
    journal.init(id, context.getNamespaceResolver());
    journal.setRecords(records);
    ClusterNode clusterNode = new ClusterNode();
    clusterNode.init(context);
    if (disableAutoSync) {
        clusterNode.disableAutoSync();
    }
    return clusterNode;
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) MemoryJournal(org.apache.jackrabbit.core.journal.MemoryJournal) ClusterConfig(org.apache.jackrabbit.core.config.ClusterConfig)

Example 12 with NamespaceResolver

use of org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver in project jackrabbit by apache.

the class NameParserTest method testExpandedJcrNames.

public void testExpandedJcrNames() throws NamespaceException, IllegalNameException {
    NamespaceResolver resolver = new TestNamespaceResolver();
    List<String[]> valid = new ArrayList<String[]>();
    // valid qualified jcr-names:
    // String-array consisting of { jcrName , uri , localName }
    valid.add(new String[] { "abc:{c}", "abc", "{c}" });
    valid.add(new String[] { "abc:}c", "abc", "}c" });
    valid.add(new String[] { "abc:c}", "abc", "c}" });
    valid.add(new String[] { "{ab", "", "{ab" });
    valid.add(new String[] { "ab}", "", "ab}" });
    valid.add(new String[] { "a}bc", "", "a}bc" });
    valid.add(new String[] { "{", "", "{" });
    valid.add(new String[] { "}", "", "}" });
    valid.add(new String[] { "abc", "", "abc" });
    valid.add(new String[] { "abc{abc}", "", "abc{abc}" });
    valid.add(new String[] { "{{abc}", "", "{{abc}" });
    valid.add(new String[] { "{abc{abc}", "", "{abc{abc}" });
    valid.add(new String[] { "abc {", "", "abc {" });
    valid.add(new String[] { "abc { }", "", "abc { }" });
    valid.add(new String[] { "{ ab }", "", "{ ab }" });
    valid.add(new String[] { "{ }abc", "", "{ }abc" });
    // unknown uri -> but valid non-prefixed jcr-name
    valid.add(new String[] { "{test}abc", "", "{test}abc" });
    valid.add(new String[] { "{ab}", "", "{ab}" });
    valid.add(new String[] { ".{.}", "", ".{.}" });
    // valid expanded jcr-names:
    // String-array consisting of { jcrName , uri , localName }
    valid.add(new String[] { "{http://jackrabbit.apache.org}abc", "http://jackrabbit.apache.org", "abc" });
    valid.add(new String[] { "{http://jackrabbit.apache.org:80}abc", "http://jackrabbit.apache.org:80", "abc" });
    valid.add(new String[] { "{http://jackrabbit.apache.org/info}abc", "http://jackrabbit.apache.org/info", "abc" });
    valid.add(new String[] { "{jcr:jackrabbit}abc", "jcr:jackrabbit", "abc" });
    valid.add(new String[] { "{abc:}def", "abc:", "def" });
    valid.add(new String[] { "{}abc", "", "abc" });
    for (Object aValid : valid) {
        String[] strs = (String[]) aValid;
        try {
            Name n = NameParser.parse(strs[0], resolver, factory);
            assertEquals("URI mismatch", strs[1], n.getNamespaceURI());
            assertEquals("Local name mismatch", strs[2], n.getLocalName());
        } catch (Exception e) {
            fail(e.getMessage() + " -> " + strs[0]);
        }
    }
    // invalid jcr-names (neither expanded nor qualified form)
    List<String> invalid = new ArrayList<String>();
    // invalid prefix
    invalid.add("{a:b");
    invalid.add("}a:b");
    invalid.add("a{b:c");
    invalid.add("a}b:c");
    // unknown uri -> but invalid local name with ':' and or '/'
    invalid.add("{http//test.apache.org}abc");
    invalid.add("{test/test/test}abc");
    // invalid local name containing '/'
    invalid.add("{http://jackrabbit.apache.org}abc/dfg");
    // invalid local name containing ':'
    invalid.add("{http://jackrabbit.apache.org}abc:dfg");
    // invalid local name containing ':' and '/'
    invalid.add("{{http://jackrabbit.apache.org}abc:dfg}");
    // invalid local name containing '/'
    invalid.add("/a/b/c");
    // known uri but local name missing -> must fail.
    invalid.add("{http://jackrabbit.apache.org}");
    invalid.add("{}");
    for (Object anInvalid : invalid) {
        String jcrName = (String) anInvalid;
        try {
            NameParser.parse(jcrName, resolver, factory);
            fail("Parsing '" + jcrName + "' should fail. Not a valid jcr name.");
        } catch (IllegalNameException e) {
        //ok
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name) JcrName(org.apache.jackrabbit.spi.commons.name.JcrName)

Example 13 with NamespaceResolver

use of org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver in project jackrabbit by apache.

the class TestAll method getDefaultValue.

/**
     * Returns the string value of the identified property default value.
     *
     * @param def property definition
     * @param index default value index
     * @return default value
     */
private String getDefaultValue(QPropertyDefinition def, int index) {
    try {
        QValue[] values = def.getDefaultValues();
        NamespaceResolver nsResolver = new AdditionalNamespaceResolver(registry);
        NamePathResolver resolver = new DefaultNamePathResolver(nsResolver);
        ValueFactoryQImpl factory = new ValueFactoryQImpl(InternalValueFactory.getInstance(), resolver);
        return factory.createValue(values[index]).getString();
    } catch (RepositoryException e) {
        throw new AssertionFailedError(e.getMessage());
    }
}
Also used : NamePathResolver(org.apache.jackrabbit.spi.commons.conversion.NamePathResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) QValue(org.apache.jackrabbit.spi.QValue) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) DefaultNamePathResolver(org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver) RepositoryException(javax.jcr.RepositoryException) ValueFactoryQImpl(org.apache.jackrabbit.spi.commons.value.ValueFactoryQImpl) AssertionFailedError(junit.framework.AssertionFailedError)

Example 14 with NamespaceResolver

use of org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver in project jackrabbit by apache.

the class RepositoryConfigurationParser method getJournalFactory.

/**
     * Parses journal configuration. Journal configuration uses the following format:
     * <pre>
     *   &lt;Journal class="..."&gt;
     *     &lt;param name="..." value="..."&gt;
     *     ...
     *   &lt;/Journal&gt;
     * </pre>
     * <p>
     * <code>Journal</code> is a {@link #parseBeanConfig(Element,String) bean configuration}
     * element.
     *
     * @param cluster parent cluster element
     * @param home repository home directory
     * @param id cluster node id
     * @return journal factory
     * @throws ConfigurationException if the configuration is broken
     */
protected JournalFactory getJournalFactory(final Element cluster, final File home, final String id) throws ConfigurationException {
    return new JournalFactory() {

        public Journal getJournal(NamespaceResolver resolver) throws RepositoryException {
            BeanConfig config = parseBeanConfig(cluster, JOURNAL_ELEMENT);
            Journal journal = config.newInstance(Journal.class);
            if (journal instanceof AbstractJournal) {
                ((AbstractJournal) journal).setRepositoryHome(home);
            }
            try {
                journal.init(id, resolver);
            } catch (JournalException e) {
                // TODO: Should JournalException extend RepositoryException?
                throw new RepositoryException("Journal initialization failed: " + journal, e);
            }
            return journal;
        }
    };
}
Also used : JournalFactory(org.apache.jackrabbit.core.journal.JournalFactory) AbstractJournal(org.apache.jackrabbit.core.journal.AbstractJournal) JournalException(org.apache.jackrabbit.core.journal.JournalException) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) Journal(org.apache.jackrabbit.core.journal.Journal) AbstractJournal(org.apache.jackrabbit.core.journal.AbstractJournal) RepositoryException(javax.jcr.RepositoryException)

Example 15 with NamespaceResolver

use of org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver in project jackrabbit by apache.

the class IndexingConfigurationImpl method init.

/**
     * {@inheritDoc}
     */
public void init(Element config, QueryHandlerContext context, NamespaceMappings nsMappings) throws Exception {
    configuration = config;
    ism = context.getItemStateManager();
    hmgr = new HierarchyManagerImpl(context.getRootId(), ism);
    NamespaceResolver nsResolver = new AdditionalNamespaceResolver(getNamespaces(config));
    resolver = new ParsingNameResolver(NameFactoryImpl.getInstance(), nsResolver);
    ntReg = context.getNodeTypeRegistry();
    ntReg.addListener(this);
    refreshIndexRules();
    List<AggregateRule> idxAggregates = new ArrayList<AggregateRule>();
    NodeList indexingConfigs = config.getChildNodes();
    for (int i = 0; i < indexingConfigs.getLength(); i++) {
        Node configNode = indexingConfigs.item(i);
        if (configNode.getNodeName().equals("aggregate")) {
            idxAggregates.add(new AggregateRuleImpl(configNode, resolver, ism, hmgr));
        } else if (configNode.getNodeName().equals("analyzers")) {
            NodeList childNodes = configNode.getChildNodes();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node analyzerNode = childNodes.item(j);
                if (analyzerNode.getNodeName().equals("analyzer")) {
                    Analyzer analyzer = JackrabbitAnalyzer.getAnalyzerInstance(analyzerNode.getAttributes().getNamedItem("class").getNodeValue());
                    NodeList propertyChildNodes = analyzerNode.getChildNodes();
                    for (int k = 0; k < propertyChildNodes.getLength(); k++) {
                        Node propertyNode = propertyChildNodes.item(k);
                        if (propertyNode.getNodeName().equals("property")) {
                            // get property name
                            Name propName = resolver.getQName(getTextContent(propertyNode));
                            String fieldName = nsMappings.translateName(propName);
                            // set analyzer for the fulltext property fieldname
                            int idx = fieldName.indexOf(':');
                            fieldName = fieldName.substring(0, idx + 1) + FieldNames.FULLTEXT_PREFIX + fieldName.substring(idx + 1);
                            Object prevAnalyzer = analyzers.put(fieldName, analyzer);
                            if (prevAnalyzer != null) {
                                log.warn("Property " + propName.getLocalName() + " has been configured for multiple analyzers. " + " Last configured analyzer is used");
                            }
                        }
                    }
                }
            }
        }
    }
    if (idxAggregates.isEmpty()) {
        aggregateRules = null;
    } else {
        aggregateRules = idxAggregates.toArray(new AggregateRule[idxAggregates.size()]);
    }
}
Also used : ParsingNameResolver(org.apache.jackrabbit.spi.commons.conversion.ParsingNameResolver) AdditionalNamespaceResolver(org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Analyzer(org.apache.lucene.analysis.Analyzer) Name(org.apache.jackrabbit.spi.Name) NamespaceResolver(org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver) AdditionalNamespaceResolver(org.apache.jackrabbit.core.nodetype.xml.AdditionalNamespaceResolver) HierarchyManagerImpl(org.apache.jackrabbit.core.HierarchyManagerImpl)

Aggregations

NamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver)21 DefaultNamePathResolver (org.apache.jackrabbit.spi.commons.conversion.DefaultNamePathResolver)12 RepositoryException (javax.jcr.RepositoryException)10 AbstractNamespaceResolver (org.apache.jackrabbit.spi.commons.namespace.AbstractNamespaceResolver)8 ClusterConfig (org.apache.jackrabbit.core.config.ClusterConfig)6 Batch (org.apache.jackrabbit.spi.Batch)6 ClusterNode (org.apache.jackrabbit.core.cluster.ClusterNode)4 SimpleClusterContext (org.apache.jackrabbit.core.cluster.SimpleClusterContext)4 JournalFactory (org.apache.jackrabbit.core.journal.JournalFactory)4 MemoryJournal (org.apache.jackrabbit.core.journal.MemoryJournal)3 QValue (org.apache.jackrabbit.spi.QValue)3 ArrayList (java.util.ArrayList)2 Name (org.apache.jackrabbit.spi.Name)2 NamePathResolver (org.apache.jackrabbit.spi.commons.conversion.NamePathResolver)2 File (java.io.File)1 HashMap (java.util.HashMap)1 NamespaceException (javax.jcr.NamespaceException)1 Value (javax.jcr.Value)1 AssertionFailedError (junit.framework.AssertionFailedError)1 HierarchyManagerImpl (org.apache.jackrabbit.core.HierarchyManagerImpl)1