I m using the below code to get the list of packages in the give java project. But it is including the folders also in the list. Please suggest a way to ignore folders.
final IPackageFragmentRoot[] packageFragmentRootArray = workingJavaProject.getJavaProject().getAllPackageFragmentRoots();
for (final IPackageFragmentRoot packageFragmentRoot : pkgFrgmRoots) {
if (!packageFragmentRoot.isArchive()) {
for (final IJavaElement pkg : packageFragmentRoot.getChildren()) {
if (pkg != null && !isEmpty(pkg.getElementName()) && pkg instanceof IPackageFragment) {
allPackages.add((IPackageFragment) pkg);
}
}
}
}
IPackageFragment can be an instantiate of IFiles, IFolders, or IStorages. One possible solution:
if (pkg != null && !isEmpty(pkg.getElementName()) && pkg instanceof IPackageFragment) {
if (!(pkg instanceof IFolder)) {
allPackages.add((IPackageFragment) pkg);
}
}
Related
I try to read a PDF document using the itext 7.1.9 and I get an exception that looks like the following:
com.itextpdf.kernel.pdf.canvas.parser.util.InlineImageParsingUtils$InlineImageParseException: Unexpected ColorSpace: /R9.
at com.itextpdf.kernel.pdf.canvas.parser.util.InlineImageParsingUtils.getComponentsPerPixel(InlineImageParsingUtils.java:257)
at com.itextpdf.kernel.pdf.canvas.parser.util.InlineImageParsingUtils.computeBytesPerRow(InlineImageParsingUtils.java:271)
at com.itextpdf.kernel.pdf.canvas.parser.util.InlineImageParsingUtils.parseUnfilteredSamples(InlineImageParsingUtils.java:298)
at com.itextpdf.kernel.pdf.canvas.parser.util.InlineImageParsingUtils.parseSamples(InlineImageParsingUtils.java:345)
at com.itextpdf.kernel.pdf.canvas.parser.util.InlineImageParsingUtils.parse(InlineImageParsingUtils.java:163)
at com.itextpdf.kernel.pdf.canvas.parser.util.PdfCanvasParser.parse(PdfCanvasParser.java:119)
at com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor.processContent(PdfCanvasProcessor.java:283)
at com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor.processPageContent(PdfCanvasProcessor.java:306)
at com.itextpdf.kernel.pdf.canvas.parser.PdfDocumentContentParser.processContent(PdfDocumentContentParser.java:77)
at com.itextpdf.kernel.pdf.canvas.parser.PdfDocumentContentParser.processContent(PdfDocumentContentParser.java:90)
I suppose this method must be fixed in itext 7 library:
private static int getComponentsPerPixel(PdfName colorSpaceName, PdfDictionary colorSpaceDic) {
if (colorSpaceName == null) {
return 1;
} else if (colorSpaceName.equals(PdfName.DeviceGray)) {
return 1;
} else if (colorSpaceName.equals(PdfName.DeviceRGB)) {
return 3;
} else if (colorSpaceName.equals(PdfName.DeviceCMYK)) {
return 4;
} else {
if (colorSpaceDic != null) {
PdfArray colorSpace = colorSpaceDic.getAsArray(colorSpaceName);
if (colorSpace != null) {
if (PdfName.Indexed.equals(colorSpace.getAsName(0))) { // the fail is on here. colorSpace.getAsName(0) returns /ICCBased
return 1;
}
} else {
PdfName tempName = colorSpaceDic.getAsName(colorSpaceName);
if (tempName != null) {
return getComponentsPerPixel(tempName, colorSpaceDic);
}
}
}
throw (new InlineImageParseException("Unexpected ColorSpace: {0}.")).setMessageParams(new Object[]{colorSpaceName});
}
}
I don't understand why I get it and how to fix it.
This issue has been fixed in iText more than a year ago. The fix has first been released in version 7.1.16.
Thus, please update your iText version.
For details, the fix has been added in commit df4013c8f141059a91373008ac4a7013f6be0852 authored on 2021-04-14 10:36:24 and committed on 2021-05-25 15:11:36 with the comment
Add support processing inline image with ICCBased color space in resources
DEVSIX-5295
I got the pptx file with simple presentation. It has background image, white text on it and this text has shadow. I need to simplify presentation and remove all this things (set backgroun to white, font color to black and remove shadows)
Change bachground and font colors are pretty straightforward, like this
SlideShow ppt = SlideShowFactory.create(inputStream);
List<Slide> slides= ppt.getSlides();
for (int i = 0; i< slides.size(); i++) {
Slide slide = slides.get(i);
((XSLFSlide)slide).getBackground().setFillColor(Color.white);
XSLFTextShape[] shapes = ((XSLFSlide) slide).getPlaceholders();
for (XSLFTextShape textShape : shapes) {
List<XSLFTextParagraph> textparagraphs = textShape.getTextParagraphs();
for (XSLFTextParagraph para : textparagraphs) {
List<XSLFTextRun> textruns = para.getTextRuns();
for (XSLFTextRun incomingTextRun : textruns) {
incomingTextRun.setFontColor(Color.black);
}
}
But i can't figure out how to remove shadows. Here is examle before and after
I tried to call getShadow() method on TextShape, but it's null, in XSLFTextRun there is no methods to manage text shadows. For HSLF i saw that there is setShadowed() for TextRun.
But how to deal with shadows in XSLF?
Thanks!
UPDATE:
Thanks Axel Richter for really valuable answer.
In my doc i found two cases with shadowed text.
First one is as Axel described, solution is to clean shadow from CTRegularTextRun. Also i find out that XSLFTextParagraph.getTextRuns() may contain LineBreak objects, so before casting XSLFTextRun.getXMLObject() - it's good idea to check that it's instance of CTRegularTextRun and not CTTextLineBreak
Code:
private void clearShadowFromTextRun(XSLFTextRun run) {
if (run.getXmlObject() instanceof CTRegularTextRun) {
CTRegularTextRun cTRun = (CTRegularTextRun) run.getXmlObject();
if (cTRun.getRPr() != null) {
if (cTRun.getRPr().getEffectLst() != null) {
if (cTRun.getRPr().getEffectLst().getOuterShdw() != null) {
cTRun.getRPr().getEffectLst().unsetOuterShdw();
}
}
}
}
}
Second case - SlideMaster contains some styles definitions for body and title. So if we want remove all shadows competely - we should clear them too.
Code:
private void clearSlideMastersShadowStyles(XMLSlideShow ppt) {
List<XSLFSlideMaster> slideMasters = ppt.getSlideMasters();
for (XSLFSlideMaster slideMaster : slideMasters) {
CTSlideMaster ctSlideMaster = slideMaster.getXmlObject();
if (ctSlideMaster.getTxStyles() != null) {
if (ctSlideMaster.getTxStyles().getTitleStyle() != null) {
clearShadowsFromStyle(ctSlideMaster.getTxStyles().getTitleStyle());
}
if (ctSlideMaster.getTxStyles().getBodyStyle() != null) {
clearShadowsFromStyle(ctSlideMaster.getTxStyles().getBodyStyle());
}
if (ctSlideMaster.getTxStyles().getOtherStyle() != null) {
clearShadowsFromStyle(ctSlideMaster.getTxStyles().getOtherStyle());
}
}
}
}
private void clearShadowsFromStyle(CTTextListStyle ctTextListStyle) {
if (ctTextListStyle.getLvl1PPr() != null) {
if (ctTextListStyle.getLvl1PPr().getDefRPr() != null)
if (ctTextListStyle.getLvl1PPr().getDefRPr().getEffectLst() != null)
if (ctTextListStyle.getLvl1PPr().getDefRPr().getEffectLst().getOuterShdw() != null)
ctTextListStyle.getLvl1PPr().getDefRPr().getEffectLst().unsetOuterShdw();
}
//same stuff for other 8 levels. Ugly uhh...
}
Settings of text shadow is not yet implemented in XSLFTextRun. But of course they are set in the XML.
A run having shadowed text looks like:
<a:r>
<a:rPr lang="de-DE" smtClean="0" dirty="0" b="1">
<a:effectLst>
<a:outerShdw dir="2700000" algn="tl" dist="38100" blurRad="38100">
<a:srgbClr val="000000">
<a:alpha val="43137"/>
</a:srgbClr>
</a:outerShdw>
</a:effectLst>
</a:rPr>
<a:t>The text...</a:t>
</a:r>
As you see there is a rPr ( run properties) having a effectLst having a outerShdw element. We can use ooxml-schemas classes and methods to set and unset this.
...
incomingTextRun.setFontColor(Color.black);
org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun cTRun = (org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)incomingTextRun.getXmlObject();
if (cTRun.getRPr() != null) {
if (cTRun.getRPr().getEffectLst() != null) {
if (cTRun.getRPr().getEffectLst().getOuterShdw() != null) {
cTRun.getRPr().getEffectLst().unsetOuterShdw();
}
}
}
...
I have this JavaJaxRs dictionary with my templates:
/templates/JavaJaxRs
I edited some of them. And want to use them for my API generation (Code was inspired from this approach from https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java):
System.out.println("Generating API for: " + location);
DefaultGenerator generator = new DefaultGenerator();
Swagger swagger = new SwaggerParser().read(location);
CodegenConfig config = CodegenConfigLoader.forName(this.language);
config.setOutputDir(new File(this.apiGeneratedSrcPath).getPath());
if (null != templateDirectory) {
config.additionalProperties().put(TEMPLATE_DIR_PARAM, templateDirectory);
}
if (null != modelPackage) {
config.additionalProperties().put(MODEL_PACKAGE_PARAM, modelPackage);
}
if (null != apiPackage) {
config.additionalProperties().put(API_PACKAGE_PARAM, apiPackage);
}
if (null != invokerPackage) {
config.additionalProperties().put(INVOKER_PACKAGE_PARAM, invokerPackage);
}
if (configOptions != null) {
for (CliOption langCliOption : config.cliOptions()) {
if (configOptions.containsKey(langCliOption.getOpt())) {
config.additionalProperties().put(langCliOption.getOpt(),
configOptions.get(langCliOption.getOpt()));
}
}
}
if (null != configurationFile) {
Config genConfig = ConfigParser.read(configurationFile);
if (null != genConfig) {
for (CliOption langCliOption : config.cliOptions()) {
if (genConfig.hasOption(langCliOption.getOpt())) {
config.additionalProperties().put(langCliOption.getOpt(), genConfig.getOption(langCliOption.getOpt()));
}
}
} else {
throw new RuntimeException("Unable to read configuration file");
}
}
ClientOptInput input = new ClientOptInput().opts(new ClientOpts()).swagger(swagger);
input.setConfig(config);
generator.opts(input).generate();
Somehow i always get the code generated with the standard template file.
UPDATE:
When i remember correctly i had a conditional bug on:
if(null != templateDirectory)
config.additionalProperties().put(TEMPLATE_DIR_PARAM, templateDirectory);
or somewhere else but with the right condition, code was working as intended.
I let the question stay here, maybe it will help some other users.
You can get the help options for the code generator like such:
java -jar swagger-codegen-cli.jar help generate
Which should tell you that you can override the template location with the -t parameter:
java -java swagger-codegen-cli.jar generate -l {language} -t path/to/templates
Regarding the above ava -java swagger-codegen-cli.jar generate -l {language} -t path/to/templates,
I've managed to make it work with current being-worked-on-release (2.2.0).
With 2.1.6 (current GA) it does not work.
I have posted the following on swagger-codegen at GitHub:
https://github.com/swagger-api/swagger-codegen/issues/3188
Did not get any attention though...
I am searching for a .txt file that is located at change set.
Then I need to create locally over my pc the full path directory of this file.
For example if there a file called"test.txt" that it's located at:
Project1-->Folder1-->Folder2-->test.txt
Till now I have managed to search for this file.
Now I need to fetch the full directory and create similar one over my pc:
Result at my pc:
Folder1-->Folder2-->test.txt
That's what I did to search for the file within a changeset and retrieve it:
public IFileItem getTextFileFile(IChangeSet changeSet, ITeamRepository repository) throws TeamRepositoryException{
IVersionableManager vm = SCMPlatform.getWorkspaceManager(repository).versionableManager();
List changes = changeSet.changes();
IFileItem toReturn = null;
for(int i=0;i<changes.size();i++) {="" <br=""> Change change = (Change) changes.get(i);
IVersionableHandle after = change.afterState();
if( after != null && after instanceof IFileItemHandle) {
IFileItem fileItem = (IFileItem) vm.fetchCompleteState(after, null);
if(fileItem.getName().contains(".txt")) {
toReturn = fileItem;
break;
} else {
continue;
}
}
}
if(toReturn == null){
throw new TeamRepositoryException("Could not find the file");
}
return toReturn;
}
I use RTC:4
Win:XP
Thanks in advance.
I have the following IConfiguration that I fetched by the following:
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository);
IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setPartialOwnerNameIgnoreCase(projectAreaName);
List <iworkspacehandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, Application.getMonitor());
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandles.get(0),Application.getMonitor());
IComponentHandle component = changeSet.getComponent();
IConfiguration configuration = workspaceConnection.configuration(component);
List lst = new ArrayList<string>();
lst=configuration.locateAncestors(lst,Application.getMonitor());
=========================================
Now to get the full path of the file item ,I made the following method I got from :
https://jazz.net/forum/questions/94927/how-do-i-find-moved-from-location-for-a-movedreparented-item-using-rtc-4-java-api
=========================================
private String getFullPath(List ancestor, ITeamRepository repository)
throws TeamRepositoryException {
String directoryPath = "";
for (Object ancestorObj : ancestor) {
IAncestorReport ancestorImpl = (IAncestorReport) ancestorObj;
for (Object nameItemPairObj : ancestorImpl.getNameItemPairs()) {
NameItemPairImpl nameItemPair = (NameItemPairImpl) nameItemPairObj;
Object item = SCMPlatform.getWorkspaceManager(repository)
.versionableManager()
.fetchCompleteState(nameItemPair.getItem(), null);
String pathName = "";
if (item instanceof IFolder) {
pathName = ((IFolder) item).getName();
}
else if (item instanceof IFileItem) {
pathName = ((IFileItem) item).getName();
}
if (!pathName.equals(""))
directoryPath = directoryPath + "\\" + pathName;
}
}
return directoryPath;
}
=========================================
I'm using Google Drive SDK v2 on Android to get the list of root folders. Currently I see these required steps - which seem to load forever. Is there no faster way?
I tried to use the search with the q= parameter but I don't get it to work (FileList vs. Files.List) - different API levels?
FileList files = drive.files().list().setQ("'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false");
This is what I do currently:
About about = drive.about().get().execute();
if (about != null) {
ChildList childList = drive.children().list(about.getRootFolderId()).execute();
if (childList != null) {
List<ChildReference> listChildReference = childList.getItems();
for (ChildReference childReference : listChildReference) {
File file = drive.files().get(childReference.getId()).execute();
if (file != null) {
String fileExtension = file.getFileExtension();
String mimeType = file.getMimeType();
if (mimeType != null
&& mimeType.equals("application/vnd.google-apps.folder")
&& (fileExtension == null || fileExtension.equals(""))) {
Log.d(this.getClass().getName(), file.getTitle());
}
}
}
}
}
What's the fastest for an Android app?
Thanks in advance.
My personal opinion is avoid the Drive SDK and call the REST API directly. It's a fairly simple API, and the way the documentation is structured, you are forced to understand it anyway in order to use the SDK. You have the benefit that if something doesn't work, you can directly compare your app with what's happening on the wire and resolve any problems.
Found it:
#Override
protected ArrayList<File> doInBackground(final Void... voids) {
ArrayList<File> result = new ArrayList<File>();
Files.List request = null;
boolean ok = true;
do {
try {
request = drive
.files()
.list()
.setMaxResults(200)
.setQ("'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false");
FileList files = request.execute();
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
} catch (IOException exception) {
ok = false;
}
} while (ok && request.getPageToken() != null && request.getPageToken().length() > 0);
return result;
}