Read and change zoom level of named destinations in pdf - java

I'd like to read and change zoom level of named destinations in a pdf file using iText 7. Ive come up with the following code:
Map<String, PdfObject> names =
document.getCatalog().getNameTree(PdfName.Dests).getNames();
for (Map.Entry<String, PdfObject> dest : names.entrySet()) {
if (dest.getValue().isArray()) {
PdfArray arr = (PdfArray) dest.getValue();
PdfName asName = arr.getAsName(1); // /Fit
arr.set(1, FitR);
//System.out.println();
arr.setModified();
}
}
However, this code fails to work against my example file and has other flaws as well.
Most importantly, it tries to deal with one type of zoom (/Fit), but other types (/XYZ and so on) should also be handled with. Second, I don't know how to get the page number of named destination as key pair named of destination and its zoom value doesn't seem to have this information. Please see a screenshot of debug session below:
Note, at SO there is already a question dealing with exactly the same topic. The thing is the answer to that question give too little information to deal with this problem.

Related

Creating URL based on an API key in OSRMRoadManager

I've signed up for an API on openrouteservice.org. How do I import it into OSRMRoadManager? I've tried all the combinations from the examples on their website, but my every try results in the 403 error with a comment org.json.JSONException: No value for code and a link to the following:
{
"error": "Daily quota reached or API key unauthorized"
}
(I haven't used that API before, so I couldn't have used up the quota. The key is valid, as I have tested it with the links from the aforementioned website)
My Kotlin code (in my most recent attempt) is as following ([MY_API_KEY] is obviously replacing my real key):
val roadManager = OSRMRoadManager(context, context?.packageName)
(roadManager as OSRMRoadManager).setService("https://api.openrouteservice.org/v2/directions/driving-car/geojson?api_key=[MY_API_KEY]")
val waypoints = ArrayList<GeoPoint>()
waypoints.add(GeoPoint(lastLocLat, lastLocLong)) //last known location
val endPoint = GeoPoint(randomOverlay.getItem(0).point.latitude, randomOverlay.getItem(0).point.longitude) //destination
waypoints.add(endPoint)
val road = roadManager.getRoad(waypoints)
My guess is that the waypoint coordinates should be included differently in the link, but I don't know how to alter that.
openrouteservice directions format is not identical to OSRM, so you cannot use OSRMRoadManager.
If you really - really - want to use openrouteservice, you will have to develop corresponding openrouteserviceRoadManager.
Alternative: use one among the 3 routing services already accessible with OBP. Pros and cons here.

HERE Api: How do I request PDE data for Safety_Alerts layer without getting Bad Request?

