private File getRepositoryStorageDir(ConfigurationPropertyProvider propProvider, ServerEnvironment serverenv) { String dirName = propProvider.getProperty(XRepository.PROPERTY_REPOSITORY_STORAGE_DIR, null); if (dirName == null) { try { File storageDir = new File(serverenv.getServerDataDir().getPath() + File.separator + "repository"); dirName = storageDir.getCanonicalPath(); } catch (IOException ex) { throw MESSAGES.cannotCreateRepositoryStorageArea(ex); } } return new File(dirName).getAbsoluteFile(); }
private RepositoryXMLReader(InputStream input) { try { reader = XMLInputFactory.newInstance().createXMLStreamReader(input); } catch (Exception ex) { throw MESSAGES.cannotInitializeRepositoryReader(ex); } try { reader.require(START_DOCUMENT, null, null); reader.nextTag(); reader.require(START_ELEMENT, REPOSITORY_NAMESPACE, REPOSITORY.getLocalName()); for (int i = 0; i < reader.getAttributeCount(); i++) { attributes.put(reader.getAttributeLocalName(i), reader.getAttributeValue(i)); } } catch (Exception ex) { throw MESSAGES.cannotReadResourceElement(ex, reader.getLocation()); } }
private RepositoryXMLWriter(OutputStream output) { try { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(output); } catch (Exception ex) { throw MESSAGES.cannotInitializeRepositoryWriter(ex); } }
@Override public synchronized XResource addResource(XResource res) throws RepositoryStorageException { if (res == null) throw MESSAGES.illegalArgumentNull("resource"); throw MESSAGES.cannotAddMavenResourceToStorage(null, res); XIdentityCapability iaux = aux.adapt(XIdentityCapability.class); if (icap.getAttributes().equals(iaux.getAttributes())) { throw MESSAGES.resourceAlreadyExists(res);
private synchronized XResource addResourceInternal(XResource res, boolean writeXML) throws RepositoryStorageException { if (res == null) throw MESSAGES.illegalArgumentNull("resource"); XIdentityCapability icap = res.getIdentityCapability(); if (XResource.MAVEN_IDENTITY_NAMESPACE.equals(icap.getNamespace())) throw MESSAGES.cannotAddMavenResourceToStorage(null, res); String moduleId = (String) icap.getAttribute(XResource.MODULE_IDENTITY_NAMESPACE); if (res.isAbstract() || moduleId != null) { return addAbstractResource(res, writeXML); } else { return addContentResource(res, writeXML); } }
public FileBasedRepositoryStorage(XRepository repository, File storageDir, ConfigurationPropertyProvider propProvider) { super(repository); if (storageDir == null) throw MESSAGES.illegalArgumentNull("storageDir"); if (propProvider == null) throw MESSAGES.illegalArgumentNull("propProvider"); this.storageDir = storageDir; String filename = propProvider.getProperty(XRepository.PROPERTY_REPOSITORY_STORAGE_FILE, REPOSITORY_XML_NAME); repoFile = new File(storageDir.getAbsolutePath() + File.separator + filename).getAbsoluteFile(); // Initialize repository content if (repoFile.exists()) { RepositoryReader reader; try { reader = RepositoryXMLReader.create(new FileInputStream(repoFile)); } catch (IOException ex) { throw MESSAGES.cannotInitializeRepositoryReader(ex); } String incatt = reader.getRepositoryAttributes().get(Attribute.INCREMENT.getLocalName()); Long increment = new Long(incatt != null ? incatt : "0"); XResource res = reader.nextResource(); while(res != null) { addResourceInternal(res, false); res = reader.nextResource(); } long delta = increment - getResourceIndex().get(); getResourceIndex().addAndGet(delta); reader.close(); } }
private XResource addContentResource(XResource res, boolean writeXML) throws RepositoryStorageException { List<Capability> ccaps = res.getCapabilities(ContentNamespace.CONTENT_NAMESPACE); if (ccaps.isEmpty()) throw MESSAGES.cannotObtainContentCapablility(res); throw MESSAGES.cannotObtainContentURL(res);
@Override public InputStream getContent() { try { if (contentURL.getProtocol().equals("file")) { return new FileInputStream(urlToFile(contentURL)); } else { return contentURL.openStream(); } } catch (IOException ex) { throw MESSAGES.cannotObtainInputStream(ex, this); } catch (URISyntaxException ex) { throw MESSAGES.cannotObtainInputStream(ex, this); } } }
public Module loadModule(ModuleIdentifier identifier) { Module module; try { module = moduleLoader.loadModule(identifier); } catch (ModuleLoadException ex) { throw MESSAGES.cannotObtainModuleResource(ex, identifier); } return module; }
private InputStream getResourceContent(XCapability ccap) { InputStream input; Resource resource = ccap.getResource(); Capability defaultContent = resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE).get(0); if (defaultContent == ccap && resource instanceof RepositoryContent) { input = ((RepositoryContent) resource).getContent(); } else { String contentURL = (String) ccap.getAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE); try { input = new URL(contentURL).openStream(); } catch (IOException ex) { throw MESSAGES.cannotAccessContentURL(ex, contentURL); } } return input; }
private XResourceBuilder<XResource> createResourceInternal(XResource resource) { XResourceBuilder<XResource> factory = null; for (Capability cap : resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) { XCapability ccap = (XCapability)cap; Map<String, Object> contentAtts = new HashMap<String, Object>(); String mimeType = (String) ccap.getAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE); if (mimeType != null) { contentAtts.put(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, mimeType); } InputStream input = getResourceContent(ccap); try { URL contentURL = addResourceContent(input, contentAtts); if (factory == null) { factory = URLResourceBuilderFactory.create(contentURL, contentAtts); } else { factory.addCapability(ContentNamespace.CONTENT_NAMESPACE, contentAtts, null); } } catch (IOException ex) { throw MESSAGES.cannotAddResourceToStorage(ex, mimeType); } } return factory; }
private void writeRepositoryXML() { RepositoryWriter writer; try { repoFile.getParentFile().mkdirs(); writer = RepositoryXMLWriter.create(new FileOutputStream(repoFile)); } catch (IOException ex) { throw MESSAGES.cannotInitializeRepositoryWriter(ex); } Map<String, String> attributes = new HashMap<String, String>(); attributes.put(Attribute.NAME.getLocalName(), getRepository().getName()); attributes.put(Attribute.INCREMENT.getLocalName(), new Long(getResourceIndex().get()).toString()); writer.writeRepositoryElement(attributes); RepositoryReader reader = getRepositoryReader(); XResource resource = reader.nextResource(); while(resource != null) { writer.writeResource(resource); resource = reader.nextResource(); } writer.close(); }