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;
}
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
}
}
}
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());
}
}
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>
* <Journal class="...">
* <param name="..." value="...">
* ...
* </Journal>
* </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;
}
};
}
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()]);
}
}
Aggregations