I am creating an Android App that accesses the HERE Platform Data Extension Api (= PDE). Therefore I first load a map centering on my current location. This works fine so far. Then I try to load data from the PDE for the layer "SAFETY_ALERTS", but I get a 400 Error there with the message "tilexy lists 992 tiles but the limit is 64 tiles".
I am not sure where this "tilexy" comes from. I already researched through as much documentation of the PDE as I could find online, but I couldn't find an answer.
Set<String> layers = new HashSet<>(Arrays.asList("SAFETY_ALERTS"));
GeoBoundingBox bbox = map.getBoundingBox();
final PlatformDataRequest request = PlatformDataRequest.createBoundingBoxRequest(layers, bbox);
request.execute(new PlatformDataRequest.Listener<PlatformDataResult>() {
#Override
public void onCompleted(PlatformDataResult platformDataResult, PlatformDataRequest.Error error) {
if (error == null) {
//do something
} else {
//show error --> Here is where I get
}
I expected to get a PlatformDataItemCollection, which is a List of PlatformDataItems (they implement Map). Instead I got the 400-Error.
Does somebody know where this error comes from and can help me fix my mistake?
As per the error message, it would be advisable to check the API call as it seems that more than 64 coordinates has been passed in tilexy parameter in the rest call. tilexy is a string, which is passed in comma separated sequence of tilex,tiley pairs for the requested tiles. The tilex and tiley values are described in the "tile" resource.
please refer following documentation for more reference
developer.here.com/documentation/platform-data/topics/example-tiles.html
Happy Coding..!!

How am I supposed to extract properties from a node in Apache Jackrabbit from xml?

I have been playing around with the example number three in here http://jackrabbit.apache.org/jcr/first-hops.html , however to me it remains unclear how to get access to the properties of a node.
In the first screenshot
I used the debugger from my IDE and I evaluated this expression
session.getNode("/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn").getProperty("jcr:xmltext/jcr:xmlcharacters").getString().trim();
You can see how I can get access to "jcr:xmltest/jcr:xmlcharacters" and have 2 as a result.
However, when I try to get this information, get this property out of the node, I am unable to perform this operation as in this screenshot.
This is the code fragment in the above screenshot:
var node = session.getNode("/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn");
var properties = node.getProperties();
List<string> result = new ArrayList<>();
while(properties.hasNext()) {
Property property = properties.nextProperty();
result.add(property.getString().trim());
}
return result;
You can see how I get as a response only a value containing "nt:unstructured".
Unfortunately I couldn't find many code examples online, on Github, etc. many outdated, and also, there are not books as there are for Scrapy or other libraries/frameworks.
Thank you in advance.
Have a nice day!
Davide
In the first case, you are looking at the properties of:
/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn/jcr:xmltext
In the second case:
/importxml/xhtml:html/xhtml:body/mathml:math/mathml:apply/mathml:apply[2]/mathml:apply[2]/mathml:cn
Note the different paths.

Open an XML file in Eclipse at a specific line number

I'm writing an eclipse pluging and I need to open an XML file at a specific line number (where the error is).
I have followed the accepted answer on this question and it actually works... with the undesired side effect of generating resourceChanged() events in my FileSystemChangesListener listener.
Is there a way of jumping to the specific line without producing file changes? These events trigger other executions in the plugin.
I tried adding the TRANSIENT parameter as true to no avail as in:
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(IMarker.LINE_NUMBER, lineNumber);
map.put(IMarker.TRANSIENT, true); // doesn't make any difference.
marker.setAttributes(map);
IDE.openEditor(page, marker);
Still generates the resourceChanged() event.
The IFile.createMarker call is generating the resource changed event, you can't prevent this.
However you can identify that this is a create marker event in the IResourceData you receive - the getFlags() method will have the IResourceData.MARKERS flag set.
Note that resource deltas can be merged so there may be several flags set - for example if IResourceDelta.CONTENT is set the file's contents have also changed.

How to correctly update SNMP4j agent MIB values correctly

I'm trying to create an SNMP4j agent and am finding it difficult to understand the process correctly. I have successfully created an agent that can be queried from the command line using snmpwalk. What I am having difficulty with is understanding how I am meant to update the values stored in my implemented MIB.
The following shows the relevant code I use for creating the MIB (I implement Host-Resources-MIB)
agent = new Agent("0.0.0.0/" + port);
agent.start();
agent.unregisterManagedObject(agent.getSnmpv2MIB());
modules = new Modules(DefaultMOFactory.getInstance());
HrSWRunEntryRow thisRow = modules.getHostResourcesMib().getHrSWRunEntry()
.createRow(oidHrSWRunEntry);
final OID ashEnterpriseMIB = new OID(".1.3.6.1.4.1.49266.0");
thisRow.setHrSWRunIndex(new Integer32(1));
thisRow.setHrSWRunName(new OctetString("RunnableAgent"));
thisRow.setHrSWRunID(ashEnterpriseMIB);
thisRow.setHrSWRunPath(new OctetString("All is good in the world")); // Max 128 characters
thisRow.setHrSWRunParameters(new OctetString("Everything is working")); // Max 128 characters
thisRow.setHrSWRunType(new Integer32(HrSWRunTypeEnum.application));
thisRow.setHrSWRunStatus(new Integer32(HrSWRunStatusEnum.running));
modules.getHostResourcesMib().getHrSWRunEntry().addRow(thisRow);
agent.registerManagedObject(modules.getHostResourcesMib());
This appears to be sufficient to create a runnable agent. What I do not understand is how I am meant to change the values stored in the MIB (how do I, for example, change the value of HrSWRunStatus). There seem to be a few kludge ways but they don't seem to fit with the way the library is written.
I have come across numerous references to using/overriding the methods
prepare
commit
undo
cleanup
But cannot find any examples where this is done. Any help would be gratefully received.
In protected void registerManagedObjects(), you need to do something like new MOMutableColumn(columnId, SMIConstants.SYNTAX_INTEGER, MOAccessImpl.ACCESS_READ_WRITE, null); for your HrSWRunStatus. Take a look at the TestAgent.java example of SNMP4J-agent source.

Categories