本文整理了Java中org.geoserver.platform.resource.Resource.getContents
方法的一些代码示例,展示了Resource.getContents
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.getContents
方法的具体详情如下:
包路径:org.geoserver.platform.resource.Resource
类名称:Resource
方法名:getContents
[英]Returns a resource full contents as a byte array. Usage is suggested only if the resource is known to be small (e.g. a configuration file).
[中]以字节数组的形式返回资源完整内容。仅当已知资源较小(例如配置文件)时,才建议使用。
代码示例来源:origin: geoserver/geoserver
/** Helper method which uses xstream to depersist an object as xml from disk. */
<T> T depersist(XStreamPersister xp, Resource f, Class<T> clazz) throws IOException {
try (InputStream in = new ByteArrayInputStream(f.getContents())) {
return xp.load(in, clazz);
}
}
代码示例来源:origin: geoserver/geoserver
@Override
public WorkspaceContents apply(Resource rd) throws IOException {
Resource wr = rd.get("workspace.xml");
Resource nr = rd.get("namespace.xml");
if (Resources.exists(wr) && Resources.exists(nr)) {
byte[] contents = wr.getContents();
byte[] nrContents = nr.getContents();
return new WorkspaceContents(rd, contents, nrContents);
} else {
LOGGER.warning("Ignoring workspace directory " + rd.path());
return null;
}
}
}
代码示例来源:origin: geoserver/geoserver
@Override
public LayerContents apply(Resource rd) throws IOException {
Resource r = rd.get(resourceFileName);
Resource lr = rd.get("layer.xml");
if (Resources.exists(r) && Resources.exists(lr)) {
byte[] contents = r.getContents();
byte[] lrContents = lr.getContents();
return new LayerContents(rd, contents, lrContents);
} else {
LOGGER.warning("Ignoring " + resourceType + " directory " + rd.path());
return null;
}
}
}
代码示例来源:origin: geoserver/geoserver
void loadLayerGroups(Resource layerGroups, Catalog catalog, XStreamPersister xp) {
try (AsynchResourceIterator<byte[]> it =
new AsynchResourceIterator<>(layerGroups, XML_FILTER, r -> r.getContents())) {
while (it.hasNext()) {
try {
LayerGroupInfo lg = depersist(xp, it.next(), LayerGroupInfo.class);
if (lg.getLayers() == null || lg.getLayers().size() == 0) {
LOGGER.warning(
"Skipping empty layer group '" + lg.getName() + "', it is invalid");
continue;
}
catalog.add(lg);
LOGGER.info("Loaded layer group '" + lg.getName() + "'");
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to load layer group", e);
}
}
}
}
代码示例来源:origin: geoserver/geoserver
void loadStyles(Resource styles, Catalog catalog, XStreamPersister xp) throws IOException {
Filter<Resource> styleFilter =
r -> XML_FILTER.accept(r) && !Resources.exists(styles.get(r.name() + ".xml"));
try (AsynchResourceIterator<byte[]> it =
new AsynchResourceIterator<>(styles, styleFilter, r -> r.getContents())) {
while (it.hasNext()) {
try {
StyleInfo s = depersist(xp, it.next(), StyleInfo.class);
catalog.add(s);
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Loaded style '" + s.getName() + "'");
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to load style", e);
}
}
}
}
代码示例来源:origin: geoserver/geoserver
Resource f = sd.get("datastore.xml");
if (Resources.exists(f)) {
return new StoreContents(f, f.getContents());
return new StoreContents(f, f.getContents());
return new StoreContents(f, f.getContents());
return new StoreContents(f, f.getContents());
代码示例来源:origin: stackoverflow.com
ResourceSet resourceSet = ResourceSetFactory.createResourceSet();
Resource resource = resourceSet.getResource(xmlURI, true);
resource.load(Collections.EMPTY_MAP);
EObject root = resource.getContents().get(0);
代码示例来源:origin: stackoverflow.com
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
resourceSet.getPackageRegistry().put("http://www.eclipse.org/uml2/2.0.0/UML", UMLPackage.eINSTANCE);
Resource r = resourceSet.getResource(uriToYourFile,true);
YourModelRootType root = (YourModelRootType) r.getContents().get(0);
代码示例来源:origin: org.geoserver/gs-gwc
private GeoServerTileLayerInfoImpl depersist(final Resource res) throws IOException {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Depersisting GeoServerTileLayerInfo from " + res.path());
}
GeoServerTileLayerInfoImpl info;
try (Reader reader =
new InputStreamReader(new ByteArrayInputStream(res.getContents()), "UTF-8")) {
info = (GeoServerTileLayerInfoImpl) serializer.fromXML(reader);
}
return info;
}
代码示例来源:origin: stackoverflow.com
// creating the injector
Injector injector = new MyLanguageStandaloneSetup().createInjectorAndDoEMFRegistration()
// obtain a resource set
XtextResourceSet resourceSet = injector.get(XtextResourceSet.class);
// load file
Resource resource = resourceSet.getResource(URI.create("path/to/file.mylanguage"), true);
// obtain root AST element
MyModel model = (MyModel) resource.getContents().get(0);
代码示例来源:origin: stackoverflow.com
// "workspace" is a string that contains the path to the workspace containing the DSL program.
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri(workspace);
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
// "DSLProgram" is a string that contains the path to the file of the DSL program relative to the workspace set above.
Resource resource = resourceSet.getResource(URI.createURI("platform:/resource/" + DSLProgram), true);
Model model = (Model) resource.getContents().get(0);
代码示例来源:origin: stackoverflow.com
private void exportXMI(String absuloteTargetFolderPath) {
// change MyLanguage with your language name
Injector injector = new MyLanguageStandaloneSetup()
.createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector
.getInstance(XtextResourceSet.class);
// .ext ist the extension of the model file
String inputURI = "file:///" + absuloteTargetFolderPath + "/MyFile.ext";
String outputURI = "file:///" + absuloteTargetFolderPath + "/MyFile.xmi";
URI uri = URI.createURI(inputURI);
Resource xtextResource = resourceSet.getResource(uri, true);
EcoreUtil.resolveAll(xtextResource);
Resource xmiResource = resourceSet
.createResource(URI.createURI(outputURI));
xmiResource.getContents().add(xtextResource.getContents().get(0));
try {
xmiResource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
//Generate your URI
ResourceFactoryImpl factory = new ResourceFactoryImpl();
URI sourceURI = URI.createURI("your xml path");
Resource loadResource = (ResourceImpl)factory.createResource(sourceURI);
System.out.println(sourceURI.path());
//Add loading options
Map<String, Boolean> options = new HashMap<String, Boolean>();
options.put(XMLResource.OPTION_SUPPRESS_DOCUMENT_ROOT, true);
//Load XML
loadResource.load( options);
//Create XMI output
URI targetURI = URI.createURI("your xmi path");
Resource resourceOut = new ResourceImpl(targetURI);
//Generating your EObjects from XML model
EList listObj = loadResource.getContents();
EObject obj = (EObject) listObj.get(0);
resourceOut.getContents().add(obj);
resourceOut.save(options);
代码示例来源:origin: stackoverflow.com
ResourceSet set = new ResourceSetImpl();
UMLResourcesUtil.init(set);
Resource res = set.getResource(typesUri, true);
EObject eobj = res.getContents().get(0);
代码示例来源:origin: stackoverflow.com
/*
* load existing EPackage
*/
EcorePackage.eINSTANCE.eClass();
/*Initialize your EPackage*/
final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
final Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put(EcorePackage.eNAME, new XMIResourceFactoryImpl());
final ResourceSet resSet = new ResourceSetImpl();
Resource resource = null;
try {
resource = resSet.getResource(URI.createFileURI("/Your/Path/To/Directory/myTest.ecore"), true);
} catch (Exception e) {
e.printStackTrace();
}
/*load root and cast to EPackage*/
final EPackage root = (EPackage) resource.getContents().get(0);
代码示例来源:origin: stackoverflow.com
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("key", new XMIResourceFactoryImpl());
ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.createResource(URI.createFileURI(fileName));
resource.getContents().add(data);
resource.save(Collections.EMPTY_MAP);
代码示例来源:origin: stackoverflow.com
/*
* Save your EPackage to file ecore file:
*/
/*Initialize your EPackage*/
myPackage.eClass();
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
/*add default .ecore extension for ecore file*/
m.put(EcorePackage.eNAME, new XMIResourceFactoryImpl());
// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();
// create a resource
Resource resource = null;
try {
resource = resSet.createResource(URI.createFileURI("/Your/Path/To/Directory/myTest.ecore"));
} catch (Exception e) {
e.printStackTrace();
}
/*add your EPackage as root, everything is hierarchical included in this first node*/
resource.getContents().add(myPackage);
// now save the content.
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
public static EObject loadEObjectFromString(String myModelXml, EPackage ePackage) throws IOException {
// Create a ResourceSet
ResourceSet resourceSet = new ResourceSetImpl();
// register XMIRegistryResourceFactoryIml
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
// register your epackage to the resource set so it has a reference to your ecore
// you can get an instance to your epackage by calling YourEPackageClass.getInstace();
resourceSet.getPackageRegistry().put(ePackage.getNsURI(), ePackage);
Resource resource = resourceSet.createResource(URI.createURI("*.modelextension"));
resource.load(new URIConverter.ReadableInputStream(myModelXml), null);
// return the root model object and there you have it, all you need is to
// cast it to the right EObject based on your model
return resource.getContents().get(0);
}
代码示例来源:origin: org.geoserver/gs-restconfig
@Test
public void testRawPutAsInvalidSLD() throws Exception {
String xml = "This is not valid SLD";
MockHttpServletResponse response =
putAsServletResponse(
RestBaseController.ROOT_PATH + "/styles/Ponds?raw=true",
xml,
SLDHandler.MIMETYPE_10);
assertEquals(200, response.getStatus());
StyleInfo styleInfo = catalog.getStyleByName("Ponds");
String fileName = styleInfo.getFilename();
GeoServerResourceLoader resources = getGeoServer().getCatalog().getResourceLoader();
Resource resource = resources.get("styles/" + fileName);
String content = new String(resource.getContents());
assertFalse("replaced", content.contains("<sld:Name>foo</sld:Name>"));
assertTrue("replaced", content.contains("not valid"));
}
代码示例来源:origin: org.geoserver.extension/gs-css
@Test
public void testPostCSS() throws Exception {
Catalog cat = getCatalog();
assertNull("foo not available", cat.getStyleByName("foo"));
String content = newCSS();
MockHttpServletResponse response =
postAsServletResponse("/rest/styles?name=foo", content, CssHandler.MIME_TYPE);
assertEquals(201, response.getStatus());
GeoServerResourceLoader resources = catalog.getResourceLoader();
Resource resource = resources.get("/styles/foo.css");
String definition = new String(resource.getContents());
assertTrue("is css", definition.contains("stroke: red"));
StyleInfo styleInfo = catalog.getStyleByName("foo");
Style s = styleInfo.getStyle();
ByteArrayOutputStream out = new ByteArrayOutputStream();
SLDHandler handler = new SLDHandler();
handler.encode(Styles.sld(s), SLDHandler.VERSION_10, false, out);
content = new String(out.toByteArray());
assertTrue(content.contains("<sld:Name>foo</sld:Name>"));
catalog.remove(styleInfo);
}
内容来源于网络,如有侵权,请联系作者删除!