private void print(CommandInvocation commandInvocation, StoredQuery storedQuery) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(StoredQuery.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(storedQuery, commandInvocation.getShell().out()); }
/** * Outputs an RDF to stdout. * @param ontology */ private void printOntology(CommandInvocation commandInvocation, RDF ontology) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(RDF.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(ontology, commandInvocation.getShell().out()); }
/** * Prints out a single property from the s-ramp meta-data. * @param propertyName * @param propertyValue */ private void printProperty(String propertyName, String propertyValue) { if (propertyValue != null) commandInvocation.getShell().out().printf(" %1$s: %2$s\n", propertyName, propertyValue); }
/** * Outputs an RDF to a file. * @param ontology * @param filePath */ private void saveOntologyToFile(CommandInvocation commandInvocation, RDF ontology, File filePath) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(RDF.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(ontology, filePath); commandInvocation.getShell().out().println(Messages.i18n.format("GetOntology.OntologySaved", filePath.getCanonicalPath())); }
@Override public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException { try { if (help) { return doHelp(commandInvocation); } return doExecute(commandInvocation); } catch (Exception e) { commandInvocation.getShell().out().println(e.getMessage()); return CommandResult.FAILURE; } }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { ArtificerAtomApiClient client = client(commandInvocation); List<OntologySummary> ontologies = context(commandInvocation).getCurrentOntologyFeed(); if (client == null) { commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status1")); } else { commandInvocation.getShell().out().println(Messages.i18n.format("Status.Status2", client.getEndpoint())); } if (CollectionUtils.isEmpty(ontologies)) { commandInvocation.getShell().out().println(Messages.i18n.format("OntologyStatus.Status1")); } else { commandInvocation.getShell().out().println(Messages.i18n.format("OntologyStatus.Status2", ontologies.size())); } return CommandResult.SUCCESS; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { ArtificerAtomApiClient client = client(commandInvocation); BaseArtifactType artifact = currentArtifact(commandInvocation); try { client.updateArtifactMetaData(artifact); commandInvocation.getShell().out().println(Messages.i18n.format("UpdateMetaData.Success", artifact.getName())); } catch (Exception e) { commandInvocation.getShell().out().println(Messages.i18n.format("UpdateMetaData.Failure")); commandInvocation.getShell().out().println("\t" + e.getMessage()); return CommandResult.FAILURE; } return CommandResult.SUCCESS; }
protected CommandResult doHelp(CommandInvocation commandInvocation) { commandInvocation.getShell().out().println(commandInvocation.getHelpInfo(getName())); return CommandResult.SUCCESS; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { if (CollectionUtils.isEmpty(arguments)) { return doHelp(commandInvocation); } String pathToArchive = requiredArgument(commandInvocation, arguments, 0); File archiveFile = new File(pathToArchive); ArtificerArchive archive = new ArtificerArchive(archiveFile); context(commandInvocation).setCurrentArchive(archive); commandInvocation.getShell().out().println(Messages.i18n.format("OpenArchive.Opened", archiveFile.getCanonicalPath())); return CommandResult.SUCCESS; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { BaseArtifactType artifact = currentArtifact(commandInvocation); // Print out the meta-data information commandInvocation.getShell().out().println(Messages.i18n.format("RefreshMetaData.MetaDataFor", artifact.getUuid())); commandInvocation.getShell().out().println("--------------"); PrintArtifactMetaDataVisitor visitor = new PrintArtifactMetaDataVisitor(commandInvocation); ArtifactVisitorHelper.visitArtifact(visitor, artifact); return CommandResult.SUCCESS; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { if (context(commandInvocation).getCurrentArchive() != null) { commandInvocation.getShell().out().println(Messages.i18n.format("NewArchive.AlreadyOpen")); return CommandResult.FAILURE; } ArtificerArchive archive = new ArtificerArchive(); context(commandInvocation).setCurrentArchive(archive); commandInvocation.getShell().out().println(Messages.i18n.format("NewArchive.Opened")); return CommandResult.SUCCESS; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { context(commandInvocation).setClient(null); commandInvocation.getShell().out().println(Messages.i18n.format("Disconnect.Success")); return CommandResult.SUCCESS; }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { if (CollectionUtils.isEmpty(arguments)) { return doHelp(commandInvocation); } String archivePathArg = requiredArgument(commandInvocation, arguments, 0); ArtificerArchive archive = currentArchive(commandInvocation); boolean success = archive.removeEntry(archivePathArg); if (success) { commandInvocation.getShell().out().println(Messages.i18n.format("RemoveEntry.EntryDeleted")); } else { commandInvocation.getShell().out().println(Messages.i18n.format("RemoveEntry.NoEntryFound", archivePathArg)); } return CommandResult.SUCCESS; } }
/** * @see org.artificer.common.visitors.HierarchicalArtifactVisitor#visitNamedWsdlDerived(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.NamedWsdlDerivedArtifactType) */ @Override protected void visitNamedWsdlDerived(NamedWsdlDerivedArtifactType artifact) { commandInvocation.getShell().out().println(Messages.i18n.format("PrintArtifact.NamedWsdlHeading")); printProperty(Messages.i18n.format("PrintArtifact.NCName"), artifact.getNCName()); }
/** * @see org.artificer.common.visitors.HierarchicalArtifactVisitor#visitDerived(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.DerivedArtifactType) */ @Override protected void visitDerived(DerivedArtifactType artifact) { commandInvocation.getShell().out().println(Messages.i18n.format("PrintArtifact.DerivedArtifactInfoHeading")); DocumentArtifactTarget relatedDocument = artifact.getRelatedDocument(); printRelationship(Messages.i18n.format("PrintArtifact.RelatedDoc"), relatedDocument); }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { try { client(commandInvocation).uploadBatch(currentArchive(commandInvocation)); // Success! Close the archive. ArtificerArchive.closeQuietly(context(commandInvocation).getCurrentArchive()); context(commandInvocation).setCurrentArchive(null); commandInvocation.getShell().out().println(Messages.i18n.format("UploadArchive.Success")); } catch (Exception e) { commandInvocation.getShell().out().println(Messages.i18n.format("UploadArchive.Failure")); commandInvocation.getShell().out().println("\t" + e.getMessage()); return CommandResult.FAILURE; } return CommandResult.SUCCESS; }
/** * @see org.artificer.common.visitors.HierarchicalArtifactVisitor#visitXmlDocument(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.XmlDocument) */ @Override protected void visitXmlDocument(XmlDocument artifact) { commandInvocation.getShell().out().println(Messages.i18n.format("PrintArtifact.XmlDocumentHeading")); printProperty(Messages.i18n.format("PrintArtifact.ContentEncoding"), artifact.getContentEncoding()); }
/** * @see org.artificer.common.visitors.HierarchicalArtifactVisitor#visitDocument(org.oasis_open.docs.s_ramp.ns.s_ramp_v1.DocumentArtifactType) */ @Override protected void visitDocument(DocumentArtifactType artifact) { commandInvocation.getShell().out().println(Messages.i18n.format("PrintArtifact.DocumentInfoHeading")); printProperty(Messages.i18n.format("PrintArtifact.ContentType"), artifact.getContentType()); printProperty(Messages.i18n.format("PrintArtifact.ContentSize"), String.valueOf(artifact.getContentSize())); }
@Override protected CommandResult doExecute(CommandInvocation commandInvocation) throws Exception { ArtificerArchive.closeQuietly(context(commandInvocation).getCurrentArchive()); context(commandInvocation).setCurrentArchive(null); commandInvocation.getShell().out().println(Messages.i18n.format("CloseArchive.Closed")); return CommandResult.SUCCESS; }
protected String promptForInput(String prompt, Character mask, CommandInvocation invocation) throws IOException, InterruptedException { ConsoleBuffer consoleBuffer = new AeshConsoleBufferBuilder() .shell(invocation.getShell()) .prompt(new Prompt(prompt, mask)) .create(); InputProcessor inputProcessor = new AeshInputProcessorBuilder() .consoleBuffer(consoleBuffer) .create(); consoleBuffer.displayPrompt(); String result; do { result = inputProcessor.parseOperation(invocation.getInput()); } while(result == null ); return result; }