use of org.apache.sling.ide.transport.RepositoryException in project sling by apache.
the class JcrNewNodeHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getCurrentSelection(event);
JcrNode node = SelectionUtils.getFirst(sel, JcrNode.class);
if (node == null) {
return null;
}
Shell shell = HandlerUtil.getActiveShell(event);
if (!node.canCreateChild()) {
MessageDialog.openInformation(shell, "Cannot create node", "Node is not covered by the workspace filter as defined in filter.xml");
return null;
}
Repository repository = ServerUtil.getDefaultRepository(node.getProject());
NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
if (!doNotAskAgain) {
MessageDialog dialog = new MessageDialog(null, "Unable to validate node type", null, "Unable to validate node types since project " + node.getProject().getName() + " is not associated with a server or the server is not started.", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Cancel", "Continue (do not ask again)", "Continue" }, 1) {
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
setShellStyle(getShellStyle() | SWT.SHEET);
}
};
int choice = dialog.open();
if (choice <= 0) {
return null;
}
if (choice == 1) {
doNotAskAgain = true;
}
}
}
final NodeType nodeType = node.getNodeType();
if (nodeType != null && nodeType.getName() != null && nodeType.getName().equals("nt:file")) {
MessageDialog.openInformation(shell, "Cannot create node", "Node of type nt:file cannot have children");
return null;
}
try {
final NewNodeDialog nnd = new NewNodeDialog(shell, node, ntManager);
if (nnd.open() == IStatus.OK) {
node.createChild(nnd.getValue(), nnd.getChosenNodeType());
return null;
}
} catch (RepositoryException e1) {
Activator.getDefault().getPluginLogger().warn("Could not open NewNodeDialog due to " + e1, e1);
}
return null;
}
use of org.apache.sling.ide.transport.RepositoryException in project sling by apache.
the class DeleteNodeCommand method execute.
@Override
public Result<Void> execute() {
PostMethod post = new PostMethod(getPath());
try {
Part[] parts = { new StringPart(":operation", "delete") };
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()));
httpClient.getParams().setAuthenticationPreemptive(true);
int responseStatus = httpClient.executeMethod(post);
return resultForResponseStatus(responseStatus);
} catch (Exception e) {
return AbstractResult.failure(new RepositoryException(e));
} finally {
post.releaseConnection();
}
}
use of org.apache.sling.ide.transport.RepositoryException in project sling by apache.
the class GetNodeContentCommand method execute.
@Override
public Result<ResourceProxy> execute() {
GetMethod get = new GetMethod(getPath());
try {
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword());
httpClient.getState().setCredentials(new AuthScope(repositoryInfo.getHost(), repositoryInfo.getPort(), AuthScope.ANY_REALM), defaultcreds);
int responseStatus = httpClient.executeMethod(get);
// return EncodingUtil.getString(rawdata, m.getResponseCharSet());
if (!isSuccessStatus(responseStatus))
return failureResultForStatusCode(responseStatus);
ResourceProxy resource = new ResourceProxy(path);
try (JsonReader jsonReader = new JsonReader(new InputStreamReader(get.getResponseBodyAsStream(), get.getResponseCharSet()))) {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
JsonToken token = jsonReader.peek();
if (token == JsonToken.STRING) {
resource.addProperty(name, jsonReader.nextString());
} else {
jsonReader.skipValue();
}
}
jsonReader.endObject();
}
return AbstractResult.success(resource);
} catch (Exception e) {
return AbstractResult.failure(new RepositoryException(e));
} finally {
get.releaseConnection();
}
}
use of org.apache.sling.ide.transport.RepositoryException in project sling by apache.
the class UpdateContentCommand method execute.
@Override
public Result<Void> execute() {
PostMethod post = new PostMethod(getPath());
try {
List<Part> parts = new ArrayList<>();
for (Map.Entry<String, Object> property : properties.entrySet()) {
if (ProtectedNodes.exists(property.getKey())) {
continue;
}
Object propValue = property.getValue();
if (propValue instanceof String) {
parts.add(new StringPart(property.getKey(), (String) propValue));
} else if (property != null) {
// TODO handle multi-valued properties
System.err.println("Unable to handle property " + property.getKey() + " of type " + property.getValue().getClass());
}
}
File f = new File(fileInfo.getLocation());
if (f.isFile()) {
parts.add(new FilePart(fileInfo.getName(), f));
}
post.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post.getParams()));
httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()));
httpClient.getParams().setAuthenticationPreemptive(true);
int responseStatus = httpClient.executeMethod(post);
return resultForResponseStatus(responseStatus);
} catch (Exception e) {
return AbstractResult.failure(new RepositoryException(e));
} finally {
post.releaseConnection();
}
}
use of org.apache.sling.ide.transport.RepositoryException in project sling by apache.
the class JcrNode method getSerializationKind.
private SerializationKind getSerializationKind(String nodeType) {
final SerializationKindManager skm = new SerializationKindManager();
final Repository repo = ServerUtil.getDefaultRepository(getProject());
if (repo == null) {
return getFallbackSerializationKind(nodeType);
}
try {
skm.init(repo);
//TODO: mixins not yet supported
return skm.getSerializationKind(nodeType, new ArrayList<String>());
} catch (RepositoryException e) {
e.printStackTrace();
return getFallbackSerializationKind(nodeType);
}
}
Aggregations