本文整理汇总了Java中com.rometools.rome.io.impl.Atom10Parser类的典型用法代码示例。如果您正苦于以下问题:Java Atom10Parser类的具体用法?Java Atom10Parser怎么用?Java Atom10Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Atom10Parser类属于com.rometools.rome.io.impl包,在下文中一共展示了Atom10Parser类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGenerator
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/**
* Parser-Test (INSPIRE Service Feed)
* @throws java.io.IOException
* @throws org.jdom2.JDOMException
* @throws com.rometools.rome.io.FeedException
*/
public void testGenerator() throws IOException, JDOMException, IllegalArgumentException, FeedException {
final String file = "src/test/resources/dgm200.xml";
final Document xml = new SAXBuilder().build(new File(file));
// parse Atom
Feed atomFeed = (Feed) new Atom10Parser().parse(xml, true, Locale.GERMAN);
// get first Entry-Element
Entry atomEntry = (Entry) atomFeed.getEntries().get(0);
// get INSPIRE_DLS-Module
InspireDlsModule inspireDlsModule = (InspireDlsModuleImpl) atomEntry.getModule(InspireDlsModule.URI);
assertTrue(inspireDlsModule.getSpatialDatasetIdentifier().getCode().equals("DEBY_1d4ab890-27e7-3ebb-95ba-2d2ab8071871"));
assertTrue(inspireDlsModule.getSpatialDatasetIdentifier().getNamespace().equals("http://www.geodaten.bayern.de"));
System.out.println(inspireDlsModule.getSpatialDatasetIdentifier());
}
示例2: getEntry
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/**
* Get full entry specified by entry edit URI. Note that entry may or may not be associated with
* this collection.
*
* @return ClientEntry or ClientMediaEntry specified by URI.
*/
public ClientEntry getEntry(final String uri) throws ProponoException {
final GetMethod method = new GetMethod(uri);
authStrategy.addAuthentication(httpClient, method);
try {
httpClient.executeMethod(method);
if (method.getStatusCode() != 200) {
throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode());
}
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(method.getResponseBodyAsStream()), uri, Locale.US);
if (!romeEntry.isMediaEntry()) {
return new ClientEntry(service, this, romeEntry, false);
} else {
return new ClientMediaEntry(service, this, romeEntry, false);
}
} catch (final Exception e) {
throw new ProponoException("ERROR: getting or parsing entry/media, HTTP code: ", e);
} finally {
method.releaseConnection();
}
}
示例3: getEntry
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/**
* Get full entry from service by entry edit URI.
*/
public ClientEntry getEntry(final String uri) throws ProponoException {
final GetMethod method = new GetMethod(uri);
authStrategy.addAuthentication(httpClient, method);
try {
httpClient.executeMethod(method);
if (method.getStatusCode() != 200) {
throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode());
}
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(method.getResponseBodyAsStream()), uri, Locale.US);
if (!romeEntry.isMediaEntry()) {
return new ClientEntry(this, null, romeEntry, false);
} else {
return new ClientMediaEntry(this, null, romeEntry, false);
}
} catch (final Exception e) {
throw new ProponoException("ERROR: getting or parsing entry/media", e);
} finally {
method.releaseConnection();
}
}
示例4: testEntryIteration
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
public void testEntryIteration(final String type, final String endpoint) throws Exception {
final BlogConnection conn = BlogConnectionFactory.getBlogConnection(type, endpoint, username, password);
assertNotNull(conn);
final String title1 = "Test content";
final String content1 = "Test content";
final Blog blog = conn.getBlogs().get(0);
for (int i = 0; i < 10; i++) {
final BlogEntry entry = blog.newEntry();
entry.setTitle(title1);
entry.setContent(new BlogEntry.Content(content1));
entry.save();
final String token = entry.getToken();
assertTrue(Atom10Parser.isAbsoluteURI(token));
assertNotNull(token);
}
for (final Iterator<BlogEntry> it = blog.getEntries(); it.hasNext();) {
final BlogEntry blogEntry = it.next();
assertTrue(Atom10Parser.isAbsoluteURI(blogEntry.getToken()));
blogEntry.delete();
}
}
示例5: addToCollection
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
void addToCollection(final ClientCollection col) throws ProponoException {
setCollection(col);
final EntityEnclosingMethod method = new PostMethod(getCollection().getHrefResolved());
addAuthentication(method);
final StringWriter sw = new StringWriter();
int code = -1;
try {
Atom10Generator.serializeEntry(this, sw);
method.setRequestEntity(new StringRequestEntity(sw.toString(), null, null));
method.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
getHttpClient().executeMethod(method);
final InputStream is = method.getResponseBodyAsStream();
code = method.getStatusCode();
if (code != 200 && code != 201) {
throw new ProponoException("ERROR HTTP status=" + code + " : " + Utilities.streamToString(is));
}
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), getCollection().getHrefResolved(), Locale.US);
BeanUtils.copyProperties(this, romeEntry);
} catch (final Exception e) {
final String msg = "ERROR: saving entry, HTTP code: " + code;
LOG.debug(msg, e);
throw new ProponoException(msg, e);
} finally {
method.releaseConnection();
}
final Header locationHeader = method.getResponseHeader("Location");
if (locationHeader == null) {
LOG.warn("WARNING added entry, but no location header returned");
} else if (getEditURI() == null) {
final List<Link> links = getOtherLinks();
final Link link = new Link();
link.setHref(locationHeader.getValue());
link.setRel("edit");
links.add(link);
setOtherLinks(links);
}
}
示例6: loadAtomResourceEntry
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
private Entry loadAtomResourceEntry(final InputStream in, final File file) {
try {
final Entry entry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in)), null, Locale.US);
updateMediaEntryAppLinks(entry, file.getName(), true);
return entry;
} catch (final Exception e) {
e.printStackTrace();
return null;
}
}
示例7: loadAtomEntry
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/**
* Create a Rome Atom entry based on a Roller entry. Content is escaped. Link is stored as
* rel=alternate link.
*/
private Entry loadAtomEntry(final InputStream in) {
try {
return Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(in, "UTF-8")), null, Locale.US);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
}
示例8: getHrefResolved
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/** Get resolved URI of the collection, or null if impossible to determine */
public String getHrefResolved() {
if (Atom10Parser.isAbsoluteURI(href)) {
return href;
} else if (baseURI != null && collectionElement != null) {
final int lastslash = baseURI.lastIndexOf("/");
return Atom10Parser.resolveURI(baseURI.substring(0, lastslash), collectionElement, href);
}
return null;
}
示例9: getHrefResolved
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/** Get unresolved URI of the collection, or null if impossible to determine */
public String getHrefResolved() {
if (Atom10Parser.isAbsoluteURI(href)) {
return href;
} else if (baseURI != null && categoriesElement != null) {
return Atom10Parser.resolveURI(baseURI, categoriesElement, href);
}
return null;
}
示例10: setUp
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
Atom10Parser.setResolveURIs(true);
}
示例11: tearDown
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
@Override
protected void tearDown() throws Exception {
Atom10Parser.setResolveURIs(false);
super.tearDown();
}
示例12: addToCollection
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/** Package access, to be called by DefaultClientCollection */
@Override
void addToCollection(final ClientCollection col) throws ProponoException {
setCollection(col);
final EntityEnclosingMethod method = new PostMethod(col.getHrefResolved());
getCollection().addAuthentication(method);
try {
final Content c = getContents().get(0);
if (inputStream != null) {
method.setRequestEntity(new InputStreamRequestEntity(inputStream));
} else {
method.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(getBytes())));
}
method.setRequestHeader("Content-type", c.getType());
method.setRequestHeader("Title", getTitle());
method.setRequestHeader("Slug", getSlug());
getCollection().getHttpClient().executeMethod(method);
if (inputStream != null) {
inputStream.close();
}
final InputStream is = method.getResponseBodyAsStream();
if (method.getStatusCode() == 200 || method.getStatusCode() == 201) {
final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), col.getHrefResolved(), Locale.US);
BeanUtils.copyProperties(this, romeEntry);
} else {
throw new ProponoException("ERROR HTTP status-code=" + method.getStatusCode() + " status-line: " + method.getStatusLine());
}
} catch (final IOException ie) {
throw new ProponoException("ERROR: saving media entry", ie);
} catch (final JDOMException je) {
throw new ProponoException("ERROR: saving media entry", je);
} catch (final FeedException fe) {
throw new ProponoException("ERROR: saving media entry", fe);
} catch (final IllegalAccessException ae) {
throw new ProponoException("ERROR: saving media entry", ae);
} catch (final InvocationTargetException te) {
throw new ProponoException("ERROR: saving media entry", te);
}
final Header locationHeader = method.getResponseHeader("Location");
if (locationHeader == null) {
LOG.warn("WARNING added entry, but no location header returned");
} else if (getEditURI() == null) {
final List<Link> links = getOtherLinks();
final Link link = new Link();
link.setHref(locationHeader.getValue());
link.setRel("edit");
links.add(link);
setOtherLinks(links);
}
}
示例13: doPut
import com.rometools.rome.io.impl.Atom10Parser; //导入依赖的package包/类
/**
* Handles an Atom PUT by calling handler to identify URI, reading/parsing data, calling handler
* and writing results to response.
*/
@Override
protected void doPut(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
LOG.debug("Entering");
final AtomHandler handler = createAtomRequestHandler(req, res);
final String userName = handler.getAuthenticatedUsername();
if (userName != null) {
final AtomRequest areq = new AtomRequestImpl(req);
try {
if (handler.isEntryURI(areq)) {
// parse incoming entry
final Entry unsavedEntry = Atom10Parser.parseEntry(new BufferedReader(new InputStreamReader(req.getInputStream(), "UTF-8")), null,
Locale.US);
// call handler to put entry
handler.putEntry(areq, unsavedEntry);
res.setStatus(HttpServletResponse.SC_OK);
} else if (handler.isMediaEditURI(areq)) {
// hand input stream to handler
handler.putMedia(areq);
res.setStatus(HttpServletResponse.SC_OK);
} else {
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
} catch (final AtomException ae) {
res.sendError(ae.getStatus(), ae.getMessage());
LOG.debug("An error occured while processing PUT", ae);
} catch (final Exception e) {
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
LOG.debug("An error occured while processing PUT", e);
}
} else {
res.setHeader("WWW-Authenticate", "BASIC realm=\"AtomPub\"");
// Wanted to use sendError() here but Tomcat sends 403 forbidden
// when I do that, so sticking with setStatus() for time being.
res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
LOG.debug("Exiting");
}