public void setDefaultNamespace(NamespaceInfo defaultNamespace) { if (defaultNamespace != null) { NamespaceInfo ns = getNamespaceByPrefix(defaultNamespace.getPrefix()); if (ns == null) { throw new IllegalArgumentException( "No such namespace: '" + defaultNamespace.getPrefix() + "'"); } else { defaultNamespace = ns; } } facade.setDefaultNamespace(defaultNamespace); }
public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof NamespaceInfo)) { return false; } final NamespaceInfo other = (NamespaceInfo) obj; if (prefix == null) { if (other.getPrefix() != null) return false; } else if (!prefix.equals(other.getPrefix())) return false; if (uri == null) { if (other.getURI() != null) return false; } else if (!uri.equals(other.getURI())) return false; return true; } }
private void addNamespace(NamespaceInfo ns) throws IOException { LOGGER.fine("Persisting namespace " + ns.getPrefix()); Resource xml = dd.config(ns); persist(ns, xml); }
private void modifyNamespace(NamespaceInfo ns) throws IOException { LOGGER.fine("Persisting namespace " + ns.getPrefix()); Resource xml = dd.config(ns); persist(ns, xml); }
private void removeNamespace(NamespaceInfo ns) throws IOException { LOGGER.fine("Removing namespace " + ns.getPrefix()); Resource directory = dd.get(ns); rmRes(directory); }
public NamespaceInfo getNamespaceByPrefix(String prefix) { if (prefix == null || Catalog.DEFAULT.equals(prefix)) { NamespaceInfo ns = getDefaultNamespace(); if (ns != null) { prefix = ns.getPrefix(); } } return facade.getNamespaceByPrefix(prefix); }
public String prefixedName() { return getNamespace().getPrefix() + ":" + getName(); }
@Override public Boolean evaluate(Object object) { WorkspaceInfo wsInfo = getCatalog() .getWorkspaceByName( ((NamespaceInfo) object).getPrefix()); return !hideWorkspace(wsInfo); } };
/** Given a namespace and user, returns it back if the user can access it, null otherwise */ protected <T extends NamespaceInfo> T checkAccess( Authentication user, T ns, MixedModeBehavior mixedModeBehavior) { if (ns == null) return null; // route the security check thru the associated workspace info WorkspaceInfo ws = delegate.getWorkspaceByName(ns.getPrefix()); if (ws == null) { // temporary workaround, build a fake workspace, as we're probably // in between a change of workspace/namespace name ws = delegate.getFactory().createWorkspace(); ws.setName(ns.getPrefix()); } WorkspaceInfo info = checkAccess(user, ws, mixedModeBehavior); if (info == null) return null; else return ns; }
/** * Retrieve a resource in the the configuration directory of the workspace associated with a * namespace. An empty path will retrieve the directory itself. A null namespace will retrieve * the resouce in the global configuration directory. * * @param ns The namespace * @return A {@link Resource} */ public @Nonnull Resource get(NamespaceInfo ns, String... path) { Resource r; if (ns == null) { r = get(Paths.path(path)); } else { r = getWorkspaces(ns.getPrefix(), Paths.path(path)); } assert r != null; return r; }
/** When a namespace is removed, makes sure the associated workspace is removed as well. */ public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException { if (event.getSource() instanceof NamespaceInfo) { NamespaceInfo ns = (NamespaceInfo) event.getSource(); WorkspaceInfo ws = catalog.getWorkspaceByName(ns.getPrefix()); if (ws != null) { catalog.remove(ws); } } }
public String getPrefix(Name name) { Catalog cat = getCatalog(); if (cat == null) { return ""; } if (name.getNamespaceURI() == null) { return ""; } NamespaceInfo ni = cat.getNamespaceByURI(name.getNamespaceURI()); return ni == null ? "" : ni.getPrefix(); }
/** * Get the QName for a layer specified by the layername that would be used in a request. * * @param typename the layer name for the type */ protected QName resolveLayerName(String typename) { int i = typename.indexOf(":"); String prefix = typename.substring(0, i); String name = typename.substring(i + 1); NamespaceInfo ns = getCatalog().getNamespaceByPrefix(prefix); QName qname = new QName(ns.getURI(), name, ns.getPrefix()); return qname; }
/** * Get the QName for a layer specified by the layername that would be used in a request. * * @param typename the layer name for the type */ protected QName resolveLayerName(String typename) { int i = typename.indexOf(":"); String prefix = typename.substring(0, i); String name = typename.substring(i + 1); NamespaceInfo ns = getCatalog().getNamespaceByPrefix(prefix); QName qname = new QName(ns.getURI(), name, ns.getPrefix()); return qname; }
@Override public Boolean evaluate(Object object) { CatalogInfo info = (CatalogInfo) object; if (info instanceof NamespaceInfo) { info = getCatalog().getWorkspaceByName(((NamespaceInfo) info).getPrefix()); } if (info == null) { return false; } WrapperPolicy policy = getSecurityWrapper() .buildWrapperPolicy( resourceAccesssManager, user, info, MixedModeBehavior.HIDE); AccessLevel accessLevel = policy.getAccessLevel(); boolean visible = !AccessLevel.HIDDEN.equals(accessLevel); return Boolean.valueOf(visible); } }
public LayerInfo getLayerByName(Name name) { if (name.getNamespaceURI() != null) { NamespaceInfo ns = getNamespaceByURI(name.getNamespaceURI()); if (ns != null) { return getLayerByName(ns.getPrefix() + ":" + name.getLocalPart()); } } return getLayerByName(name.getLocalPart()); }
/** Helper method that checks that the provided namespace has the expected content. */ protected void checkNamespace( NamespaceInfo namespace, String expectedPrefix, String expectedNamespaceUri, boolean expectedIsolation) { assertThat(namespace, notNullValue()); assertThat(namespace.getPrefix(), is(expectedPrefix)); assertThat(namespace.getName(), is(expectedPrefix)); assertThat(namespace.getURI(), is(expectedNamespaceUri)); assertThat(namespace.isIsolated(), is(expectedIsolation)); }
/** * Helper method that will make sure that the workspace associated to the provided namespace has * the same isolation. * * <p>If the associated namespace doesn't exists nothing will be done. * * @param namespace a catalog namespace */ private void syncWorkspaceIsolation(NamespaceInfo namespace) { // get the workspace associated to the namespace, may be NULL WorkspaceInfo workspace = catalog.getWorkspaceByName(namespace.getPrefix()); if (workspace != null && namespace.isIsolated() != workspace.isIsolated()) { // update the workspace isolation workspace.setIsolated(namespace.isIsolated()); catalog.save(workspace); } } }
@Test public void testGetLayersWithSameName() throws Exception { LayerInfo layerInfo1 = catalog.getLayerByName(new NameImpl("ws1", "lc")); ResourceInfo resource1 = layerInfo1.getResource(); NamespaceInfo namespace1 = resource1.getNamespace(); String nsPrefix1 = namespace1.getPrefix(); LayerInfo layerInfo2 = catalog.getLayerByName(new NameImpl("ws2", "lc")); ResourceInfo resource2 = layerInfo2.getResource(); NamespaceInfo namespace2 = resource2.getNamespace(); String nsPrefix2 = namespace2.getPrefix(); assertEquals("Invalid namespace prefix", "ws1", nsPrefix1); assertEquals("Invalid namespace prefix", "ws2", nsPrefix2); }
@Test public void testGetNamespaceByPrefix() { catalog.add(ns); NamespaceInfo ns2 = catalog.getNamespaceByPrefix(ns.getPrefix()); assertNotNull(ns2); assertFalse(ns == ns2); assertEquals(ns, ns2); NamespaceInfo ns3 = catalog.getNamespaceByPrefix(null); assertNotNull(ns3); assertFalse(ns == ns3); assertEquals(ns, ns3); NamespaceInfo ns4 = catalog.getNamespaceByPrefix(Catalog.DEFAULT); assertNotNull(ns4); assertFalse(ns == ns4); assertEquals(ns, ns4); }